return n
}
+// newfuncname generates a new name node for a function or method.
+// TODO(rsc): Use an ODCLFUNC node instead. See comment in CL 7360.
+func newfuncname(s *Sym) *Node {
+ n := newname(s)
+ n.Func = new(Func)
+ return n
+}
+
/*
* this generates a new name node for a name
* being declared.
Yyerror("methods must have a unique non-blank name")
}
+ n.Func = new(Func)
dclcontext = PPARAM
markdcl()
Funcdepth++
}
if t.Sym == nil || isblank(n) {
- return newname(n.Sym)
+ return newfuncname(n.Sym)
}
var p string
}
if exportname(t.Sym.Name) {
- n = newname(Lookup(p))
+ n = newfuncname(Lookup(p))
} else {
- n = newname(Pkglookup(p, t.Sym.Pkg))
+ n = newfuncname(Pkglookup(p, t.Sym.Pkg))
}
return n
s1 := Pkglookup(s.Name+"·f", s.Pkg)
if s1.Def == nil {
- s1.Def = newname(s1)
+ s1.Def = newfuncname(s1)
s1.Def.Shortname = newname(s)
funcsyms = list(funcsyms, s1.Def)
}
List *NodeList
Rlist *NodeList
- Op uint8
- Nointerface bool
- Ullman uint8 // sethi/ullman number
- Addable uint8 // type of addressability - 0 is not addressable
- Etype uint8 // op for OASOP, etype for OTYPE, exclam for export
- Bounded bool // bounds check unnecessary
- Class uint8 // PPARAM, PAUTO, PEXTERN, etc
- Method uint8 // OCALLMETH name
- Embedded uint8 // ODCLFIELD embedded type
- Colas uint8 // OAS resulting from :=
- Diag uint8 // already printed error about this
- Noescape bool // func arguments do not escape
- Nosplit bool // func should not execute on separate stack
- Nowritebarrier bool // emit compiler error instead of write barrier
- Walkdef uint8
- Typecheck uint8
- Local bool
- Dodata uint8
- Initorder uint8
- Used bool
- Isddd bool // is the argument variadic
- Readonly bool
- Implicit bool
- Addrtaken bool // address taken, even if not moved to heap
- Assigned bool // is the variable ever assigned to
- Captured bool // is the variable captured by a closure
- Byval bool // is the variable captured by value or by reference
- Dupok bool // duplicate definitions ok (for func)
- Wrapper bool // is method wrapper (for func)
- Reslice bool // this is a reslice x = x[0:y] or x = append(x, ...)
- Likely int8 // likeliness of if statement
- Hasbreak bool // has break statement
- Needzero bool // if it contains pointers, needs to be zeroed on function entry
- Needctxt bool // function uses context register (has closure variables)
- Esc uint8 // EscXXX
- Funcdepth int32
+ Op uint8
+ Nointerface bool
+ Ullman uint8 // sethi/ullman number
+ Addable uint8 // type of addressability - 0 is not addressable
+ Etype uint8 // op for OASOP, etype for OTYPE, exclam for export
+ Bounded bool // bounds check unnecessary
+ Class uint8 // PPARAM, PAUTO, PEXTERN, etc
+ Method uint8 // OCALLMETH name
+ Embedded uint8 // ODCLFIELD embedded type
+ Colas uint8 // OAS resulting from :=
+ Diag uint8 // already printed error about this
+ Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
+ Walkdef uint8
+ Typecheck uint8
+ Local bool
+ Dodata uint8
+ Initorder uint8
+ Used bool
+ Isddd bool // is the argument variadic
+ Readonly bool
+ Implicit bool
+ Addrtaken bool // address taken, even if not moved to heap
+ Assigned bool // is the variable ever assigned to
+ Captured bool // is the variable captured by a closure
+ Byval bool // is the variable captured by value or by reference
+ Reslice bool // this is a reslice x = x[0:y] or x = append(x, ...)
+ Likely int8 // likeliness of if statement
+ Hasbreak bool // has break statement
+ Needzero bool // if it contains pointers, needs to be zeroed on function entry
+ Esc uint8 // EscXXX
+ Funcdepth int32
// most nodes
- Type *Type
- Orig *Node // original form, for printing, and tracking copies of ONAMEs
+ Type *Type
+ Orig *Node // original form, for printing, and tracking copies of ONAMEs
+ Nname *Node
// func
- Nname *Node
- Shortname *Node
- Enter *NodeList
- Exit *NodeList
- Cvars *NodeList // closure params
- Dcl *NodeList // autodcl for this func/closure
- Inl *NodeList // copy of the body for use in inlining
- Inldcl *NodeList // copy of dcl for use in inlining
- Closgen int
- Outerfunc *Node
+ *Func
// OLITERAL/OREGISTER
Val Val
Escretval *NodeList // on OCALLxxx, list of dummy return values
Escloopdepth int // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
- Sym *Sym // various
- InlCost int32 // unique name for OTYPE/ONAME
- Vargen int32
- Lineno int32
+ Sym *Sym // various
+ Vargen int32 // unique name for OTYPE/ONAME
+ Lineno int32
+ Xoffset int64
+ Stkdelta int64 // offset added by stack frame compaction phase.
+ Ostk int32 // 6g only
+ Iota int32
+ Walkgen uint32
+ Esclevel int32
+ Opt interface{} // for optimization passes
+}
+
+// Func holds Node fields used only with function-like nodes.
+type Func struct {
+ Shortname *Node
+ Enter *NodeList
+ Exit *NodeList
+ Cvars *NodeList // closure params
+ Dcl *NodeList // autodcl for this func/closure
+ Inldcl *NodeList // copy of dcl for use in inlining
+ Closgen int
+ Outerfunc *Node
+
+ Inl *NodeList // copy of the body for use in inlining
+ InlCost int32
+
Endlineno int32
- Xoffset int64
- Stkdelta int64 // offset added by stack frame compaction phase.
- Ostk int32
- Iota int32
- Walkgen uint32
- Esclevel int32
- Opt interface{} // for optimization passes
+
+ Nosplit bool // func should not execute on separate stack
+ Nowritebarrier bool // emit compiler error instead of write barrier
+ Dupok bool // duplicate definitions ok
+ Wrapper bool // is method wrapper
+ Needctxt bool // function uses context register (has closure variables)
}
// Node ops.
t.Rlist = yyDollar[5].list
yyVAL.node = Nod(ODCLFUNC, nil, nil)
- yyVAL.node.Nname = newname(yyDollar[1].sym)
+ yyVAL.node.Nname = newfuncname(yyDollar[1].sym)
yyVAL.node.Nname.Defn = yyVAL.node
yyVAL.node.Nname.Ntype = t // TODO: check if nname already has an ntype
declare(yyVAL.node.Nname, PFUNC)
t.Rlist = yyDollar[8].list
yyVAL.node = Nod(ODCLFUNC, nil, nil)
- yyVAL.node.Shortname = newname(yyDollar[4].sym)
+ yyVAL.node.Shortname = newfuncname(yyDollar[4].sym)
yyVAL.node.Nname = methodname1(yyVAL.node.Shortname, rcvr.Right)
yyVAL.node.Nname.Defn = yyVAL.node
yyVAL.node.Nname.Ntype = t
Yyerror("inconsistent definition for func %v during import\n\t%v\n\t%v", Sconv(s, 0), Tconv(s.Def.Type, 0), Tconv(t, 0))
}
- yyVAL.node = newname(s)
+ yyVAL.node = newfuncname(s)
yyVAL.node.Type = t
declare(yyVAL.node, PFUNC)