@@ -344,14 +344,22 @@ func (n *Node) CanBeAnSSASym() {
344
344
345
345
// Name holds Node fields used only by named nodes (ONAME, OTYPE, OPACK, OLABEL, some OLITERAL).
346
346
type Name struct {
347
- Pack * Node // real package for import . names
348
- Pkg * types.Pkg // pkg for OPACK nodes
349
- Defn * Node // initializing assignment
350
- Curfn * Node // function for local variables
351
- Param * Param // additional fields for ONAME, OTYPE
352
- Decldepth int32 // declaration loop depth, increased for every loop or label
353
- Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one.
354
- flags bitset16
347
+ Pack * Node // real package for import . names
348
+ Pkg * types.Pkg // pkg for OPACK nodes
349
+ // For a local variable (not param) or extern, the initializing assignment (OAS or OAS2).
350
+ // For a closure var, the ONAME node of the outer captured variable
351
+ Defn * Node
352
+ // The ODCLFUNC node (for a static function/method or a closure) in which
353
+ // local variable or param is declared.
354
+ Curfn * Node
355
+ Param * Param // additional fields for ONAME, OTYPE
356
+ Decldepth int32 // declaration loop depth, increased for every loop or label
357
+ // Unique number for ONAME nodes within a function. Function outputs
358
+ // (results) are numbered starting at one, followed by function inputs
359
+ // (parameters), and then local variables. Vargen is used to distinguish
360
+ // local variables/params with the same name.
361
+ Vargen int32
362
+ flags bitset16
355
363
}
356
364
357
365
const (
@@ -608,10 +616,16 @@ func (p *Param) SetEmbedFiles(list []string) {
608
616
// Func holds Node fields used only with function-like nodes.
609
617
type Func struct {
610
618
Shortname * types.Sym
611
- Enter Nodes // for example, allocate and initialize memory for escaping parameters
612
- Exit Nodes
613
- Cvars Nodes // closure params
614
- Dcl []* Node // autodcl for this func/closure
619
+ // Extra entry code for the function. For example, allocate and initialize
620
+ // memory for escaping parameters. However, just for OCLOSURE, Enter is a
621
+ // list of ONAME nodes of captured variables
622
+ Enter Nodes
623
+ Exit Nodes
624
+ // ONAME nodes for closure params, each should have closurevar set
625
+ Cvars Nodes
626
+ // ONAME nodes for all params/locals for this func/closure, does NOT
627
+ // include closurevars until transformclosure runs.
628
+ Dcl []* Node
615
629
616
630
// Parents records the parent scope of each scope within a
617
631
// function. The root scope (0) has no parent, so the i'th
@@ -630,7 +644,7 @@ type Func struct {
630
644
DebugInfo * ssa.FuncDebug
631
645
Ntype * Node // signature
632
646
Top int // top context (ctxCallee, etc)
633
- Closure * Node // OCLOSURE <-> ODCLFUNC
647
+ Closure * Node // OCLOSURE <-> ODCLFUNC (see header comment above)
634
648
Nname * Node // The ONAME node associated with an ODCLFUNC (both have same Type)
635
649
lsym * obj.LSym
636
650
@@ -680,6 +694,8 @@ const (
680
694
funcWrapper // is method wrapper
681
695
funcNeedctxt // function uses context register (has closure variables)
682
696
funcReflectMethod // function calls reflect.Type.Method or MethodByName
697
+ // true if closure inside a function; false if a simple function or a
698
+ // closure in a global variable initialization
683
699
funcIsHiddenClosure
684
700
funcHasDefer // contains a defer statement
685
701
funcNilCheckDisabled // disable nil checks when compiling this function
@@ -731,8 +747,10 @@ const (
731
747
OXXX Op = iota
732
748
733
749
// names
734
- ONAME // var or func name
735
- ONONAME // unnamed arg or return value: f(int, string) (int, error) { etc }
750
+ ONAME // var or func name
751
+ // Unnamed arg or return value: f(int, string) (int, error) { etc }
752
+ // Also used for a qualified package identifier that hasn't been resolved yet.
753
+ ONONAME
736
754
OTYPE // type name
737
755
OPACK // import
738
756
OLITERAL // literal
@@ -752,14 +770,18 @@ const (
752
770
OSTR2BYTES // Type(Left) (Type is []byte, Left is a string)
753
771
OSTR2BYTESTMP // Type(Left) (Type is []byte, Left is a string, ephemeral)
754
772
OSTR2RUNES // Type(Left) (Type is []rune, Left is a string)
755
- OAS // Left = Right or (if Colas=true) Left := Right
756
- OAS2 // List = Rlist (x, y, z = a, b, c)
757
- OAS2DOTTYPE // List = Right (x, ok = I.(int))
758
- OAS2FUNC // List = Right (x, y = f())
759
- OAS2MAPR // List = Right (x, ok = m["foo"])
760
- OAS2RECV // List = Right (x, ok = <-c)
761
- OASOP // Left Etype= Right (x += y)
762
- OCALL // Left(List) (function call, method call or type conversion)
773
+ // Left = Right or (if Colas=true) Left := Right
774
+ // If Colas, then Ninit includes a DCL node for Left.
775
+ OAS
776
+ // List = Rlist (x, y, z = a, b, c) or (if Colas=true) List := Rlist
777
+ // If Colas, then Ninit includes DCL nodes for List
778
+ OAS2
779
+ OAS2DOTTYPE // List = Right (x, ok = I.(int))
780
+ OAS2FUNC // List = Right (x, y = f())
781
+ OAS2MAPR // List = Right (x, ok = m["foo"])
782
+ OAS2RECV // List = Right (x, ok = <-c)
783
+ OASOP // Left Etype= Right (x += y)
784
+ OCALL // Left(List) (function call, method call or type conversion)
763
785
764
786
// OCALLFUNC, OCALLMETH, and OCALLINTER have the same structure.
765
787
// Prior to walk, they are: Left(List), where List is all regular arguments.
0 commit comments