1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 import "cmd/internal/src"
9 // ----------------------------------------------------------------------------
19 // commented out for now since not yet used
20 // doc *Comment // nil means no comment(s) attached
24 func (n *node) Pos() src.Pos {
28 func (*node) aNode() {}
30 // TODO(gri) we may be able to get rid of init here and in Node
31 func (n *node) init(p *parser) {
35 // ----------------------------------------------------------------------------
38 // package PkgName; DeclList[0], DeclList[1], ...
46 // ----------------------------------------------------------------------------
58 LocalPkgName *Name // including "."; nil means no rename present
60 Group *Group // nil means not part of a group
66 // NameList Type = Values
69 Type Expr // nil means no type
70 Values Expr // nil means no values
71 Group *Group // nil means not part of a group
80 Group *Group // nil means not part of a group
86 // NameList Type = Values
90 Type Expr // nil means no type
91 Values Expr // nil means no values
92 Group *Group // nil means not part of a group
96 // func Name Type { Body }
98 // func Receiver Name Type { Body }
99 // func Receiver Name Type
101 Attr map[string]bool // go:attr map
102 Recv *Field // nil means regular function
105 Body []Stmt // nil means no body (forward declaration)
106 Pragma Pragma // TODO(mdempsky): Cleaner solution.
107 EndLine uint // TODO(mdempsky): Cleaner solution.
112 type decl struct{ node }
114 func (*decl) aDecl() {}
116 // All declarations belonging to the same group point to the same Group node.
118 dummy int // not empty so we are guaranteed different Group instances
121 // ----------------------------------------------------------------------------
143 // Type { ElemList[0], ElemList[1], ... }
144 CompositeLit struct {
145 Type Expr // nil means no literal type
147 NKeys int // number of elements with keys
148 EndLine uint // TODO(mdempsky): Cleaner solution.
153 KeyValueExpr struct {
158 // func Type { Body }
162 EndLine uint // TODO(mdempsky): Cleaner solution.
173 SelectorExpr struct {
186 // X[Index[0] : Index[1] : Index[2]]
190 // Full indicates whether this is a simple or full slice expression.
191 // In a valid AST, this is equivalent to Index[2] != nil.
192 // TODO(mdempsky): This is only needed to report the "3-index
193 // slice of string" error when Index[2] is missing.
201 // TODO(gri) consider using Name{"..."} instead of nil (permits attaching of comments)
208 X, Y Expr // Y == nil means unary expression
212 // Fun(ArgList[0], ArgList[1], ...)
216 HasDots bool // last argument is followed by ...
220 // ElemList[0], ElemList[1], ...
228 // TODO(gri) consider using Name{"..."} instead of nil (permits attaching of comments)
229 Len Expr // nil means Len is ...
246 // struct { FieldList[0] TagList[0]; FieldList[1] TagList[1]; ... }
249 TagList []*BasicLit // i >= len(TagList) || TagList[i] == nil means no tag for field i
256 Name *Name // nil means anonymous field/parameter (structs/parameters), or embedded interface (interfaces)
257 Type Expr // field names declared in a list share the same Type (identical pointers)
261 // interface { MethodList[0]; MethodList[1]; ... }
262 InterfaceType struct {
284 Dir ChanDir // 0 means no direction
290 type expr struct{ node }
292 func (*expr) aExpr() {}
302 // ----------------------------------------------------------------------------
311 SimpleStmt interface {
337 Chan, Value Expr // Chan <- Value
347 Op Operator // 0 means no operation
348 Lhs, Rhs Expr // Rhs == ImplicitOne means Lhs++ (Op == Add) or Lhs-- (Op == Sub)
353 Tok token // Break, Continue, Fallthrough, or Goto
359 Tok token // Go or Defer
365 Results Expr // nil means no explicit return values
373 Else Stmt // either *IfStmt or *BlockStmt
378 Init SimpleStmt // incl. *RangeClause
400 Lhs Expr // nil means no Lhs = or Lhs :=
406 TypeSwitchGuard struct {
407 // TODO(gri) consider using Name{"..."} instead of nil (permits attaching of comments)
408 Lhs *Name // nil means no Lhs :=
414 Cases Expr // nil means default clause
420 Comm SimpleStmt // send or receive stmt; nil means default clause
426 type stmt struct{ node }
428 func (stmt) aStmt() {}
430 type simpleStmt struct {
434 func (simpleStmt) aSimpleStmt() {}
436 // ----------------------------------------------------------------------------
439 // TODO(gri) Consider renaming to CommentPos, CommentPlacement, etc.
440 // Kind = Above doesn't make much sense.
441 type CommentKind uint
444 Above CommentKind = iota
450 type Comment struct {