// Don't use range--typecheck can add closures to xtop.
timings.Start("fe", "typecheck", "top1")
for i := 0; i < len(xtop); i++ {
- if xtop[i].Op != ODCL && xtop[i].Op != OAS && xtop[i].Op != OAS2 {
- xtop[i] = typecheck(xtop[i], Etop)
+ n := xtop[i]
+ if op := n.Op; op != ODCL && op != OAS && op != OAS2 {
+ xtop[i] = typecheck(n, Etop)
}
}
// Don't use range--typecheck can add closures to xtop.
timings.Start("fe", "typecheck", "top2")
for i := 0; i < len(xtop); i++ {
- if xtop[i].Op == ODCL || xtop[i].Op == OAS || xtop[i].Op == OAS2 {
- xtop[i] = typecheck(xtop[i], Etop)
+ n := xtop[i]
+ if op := n.Op; op == ODCL || op == OAS || op == OAS2 {
+ xtop[i] = typecheck(n, Etop)
}
}
resumecheckwidth()
timings.Start("fe", "typecheck", "func")
var fcount int64
for i := 0; i < len(xtop); i++ {
- if xtop[i].Op == ODCLFUNC || xtop[i].Op == OCLOSURE {
- Curfn = xtop[i]
+ n := xtop[i]
+ if op := n.Op; op == ODCLFUNC || op == OCLOSURE {
+ Curfn = n
decldepth = 1
saveerrors()
typecheckslice(Curfn.Nbody.Slice(), Etop)
timings.Start("be", "compilefuncs")
fcount = 0
for i := 0; i < len(xtop); i++ {
- if xtop[i].Op == ODCLFUNC {
- funccompile(xtop[i])
+ n := xtop[i]
+ if n.Op == ODCLFUNC {
+ funccompile(n)
fcount++
}
}
func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
names := p.declNames(decl.NameList)
-
- var typ *Node
- if decl.Type != nil {
- typ = p.typeExpr(decl.Type)
- }
+ typ := p.typeExprOrNil(decl.Type)
var exprs []*Node
if decl.Values != nil {
func (p *noder) constDecl(decl *syntax.ConstDecl) []*Node {
names := p.declNames(decl.NameList)
-
- var typ *Node
- if decl.Type != nil {
- typ = p.typeExpr(decl.Type)
- }
+ typ := p.typeExprOrNil(decl.Type)
var exprs []*Node
if decl.Values != nil {
}
name := typedcl0(p.name(decl.Name))
- name.Name.Param.Pragma = Pragma(decl.Pragma)
-
- var typ *Node
- if decl.Type != nil {
- typ = p.typeExpr(decl.Type)
+ pragma := Pragma(decl.Pragma)
+ if pragma != 0 && decl.Alias {
+ yyerror("cannot specify directive with type alias")
+ pragma = 0
}
+ name.Name.Param.Pragma = pragma
+
+ typ := p.typeExprOrNil(decl.Type)
return typedcl1(name, typ, true)
}
return p.expr(typ)
}
+func (p *noder) typeExprOrNil(typ syntax.Expr) *Node {
+ if typ != nil {
+ return p.expr(typ)
+ }
+ return nil
+}
+
func (p *noder) chanDir(dir syntax.ChanDir) ChanDir {
switch dir {
case 0: