/
ast_bootstrap.go
574 lines (464 loc) · 11.6 KB
/
ast_bootstrap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
package golang
import "fmt"
// // SliceOfString represents a slice of a file and its 0-based start position.
// type SliceOfString struct {
// Text string
// Pos int
// }
// Token ...
type Token struct {
Kind string
// Text SliceOfString
Text string
}
// ArrayType ...
type ArrayType struct {
Lbrack Token // "["
Len Expr // Ellipsis node for [...]T array types, nil for slice types
Elt Expr // element type
}
// AssignStmt ...
type AssignStmt struct {
LHS []Expr
Tok Token
RHS []Expr
}
// BadDecl ...
type BadDecl struct {
Token Token
}
// BadExpr ...
type BadExpr struct {
Token Token
}
// BadStmt ...
type BadStmt struct {
Token Token
}
// BasicLit ...
type BasicLit struct {
Token Token
}
// BinaryExpr ...
type BinaryExpr struct {
X Expr
Op Token
Y Expr
}
// BlockStmt ...
type BlockStmt struct {
Lbrace Token // "{"
List []Stmt
Rbrace Token // "}"
}
// BranchStmt ...
type BranchStmt struct {
Tok Token // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH)
Label *Ident // label name; or nil
}
// CallExpr ...
type CallExpr struct {
Fun Expr // function expression
Lparen Token // "("
Args []Expr // function arguments; or nil
Ellipsis Token // "..." (token.NoPos if there is no "...")
Rparen Token // ")"
}
// CaseClause ...
type CaseClause struct {
Case Token // "case" or "default" keyword
List []Expr // list of expressions or types; nil means default case
Colon Token
Body []Stmt // statement list; or nil
}
// ChanType ...
type ChanType struct {
Begin Token // "chan" keyword or "<-" (whichever comes first)
Arrow Token // "<-" (token.NoPos if there is no "<-"); added in Go 1.1
// Dir {|"SEND", "RECV"|} powerset without {||}
Dir string
Value Expr // value type
}
// CommClause ...
type CommClause struct {
Case Token // "case" or "default" keyword
Comm Stmt // send or receive statement; nil means default case
Colon Token // ":"
Body []Stmt // statement list; or nil
}
// Comment ...
type Comment struct {
Token Token
}
// CommentGroup ...
type CommentGroup struct {
List []Comment // len(List) > 0
}
// CompositeLit ...
type CompositeLit struct {
Type Expr // literal type; or nil
Lbrace Token // "{"
Elts []Expr // list of composite elements; or nil
Rbrace Token // "}"
Incomplete bool // true if (source) expressions are missing in the Elts list; added in Go 1.11
}
// DeclStmt ...
type DeclStmt struct {
Decl Decl // GenDecl with CONST, TYPE, or VAR token
}
// DeferStmt ...
type DeferStmt struct {
Defer Token // "defer" keyword
Call CallExpr
}
// Ellipsis ...
type Ellipsis struct {
Ellipsis Token // "..."
Elt Expr // ellipsis element type (parameter lists only); or nil
}
// EmptyStmt ...
type EmptyStmt struct {
Semicolon Token // following ";"
Implicit bool // if set, ";" was omitted in the source; added in Go 1.5
}
// ExprStmt ...
type ExprStmt struct {
X Expr // expression
}
// Field ...
type Field struct {
Doc *CommentGroup // associated documentation; or nil
Names []Ident // field/method/parameter names; or nil
Type Expr // field/method/parameter type
Tag *BasicLit // field tag; or nil
Comment *CommentGroup // line comments; or nil
}
// FieldList ...
type FieldList struct {
Opening Token // opening parenthesis/brace, if any
List []Field // field list; or nil
Closing Token // closing parenthesis/brace, if any
}
// File ...
type File struct {
Doc *CommentGroup // associated documentation; or nil
Package Token // "package" keyword
Name Ident // package name
Decls []Decl // top-level declarations; or nil
Imports []ImportSpec // imports in this file
Unresolved []Ident // unresolved identifiers in this file
Comments []CommentGroup // list of all comments in the source file
}
// ForStmt ...
type ForStmt struct {
For Token // "for" keyword
Init Stmt // initialization statement; or nil
Cond Expr // condition; or nil
Post Stmt // post iteration statement; or nil
Body BlockStmt
}
// FuncDecl ...
type FuncDecl struct {
Doc *CommentGroup // associated documentation; or nil
Recv *FieldList // receiver (methods); or nil (functions)
Name Ident // function/method name
Type FuncType // function signature: parameters, results, and "func" keyword
Body *BlockStmt // function body; or nil for external (non-Go) function
}
// FuncLit ...
type FuncLit struct {
Type FuncType // function type
Body BlockStmt // function body
}
// FuncType ...
type FuncType struct {
Func Token // "func" keyword (token.NoPos if there is no "func")
Params FieldList // (incoming) parameters; non-nil
Results *FieldList // (outgoing) results; or nil
}
// GenDecl ...
type GenDecl struct {
Doc *CommentGroup // associated documentation; or nil
Tok Token // IMPORT, CONST, TYPE, VAR
Lparen Token // '(', if any
Specs []Spec
Rparen Token // ')', if any
}
// GoStmt ...
type GoStmt struct {
Go Token // "go" keyword
Call CallExpr
}
// Ident ...
type Ident struct {
Name Token // identifier name
}
// IfStmt ...
type IfStmt struct {
If Token // "if" keyword
Init Stmt // initialization statement; or nil
Cond Expr // condition
Body BlockStmt
Else Stmt // else branch; or nil
}
// ImportSpec ...
type ImportSpec struct {
Doc *CommentGroup // associated documentation; or nil
Name *Ident // local package name (including "."); or nil
Path BasicLit // import path
Comment *CommentGroup // line comments; or nil
EndPos Token // end of spec (overrides Path.Pos if nonzero)
}
// IncDecStmt ...
type IncDecStmt struct {
X Expr
Tok Token
}
// IndexExpr ...
type IndexExpr struct {
X Expr
Lbrack Token // "["
Index Expr
Rbrack Token // "]"
}
// InterfaceType ...
type InterfaceType struct {
Interface Token // "interface" keyword
Methods FieldList // list of methods
Incomplete bool // true if (source) methods are missing in the Methods list
}
// KeyValueExpr ...
type KeyValueExpr struct {
Key Expr
Colon Token
Value Expr
}
// LabeledStmt ...
type LabeledStmt struct {
Label Ident
Colon Token
Stmt Stmt
}
// MapType ...
type MapType struct {
Map Token // "map" keyword
Key Expr
Value Expr
}
// ParenExpr ...
type ParenExpr struct {
Lparen Token // "("
X Expr // parenthesized expression
Rparen Token // ")"
}
// RangeStmt ...
type RangeStmt struct {
For Token // "for" keyword
Key Expr // Key may be nil
Value Expr // Value may be nil
Tok Token // invalid if Key == nil
X Expr // value to range over
Body BlockStmt
}
// ReturnStmt ...
type ReturnStmt struct {
Return Token // "return" keyword
Results []Expr // result expressions; or nil
}
// SelectStmt ...
type SelectStmt struct {
Select Token // "select" keyword
Body BlockStmt // CommClauses only
}
// SelectorExpr ...
type SelectorExpr struct {
X Expr // expression
Sel Ident // field selector
}
// SendStmt ...
type SendStmt struct {
Chan Expr
Arrow Token // "<-"
Value Expr
}
// SliceExpr ...
type SliceExpr struct {
X Expr // expression
Lbrack Token // "["
Low Expr // begin of slice range; or nil
High Expr // end of slice range; or nil
Max Expr // maximum capacity of slice; or nil; added in Go 1.2
Slice3 bool // true if 3-index slice (2 colons present); added in Go 1.2
Rbrack Token // "]"
}
// StarExpr ...
type StarExpr struct {
Star Token // "*"
X Expr // operand
}
// StructType ...
type StructType struct {
Struct Token // "struct" keyword
Fields FieldList // list of field declarations
Incomplete bool // true if (source) fields are missing in the Fields list
}
// SwitchStmt ...
type SwitchStmt struct {
Switch Token // "switch" keyword
Init Stmt // initialization statement; or nil
Tag Expr // tag expression; or nil
Body BlockStmt // CaseClauses only
}
// TypeAssertExpr ...
type TypeAssertExpr struct {
X Expr // expression
Lparen Token // "("; added in Go 1.2
Type Expr // asserted type; nil means type switch X.(type)
Rparen Token // ")"; added in Go 1.2
}
// TypeSpec ...
type TypeSpec struct {
Doc *CommentGroup // associated documentation; or nil
Name Ident // type name
Assign Token // '=', if any; added in Go 1.9
Type Expr // Ident, ParenExpr, SelectorExpr, StarExpr, or any of the XxxTypes
Comment *CommentGroup // line comments; or nil
}
// TypeSwitchStmt ...
type TypeSwitchStmt struct {
Switch Token // "switch" keyword
Init Stmt // initialization statement; or nil
Assign Stmt // x := y.(type) or y.(type)
Body BlockStmt // CaseClauses only
}
// UnaryExpr ...
type UnaryExpr struct {
Op Token
X Expr
}
// ValueSpec ...
type ValueSpec struct {
Doc *CommentGroup // associated documentation; or nil
Names []Ident // value names (len(Names) > 0)
Type Expr // value type; or nil
Values []Expr // initial values; or nil
Comment *CommentGroup // line comments; or nil
}
// Expr ...
type Expr interface {
fmt.Formatter
GoIsExpr()
}
// GoIsExpr ...
func (*BadExpr) GoIsExpr() {}
// GoIsExpr ...
func (*Ident) GoIsExpr() {}
// GoIsExpr ...
func (*Ellipsis) GoIsExpr() {}
// GoIsExpr ...
func (*BasicLit) GoIsExpr() {}
// GoIsExpr ...
func (*FuncLit) GoIsExpr() {}
// GoIsExpr ...
func (*CompositeLit) GoIsExpr() {}
// GoIsExpr ...
func (*ParenExpr) GoIsExpr() {}
// GoIsExpr ...
func (*SelectorExpr) GoIsExpr() {}
// GoIsExpr ...
func (*IndexExpr) GoIsExpr() {}
// GoIsExpr ...
func (*SliceExpr) GoIsExpr() {}
// GoIsExpr ...
func (*TypeAssertExpr) GoIsExpr() {}
// GoIsExpr ...
func (*CallExpr) GoIsExpr() {}
// GoIsExpr ...
func (*StarExpr) GoIsExpr() {}
// GoIsExpr ...
func (*UnaryExpr) GoIsExpr() {}
// GoIsExpr ...
func (*BinaryExpr) GoIsExpr() {}
// GoIsExpr ...
func (*KeyValueExpr) GoIsExpr() {}
// GoIsExpr ...
func (*ArrayType) GoIsExpr() {}
// GoIsExpr ...
func (*StructType) GoIsExpr() {}
// GoIsExpr ...
func (*FuncType) GoIsExpr() {}
// GoIsExpr ...
func (*InterfaceType) GoIsExpr() {}
// GoIsExpr ...
func (*MapType) GoIsExpr() {}
// GoIsExpr ...
func (*ChanType) GoIsExpr() {}
// Stmt ...
type Stmt interface {
fmt.Formatter
GoIsStmt()
}
// GoIsStmt ...
func (*AssignStmt) GoIsStmt() {}
// GoIsStmt ...
func (*BadStmt) GoIsStmt() {}
// GoIsStmt ...
func (*BlockStmt) GoIsStmt() {}
// GoIsStmt ...
func (*BranchStmt) GoIsStmt() {}
// GoIsStmt ...
func (*CaseClause) GoIsStmt() {}
// GoIsStmt ...
func (*CommClause) GoIsStmt() {}
// GoIsStmt ...
func (*DeclStmt) GoIsStmt() {}
// GoIsStmt ...
func (*DeferStmt) GoIsStmt() {}
// GoIsStmt ...
func (*EmptyStmt) GoIsStmt() {}
// GoIsStmt ...
func (*ExprStmt) GoIsStmt() {}
// GoIsStmt ...
func (*ForStmt) GoIsStmt() {}
// GoIsStmt ...
func (*GoStmt) GoIsStmt() {}
// GoIsStmt ...
func (*IfStmt) GoIsStmt() {}
// GoIsStmt ...
func (*IncDecStmt) GoIsStmt() {}
// GoIsStmt ...
func (*LabeledStmt) GoIsStmt() {}
// GoIsStmt ...
func (*RangeStmt) GoIsStmt() {}
// GoIsStmt ...
func (*ReturnStmt) GoIsStmt() {}
// GoIsStmt ...
func (*SelectStmt) GoIsStmt() {}
// GoIsStmt ...
func (*SendStmt) GoIsStmt() {}
// GoIsStmt ...
func (*SwitchStmt) GoIsStmt() {}
// GoIsStmt ...
func (*TypeSwitchStmt) GoIsStmt() {}
// Decl ...
type Decl interface {
fmt.Formatter
GoIsDecl()
}
// GoIsDecl ...
func (*BadDecl) GoIsDecl() {}
// GoIsDecl ...
func (*FuncDecl) GoIsDecl() {}
// GoIsDecl ...
func (*GenDecl) GoIsDecl() {}
// Spec ...
type Spec interface {
fmt.Formatter
GoIsSpec()
}
// GoIsSpec ...
func (*ImportSpec) GoIsSpec() {}
// GoIsSpec ...
func (*TypeSpec) GoIsSpec() {}
// GoIsSpec ...
func (*ValueSpec) GoIsSpec() {}