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