1 | from asdl import pybase
|
2 | from mycpp import mops
|
3 | from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
|
4 |
|
5 | from asdl import runtime # For runtime.NO_SPID
|
6 | from asdl.runtime import NewRecord, NewLeaf, TraversalState
|
7 | from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
|
8 |
|
9 | class op_t(pybase.SimpleObj):
|
10 | pass
|
11 |
|
12 | class op_e(object):
|
13 | Plus = op_t(1)
|
14 | Minus = op_t(2)
|
15 |
|
16 | _op_str = {
|
17 | 1: 'Plus',
|
18 | 2: 'Minus',
|
19 | }
|
20 |
|
21 | def op_str(val, dot=True):
|
22 | # type: (op_t, bool) -> str
|
23 | v = _op_str[val]
|
24 | if dot:
|
25 | return "op.%s" % v
|
26 | else:
|
27 | return v
|
28 |
|
29 | class kexpr_e(object):
|
30 | Bool = 65
|
31 | Int = 66
|
32 | Str = 67
|
33 | MultiStr = 68
|
34 | Unary = 5
|
35 | Binary = 6
|
36 | Ternary = 7
|
37 | Call = 8
|
38 |
|
39 | _kexpr_str = {
|
40 | 5: 'Unary',
|
41 | 6: 'Binary',
|
42 | 7: 'Ternary',
|
43 | 8: 'Call',
|
44 | 65: 'Bool',
|
45 | 66: 'Int',
|
46 | 67: 'Str',
|
47 | 68: 'MultiStr',
|
48 | }
|
49 |
|
50 | def kexpr_str(tag, dot=True):
|
51 | # type: (int, bool) -> str
|
52 | v = _kexpr_str[tag]
|
53 | if dot:
|
54 | return "kexpr.%s" % v
|
55 | else:
|
56 | return v
|
57 |
|
58 | class kexpr_t(pybase.CompoundObj):
|
59 | def tag(self):
|
60 | # type: () -> int
|
61 | return self._type_tag
|
62 |
|
63 | class kexpr(object):
|
64 | class Unary(kexpr_t):
|
65 | _type_tag = 5
|
66 | __slots__ = ('op', 'child')
|
67 |
|
68 | def __init__(self, op, child):
|
69 | # type: (Token, kexpr_t) -> None
|
70 | self.op = op
|
71 | self.child = child
|
72 |
|
73 | @staticmethod
|
74 | def CreateNull(alloc_lists=False):
|
75 | # type: () -> kexpr.Unary
|
76 | return kexpr.Unary(cast('Token', None), cast('kexpr_t', None))
|
77 |
|
78 | def PrettyTree(self, do_abbrev, trav=None):
|
79 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
80 | trav = trav or TraversalState()
|
81 | heap_id = id(self)
|
82 | if heap_id in trav.seen:
|
83 | return hnode.AlreadySeen(heap_id)
|
84 | trav.seen[heap_id] = True
|
85 |
|
86 | out_node = NewRecord('kexpr.Unary')
|
87 | L = out_node.fields
|
88 |
|
89 | assert self.op is not None
|
90 | x0 = self.op.PrettyTree(do_abbrev, trav=trav)
|
91 | L.append(Field('op', x0))
|
92 |
|
93 | assert self.child is not None
|
94 | x1 = self.child.PrettyTree(do_abbrev, trav=trav)
|
95 | L.append(Field('child', x1))
|
96 |
|
97 | return out_node
|
98 |
|
99 | class Binary(kexpr_t):
|
100 | _type_tag = 6
|
101 | __slots__ = ('op', 'left', 'right')
|
102 |
|
103 | def __init__(self, op, left, right):
|
104 | # type: (Token, kexpr_t, kexpr_t) -> None
|
105 | self.op = op
|
106 | self.left = left
|
107 | self.right = right
|
108 |
|
109 | @staticmethod
|
110 | def CreateNull(alloc_lists=False):
|
111 | # type: () -> kexpr.Binary
|
112 | return kexpr.Binary(cast('Token', None), cast('kexpr_t', None), cast('kexpr_t', None))
|
113 |
|
114 | def PrettyTree(self, do_abbrev, trav=None):
|
115 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
116 | trav = trav or TraversalState()
|
117 | heap_id = id(self)
|
118 | if heap_id in trav.seen:
|
119 | return hnode.AlreadySeen(heap_id)
|
120 | trav.seen[heap_id] = True
|
121 |
|
122 | out_node = NewRecord('kexpr.Binary')
|
123 | L = out_node.fields
|
124 |
|
125 | assert self.op is not None
|
126 | x0 = self.op.PrettyTree(do_abbrev, trav=trav)
|
127 | L.append(Field('op', x0))
|
128 |
|
129 | assert self.left is not None
|
130 | x1 = self.left.PrettyTree(do_abbrev, trav=trav)
|
131 | L.append(Field('left', x1))
|
132 |
|
133 | assert self.right is not None
|
134 | x2 = self.right.PrettyTree(do_abbrev, trav=trav)
|
135 | L.append(Field('right', x2))
|
136 |
|
137 | return out_node
|
138 |
|
139 | class Ternary(kexpr_t):
|
140 | _type_tag = 7
|
141 | __slots__ = ('op', 'left', 'cond', 'right')
|
142 |
|
143 | def __init__(self, op, left, cond, right):
|
144 | # type: (Token, kexpr_t, kexpr_t, kexpr_t) -> None
|
145 | self.op = op
|
146 | self.left = left
|
147 | self.cond = cond
|
148 | self.right = right
|
149 |
|
150 | @staticmethod
|
151 | def CreateNull(alloc_lists=False):
|
152 | # type: () -> kexpr.Ternary
|
153 | return kexpr.Ternary(cast('Token', None), cast('kexpr_t', None), cast('kexpr_t', None), cast('kexpr_t', None))
|
154 |
|
155 | def PrettyTree(self, do_abbrev, trav=None):
|
156 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
157 | trav = trav or TraversalState()
|
158 | heap_id = id(self)
|
159 | if heap_id in trav.seen:
|
160 | return hnode.AlreadySeen(heap_id)
|
161 | trav.seen[heap_id] = True
|
162 |
|
163 | out_node = NewRecord('kexpr.Ternary')
|
164 | L = out_node.fields
|
165 |
|
166 | assert self.op is not None
|
167 | x0 = self.op.PrettyTree(do_abbrev, trav=trav)
|
168 | L.append(Field('op', x0))
|
169 |
|
170 | assert self.left is not None
|
171 | x1 = self.left.PrettyTree(do_abbrev, trav=trav)
|
172 | L.append(Field('left', x1))
|
173 |
|
174 | assert self.cond is not None
|
175 | x2 = self.cond.PrettyTree(do_abbrev, trav=trav)
|
176 | L.append(Field('cond', x2))
|
177 |
|
178 | assert self.right is not None
|
179 | x3 = self.right.PrettyTree(do_abbrev, trav=trav)
|
180 | L.append(Field('right', x3))
|
181 |
|
182 | return out_node
|
183 |
|
184 | class Call(kexpr_t):
|
185 | _type_tag = 8
|
186 | __slots__ = ('f', 'args')
|
187 |
|
188 | def __init__(self, f, args):
|
189 | # type: (kexpr_t, List[kexpr_t]) -> None
|
190 | self.f = f
|
191 | self.args = args
|
192 |
|
193 | @staticmethod
|
194 | def CreateNull(alloc_lists=False):
|
195 | # type: () -> kexpr.Call
|
196 | return kexpr.Call(cast('kexpr_t', None), [] if alloc_lists else cast('List[kexpr_t]', None))
|
197 |
|
198 | def PrettyTree(self, do_abbrev, trav=None):
|
199 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
200 | trav = trav or TraversalState()
|
201 | heap_id = id(self)
|
202 | if heap_id in trav.seen:
|
203 | return hnode.AlreadySeen(heap_id)
|
204 | trav.seen[heap_id] = True
|
205 |
|
206 | out_node = NewRecord('kexpr.Call')
|
207 | L = out_node.fields
|
208 |
|
209 | assert self.f is not None
|
210 | x0 = self.f.PrettyTree(do_abbrev, trav=trav)
|
211 | L.append(Field('f', x0))
|
212 |
|
213 | if self.args is not None: # List
|
214 | x1 = hnode.Array([])
|
215 | for i1 in self.args:
|
216 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
217 | i1.PrettyTree(do_abbrev, trav=trav))
|
218 | x1.children.append(h)
|
219 | L.append(Field('args', x1))
|
220 |
|
221 | return out_node
|
222 |
|
223 | pass
|
224 |
|
225 | class ktype_e(object):
|
226 | Bool = 1
|
227 | Int = 2
|
228 | Str = 3
|
229 | List = 4
|
230 | Dict = 5
|
231 | Class = 6
|
232 | Data = 7
|
233 | Enum = 8
|
234 |
|
235 | _ktype_str = {
|
236 | 1: 'Bool',
|
237 | 2: 'Int',
|
238 | 3: 'Str',
|
239 | 4: 'List',
|
240 | 5: 'Dict',
|
241 | 6: 'Class',
|
242 | 7: 'Data',
|
243 | 8: 'Enum',
|
244 | }
|
245 |
|
246 | def ktype_str(tag, dot=True):
|
247 | # type: (int, bool) -> str
|
248 | v = _ktype_str[tag]
|
249 | if dot:
|
250 | return "ktype.%s" % v
|
251 | else:
|
252 | return v
|
253 |
|
254 | class ktype_t(pybase.CompoundObj):
|
255 | def tag(self):
|
256 | # type: () -> int
|
257 | return self._type_tag
|
258 |
|
259 | class ktype__Bool(ktype_t):
|
260 | _type_tag = 1
|
261 | __slots__ = ()
|
262 |
|
263 | def __init__(self, ):
|
264 | # type: () -> None
|
265 | pass
|
266 |
|
267 | def PrettyTree(self, do_abbrev, trav=None):
|
268 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
269 | trav = trav or TraversalState()
|
270 | heap_id = id(self)
|
271 | if heap_id in trav.seen:
|
272 | return hnode.AlreadySeen(heap_id)
|
273 | trav.seen[heap_id] = True
|
274 |
|
275 | out_node = NewRecord('ktype.Bool')
|
276 | L = out_node.fields
|
277 |
|
278 | return out_node
|
279 |
|
280 | class ktype__Int(ktype_t):
|
281 | _type_tag = 2
|
282 | __slots__ = ()
|
283 |
|
284 | def __init__(self, ):
|
285 | # type: () -> None
|
286 | pass
|
287 |
|
288 | def PrettyTree(self, do_abbrev, trav=None):
|
289 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
290 | trav = trav or TraversalState()
|
291 | heap_id = id(self)
|
292 | if heap_id in trav.seen:
|
293 | return hnode.AlreadySeen(heap_id)
|
294 | trav.seen[heap_id] = True
|
295 |
|
296 | out_node = NewRecord('ktype.Int')
|
297 | L = out_node.fields
|
298 |
|
299 | return out_node
|
300 |
|
301 | class ktype__Str(ktype_t):
|
302 | _type_tag = 3
|
303 | __slots__ = ()
|
304 |
|
305 | def __init__(self, ):
|
306 | # type: () -> None
|
307 | pass
|
308 |
|
309 | def PrettyTree(self, do_abbrev, trav=None):
|
310 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
311 | trav = trav or TraversalState()
|
312 | heap_id = id(self)
|
313 | if heap_id in trav.seen:
|
314 | return hnode.AlreadySeen(heap_id)
|
315 | trav.seen[heap_id] = True
|
316 |
|
317 | out_node = NewRecord('ktype.Str')
|
318 | L = out_node.fields
|
319 |
|
320 | return out_node
|
321 |
|
322 | class ktype(object):
|
323 | Bool = ktype__Bool()
|
324 |
|
325 | Int = ktype__Int()
|
326 |
|
327 | Str = ktype__Str()
|
328 |
|
329 | class List(ktype_t):
|
330 | _type_tag = 4
|
331 | __slots__ = ('T',)
|
332 |
|
333 | def __init__(self, T):
|
334 | # type: (ktype_t) -> None
|
335 | self.T = T
|
336 |
|
337 | @staticmethod
|
338 | def CreateNull(alloc_lists=False):
|
339 | # type: () -> ktype.List
|
340 | return ktype.List(cast('ktype_t', None))
|
341 |
|
342 | def PrettyTree(self, do_abbrev, trav=None):
|
343 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
344 | trav = trav or TraversalState()
|
345 | heap_id = id(self)
|
346 | if heap_id in trav.seen:
|
347 | return hnode.AlreadySeen(heap_id)
|
348 | trav.seen[heap_id] = True
|
349 |
|
350 | out_node = NewRecord('ktype.List')
|
351 | L = out_node.fields
|
352 |
|
353 | assert self.T is not None
|
354 | x0 = self.T.PrettyTree(do_abbrev, trav=trav)
|
355 | L.append(Field('T', x0))
|
356 |
|
357 | return out_node
|
358 |
|
359 | class Dict(ktype_t):
|
360 | _type_tag = 5
|
361 | __slots__ = ('K', 'V')
|
362 |
|
363 | def __init__(self, K, V):
|
364 | # type: (ktype_t, ktype_t) -> None
|
365 | self.K = K
|
366 | self.V = V
|
367 |
|
368 | @staticmethod
|
369 | def CreateNull(alloc_lists=False):
|
370 | # type: () -> ktype.Dict
|
371 | return ktype.Dict(cast('ktype_t', None), cast('ktype_t', None))
|
372 |
|
373 | def PrettyTree(self, do_abbrev, trav=None):
|
374 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
375 | trav = trav or TraversalState()
|
376 | heap_id = id(self)
|
377 | if heap_id in trav.seen:
|
378 | return hnode.AlreadySeen(heap_id)
|
379 | trav.seen[heap_id] = True
|
380 |
|
381 | out_node = NewRecord('ktype.Dict')
|
382 | L = out_node.fields
|
383 |
|
384 | assert self.K is not None
|
385 | x0 = self.K.PrettyTree(do_abbrev, trav=trav)
|
386 | L.append(Field('K', x0))
|
387 |
|
388 | assert self.V is not None
|
389 | x1 = self.V.PrettyTree(do_abbrev, trav=trav)
|
390 | L.append(Field('V', x1))
|
391 |
|
392 | return out_node
|
393 |
|
394 | class Class(ktype_t):
|
395 | _type_tag = 6
|
396 | __slots__ = ('name',)
|
397 |
|
398 | def __init__(self, name):
|
399 | # type: (str) -> None
|
400 | self.name = name
|
401 |
|
402 | @staticmethod
|
403 | def CreateNull(alloc_lists=False):
|
404 | # type: () -> ktype.Class
|
405 | return ktype.Class('')
|
406 |
|
407 | def PrettyTree(self, do_abbrev, trav=None):
|
408 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
409 | trav = trav or TraversalState()
|
410 | heap_id = id(self)
|
411 | if heap_id in trav.seen:
|
412 | return hnode.AlreadySeen(heap_id)
|
413 | trav.seen[heap_id] = True
|
414 |
|
415 | out_node = NewRecord('ktype.Class')
|
416 | L = out_node.fields
|
417 |
|
418 | x0 = NewLeaf(self.name, color_e.StringConst)
|
419 | L.append(Field('name', x0))
|
420 |
|
421 | return out_node
|
422 |
|
423 | class Data(ktype_t):
|
424 | _type_tag = 7
|
425 | __slots__ = ('fields',)
|
426 |
|
427 | def __init__(self, fields):
|
428 | # type: (List[Field_]) -> None
|
429 | self.fields = fields
|
430 |
|
431 | @staticmethod
|
432 | def CreateNull(alloc_lists=False):
|
433 | # type: () -> ktype.Data
|
434 | return ktype.Data([] if alloc_lists else cast('List[Field_]', None))
|
435 |
|
436 | def PrettyTree(self, do_abbrev, trav=None):
|
437 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
438 | trav = trav or TraversalState()
|
439 | heap_id = id(self)
|
440 | if heap_id in trav.seen:
|
441 | return hnode.AlreadySeen(heap_id)
|
442 | trav.seen[heap_id] = True
|
443 |
|
444 | out_node = NewRecord('ktype.Data')
|
445 | L = out_node.fields
|
446 |
|
447 | if self.fields is not None: # List
|
448 | x0 = hnode.Array([])
|
449 | for i0 in self.fields:
|
450 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
451 | i0.PrettyTree(do_abbrev, trav=trav))
|
452 | x0.children.append(h)
|
453 | L.append(Field('fields', x0))
|
454 |
|
455 | return out_node
|
456 |
|
457 | class Enum(ktype_t):
|
458 | _type_tag = 8
|
459 | __slots__ = ('variants',)
|
460 |
|
461 | def __init__(self, variants):
|
462 | # type: (List[variant]) -> None
|
463 | self.variants = variants
|
464 |
|
465 | @staticmethod
|
466 | def CreateNull(alloc_lists=False):
|
467 | # type: () -> ktype.Enum
|
468 | return ktype.Enum([] if alloc_lists else cast('List[variant]', None))
|
469 |
|
470 | def PrettyTree(self, do_abbrev, trav=None):
|
471 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
472 | trav = trav or TraversalState()
|
473 | heap_id = id(self)
|
474 | if heap_id in trav.seen:
|
475 | return hnode.AlreadySeen(heap_id)
|
476 | trav.seen[heap_id] = True
|
477 |
|
478 | out_node = NewRecord('ktype.Enum')
|
479 | L = out_node.fields
|
480 |
|
481 | if self.variants is not None: # List
|
482 | x0 = hnode.Array([])
|
483 | for i0 in self.variants:
|
484 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
485 | i0.PrettyTree(do_abbrev, trav=trav))
|
486 | x0.children.append(h)
|
487 | L.append(Field('variants', x0))
|
488 |
|
489 | return out_node
|
490 |
|
491 | pass
|
492 |
|
493 | class stmt_e(object):
|
494 | VarDecl = 1
|
495 | PlaceMutation = 2
|
496 | If = 3
|
497 | Switch = 4
|
498 | For = 5
|
499 | While = 6
|
500 | Break = 7
|
501 | Continue = 8
|
502 | Return = 9
|
503 | Try = 10
|
504 | With = 11
|
505 |
|
506 | _stmt_str = {
|
507 | 1: 'VarDecl',
|
508 | 2: 'PlaceMutation',
|
509 | 3: 'If',
|
510 | 4: 'Switch',
|
511 | 5: 'For',
|
512 | 6: 'While',
|
513 | 7: 'Break',
|
514 | 8: 'Continue',
|
515 | 9: 'Return',
|
516 | 10: 'Try',
|
517 | 11: 'With',
|
518 | }
|
519 |
|
520 | def stmt_str(tag, dot=True):
|
521 | # type: (int, bool) -> str
|
522 | v = _stmt_str[tag]
|
523 | if dot:
|
524 | return "stmt.%s" % v
|
525 | else:
|
526 | return v
|
527 |
|
528 | class stmt_t(pybase.CompoundObj):
|
529 | def tag(self):
|
530 | # type: () -> int
|
531 | return self._type_tag
|
532 |
|
533 | class stmt__If(stmt_t):
|
534 | _type_tag = 3
|
535 | __slots__ = ()
|
536 |
|
537 | def __init__(self, ):
|
538 | # type: () -> None
|
539 | pass
|
540 |
|
541 | def PrettyTree(self, do_abbrev, trav=None):
|
542 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
543 | trav = trav or TraversalState()
|
544 | heap_id = id(self)
|
545 | if heap_id in trav.seen:
|
546 | return hnode.AlreadySeen(heap_id)
|
547 | trav.seen[heap_id] = True
|
548 |
|
549 | out_node = NewRecord('stmt.If')
|
550 | L = out_node.fields
|
551 |
|
552 | return out_node
|
553 |
|
554 | class stmt__Switch(stmt_t):
|
555 | _type_tag = 4
|
556 | __slots__ = ()
|
557 |
|
558 | def __init__(self, ):
|
559 | # type: () -> None
|
560 | pass
|
561 |
|
562 | def PrettyTree(self, do_abbrev, trav=None):
|
563 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
564 | trav = trav or TraversalState()
|
565 | heap_id = id(self)
|
566 | if heap_id in trav.seen:
|
567 | return hnode.AlreadySeen(heap_id)
|
568 | trav.seen[heap_id] = True
|
569 |
|
570 | out_node = NewRecord('stmt.Switch')
|
571 | L = out_node.fields
|
572 |
|
573 | return out_node
|
574 |
|
575 | class stmt__For(stmt_t):
|
576 | _type_tag = 5
|
577 | __slots__ = ()
|
578 |
|
579 | def __init__(self, ):
|
580 | # type: () -> None
|
581 | pass
|
582 |
|
583 | def PrettyTree(self, do_abbrev, trav=None):
|
584 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
585 | trav = trav or TraversalState()
|
586 | heap_id = id(self)
|
587 | if heap_id in trav.seen:
|
588 | return hnode.AlreadySeen(heap_id)
|
589 | trav.seen[heap_id] = True
|
590 |
|
591 | out_node = NewRecord('stmt.For')
|
592 | L = out_node.fields
|
593 |
|
594 | return out_node
|
595 |
|
596 | class stmt__While(stmt_t):
|
597 | _type_tag = 6
|
598 | __slots__ = ()
|
599 |
|
600 | def __init__(self, ):
|
601 | # type: () -> None
|
602 | pass
|
603 |
|
604 | def PrettyTree(self, do_abbrev, trav=None):
|
605 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
606 | trav = trav or TraversalState()
|
607 | heap_id = id(self)
|
608 | if heap_id in trav.seen:
|
609 | return hnode.AlreadySeen(heap_id)
|
610 | trav.seen[heap_id] = True
|
611 |
|
612 | out_node = NewRecord('stmt.While')
|
613 | L = out_node.fields
|
614 |
|
615 | return out_node
|
616 |
|
617 | class stmt__Break(stmt_t):
|
618 | _type_tag = 7
|
619 | __slots__ = ()
|
620 |
|
621 | def __init__(self, ):
|
622 | # type: () -> None
|
623 | pass
|
624 |
|
625 | def PrettyTree(self, do_abbrev, trav=None):
|
626 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
627 | trav = trav or TraversalState()
|
628 | heap_id = id(self)
|
629 | if heap_id in trav.seen:
|
630 | return hnode.AlreadySeen(heap_id)
|
631 | trav.seen[heap_id] = True
|
632 |
|
633 | out_node = NewRecord('stmt.Break')
|
634 | L = out_node.fields
|
635 |
|
636 | return out_node
|
637 |
|
638 | class stmt__Continue(stmt_t):
|
639 | _type_tag = 8
|
640 | __slots__ = ()
|
641 |
|
642 | def __init__(self, ):
|
643 | # type: () -> None
|
644 | pass
|
645 |
|
646 | def PrettyTree(self, do_abbrev, trav=None):
|
647 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
648 | trav = trav or TraversalState()
|
649 | heap_id = id(self)
|
650 | if heap_id in trav.seen:
|
651 | return hnode.AlreadySeen(heap_id)
|
652 | trav.seen[heap_id] = True
|
653 |
|
654 | out_node = NewRecord('stmt.Continue')
|
655 | L = out_node.fields
|
656 |
|
657 | return out_node
|
658 |
|
659 | class stmt__Try(stmt_t):
|
660 | _type_tag = 10
|
661 | __slots__ = ()
|
662 |
|
663 | def __init__(self, ):
|
664 | # type: () -> None
|
665 | pass
|
666 |
|
667 | def PrettyTree(self, do_abbrev, trav=None):
|
668 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
669 | trav = trav or TraversalState()
|
670 | heap_id = id(self)
|
671 | if heap_id in trav.seen:
|
672 | return hnode.AlreadySeen(heap_id)
|
673 | trav.seen[heap_id] = True
|
674 |
|
675 | out_node = NewRecord('stmt.Try')
|
676 | L = out_node.fields
|
677 |
|
678 | return out_node
|
679 |
|
680 | class stmt__With(stmt_t):
|
681 | _type_tag = 11
|
682 | __slots__ = ()
|
683 |
|
684 | def __init__(self, ):
|
685 | # type: () -> None
|
686 | pass
|
687 |
|
688 | def PrettyTree(self, do_abbrev, trav=None):
|
689 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
690 | trav = trav or TraversalState()
|
691 | heap_id = id(self)
|
692 | if heap_id in trav.seen:
|
693 | return hnode.AlreadySeen(heap_id)
|
694 | trav.seen[heap_id] = True
|
695 |
|
696 | out_node = NewRecord('stmt.With')
|
697 | L = out_node.fields
|
698 |
|
699 | return out_node
|
700 |
|
701 | class stmt(object):
|
702 | class VarDecl(stmt_t):
|
703 | _type_tag = 1
|
704 | __slots__ = ('keyword',)
|
705 |
|
706 | def __init__(self, keyword):
|
707 | # type: (Token) -> None
|
708 | self.keyword = keyword
|
709 |
|
710 | @staticmethod
|
711 | def CreateNull(alloc_lists=False):
|
712 | # type: () -> stmt.VarDecl
|
713 | return stmt.VarDecl(cast('Token', None))
|
714 |
|
715 | def PrettyTree(self, do_abbrev, trav=None):
|
716 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
717 | trav = trav or TraversalState()
|
718 | heap_id = id(self)
|
719 | if heap_id in trav.seen:
|
720 | return hnode.AlreadySeen(heap_id)
|
721 | trav.seen[heap_id] = True
|
722 |
|
723 | out_node = NewRecord('stmt.VarDecl')
|
724 | L = out_node.fields
|
725 |
|
726 | assert self.keyword is not None
|
727 | x0 = self.keyword.PrettyTree(do_abbrev, trav=trav)
|
728 | L.append(Field('keyword', x0))
|
729 |
|
730 | return out_node
|
731 |
|
732 | class PlaceMutation(stmt_t):
|
733 | _type_tag = 2
|
734 | __slots__ = ('keyword',)
|
735 |
|
736 | def __init__(self, keyword):
|
737 | # type: (Token) -> None
|
738 | self.keyword = keyword
|
739 |
|
740 | @staticmethod
|
741 | def CreateNull(alloc_lists=False):
|
742 | # type: () -> stmt.PlaceMutation
|
743 | return stmt.PlaceMutation(cast('Token', None))
|
744 |
|
745 | def PrettyTree(self, do_abbrev, trav=None):
|
746 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
747 | trav = trav or TraversalState()
|
748 | heap_id = id(self)
|
749 | if heap_id in trav.seen:
|
750 | return hnode.AlreadySeen(heap_id)
|
751 | trav.seen[heap_id] = True
|
752 |
|
753 | out_node = NewRecord('stmt.PlaceMutation')
|
754 | L = out_node.fields
|
755 |
|
756 | assert self.keyword is not None
|
757 | x0 = self.keyword.PrettyTree(do_abbrev, trav=trav)
|
758 | L.append(Field('keyword', x0))
|
759 |
|
760 | return out_node
|
761 |
|
762 | If = stmt__If()
|
763 |
|
764 | Switch = stmt__Switch()
|
765 |
|
766 | For = stmt__For()
|
767 |
|
768 | While = stmt__While()
|
769 |
|
770 | Break = stmt__Break()
|
771 |
|
772 | Continue = stmt__Continue()
|
773 |
|
774 | class Return(stmt_t):
|
775 | _type_tag = 9
|
776 | __slots__ = ('e',)
|
777 |
|
778 | def __init__(self, e):
|
779 | # type: (kexpr_t) -> None
|
780 | self.e = e
|
781 |
|
782 | @staticmethod
|
783 | def CreateNull(alloc_lists=False):
|
784 | # type: () -> stmt.Return
|
785 | return stmt.Return(cast('kexpr_t', None))
|
786 |
|
787 | def PrettyTree(self, do_abbrev, trav=None):
|
788 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
789 | trav = trav or TraversalState()
|
790 | heap_id = id(self)
|
791 | if heap_id in trav.seen:
|
792 | return hnode.AlreadySeen(heap_id)
|
793 | trav.seen[heap_id] = True
|
794 |
|
795 | out_node = NewRecord('stmt.Return')
|
796 | L = out_node.fields
|
797 |
|
798 | assert self.e is not None
|
799 | x0 = self.e.PrettyTree(do_abbrev, trav=trav)
|
800 | L.append(Field('e', x0))
|
801 |
|
802 | return out_node
|
803 |
|
804 | Try = stmt__Try()
|
805 |
|
806 | With = stmt__With()
|
807 |
|
808 | pass
|
809 |
|
810 | class class_def_t(pybase.SimpleObj):
|
811 | pass
|
812 |
|
813 | class class_def_e(object):
|
814 | Constructor = class_def_t(1)
|
815 | Destructor = class_def_t(2)
|
816 | Method = class_def_t(3)
|
817 | Field = class_def_t(4)
|
818 |
|
819 | _class_def_str = {
|
820 | 1: 'Constructor',
|
821 | 2: 'Destructor',
|
822 | 3: 'Method',
|
823 | 4: 'Field',
|
824 | }
|
825 |
|
826 | def class_def_str(val, dot=True):
|
827 | # type: (class_def_t, bool) -> str
|
828 | v = _class_def_str[val]
|
829 | if dot:
|
830 | return "class_def.%s" % v
|
831 | else:
|
832 | return v
|
833 |
|
834 | class mod_def_e(object):
|
835 | Global = 1
|
836 | Func = 2
|
837 | Class = 3
|
838 | Import = 4
|
839 | Include = 5
|
840 | Data = 6
|
841 | Enum = 7
|
842 |
|
843 | _mod_def_str = {
|
844 | 1: 'Global',
|
845 | 2: 'Func',
|
846 | 3: 'Class',
|
847 | 4: 'Import',
|
848 | 5: 'Include',
|
849 | 6: 'Data',
|
850 | 7: 'Enum',
|
851 | }
|
852 |
|
853 | def mod_def_str(tag, dot=True):
|
854 | # type: (int, bool) -> str
|
855 | v = _mod_def_str[tag]
|
856 | if dot:
|
857 | return "mod_def.%s" % v
|
858 | else:
|
859 | return v
|
860 |
|
861 | class mod_def_t(pybase.CompoundObj):
|
862 | def tag(self):
|
863 | # type: () -> int
|
864 | return self._type_tag
|
865 |
|
866 | class mod_def__Import(mod_def_t):
|
867 | _type_tag = 4
|
868 | __slots__ = ()
|
869 |
|
870 | def __init__(self, ):
|
871 | # type: () -> None
|
872 | pass
|
873 |
|
874 | def PrettyTree(self, do_abbrev, trav=None):
|
875 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
876 | trav = trav or TraversalState()
|
877 | heap_id = id(self)
|
878 | if heap_id in trav.seen:
|
879 | return hnode.AlreadySeen(heap_id)
|
880 | trav.seen[heap_id] = True
|
881 |
|
882 | out_node = NewRecord('mod_def.Import')
|
883 | L = out_node.fields
|
884 |
|
885 | return out_node
|
886 |
|
887 | class mod_def__Data(mod_def_t):
|
888 | _type_tag = 6
|
889 | __slots__ = ()
|
890 |
|
891 | def __init__(self, ):
|
892 | # type: () -> None
|
893 | pass
|
894 |
|
895 | def PrettyTree(self, do_abbrev, trav=None):
|
896 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
897 | trav = trav or TraversalState()
|
898 | heap_id = id(self)
|
899 | if heap_id in trav.seen:
|
900 | return hnode.AlreadySeen(heap_id)
|
901 | trav.seen[heap_id] = True
|
902 |
|
903 | out_node = NewRecord('mod_def.Data')
|
904 | L = out_node.fields
|
905 |
|
906 | return out_node
|
907 |
|
908 | class mod_def__Enum(mod_def_t):
|
909 | _type_tag = 7
|
910 | __slots__ = ()
|
911 |
|
912 | def __init__(self, ):
|
913 | # type: () -> None
|
914 | pass
|
915 |
|
916 | def PrettyTree(self, do_abbrev, trav=None):
|
917 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
918 | trav = trav or TraversalState()
|
919 | heap_id = id(self)
|
920 | if heap_id in trav.seen:
|
921 | return hnode.AlreadySeen(heap_id)
|
922 | trav.seen[heap_id] = True
|
923 |
|
924 | out_node = NewRecord('mod_def.Enum')
|
925 | L = out_node.fields
|
926 |
|
927 | return out_node
|
928 |
|
929 | class mod_def(object):
|
930 | class Global(mod_def_t):
|
931 | _type_tag = 1
|
932 | __slots__ = ('name_type',)
|
933 |
|
934 | def __init__(self, name_type):
|
935 | # type: (NameType) -> None
|
936 | self.name_type = name_type
|
937 |
|
938 | @staticmethod
|
939 | def CreateNull(alloc_lists=False):
|
940 | # type: () -> mod_def.Global
|
941 | return mod_def.Global(cast('NameType', None))
|
942 |
|
943 | def PrettyTree(self, do_abbrev, trav=None):
|
944 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
945 | trav = trav or TraversalState()
|
946 | heap_id = id(self)
|
947 | if heap_id in trav.seen:
|
948 | return hnode.AlreadySeen(heap_id)
|
949 | trav.seen[heap_id] = True
|
950 |
|
951 | out_node = NewRecord('mod_def.Global')
|
952 | L = out_node.fields
|
953 |
|
954 | assert self.name_type is not None
|
955 | x0 = self.name_type.PrettyTree(do_abbrev, trav=trav)
|
956 | L.append(Field('name_type', x0))
|
957 |
|
958 | return out_node
|
959 |
|
960 | class Func(mod_def_t):
|
961 | _type_tag = 2
|
962 | __slots__ = ('name', 'sig', 'statements')
|
963 |
|
964 | def __init__(self, name, sig, statements):
|
965 | # type: (str, Signature, List[stmt_t]) -> None
|
966 | self.name = name
|
967 | self.sig = sig
|
968 | self.statements = statements
|
969 |
|
970 | @staticmethod
|
971 | def CreateNull(alloc_lists=False):
|
972 | # type: () -> mod_def.Func
|
973 | return mod_def.Func('', cast('Signature', None), [] if alloc_lists else cast('List[stmt_t]', None))
|
974 |
|
975 | def PrettyTree(self, do_abbrev, trav=None):
|
976 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
977 | trav = trav or TraversalState()
|
978 | heap_id = id(self)
|
979 | if heap_id in trav.seen:
|
980 | return hnode.AlreadySeen(heap_id)
|
981 | trav.seen[heap_id] = True
|
982 |
|
983 | out_node = NewRecord('mod_def.Func')
|
984 | L = out_node.fields
|
985 |
|
986 | x0 = NewLeaf(self.name, color_e.StringConst)
|
987 | L.append(Field('name', x0))
|
988 |
|
989 | assert self.sig is not None
|
990 | x1 = self.sig.PrettyTree(do_abbrev, trav=trav)
|
991 | L.append(Field('sig', x1))
|
992 |
|
993 | if self.statements is not None: # List
|
994 | x2 = hnode.Array([])
|
995 | for i2 in self.statements:
|
996 | h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
|
997 | i2.PrettyTree(do_abbrev, trav=trav))
|
998 | x2.children.append(h)
|
999 | L.append(Field('statements', x2))
|
1000 |
|
1001 | return out_node
|
1002 |
|
1003 | class Class(mod_def_t):
|
1004 | _type_tag = 3
|
1005 | __slots__ = ('name', 'defs')
|
1006 |
|
1007 | def __init__(self, name, defs):
|
1008 | # type: (str, List[class_def_t]) -> None
|
1009 | self.name = name
|
1010 | self.defs = defs
|
1011 |
|
1012 | @staticmethod
|
1013 | def CreateNull(alloc_lists=False):
|
1014 | # type: () -> mod_def.Class
|
1015 | return mod_def.Class('', [] if alloc_lists else cast('List[class_def_t]', None))
|
1016 |
|
1017 | def PrettyTree(self, do_abbrev, trav=None):
|
1018 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1019 | trav = trav or TraversalState()
|
1020 | heap_id = id(self)
|
1021 | if heap_id in trav.seen:
|
1022 | return hnode.AlreadySeen(heap_id)
|
1023 | trav.seen[heap_id] = True
|
1024 |
|
1025 | out_node = NewRecord('mod_def.Class')
|
1026 | L = out_node.fields
|
1027 |
|
1028 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1029 | L.append(Field('name', x0))
|
1030 |
|
1031 | if self.defs is not None: # List
|
1032 | x1 = hnode.Array([])
|
1033 | for i1 in self.defs:
|
1034 | x1.children.append(hnode.Leaf(class_def_str(i1), color_e.TypeName))
|
1035 | L.append(Field('defs', x1))
|
1036 |
|
1037 | return out_node
|
1038 |
|
1039 | Import = mod_def__Import()
|
1040 |
|
1041 | class Include(mod_def_t):
|
1042 | _type_tag = 5
|
1043 | __slots__ = ('path',)
|
1044 |
|
1045 | def __init__(self, path):
|
1046 | # type: (str) -> None
|
1047 | self.path = path
|
1048 |
|
1049 | @staticmethod
|
1050 | def CreateNull(alloc_lists=False):
|
1051 | # type: () -> mod_def.Include
|
1052 | return mod_def.Include('')
|
1053 |
|
1054 | def PrettyTree(self, do_abbrev, trav=None):
|
1055 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1056 | trav = trav or TraversalState()
|
1057 | heap_id = id(self)
|
1058 | if heap_id in trav.seen:
|
1059 | return hnode.AlreadySeen(heap_id)
|
1060 | trav.seen[heap_id] = True
|
1061 |
|
1062 | out_node = NewRecord('mod_def.Include')
|
1063 | L = out_node.fields
|
1064 |
|
1065 | x0 = NewLeaf(self.path, color_e.StringConst)
|
1066 | L.append(Field('path', x0))
|
1067 |
|
1068 | return out_node
|
1069 |
|
1070 | Data = mod_def__Data()
|
1071 |
|
1072 | Enum = mod_def__Enum()
|
1073 |
|
1074 | pass
|
1075 |
|
1076 | class Token(pybase.CompoundObj):
|
1077 | _type_tag = 64
|
1078 | __slots__ = ('path', 'chunk', 'start', 'length')
|
1079 |
|
1080 | def __init__(self, path, chunk, start, length):
|
1081 | # type: (str, str, int, int) -> None
|
1082 | self.path = path
|
1083 | self.chunk = chunk
|
1084 | self.start = start
|
1085 | self.length = length
|
1086 |
|
1087 | @staticmethod
|
1088 | def CreateNull(alloc_lists=False):
|
1089 | # type: () -> Token
|
1090 | return Token('', '', -1, -1)
|
1091 |
|
1092 | def PrettyTree(self, do_abbrev, trav=None):
|
1093 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1094 | trav = trav or TraversalState()
|
1095 | heap_id = id(self)
|
1096 | if heap_id in trav.seen:
|
1097 | return hnode.AlreadySeen(heap_id)
|
1098 | trav.seen[heap_id] = True
|
1099 |
|
1100 | out_node = NewRecord('Token')
|
1101 | L = out_node.fields
|
1102 |
|
1103 | x0 = NewLeaf(self.path, color_e.StringConst)
|
1104 | L.append(Field('path', x0))
|
1105 |
|
1106 | x1 = NewLeaf(self.chunk, color_e.StringConst)
|
1107 | L.append(Field('chunk', x1))
|
1108 |
|
1109 | x2 = hnode.Leaf(str(self.start), color_e.OtherConst)
|
1110 | L.append(Field('start', x2))
|
1111 |
|
1112 | x3 = hnode.Leaf(str(self.length), color_e.OtherConst)
|
1113 | L.append(Field('length', x3))
|
1114 |
|
1115 | return out_node
|
1116 |
|
1117 | class Bool(kexpr_t):
|
1118 | _type_tag = 65
|
1119 | __slots__ = ('b', 'loc')
|
1120 |
|
1121 | def __init__(self, b, loc):
|
1122 | # type: (bool, Token) -> None
|
1123 | self.b = b
|
1124 | self.loc = loc
|
1125 |
|
1126 | @staticmethod
|
1127 | def CreateNull(alloc_lists=False):
|
1128 | # type: () -> Bool
|
1129 | return Bool(False, cast('Token', None))
|
1130 |
|
1131 | def PrettyTree(self, do_abbrev, trav=None):
|
1132 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1133 | trav = trav or TraversalState()
|
1134 | heap_id = id(self)
|
1135 | if heap_id in trav.seen:
|
1136 | return hnode.AlreadySeen(heap_id)
|
1137 | trav.seen[heap_id] = True
|
1138 |
|
1139 | out_node = NewRecord('Bool')
|
1140 | L = out_node.fields
|
1141 |
|
1142 | x0 = hnode.Leaf('T' if self.b else 'F', color_e.OtherConst)
|
1143 | L.append(Field('b', x0))
|
1144 |
|
1145 | assert self.loc is not None
|
1146 | x1 = self.loc.PrettyTree(do_abbrev, trav=trav)
|
1147 | L.append(Field('loc', x1))
|
1148 |
|
1149 | return out_node
|
1150 |
|
1151 | class Int(kexpr_t):
|
1152 | _type_tag = 66
|
1153 | __slots__ = ('i', 'loc')
|
1154 |
|
1155 | def __init__(self, i, loc):
|
1156 | # type: (int, Token) -> None
|
1157 | self.i = i
|
1158 | self.loc = loc
|
1159 |
|
1160 | @staticmethod
|
1161 | def CreateNull(alloc_lists=False):
|
1162 | # type: () -> Int
|
1163 | return Int(-1, cast('Token', None))
|
1164 |
|
1165 | def PrettyTree(self, do_abbrev, trav=None):
|
1166 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1167 | trav = trav or TraversalState()
|
1168 | heap_id = id(self)
|
1169 | if heap_id in trav.seen:
|
1170 | return hnode.AlreadySeen(heap_id)
|
1171 | trav.seen[heap_id] = True
|
1172 |
|
1173 | out_node = NewRecord('Int')
|
1174 | L = out_node.fields
|
1175 |
|
1176 | x0 = hnode.Leaf(str(self.i), color_e.OtherConst)
|
1177 | L.append(Field('i', x0))
|
1178 |
|
1179 | assert self.loc is not None
|
1180 | x1 = self.loc.PrettyTree(do_abbrev, trav=trav)
|
1181 | L.append(Field('loc', x1))
|
1182 |
|
1183 | return out_node
|
1184 |
|
1185 | class Str(kexpr_t):
|
1186 | _type_tag = 67
|
1187 | __slots__ = ('s', 'loc')
|
1188 |
|
1189 | def __init__(self, s, loc):
|
1190 | # type: (str, Token) -> None
|
1191 | self.s = s
|
1192 | self.loc = loc
|
1193 |
|
1194 | @staticmethod
|
1195 | def CreateNull(alloc_lists=False):
|
1196 | # type: () -> Str
|
1197 | return Str('', cast('Token', None))
|
1198 |
|
1199 | def PrettyTree(self, do_abbrev, trav=None):
|
1200 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1201 | trav = trav or TraversalState()
|
1202 | heap_id = id(self)
|
1203 | if heap_id in trav.seen:
|
1204 | return hnode.AlreadySeen(heap_id)
|
1205 | trav.seen[heap_id] = True
|
1206 |
|
1207 | out_node = NewRecord('Str')
|
1208 | L = out_node.fields
|
1209 |
|
1210 | x0 = NewLeaf(self.s, color_e.StringConst)
|
1211 | L.append(Field('s', x0))
|
1212 |
|
1213 | assert self.loc is not None
|
1214 | x1 = self.loc.PrettyTree(do_abbrev, trav=trav)
|
1215 | L.append(Field('loc', x1))
|
1216 |
|
1217 | return out_node
|
1218 |
|
1219 | class MultiStr(kexpr_t):
|
1220 | _type_tag = 68
|
1221 | __slots__ = ('lines',)
|
1222 |
|
1223 | def __init__(self, lines):
|
1224 | # type: (List[Token]) -> None
|
1225 | self.lines = lines
|
1226 |
|
1227 | @staticmethod
|
1228 | def CreateNull(alloc_lists=False):
|
1229 | # type: () -> MultiStr
|
1230 | return MultiStr([] if alloc_lists else cast('List[Token]', None))
|
1231 |
|
1232 | def PrettyTree(self, do_abbrev, trav=None):
|
1233 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1234 | trav = trav or TraversalState()
|
1235 | heap_id = id(self)
|
1236 | if heap_id in trav.seen:
|
1237 | return hnode.AlreadySeen(heap_id)
|
1238 | trav.seen[heap_id] = True
|
1239 |
|
1240 | out_node = NewRecord('MultiStr')
|
1241 | L = out_node.fields
|
1242 |
|
1243 | if self.lines is not None: # List
|
1244 | x0 = hnode.Array([])
|
1245 | for i0 in self.lines:
|
1246 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
1247 | i0.PrettyTree(do_abbrev, trav=trav))
|
1248 | x0.children.append(h)
|
1249 | L.append(Field('lines', x0))
|
1250 |
|
1251 | return out_node
|
1252 |
|
1253 | class Field_(pybase.CompoundObj):
|
1254 | _type_tag = 69
|
1255 | __slots__ = ('name', 'typ')
|
1256 |
|
1257 | def __init__(self, name, typ):
|
1258 | # type: (str, ktype_t) -> None
|
1259 | self.name = name
|
1260 | self.typ = typ
|
1261 |
|
1262 | @staticmethod
|
1263 | def CreateNull(alloc_lists=False):
|
1264 | # type: () -> Field_
|
1265 | return Field_('', cast('ktype_t', None))
|
1266 |
|
1267 | def PrettyTree(self, do_abbrev, trav=None):
|
1268 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1269 | trav = trav or TraversalState()
|
1270 | heap_id = id(self)
|
1271 | if heap_id in trav.seen:
|
1272 | return hnode.AlreadySeen(heap_id)
|
1273 | trav.seen[heap_id] = True
|
1274 |
|
1275 | out_node = NewRecord('Field_')
|
1276 | L = out_node.fields
|
1277 |
|
1278 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1279 | L.append(Field('name', x0))
|
1280 |
|
1281 | assert self.typ is not None
|
1282 | x1 = self.typ.PrettyTree(do_abbrev, trav=trav)
|
1283 | L.append(Field('typ', x1))
|
1284 |
|
1285 | return out_node
|
1286 |
|
1287 | class variant(pybase.CompoundObj):
|
1288 | _type_tag = 70
|
1289 | __slots__ = ('fields',)
|
1290 |
|
1291 | def __init__(self, fields):
|
1292 | # type: (List[Field_]) -> None
|
1293 | self.fields = fields
|
1294 |
|
1295 | @staticmethod
|
1296 | def CreateNull(alloc_lists=False):
|
1297 | # type: () -> variant
|
1298 | return variant([] if alloc_lists else cast('List[Field_]', None))
|
1299 |
|
1300 | def PrettyTree(self, do_abbrev, trav=None):
|
1301 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1302 | trav = trav or TraversalState()
|
1303 | heap_id = id(self)
|
1304 | if heap_id in trav.seen:
|
1305 | return hnode.AlreadySeen(heap_id)
|
1306 | trav.seen[heap_id] = True
|
1307 |
|
1308 | out_node = NewRecord('variant')
|
1309 | L = out_node.fields
|
1310 |
|
1311 | if self.fields is not None: # List
|
1312 | x0 = hnode.Array([])
|
1313 | for i0 in self.fields:
|
1314 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
1315 | i0.PrettyTree(do_abbrev, trav=trav))
|
1316 | x0.children.append(h)
|
1317 | L.append(Field('fields', x0))
|
1318 |
|
1319 | return out_node
|
1320 |
|
1321 | class NameType(pybase.CompoundObj):
|
1322 | _type_tag = 71
|
1323 | __slots__ = ('name', 'typ')
|
1324 |
|
1325 | def __init__(self, name, typ):
|
1326 | # type: (str, ktype_t) -> None
|
1327 | self.name = name
|
1328 | self.typ = typ
|
1329 |
|
1330 | @staticmethod
|
1331 | def CreateNull(alloc_lists=False):
|
1332 | # type: () -> NameType
|
1333 | return NameType('', cast('ktype_t', None))
|
1334 |
|
1335 | def PrettyTree(self, do_abbrev, trav=None):
|
1336 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1337 | trav = trav or TraversalState()
|
1338 | heap_id = id(self)
|
1339 | if heap_id in trav.seen:
|
1340 | return hnode.AlreadySeen(heap_id)
|
1341 | trav.seen[heap_id] = True
|
1342 |
|
1343 | out_node = NewRecord('NameType')
|
1344 | L = out_node.fields
|
1345 |
|
1346 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1347 | L.append(Field('name', x0))
|
1348 |
|
1349 | assert self.typ is not None
|
1350 | x1 = self.typ.PrettyTree(do_abbrev, trav=trav)
|
1351 | L.append(Field('typ', x1))
|
1352 |
|
1353 | return out_node
|
1354 |
|
1355 | class Signature(pybase.CompoundObj):
|
1356 | _type_tag = 72
|
1357 | __slots__ = ('params', 'return_type')
|
1358 |
|
1359 | def __init__(self, params, return_type):
|
1360 | # type: (List[NameType], ktype_t) -> None
|
1361 | self.params = params
|
1362 | self.return_type = return_type
|
1363 |
|
1364 | @staticmethod
|
1365 | def CreateNull(alloc_lists=False):
|
1366 | # type: () -> Signature
|
1367 | return Signature([] if alloc_lists else cast('List[NameType]', None), cast('ktype_t', None))
|
1368 |
|
1369 | def PrettyTree(self, do_abbrev, trav=None):
|
1370 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1371 | trav = trav or TraversalState()
|
1372 | heap_id = id(self)
|
1373 | if heap_id in trav.seen:
|
1374 | return hnode.AlreadySeen(heap_id)
|
1375 | trav.seen[heap_id] = True
|
1376 |
|
1377 | out_node = NewRecord('Signature')
|
1378 | L = out_node.fields
|
1379 |
|
1380 | if self.params is not None: # List
|
1381 | x0 = hnode.Array([])
|
1382 | for i0 in self.params:
|
1383 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
1384 | i0.PrettyTree(do_abbrev, trav=trav))
|
1385 | x0.children.append(h)
|
1386 | L.append(Field('params', x0))
|
1387 |
|
1388 | assert self.return_type is not None
|
1389 | x1 = self.return_type.PrettyTree(do_abbrev, trav=trav)
|
1390 | L.append(Field('return_type', x1))
|
1391 |
|
1392 | return out_node
|
1393 |
|
1394 | class Module(pybase.CompoundObj):
|
1395 | _type_tag = 73
|
1396 | __slots__ = ('name', 'defs')
|
1397 |
|
1398 | def __init__(self, name, defs):
|
1399 | # type: (str, List[mod_def_t]) -> None
|
1400 | self.name = name
|
1401 | self.defs = defs
|
1402 |
|
1403 | @staticmethod
|
1404 | def CreateNull(alloc_lists=False):
|
1405 | # type: () -> Module
|
1406 | return Module('', [] if alloc_lists else cast('List[mod_def_t]', None))
|
1407 |
|
1408 | def PrettyTree(self, do_abbrev, trav=None):
|
1409 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1410 | trav = trav or TraversalState()
|
1411 | heap_id = id(self)
|
1412 | if heap_id in trav.seen:
|
1413 | return hnode.AlreadySeen(heap_id)
|
1414 | trav.seen[heap_id] = True
|
1415 |
|
1416 | out_node = NewRecord('Module')
|
1417 | L = out_node.fields
|
1418 |
|
1419 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1420 | L.append(Field('name', x0))
|
1421 |
|
1422 | if self.defs is not None: # List
|
1423 | x1 = hnode.Array([])
|
1424 | for i1 in self.defs:
|
1425 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
1426 | i1.PrettyTree(do_abbrev, trav=trav))
|
1427 | x1.children.append(h)
|
1428 | L.append(Field('defs', x1))
|
1429 |
|
1430 | return out_node
|
1431 |
|
1432 | class Program(pybase.CompoundObj):
|
1433 | _type_tag = 74
|
1434 | __slots__ = ('main_module', 'modules')
|
1435 |
|
1436 | def __init__(self, main_module, modules):
|
1437 | # type: (str, List[Module]) -> None
|
1438 | self.main_module = main_module
|
1439 | self.modules = modules
|
1440 |
|
1441 | @staticmethod
|
1442 | def CreateNull(alloc_lists=False):
|
1443 | # type: () -> Program
|
1444 | return Program('', [] if alloc_lists else cast('List[Module]', None))
|
1445 |
|
1446 | def PrettyTree(self, do_abbrev, trav=None):
|
1447 | # type: (bool, Optional[TraversalState]) -> hnode_t
|
1448 | trav = trav or TraversalState()
|
1449 | heap_id = id(self)
|
1450 | if heap_id in trav.seen:
|
1451 | return hnode.AlreadySeen(heap_id)
|
1452 | trav.seen[heap_id] = True
|
1453 |
|
1454 | out_node = NewRecord('Program')
|
1455 | L = out_node.fields
|
1456 |
|
1457 | x0 = NewLeaf(self.main_module, color_e.StringConst)
|
1458 | L.append(Field('main_module', x0))
|
1459 |
|
1460 | if self.modules is not None: # List
|
1461 | x1 = hnode.Array([])
|
1462 | for i1 in self.modules:
|
1463 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
1464 | i1.PrettyTree(do_abbrev, trav=trav))
|
1465 | x1.children.append(h)
|
1466 | L.append(Field('modules', x1))
|
1467 |
|
1468 | return out_node
|
1469 |
|