nodes.mx raw
1 package main
2
3 import "go/constant"
4
5 type Node interface {
6 Pos() Pos
7 SetPos(Pos)
8 aNode()
9 }
10
11 type node struct {
12 pos Pos
13 }
14
15 func (n *node) Pos() Pos { return n.pos }
16 func (n *node) SetPos(pos Pos) { n.pos = pos }
17 func (*node) aNode() {}
18
19 type File struct {
20 Pragma Pragma
21 PkgName *Name
22 DeclList []Decl
23 EOF Pos
24 GoVersion string
25 node
26 }
27
28 type (
29 Decl interface {
30 Node
31 aDecl()
32 }
33
34 ImportDecl struct {
35 Group *Group
36 Pragma Pragma
37 LocalPkgName *Name
38 Path *BasicLit
39 decl
40 }
41
42 ConstDecl struct {
43 Group *Group
44 Pragma Pragma
45 NameList []*Name
46 Type Expr
47 Values Expr
48 decl
49 }
50
51 TypeDecl struct {
52 Group *Group
53 Pragma Pragma
54 Name *Name
55 TParamList []*Field
56 Alias bool
57 Type Expr
58 decl
59 }
60
61 VarDecl struct {
62 Group *Group
63 Pragma Pragma
64 NameList []*Name
65 Type Expr
66 Values Expr
67 decl
68 }
69
70 FuncDecl struct {
71 Pragma Pragma
72 Recv *Field
73 Name *Name
74 TParamList []*Field
75 Type *FuncType
76 Body *BlockStmt
77 decl
78 }
79 )
80
81 type decl struct{ node }
82
83 func (*decl) aDecl() {}
84
85 type Group struct {
86 _ int
87 }
88
89 func NewName(pos Pos, value string) *Name {
90 n := &Name{}
91 n.pos = pos
92 n.Value = value
93 return n
94 }
95
96 type (
97 Expr interface {
98 Node
99 typeInfo
100 aExpr()
101 }
102
103 BadExpr struct {
104 expr
105 }
106
107 Name struct {
108 Value string
109 expr
110 }
111
112 BasicLit struct {
113 Value string
114 Kind LitKind
115 Bad bool
116 expr
117 }
118
119 CompositeLit struct {
120 Type Expr
121 ElemList []Expr
122 NKeys int
123 Rbrace Pos
124 expr
125 }
126
127 KeyValueExpr struct {
128 Key, Value Expr
129 expr
130 }
131
132 FuncLit struct {
133 Type *FuncType
134 Body *BlockStmt
135 expr
136 }
137
138 ParenExpr struct {
139 X Expr
140 expr
141 }
142
143 SelectorExpr struct {
144 X Expr
145 Sel *Name
146 expr
147 }
148
149 IndexExpr struct {
150 X Expr
151 Index Expr
152 expr
153 }
154
155 SliceExpr struct {
156 X Expr
157 Index [3]Expr
158 Full bool
159 expr
160 }
161
162 AssertExpr struct {
163 X Expr
164 Type Expr
165 expr
166 }
167
168 TypeSwitchGuard struct {
169 Lhs *Name
170 X Expr
171 expr
172 }
173
174 Operation struct {
175 Op Operator
176 X, Y Expr
177 expr
178 }
179
180 CallExpr struct {
181 Fun Expr
182 ArgList []Expr
183 HasDots bool
184 expr
185 }
186
187 ListExpr struct {
188 ElemList []Expr
189 expr
190 }
191
192 ArrayType struct {
193 Len Expr
194 Elem Expr
195 expr
196 }
197
198 SliceType struct {
199 Elem Expr
200 expr
201 }
202
203 DotsType struct {
204 Elem Expr
205 expr
206 }
207
208 StructType struct {
209 FieldList []*Field
210 TagList []*BasicLit
211 expr
212 }
213
214 Field struct {
215 Name *Name
216 Type Expr
217 node
218 }
219
220 InterfaceType struct {
221 MethodList []*Field
222 expr
223 }
224
225 FuncType struct {
226 ParamList []*Field
227 ResultList []*Field
228 expr
229 }
230
231 MapType struct {
232 Key, Value Expr
233 expr
234 }
235
236 ChanType struct {
237 Dir ChanDir
238 Elem Expr
239 expr
240 }
241 )
242
243 type Type interface {
244 Underlying() Type
245 String() string
246 }
247
248 type typeInfo interface {
249 SetTypeInfo(TypeAndValue)
250 GetTypeInfo() TypeAndValue
251 }
252
253 type TypeAndValue struct {
254 Type Type
255 Value constant.Value
256 exprFlags
257 }
258
259 type exprFlags uint16
260
261 func (f exprFlags) IsVoid() bool { return f&1 != 0 }
262 func (f exprFlags) IsType() bool { return f&2 != 0 }
263 func (f exprFlags) IsBuiltin() bool { return f&4 != 0 }
264 func (f exprFlags) IsValue() bool { return f&8 != 0 }
265 func (f exprFlags) IsNil() bool { return f&16 != 0 }
266 func (f exprFlags) Addressable() bool { return f&32 != 0 }
267 func (f exprFlags) Assignable() bool { return f&64 != 0 }
268 func (f exprFlags) HasOk() bool { return f&128 != 0 }
269 func (f exprFlags) IsRuntimeHelper() bool { return f&256 != 0 }
270
271 func (f *exprFlags) SetIsVoid() { *f |= 1 }
272 func (f *exprFlags) SetIsType() { *f |= 2 }
273 func (f *exprFlags) SetIsBuiltin() { *f |= 4 }
274 func (f *exprFlags) SetIsValue() { *f |= 8 }
275 func (f *exprFlags) SetIsNil() { *f |= 16 }
276 func (f *exprFlags) SetAddressable() { *f |= 32 }
277 func (f *exprFlags) SetAssignable() { *f |= 64 }
278 func (f *exprFlags) SetHasOk() { *f |= 128 }
279 func (f *exprFlags) SetIsRuntimeHelper() { *f |= 256 }
280
281 type typeAndValue struct {
282 tv TypeAndValue
283 }
284
285 func (x *typeAndValue) SetTypeInfo(tv TypeAndValue) {
286 x.tv = tv
287 }
288 func (x *typeAndValue) GetTypeInfo() TypeAndValue {
289 return x.tv
290 }
291
292 type expr struct {
293 node
294 typeAndValue
295 }
296
297 func (*expr) aExpr() {}
298
299 type ChanDir uint
300
301 const (
302 _ ChanDir = iota
303 SendOnly
304 RecvOnly
305 )
306
307 type (
308 Stmt interface {
309 Node
310 aStmt()
311 }
312
313 SimpleStmt interface {
314 Stmt
315 aSimpleStmt()
316 }
317
318 EmptyStmt struct {
319 simpleStmt
320 }
321
322 LabeledStmt struct {
323 Label *Name
324 Stmt Stmt
325 stmt
326 }
327
328 BlockStmt struct {
329 List []Stmt
330 Rbrace Pos
331 stmt
332 }
333
334 ExprStmt struct {
335 X Expr
336 simpleStmt
337 }
338
339 SendStmt struct {
340 Chan, Value Expr
341 simpleStmt
342 }
343
344 DeclStmt struct {
345 DeclList []Decl
346 stmt
347 }
348
349 AssignStmt struct {
350 Op Operator
351 Lhs, Rhs Expr
352 simpleStmt
353 }
354
355 BranchStmt struct {
356 Tok Token
357 Label *Name
358 Target Stmt
359 stmt
360 }
361
362 CallStmt struct {
363 Tok Token
364 Call Expr
365 DeferAt Expr
366 stmt
367 }
368
369 ReturnStmt struct {
370 Results Expr
371 stmt
372 }
373
374 IfStmt struct {
375 Init SimpleStmt
376 Cond Expr
377 Then *BlockStmt
378 Else Stmt
379 stmt
380 }
381
382 ForStmt struct {
383 Init SimpleStmt
384 Cond Expr
385 Post SimpleStmt
386 Body *BlockStmt
387 stmt
388 }
389
390 SwitchStmt struct {
391 Init SimpleStmt
392 Tag Expr
393 Body []*CaseClause
394 Rbrace Pos
395 stmt
396 }
397
398 SelectStmt struct {
399 Body []*CommClause
400 Rbrace Pos
401 stmt
402 }
403 )
404
405 type (
406 RangeClause struct {
407 Lhs Expr
408 Def bool
409 X Expr
410 simpleStmt
411 }
412
413 CaseClause struct {
414 Cases Expr
415 Body []Stmt
416 Colon Pos
417 node
418 }
419
420 CommClause struct {
421 Comm SimpleStmt
422 Body []Stmt
423 Colon Pos
424 node
425 }
426 )
427
428 type stmt struct{ node }
429
430 func (stmt) aStmt() {}
431
432 type simpleStmt struct {
433 stmt
434 }
435
436 func (simpleStmt) aSimpleStmt() {}
437
438 type CommentKind uint
439
440 const (
441 Above CommentKind = iota
442 Below
443 Left
444 Right
445 )
446
447 type Comment struct {
448 Kind CommentKind
449 Text string
450 Next *Comment
451 }
452