1 | from asdl import pybase
|
2 | from mycpp import mops
|
3 | from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
|
4 |
|
5 |
|
6 | from asdl import runtime # For runtime.NO_SPID
|
7 | from asdl.runtime import NewRecord, NewLeaf, TraversalState
|
8 | from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
|
9 |
|
10 | class op_t(pybase.SimpleObj):
|
11 | pass
|
12 |
|
13 | class op_e(object):
|
14 | Plus = op_t(1)
|
15 | Minus = op_t(2)
|
16 |
|
17 | _op_str = {
|
18 | 1: 'op.Plus',
|
19 | 2: 'op.Minus',
|
20 | }
|
21 |
|
22 | def op_str(val):
|
23 | # type: (op_t) -> str
|
24 | return _op_str[val]
|
25 |
|
26 | class kexpr_e(object):
|
27 | Bool = 65
|
28 | Int = 66
|
29 | Str = 67
|
30 | MultiStr = 68
|
31 | Unary = 5
|
32 | Binary = 6
|
33 | Ternary = 7
|
34 | Call = 8
|
35 |
|
36 | _kexpr_str = {
|
37 | 5: 'Unary',
|
38 | 6: 'Binary',
|
39 | 7: 'Ternary',
|
40 | 8: 'Call',
|
41 | 65: 'Bool',
|
42 | 66: 'Int',
|
43 | 67: 'Str',
|
44 | 68: 'MultiStr',
|
45 | }
|
46 |
|
47 | def kexpr_str(tag, dot=True):
|
48 | # type: (int, bool) -> str
|
49 | v = _kexpr_str[tag]
|
50 | if dot:
|
51 | return "kexpr.%s" % v
|
52 | else:
|
53 | return v
|
54 |
|
55 | class kexpr_t(pybase.CompoundObj):
|
56 | def tag(self):
|
57 | # type: () -> int
|
58 | return self._type_tag
|
59 | pass
|
60 |
|
61 | class kexpr(object):
|
62 | class Unary(kexpr_t):
|
63 | _type_tag = 5
|
64 | __slots__ = ('op', 'child')
|
65 |
|
66 | def __init__(self, op, child):
|
67 | # type: (Token, kexpr_t) -> None
|
68 | self.op = op
|
69 | self.child = child
|
70 |
|
71 | @staticmethod
|
72 | def CreateNull(alloc_lists=False):
|
73 | # type: () -> kexpr.Unary
|
74 | return kexpr.Unary(cast(Token, None), cast(kexpr_t, None))
|
75 |
|
76 | def PrettyTree(self, trav=None):
|
77 | # type: (Optional[TraversalState]) -> hnode_t
|
78 | trav = trav or TraversalState()
|
79 | heap_id = id(self)
|
80 | if heap_id in trav.seen:
|
81 | return hnode.AlreadySeen(heap_id)
|
82 | trav.seen[heap_id] = True
|
83 | out_node = NewRecord('kexpr.Unary')
|
84 | L = out_node.fields
|
85 |
|
86 | assert self.op is not None
|
87 | x0 = self.op.PrettyTree(trav=trav)
|
88 | L.append(Field('op', x0))
|
89 |
|
90 | assert self.child is not None
|
91 | x1 = self.child.PrettyTree(trav=trav)
|
92 | L.append(Field('child', x1))
|
93 |
|
94 | return out_node
|
95 |
|
96 | def _AbbreviatedTree(self, trav=None):
|
97 | # type: (Optional[TraversalState]) -> hnode_t
|
98 | trav = trav or TraversalState()
|
99 | heap_id = id(self)
|
100 | if heap_id in trav.seen:
|
101 | return hnode.AlreadySeen(heap_id)
|
102 | trav.seen[heap_id] = True
|
103 | out_node = NewRecord('kexpr.Unary')
|
104 | L = out_node.fields
|
105 | assert self.op is not None
|
106 | x0 = self.op.AbbreviatedTree(trav=trav)
|
107 | L.append(Field('op', x0))
|
108 |
|
109 | assert self.child is not None
|
110 | x1 = self.child.AbbreviatedTree(trav=trav)
|
111 | L.append(Field('child', x1))
|
112 |
|
113 | return out_node
|
114 |
|
115 | def AbbreviatedTree(self, trav=None):
|
116 | # type: (Optional[TraversalState]) -> hnode_t
|
117 | return self._AbbreviatedTree(trav=trav)
|
118 |
|
119 | class Binary(kexpr_t):
|
120 | _type_tag = 6
|
121 | __slots__ = ('op', 'left', 'right')
|
122 |
|
123 | def __init__(self, op, left, right):
|
124 | # type: (Token, kexpr_t, kexpr_t) -> None
|
125 | self.op = op
|
126 | self.left = left
|
127 | self.right = right
|
128 |
|
129 | @staticmethod
|
130 | def CreateNull(alloc_lists=False):
|
131 | # type: () -> kexpr.Binary
|
132 | return kexpr.Binary(cast(Token, None), cast(kexpr_t, None), cast(kexpr_t, None))
|
133 |
|
134 | def PrettyTree(self, trav=None):
|
135 | # type: (Optional[TraversalState]) -> hnode_t
|
136 | trav = trav or TraversalState()
|
137 | heap_id = id(self)
|
138 | if heap_id in trav.seen:
|
139 | return hnode.AlreadySeen(heap_id)
|
140 | trav.seen[heap_id] = True
|
141 | out_node = NewRecord('kexpr.Binary')
|
142 | L = out_node.fields
|
143 |
|
144 | assert self.op is not None
|
145 | x0 = self.op.PrettyTree(trav=trav)
|
146 | L.append(Field('op', x0))
|
147 |
|
148 | assert self.left is not None
|
149 | x1 = self.left.PrettyTree(trav=trav)
|
150 | L.append(Field('left', x1))
|
151 |
|
152 | assert self.right is not None
|
153 | x2 = self.right.PrettyTree(trav=trav)
|
154 | L.append(Field('right', x2))
|
155 |
|
156 | return out_node
|
157 |
|
158 | def _AbbreviatedTree(self, trav=None):
|
159 | # type: (Optional[TraversalState]) -> hnode_t
|
160 | trav = trav or TraversalState()
|
161 | heap_id = id(self)
|
162 | if heap_id in trav.seen:
|
163 | return hnode.AlreadySeen(heap_id)
|
164 | trav.seen[heap_id] = True
|
165 | out_node = NewRecord('kexpr.Binary')
|
166 | L = out_node.fields
|
167 | assert self.op is not None
|
168 | x0 = self.op.AbbreviatedTree(trav=trav)
|
169 | L.append(Field('op', x0))
|
170 |
|
171 | assert self.left is not None
|
172 | x1 = self.left.AbbreviatedTree(trav=trav)
|
173 | L.append(Field('left', x1))
|
174 |
|
175 | assert self.right is not None
|
176 | x2 = self.right.AbbreviatedTree(trav=trav)
|
177 | L.append(Field('right', x2))
|
178 |
|
179 | return out_node
|
180 |
|
181 | def AbbreviatedTree(self, trav=None):
|
182 | # type: (Optional[TraversalState]) -> hnode_t
|
183 | return self._AbbreviatedTree(trav=trav)
|
184 |
|
185 | class Ternary(kexpr_t):
|
186 | _type_tag = 7
|
187 | __slots__ = ('op', 'left', 'cond', 'right')
|
188 |
|
189 | def __init__(self, op, left, cond, right):
|
190 | # type: (Token, kexpr_t, kexpr_t, kexpr_t) -> None
|
191 | self.op = op
|
192 | self.left = left
|
193 | self.cond = cond
|
194 | self.right = right
|
195 |
|
196 | @staticmethod
|
197 | def CreateNull(alloc_lists=False):
|
198 | # type: () -> kexpr.Ternary
|
199 | return kexpr.Ternary(cast(Token, None), cast(kexpr_t, None), cast(kexpr_t, None), cast(kexpr_t, None))
|
200 |
|
201 | def PrettyTree(self, trav=None):
|
202 | # type: (Optional[TraversalState]) -> hnode_t
|
203 | trav = trav or TraversalState()
|
204 | heap_id = id(self)
|
205 | if heap_id in trav.seen:
|
206 | return hnode.AlreadySeen(heap_id)
|
207 | trav.seen[heap_id] = True
|
208 | out_node = NewRecord('kexpr.Ternary')
|
209 | L = out_node.fields
|
210 |
|
211 | assert self.op is not None
|
212 | x0 = self.op.PrettyTree(trav=trav)
|
213 | L.append(Field('op', x0))
|
214 |
|
215 | assert self.left is not None
|
216 | x1 = self.left.PrettyTree(trav=trav)
|
217 | L.append(Field('left', x1))
|
218 |
|
219 | assert self.cond is not None
|
220 | x2 = self.cond.PrettyTree(trav=trav)
|
221 | L.append(Field('cond', x2))
|
222 |
|
223 | assert self.right is not None
|
224 | x3 = self.right.PrettyTree(trav=trav)
|
225 | L.append(Field('right', x3))
|
226 |
|
227 | return out_node
|
228 |
|
229 | def _AbbreviatedTree(self, trav=None):
|
230 | # type: (Optional[TraversalState]) -> hnode_t
|
231 | trav = trav or TraversalState()
|
232 | heap_id = id(self)
|
233 | if heap_id in trav.seen:
|
234 | return hnode.AlreadySeen(heap_id)
|
235 | trav.seen[heap_id] = True
|
236 | out_node = NewRecord('kexpr.Ternary')
|
237 | L = out_node.fields
|
238 | assert self.op is not None
|
239 | x0 = self.op.AbbreviatedTree(trav=trav)
|
240 | L.append(Field('op', x0))
|
241 |
|
242 | assert self.left is not None
|
243 | x1 = self.left.AbbreviatedTree(trav=trav)
|
244 | L.append(Field('left', x1))
|
245 |
|
246 | assert self.cond is not None
|
247 | x2 = self.cond.AbbreviatedTree(trav=trav)
|
248 | L.append(Field('cond', x2))
|
249 |
|
250 | assert self.right is not None
|
251 | x3 = self.right.AbbreviatedTree(trav=trav)
|
252 | L.append(Field('right', x3))
|
253 |
|
254 | return out_node
|
255 |
|
256 | def AbbreviatedTree(self, trav=None):
|
257 | # type: (Optional[TraversalState]) -> hnode_t
|
258 | return self._AbbreviatedTree(trav=trav)
|
259 |
|
260 | class Call(kexpr_t):
|
261 | _type_tag = 8
|
262 | __slots__ = ('f', 'args')
|
263 |
|
264 | def __init__(self, f, args):
|
265 | # type: (kexpr_t, List[kexpr_t]) -> None
|
266 | self.f = f
|
267 | self.args = args
|
268 |
|
269 | @staticmethod
|
270 | def CreateNull(alloc_lists=False):
|
271 | # type: () -> kexpr.Call
|
272 | return kexpr.Call(cast(kexpr_t, None), [] if alloc_lists else cast('List[kexpr_t]', None))
|
273 |
|
274 | def PrettyTree(self, trav=None):
|
275 | # type: (Optional[TraversalState]) -> hnode_t
|
276 | trav = trav or TraversalState()
|
277 | heap_id = id(self)
|
278 | if heap_id in trav.seen:
|
279 | return hnode.AlreadySeen(heap_id)
|
280 | trav.seen[heap_id] = True
|
281 | out_node = NewRecord('kexpr.Call')
|
282 | L = out_node.fields
|
283 |
|
284 | assert self.f is not None
|
285 | x0 = self.f.PrettyTree(trav=trav)
|
286 | L.append(Field('f', x0))
|
287 |
|
288 | if self.args is not None: # List
|
289 | x1 = hnode.Array([])
|
290 | for i1 in self.args:
|
291 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
292 | i1.PrettyTree(trav=trav))
|
293 | x1.children.append(h)
|
294 | L.append(Field('args', x1))
|
295 |
|
296 | return out_node
|
297 |
|
298 | def _AbbreviatedTree(self, trav=None):
|
299 | # type: (Optional[TraversalState]) -> hnode_t
|
300 | trav = trav or TraversalState()
|
301 | heap_id = id(self)
|
302 | if heap_id in trav.seen:
|
303 | return hnode.AlreadySeen(heap_id)
|
304 | trav.seen[heap_id] = True
|
305 | out_node = NewRecord('kexpr.Call')
|
306 | L = out_node.fields
|
307 | assert self.f is not None
|
308 | x0 = self.f.AbbreviatedTree(trav=trav)
|
309 | L.append(Field('f', x0))
|
310 |
|
311 | if self.args is not None: # List
|
312 | x1 = hnode.Array([])
|
313 | for i1 in self.args:
|
314 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
315 | i1.AbbreviatedTree(trav=trav))
|
316 | x1.children.append(h)
|
317 | L.append(Field('args', x1))
|
318 |
|
319 | return out_node
|
320 |
|
321 | def AbbreviatedTree(self, trav=None):
|
322 | # type: (Optional[TraversalState]) -> hnode_t
|
323 | return self._AbbreviatedTree(trav=trav)
|
324 |
|
325 | pass
|
326 |
|
327 | class ktype_e(object):
|
328 | Bool = 1
|
329 | Int = 2
|
330 | Str = 3
|
331 | List = 4
|
332 | Dict = 5
|
333 | Class = 6
|
334 | Data = 7
|
335 | Enum = 8
|
336 |
|
337 | _ktype_str = {
|
338 | 1: 'Bool',
|
339 | 2: 'Int',
|
340 | 3: 'Str',
|
341 | 4: 'List',
|
342 | 5: 'Dict',
|
343 | 6: 'Class',
|
344 | 7: 'Data',
|
345 | 8: 'Enum',
|
346 | }
|
347 |
|
348 | def ktype_str(tag, dot=True):
|
349 | # type: (int, bool) -> str
|
350 | v = _ktype_str[tag]
|
351 | if dot:
|
352 | return "ktype.%s" % v
|
353 | else:
|
354 | return v
|
355 |
|
356 | class ktype_t(pybase.CompoundObj):
|
357 | def tag(self):
|
358 | # type: () -> int
|
359 | return self._type_tag
|
360 | pass
|
361 |
|
362 | class ktype__Bool(ktype_t):
|
363 | _type_tag = 1
|
364 | __slots__ = ()
|
365 |
|
366 | def __init__(self, ):
|
367 | # type: () -> None
|
368 | pass
|
369 |
|
370 | def PrettyTree(self, trav=None):
|
371 | # type: (Optional[TraversalState]) -> hnode_t
|
372 | trav = trav or TraversalState()
|
373 | heap_id = id(self)
|
374 | if heap_id in trav.seen:
|
375 | return hnode.AlreadySeen(heap_id)
|
376 | trav.seen[heap_id] = True
|
377 | out_node = NewRecord('ktype__Bool')
|
378 | L = out_node.fields
|
379 |
|
380 | return out_node
|
381 |
|
382 | def _AbbreviatedTree(self, trav=None):
|
383 | # type: (Optional[TraversalState]) -> hnode_t
|
384 | trav = trav or TraversalState()
|
385 | heap_id = id(self)
|
386 | if heap_id in trav.seen:
|
387 | return hnode.AlreadySeen(heap_id)
|
388 | trav.seen[heap_id] = True
|
389 | out_node = NewRecord('ktype__Bool')
|
390 | L = out_node.fields
|
391 | return out_node
|
392 |
|
393 | def AbbreviatedTree(self, trav=None):
|
394 | # type: (Optional[TraversalState]) -> hnode_t
|
395 | return self._AbbreviatedTree(trav=trav)
|
396 |
|
397 | class ktype__Int(ktype_t):
|
398 | _type_tag = 2
|
399 | __slots__ = ()
|
400 |
|
401 | def __init__(self, ):
|
402 | # type: () -> None
|
403 | pass
|
404 |
|
405 | def PrettyTree(self, trav=None):
|
406 | # type: (Optional[TraversalState]) -> hnode_t
|
407 | trav = trav or TraversalState()
|
408 | heap_id = id(self)
|
409 | if heap_id in trav.seen:
|
410 | return hnode.AlreadySeen(heap_id)
|
411 | trav.seen[heap_id] = True
|
412 | out_node = NewRecord('ktype__Int')
|
413 | L = out_node.fields
|
414 |
|
415 | return out_node
|
416 |
|
417 | def _AbbreviatedTree(self, trav=None):
|
418 | # type: (Optional[TraversalState]) -> hnode_t
|
419 | trav = trav or TraversalState()
|
420 | heap_id = id(self)
|
421 | if heap_id in trav.seen:
|
422 | return hnode.AlreadySeen(heap_id)
|
423 | trav.seen[heap_id] = True
|
424 | out_node = NewRecord('ktype__Int')
|
425 | L = out_node.fields
|
426 | return out_node
|
427 |
|
428 | def AbbreviatedTree(self, trav=None):
|
429 | # type: (Optional[TraversalState]) -> hnode_t
|
430 | return self._AbbreviatedTree(trav=trav)
|
431 |
|
432 | class ktype__Str(ktype_t):
|
433 | _type_tag = 3
|
434 | __slots__ = ()
|
435 |
|
436 | def __init__(self, ):
|
437 | # type: () -> None
|
438 | pass
|
439 |
|
440 | def PrettyTree(self, trav=None):
|
441 | # type: (Optional[TraversalState]) -> hnode_t
|
442 | trav = trav or TraversalState()
|
443 | heap_id = id(self)
|
444 | if heap_id in trav.seen:
|
445 | return hnode.AlreadySeen(heap_id)
|
446 | trav.seen[heap_id] = True
|
447 | out_node = NewRecord('ktype__Str')
|
448 | L = out_node.fields
|
449 |
|
450 | return out_node
|
451 |
|
452 | def _AbbreviatedTree(self, trav=None):
|
453 | # type: (Optional[TraversalState]) -> hnode_t
|
454 | trav = trav or TraversalState()
|
455 | heap_id = id(self)
|
456 | if heap_id in trav.seen:
|
457 | return hnode.AlreadySeen(heap_id)
|
458 | trav.seen[heap_id] = True
|
459 | out_node = NewRecord('ktype__Str')
|
460 | L = out_node.fields
|
461 | return out_node
|
462 |
|
463 | def AbbreviatedTree(self, trav=None):
|
464 | # type: (Optional[TraversalState]) -> hnode_t
|
465 | return self._AbbreviatedTree(trav=trav)
|
466 |
|
467 | class ktype(object):
|
468 | Bool = ktype__Bool()
|
469 |
|
470 | Int = ktype__Int()
|
471 |
|
472 | Str = ktype__Str()
|
473 |
|
474 | class List(ktype_t):
|
475 | _type_tag = 4
|
476 | __slots__ = ('T',)
|
477 |
|
478 | def __init__(self, T):
|
479 | # type: (ktype_t) -> None
|
480 | self.T = T
|
481 |
|
482 | @staticmethod
|
483 | def CreateNull(alloc_lists=False):
|
484 | # type: () -> ktype.List
|
485 | return ktype.List(cast(ktype_t, None))
|
486 |
|
487 | def PrettyTree(self, trav=None):
|
488 | # type: (Optional[TraversalState]) -> hnode_t
|
489 | trav = trav or TraversalState()
|
490 | heap_id = id(self)
|
491 | if heap_id in trav.seen:
|
492 | return hnode.AlreadySeen(heap_id)
|
493 | trav.seen[heap_id] = True
|
494 | out_node = NewRecord('ktype.List')
|
495 | L = out_node.fields
|
496 |
|
497 | assert self.T is not None
|
498 | x0 = self.T.PrettyTree(trav=trav)
|
499 | L.append(Field('T', x0))
|
500 |
|
501 | return out_node
|
502 |
|
503 | def _AbbreviatedTree(self, trav=None):
|
504 | # type: (Optional[TraversalState]) -> hnode_t
|
505 | trav = trav or TraversalState()
|
506 | heap_id = id(self)
|
507 | if heap_id in trav.seen:
|
508 | return hnode.AlreadySeen(heap_id)
|
509 | trav.seen[heap_id] = True
|
510 | out_node = NewRecord('ktype.List')
|
511 | L = out_node.fields
|
512 | assert self.T is not None
|
513 | x0 = self.T.AbbreviatedTree(trav=trav)
|
514 | L.append(Field('T', x0))
|
515 |
|
516 | return out_node
|
517 |
|
518 | def AbbreviatedTree(self, trav=None):
|
519 | # type: (Optional[TraversalState]) -> hnode_t
|
520 | return self._AbbreviatedTree(trav=trav)
|
521 |
|
522 | class Dict(ktype_t):
|
523 | _type_tag = 5
|
524 | __slots__ = ('K', 'V')
|
525 |
|
526 | def __init__(self, K, V):
|
527 | # type: (ktype_t, ktype_t) -> None
|
528 | self.K = K
|
529 | self.V = V
|
530 |
|
531 | @staticmethod
|
532 | def CreateNull(alloc_lists=False):
|
533 | # type: () -> ktype.Dict
|
534 | return ktype.Dict(cast(ktype_t, None), cast(ktype_t, None))
|
535 |
|
536 | def PrettyTree(self, trav=None):
|
537 | # type: (Optional[TraversalState]) -> hnode_t
|
538 | trav = trav or TraversalState()
|
539 | heap_id = id(self)
|
540 | if heap_id in trav.seen:
|
541 | return hnode.AlreadySeen(heap_id)
|
542 | trav.seen[heap_id] = True
|
543 | out_node = NewRecord('ktype.Dict')
|
544 | L = out_node.fields
|
545 |
|
546 | assert self.K is not None
|
547 | x0 = self.K.PrettyTree(trav=trav)
|
548 | L.append(Field('K', x0))
|
549 |
|
550 | assert self.V is not None
|
551 | x1 = self.V.PrettyTree(trav=trav)
|
552 | L.append(Field('V', x1))
|
553 |
|
554 | return out_node
|
555 |
|
556 | def _AbbreviatedTree(self, trav=None):
|
557 | # type: (Optional[TraversalState]) -> hnode_t
|
558 | trav = trav or TraversalState()
|
559 | heap_id = id(self)
|
560 | if heap_id in trav.seen:
|
561 | return hnode.AlreadySeen(heap_id)
|
562 | trav.seen[heap_id] = True
|
563 | out_node = NewRecord('ktype.Dict')
|
564 | L = out_node.fields
|
565 | assert self.K is not None
|
566 | x0 = self.K.AbbreviatedTree(trav=trav)
|
567 | L.append(Field('K', x0))
|
568 |
|
569 | assert self.V is not None
|
570 | x1 = self.V.AbbreviatedTree(trav=trav)
|
571 | L.append(Field('V', x1))
|
572 |
|
573 | return out_node
|
574 |
|
575 | def AbbreviatedTree(self, trav=None):
|
576 | # type: (Optional[TraversalState]) -> hnode_t
|
577 | return self._AbbreviatedTree(trav=trav)
|
578 |
|
579 | class Class(ktype_t):
|
580 | _type_tag = 6
|
581 | __slots__ = ('name',)
|
582 |
|
583 | def __init__(self, name):
|
584 | # type: (str) -> None
|
585 | self.name = name
|
586 |
|
587 | @staticmethod
|
588 | def CreateNull(alloc_lists=False):
|
589 | # type: () -> ktype.Class
|
590 | return ktype.Class('')
|
591 |
|
592 | def PrettyTree(self, trav=None):
|
593 | # type: (Optional[TraversalState]) -> hnode_t
|
594 | trav = trav or TraversalState()
|
595 | heap_id = id(self)
|
596 | if heap_id in trav.seen:
|
597 | return hnode.AlreadySeen(heap_id)
|
598 | trav.seen[heap_id] = True
|
599 | out_node = NewRecord('ktype.Class')
|
600 | L = out_node.fields
|
601 |
|
602 | x0 = NewLeaf(self.name, color_e.StringConst)
|
603 | L.append(Field('name', x0))
|
604 |
|
605 | return out_node
|
606 |
|
607 | def _AbbreviatedTree(self, trav=None):
|
608 | # type: (Optional[TraversalState]) -> hnode_t
|
609 | trav = trav or TraversalState()
|
610 | heap_id = id(self)
|
611 | if heap_id in trav.seen:
|
612 | return hnode.AlreadySeen(heap_id)
|
613 | trav.seen[heap_id] = True
|
614 | out_node = NewRecord('ktype.Class')
|
615 | L = out_node.fields
|
616 | x0 = NewLeaf(self.name, color_e.StringConst)
|
617 | L.append(Field('name', x0))
|
618 |
|
619 | return out_node
|
620 |
|
621 | def AbbreviatedTree(self, trav=None):
|
622 | # type: (Optional[TraversalState]) -> hnode_t
|
623 | return self._AbbreviatedTree(trav=trav)
|
624 |
|
625 | class Data(ktype_t):
|
626 | _type_tag = 7
|
627 | __slots__ = ('fields',)
|
628 |
|
629 | def __init__(self, fields):
|
630 | # type: (List[Field_]) -> None
|
631 | self.fields = fields
|
632 |
|
633 | @staticmethod
|
634 | def CreateNull(alloc_lists=False):
|
635 | # type: () -> ktype.Data
|
636 | return ktype.Data([] if alloc_lists else cast('List[Field_]', None))
|
637 |
|
638 | def PrettyTree(self, trav=None):
|
639 | # type: (Optional[TraversalState]) -> hnode_t
|
640 | trav = trav or TraversalState()
|
641 | heap_id = id(self)
|
642 | if heap_id in trav.seen:
|
643 | return hnode.AlreadySeen(heap_id)
|
644 | trav.seen[heap_id] = True
|
645 | out_node = NewRecord('ktype.Data')
|
646 | L = out_node.fields
|
647 |
|
648 | if self.fields is not None: # List
|
649 | x0 = hnode.Array([])
|
650 | for i0 in self.fields:
|
651 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
652 | i0.PrettyTree(trav=trav))
|
653 | x0.children.append(h)
|
654 | L.append(Field('fields', x0))
|
655 |
|
656 | return out_node
|
657 |
|
658 | def _AbbreviatedTree(self, trav=None):
|
659 | # type: (Optional[TraversalState]) -> hnode_t
|
660 | trav = trav or TraversalState()
|
661 | heap_id = id(self)
|
662 | if heap_id in trav.seen:
|
663 | return hnode.AlreadySeen(heap_id)
|
664 | trav.seen[heap_id] = True
|
665 | out_node = NewRecord('ktype.Data')
|
666 | L = out_node.fields
|
667 | if self.fields is not None: # List
|
668 | x0 = hnode.Array([])
|
669 | for i0 in self.fields:
|
670 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
671 | i0.AbbreviatedTree(trav=trav))
|
672 | x0.children.append(h)
|
673 | L.append(Field('fields', x0))
|
674 |
|
675 | return out_node
|
676 |
|
677 | def AbbreviatedTree(self, trav=None):
|
678 | # type: (Optional[TraversalState]) -> hnode_t
|
679 | return self._AbbreviatedTree(trav=trav)
|
680 |
|
681 | class Enum(ktype_t):
|
682 | _type_tag = 8
|
683 | __slots__ = ('variants',)
|
684 |
|
685 | def __init__(self, variants):
|
686 | # type: (List[variant]) -> None
|
687 | self.variants = variants
|
688 |
|
689 | @staticmethod
|
690 | def CreateNull(alloc_lists=False):
|
691 | # type: () -> ktype.Enum
|
692 | return ktype.Enum([] if alloc_lists else cast('List[variant]', None))
|
693 |
|
694 | def PrettyTree(self, trav=None):
|
695 | # type: (Optional[TraversalState]) -> hnode_t
|
696 | trav = trav or TraversalState()
|
697 | heap_id = id(self)
|
698 | if heap_id in trav.seen:
|
699 | return hnode.AlreadySeen(heap_id)
|
700 | trav.seen[heap_id] = True
|
701 | out_node = NewRecord('ktype.Enum')
|
702 | L = out_node.fields
|
703 |
|
704 | if self.variants is not None: # List
|
705 | x0 = hnode.Array([])
|
706 | for i0 in self.variants:
|
707 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
708 | i0.PrettyTree(trav=trav))
|
709 | x0.children.append(h)
|
710 | L.append(Field('variants', x0))
|
711 |
|
712 | return out_node
|
713 |
|
714 | def _AbbreviatedTree(self, trav=None):
|
715 | # type: (Optional[TraversalState]) -> hnode_t
|
716 | trav = trav or TraversalState()
|
717 | heap_id = id(self)
|
718 | if heap_id in trav.seen:
|
719 | return hnode.AlreadySeen(heap_id)
|
720 | trav.seen[heap_id] = True
|
721 | out_node = NewRecord('ktype.Enum')
|
722 | L = out_node.fields
|
723 | if self.variants is not None: # List
|
724 | x0 = hnode.Array([])
|
725 | for i0 in self.variants:
|
726 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
727 | i0.AbbreviatedTree(trav=trav))
|
728 | x0.children.append(h)
|
729 | L.append(Field('variants', x0))
|
730 |
|
731 | return out_node
|
732 |
|
733 | def AbbreviatedTree(self, trav=None):
|
734 | # type: (Optional[TraversalState]) -> hnode_t
|
735 | return self._AbbreviatedTree(trav=trav)
|
736 |
|
737 | pass
|
738 |
|
739 | class stmt_e(object):
|
740 | VarDecl = 1
|
741 | PlaceMutation = 2
|
742 | If = 3
|
743 | Switch = 4
|
744 | For = 5
|
745 | While = 6
|
746 | Break = 7
|
747 | Continue = 8
|
748 | Return = 9
|
749 | Try = 10
|
750 | With = 11
|
751 |
|
752 | _stmt_str = {
|
753 | 1: 'VarDecl',
|
754 | 2: 'PlaceMutation',
|
755 | 3: 'If',
|
756 | 4: 'Switch',
|
757 | 5: 'For',
|
758 | 6: 'While',
|
759 | 7: 'Break',
|
760 | 8: 'Continue',
|
761 | 9: 'Return',
|
762 | 10: 'Try',
|
763 | 11: 'With',
|
764 | }
|
765 |
|
766 | def stmt_str(tag, dot=True):
|
767 | # type: (int, bool) -> str
|
768 | v = _stmt_str[tag]
|
769 | if dot:
|
770 | return "stmt.%s" % v
|
771 | else:
|
772 | return v
|
773 |
|
774 | class stmt_t(pybase.CompoundObj):
|
775 | def tag(self):
|
776 | # type: () -> int
|
777 | return self._type_tag
|
778 | pass
|
779 |
|
780 | class stmt__If(stmt_t):
|
781 | _type_tag = 3
|
782 | __slots__ = ()
|
783 |
|
784 | def __init__(self, ):
|
785 | # type: () -> None
|
786 | pass
|
787 |
|
788 | def PrettyTree(self, trav=None):
|
789 | # type: (Optional[TraversalState]) -> hnode_t
|
790 | trav = trav or TraversalState()
|
791 | heap_id = id(self)
|
792 | if heap_id in trav.seen:
|
793 | return hnode.AlreadySeen(heap_id)
|
794 | trav.seen[heap_id] = True
|
795 | out_node = NewRecord('stmt__If')
|
796 | L = out_node.fields
|
797 |
|
798 | return out_node
|
799 |
|
800 | def _AbbreviatedTree(self, trav=None):
|
801 | # type: (Optional[TraversalState]) -> hnode_t
|
802 | trav = trav or TraversalState()
|
803 | heap_id = id(self)
|
804 | if heap_id in trav.seen:
|
805 | return hnode.AlreadySeen(heap_id)
|
806 | trav.seen[heap_id] = True
|
807 | out_node = NewRecord('stmt__If')
|
808 | L = out_node.fields
|
809 | return out_node
|
810 |
|
811 | def AbbreviatedTree(self, trav=None):
|
812 | # type: (Optional[TraversalState]) -> hnode_t
|
813 | return self._AbbreviatedTree(trav=trav)
|
814 |
|
815 | class stmt__Switch(stmt_t):
|
816 | _type_tag = 4
|
817 | __slots__ = ()
|
818 |
|
819 | def __init__(self, ):
|
820 | # type: () -> None
|
821 | pass
|
822 |
|
823 | def PrettyTree(self, trav=None):
|
824 | # type: (Optional[TraversalState]) -> hnode_t
|
825 | trav = trav or TraversalState()
|
826 | heap_id = id(self)
|
827 | if heap_id in trav.seen:
|
828 | return hnode.AlreadySeen(heap_id)
|
829 | trav.seen[heap_id] = True
|
830 | out_node = NewRecord('stmt__Switch')
|
831 | L = out_node.fields
|
832 |
|
833 | return out_node
|
834 |
|
835 | def _AbbreviatedTree(self, trav=None):
|
836 | # type: (Optional[TraversalState]) -> hnode_t
|
837 | trav = trav or TraversalState()
|
838 | heap_id = id(self)
|
839 | if heap_id in trav.seen:
|
840 | return hnode.AlreadySeen(heap_id)
|
841 | trav.seen[heap_id] = True
|
842 | out_node = NewRecord('stmt__Switch')
|
843 | L = out_node.fields
|
844 | return out_node
|
845 |
|
846 | def AbbreviatedTree(self, trav=None):
|
847 | # type: (Optional[TraversalState]) -> hnode_t
|
848 | return self._AbbreviatedTree(trav=trav)
|
849 |
|
850 | class stmt__For(stmt_t):
|
851 | _type_tag = 5
|
852 | __slots__ = ()
|
853 |
|
854 | def __init__(self, ):
|
855 | # type: () -> None
|
856 | pass
|
857 |
|
858 | def PrettyTree(self, trav=None):
|
859 | # type: (Optional[TraversalState]) -> hnode_t
|
860 | trav = trav or TraversalState()
|
861 | heap_id = id(self)
|
862 | if heap_id in trav.seen:
|
863 | return hnode.AlreadySeen(heap_id)
|
864 | trav.seen[heap_id] = True
|
865 | out_node = NewRecord('stmt__For')
|
866 | L = out_node.fields
|
867 |
|
868 | return out_node
|
869 |
|
870 | def _AbbreviatedTree(self, trav=None):
|
871 | # type: (Optional[TraversalState]) -> hnode_t
|
872 | trav = trav or TraversalState()
|
873 | heap_id = id(self)
|
874 | if heap_id in trav.seen:
|
875 | return hnode.AlreadySeen(heap_id)
|
876 | trav.seen[heap_id] = True
|
877 | out_node = NewRecord('stmt__For')
|
878 | L = out_node.fields
|
879 | return out_node
|
880 |
|
881 | def AbbreviatedTree(self, trav=None):
|
882 | # type: (Optional[TraversalState]) -> hnode_t
|
883 | return self._AbbreviatedTree(trav=trav)
|
884 |
|
885 | class stmt__While(stmt_t):
|
886 | _type_tag = 6
|
887 | __slots__ = ()
|
888 |
|
889 | def __init__(self, ):
|
890 | # type: () -> None
|
891 | pass
|
892 |
|
893 | def PrettyTree(self, trav=None):
|
894 | # type: (Optional[TraversalState]) -> hnode_t
|
895 | trav = trav or TraversalState()
|
896 | heap_id = id(self)
|
897 | if heap_id in trav.seen:
|
898 | return hnode.AlreadySeen(heap_id)
|
899 | trav.seen[heap_id] = True
|
900 | out_node = NewRecord('stmt__While')
|
901 | L = out_node.fields
|
902 |
|
903 | return out_node
|
904 |
|
905 | def _AbbreviatedTree(self, trav=None):
|
906 | # type: (Optional[TraversalState]) -> hnode_t
|
907 | trav = trav or TraversalState()
|
908 | heap_id = id(self)
|
909 | if heap_id in trav.seen:
|
910 | return hnode.AlreadySeen(heap_id)
|
911 | trav.seen[heap_id] = True
|
912 | out_node = NewRecord('stmt__While')
|
913 | L = out_node.fields
|
914 | return out_node
|
915 |
|
916 | def AbbreviatedTree(self, trav=None):
|
917 | # type: (Optional[TraversalState]) -> hnode_t
|
918 | return self._AbbreviatedTree(trav=trav)
|
919 |
|
920 | class stmt__Break(stmt_t):
|
921 | _type_tag = 7
|
922 | __slots__ = ()
|
923 |
|
924 | def __init__(self, ):
|
925 | # type: () -> None
|
926 | pass
|
927 |
|
928 | def PrettyTree(self, trav=None):
|
929 | # type: (Optional[TraversalState]) -> hnode_t
|
930 | trav = trav or TraversalState()
|
931 | heap_id = id(self)
|
932 | if heap_id in trav.seen:
|
933 | return hnode.AlreadySeen(heap_id)
|
934 | trav.seen[heap_id] = True
|
935 | out_node = NewRecord('stmt__Break')
|
936 | L = out_node.fields
|
937 |
|
938 | return out_node
|
939 |
|
940 | def _AbbreviatedTree(self, trav=None):
|
941 | # type: (Optional[TraversalState]) -> hnode_t
|
942 | trav = trav or TraversalState()
|
943 | heap_id = id(self)
|
944 | if heap_id in trav.seen:
|
945 | return hnode.AlreadySeen(heap_id)
|
946 | trav.seen[heap_id] = True
|
947 | out_node = NewRecord('stmt__Break')
|
948 | L = out_node.fields
|
949 | return out_node
|
950 |
|
951 | def AbbreviatedTree(self, trav=None):
|
952 | # type: (Optional[TraversalState]) -> hnode_t
|
953 | return self._AbbreviatedTree(trav=trav)
|
954 |
|
955 | class stmt__Continue(stmt_t):
|
956 | _type_tag = 8
|
957 | __slots__ = ()
|
958 |
|
959 | def __init__(self, ):
|
960 | # type: () -> None
|
961 | pass
|
962 |
|
963 | def PrettyTree(self, trav=None):
|
964 | # type: (Optional[TraversalState]) -> hnode_t
|
965 | trav = trav or TraversalState()
|
966 | heap_id = id(self)
|
967 | if heap_id in trav.seen:
|
968 | return hnode.AlreadySeen(heap_id)
|
969 | trav.seen[heap_id] = True
|
970 | out_node = NewRecord('stmt__Continue')
|
971 | L = out_node.fields
|
972 |
|
973 | return out_node
|
974 |
|
975 | def _AbbreviatedTree(self, trav=None):
|
976 | # type: (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 | out_node = NewRecord('stmt__Continue')
|
983 | L = out_node.fields
|
984 | return out_node
|
985 |
|
986 | def AbbreviatedTree(self, trav=None):
|
987 | # type: (Optional[TraversalState]) -> hnode_t
|
988 | return self._AbbreviatedTree(trav=trav)
|
989 |
|
990 | class stmt__Try(stmt_t):
|
991 | _type_tag = 10
|
992 | __slots__ = ()
|
993 |
|
994 | def __init__(self, ):
|
995 | # type: () -> None
|
996 | pass
|
997 |
|
998 | def PrettyTree(self, trav=None):
|
999 | # type: (Optional[TraversalState]) -> hnode_t
|
1000 | trav = trav or TraversalState()
|
1001 | heap_id = id(self)
|
1002 | if heap_id in trav.seen:
|
1003 | return hnode.AlreadySeen(heap_id)
|
1004 | trav.seen[heap_id] = True
|
1005 | out_node = NewRecord('stmt__Try')
|
1006 | L = out_node.fields
|
1007 |
|
1008 | return out_node
|
1009 |
|
1010 | def _AbbreviatedTree(self, trav=None):
|
1011 | # type: (Optional[TraversalState]) -> hnode_t
|
1012 | trav = trav or TraversalState()
|
1013 | heap_id = id(self)
|
1014 | if heap_id in trav.seen:
|
1015 | return hnode.AlreadySeen(heap_id)
|
1016 | trav.seen[heap_id] = True
|
1017 | out_node = NewRecord('stmt__Try')
|
1018 | L = out_node.fields
|
1019 | return out_node
|
1020 |
|
1021 | def AbbreviatedTree(self, trav=None):
|
1022 | # type: (Optional[TraversalState]) -> hnode_t
|
1023 | return self._AbbreviatedTree(trav=trav)
|
1024 |
|
1025 | class stmt__With(stmt_t):
|
1026 | _type_tag = 11
|
1027 | __slots__ = ()
|
1028 |
|
1029 | def __init__(self, ):
|
1030 | # type: () -> None
|
1031 | pass
|
1032 |
|
1033 | def PrettyTree(self, trav=None):
|
1034 | # type: (Optional[TraversalState]) -> hnode_t
|
1035 | trav = trav or TraversalState()
|
1036 | heap_id = id(self)
|
1037 | if heap_id in trav.seen:
|
1038 | return hnode.AlreadySeen(heap_id)
|
1039 | trav.seen[heap_id] = True
|
1040 | out_node = NewRecord('stmt__With')
|
1041 | L = out_node.fields
|
1042 |
|
1043 | return out_node
|
1044 |
|
1045 | def _AbbreviatedTree(self, trav=None):
|
1046 | # type: (Optional[TraversalState]) -> hnode_t
|
1047 | trav = trav or TraversalState()
|
1048 | heap_id = id(self)
|
1049 | if heap_id in trav.seen:
|
1050 | return hnode.AlreadySeen(heap_id)
|
1051 | trav.seen[heap_id] = True
|
1052 | out_node = NewRecord('stmt__With')
|
1053 | L = out_node.fields
|
1054 | return out_node
|
1055 |
|
1056 | def AbbreviatedTree(self, trav=None):
|
1057 | # type: (Optional[TraversalState]) -> hnode_t
|
1058 | return self._AbbreviatedTree(trav=trav)
|
1059 |
|
1060 | class stmt(object):
|
1061 | class VarDecl(stmt_t):
|
1062 | _type_tag = 1
|
1063 | __slots__ = ('keyword',)
|
1064 |
|
1065 | def __init__(self, keyword):
|
1066 | # type: (Token) -> None
|
1067 | self.keyword = keyword
|
1068 |
|
1069 | @staticmethod
|
1070 | def CreateNull(alloc_lists=False):
|
1071 | # type: () -> stmt.VarDecl
|
1072 | return stmt.VarDecl(cast(Token, None))
|
1073 |
|
1074 | def PrettyTree(self, trav=None):
|
1075 | # type: (Optional[TraversalState]) -> hnode_t
|
1076 | trav = trav or TraversalState()
|
1077 | heap_id = id(self)
|
1078 | if heap_id in trav.seen:
|
1079 | return hnode.AlreadySeen(heap_id)
|
1080 | trav.seen[heap_id] = True
|
1081 | out_node = NewRecord('stmt.VarDecl')
|
1082 | L = out_node.fields
|
1083 |
|
1084 | assert self.keyword is not None
|
1085 | x0 = self.keyword.PrettyTree(trav=trav)
|
1086 | L.append(Field('keyword', x0))
|
1087 |
|
1088 | return out_node
|
1089 |
|
1090 | def _AbbreviatedTree(self, trav=None):
|
1091 | # type: (Optional[TraversalState]) -> hnode_t
|
1092 | trav = trav or TraversalState()
|
1093 | heap_id = id(self)
|
1094 | if heap_id in trav.seen:
|
1095 | return hnode.AlreadySeen(heap_id)
|
1096 | trav.seen[heap_id] = True
|
1097 | out_node = NewRecord('stmt.VarDecl')
|
1098 | L = out_node.fields
|
1099 | assert self.keyword is not None
|
1100 | x0 = self.keyword.AbbreviatedTree(trav=trav)
|
1101 | L.append(Field('keyword', x0))
|
1102 |
|
1103 | return out_node
|
1104 |
|
1105 | def AbbreviatedTree(self, trav=None):
|
1106 | # type: (Optional[TraversalState]) -> hnode_t
|
1107 | return self._AbbreviatedTree(trav=trav)
|
1108 |
|
1109 | class PlaceMutation(stmt_t):
|
1110 | _type_tag = 2
|
1111 | __slots__ = ('keyword',)
|
1112 |
|
1113 | def __init__(self, keyword):
|
1114 | # type: (Token) -> None
|
1115 | self.keyword = keyword
|
1116 |
|
1117 | @staticmethod
|
1118 | def CreateNull(alloc_lists=False):
|
1119 | # type: () -> stmt.PlaceMutation
|
1120 | return stmt.PlaceMutation(cast(Token, None))
|
1121 |
|
1122 | def PrettyTree(self, trav=None):
|
1123 | # type: (Optional[TraversalState]) -> hnode_t
|
1124 | trav = trav or TraversalState()
|
1125 | heap_id = id(self)
|
1126 | if heap_id in trav.seen:
|
1127 | return hnode.AlreadySeen(heap_id)
|
1128 | trav.seen[heap_id] = True
|
1129 | out_node = NewRecord('stmt.PlaceMutation')
|
1130 | L = out_node.fields
|
1131 |
|
1132 | assert self.keyword is not None
|
1133 | x0 = self.keyword.PrettyTree(trav=trav)
|
1134 | L.append(Field('keyword', x0))
|
1135 |
|
1136 | return out_node
|
1137 |
|
1138 | def _AbbreviatedTree(self, trav=None):
|
1139 | # type: (Optional[TraversalState]) -> hnode_t
|
1140 | trav = trav or TraversalState()
|
1141 | heap_id = id(self)
|
1142 | if heap_id in trav.seen:
|
1143 | return hnode.AlreadySeen(heap_id)
|
1144 | trav.seen[heap_id] = True
|
1145 | out_node = NewRecord('stmt.PlaceMutation')
|
1146 | L = out_node.fields
|
1147 | assert self.keyword is not None
|
1148 | x0 = self.keyword.AbbreviatedTree(trav=trav)
|
1149 | L.append(Field('keyword', x0))
|
1150 |
|
1151 | return out_node
|
1152 |
|
1153 | def AbbreviatedTree(self, trav=None):
|
1154 | # type: (Optional[TraversalState]) -> hnode_t
|
1155 | return self._AbbreviatedTree(trav=trav)
|
1156 |
|
1157 | If = stmt__If()
|
1158 |
|
1159 | Switch = stmt__Switch()
|
1160 |
|
1161 | For = stmt__For()
|
1162 |
|
1163 | While = stmt__While()
|
1164 |
|
1165 | Break = stmt__Break()
|
1166 |
|
1167 | Continue = stmt__Continue()
|
1168 |
|
1169 | class Return(stmt_t):
|
1170 | _type_tag = 9
|
1171 | __slots__ = ('e',)
|
1172 |
|
1173 | def __init__(self, e):
|
1174 | # type: (kexpr_t) -> None
|
1175 | self.e = e
|
1176 |
|
1177 | @staticmethod
|
1178 | def CreateNull(alloc_lists=False):
|
1179 | # type: () -> stmt.Return
|
1180 | return stmt.Return(cast(kexpr_t, None))
|
1181 |
|
1182 | def PrettyTree(self, trav=None):
|
1183 | # type: (Optional[TraversalState]) -> hnode_t
|
1184 | trav = trav or TraversalState()
|
1185 | heap_id = id(self)
|
1186 | if heap_id in trav.seen:
|
1187 | return hnode.AlreadySeen(heap_id)
|
1188 | trav.seen[heap_id] = True
|
1189 | out_node = NewRecord('stmt.Return')
|
1190 | L = out_node.fields
|
1191 |
|
1192 | assert self.e is not None
|
1193 | x0 = self.e.PrettyTree(trav=trav)
|
1194 | L.append(Field('e', x0))
|
1195 |
|
1196 | return out_node
|
1197 |
|
1198 | def _AbbreviatedTree(self, trav=None):
|
1199 | # type: (Optional[TraversalState]) -> hnode_t
|
1200 | trav = trav or TraversalState()
|
1201 | heap_id = id(self)
|
1202 | if heap_id in trav.seen:
|
1203 | return hnode.AlreadySeen(heap_id)
|
1204 | trav.seen[heap_id] = True
|
1205 | out_node = NewRecord('stmt.Return')
|
1206 | L = out_node.fields
|
1207 | assert self.e is not None
|
1208 | x0 = self.e.AbbreviatedTree(trav=trav)
|
1209 | L.append(Field('e', x0))
|
1210 |
|
1211 | return out_node
|
1212 |
|
1213 | def AbbreviatedTree(self, trav=None):
|
1214 | # type: (Optional[TraversalState]) -> hnode_t
|
1215 | return self._AbbreviatedTree(trav=trav)
|
1216 |
|
1217 | Try = stmt__Try()
|
1218 |
|
1219 | With = stmt__With()
|
1220 |
|
1221 | pass
|
1222 |
|
1223 | class class_def_t(pybase.SimpleObj):
|
1224 | pass
|
1225 |
|
1226 | class class_def_e(object):
|
1227 | Constructor = class_def_t(1)
|
1228 | Destructor = class_def_t(2)
|
1229 | Method = class_def_t(3)
|
1230 | Field = class_def_t(4)
|
1231 |
|
1232 | _class_def_str = {
|
1233 | 1: 'class_def.Constructor',
|
1234 | 2: 'class_def.Destructor',
|
1235 | 3: 'class_def.Method',
|
1236 | 4: 'class_def.Field',
|
1237 | }
|
1238 |
|
1239 | def class_def_str(val):
|
1240 | # type: (class_def_t) -> str
|
1241 | return _class_def_str[val]
|
1242 |
|
1243 | class mod_def_e(object):
|
1244 | Global = 1
|
1245 | Func = 2
|
1246 | Class = 3
|
1247 | Import = 4
|
1248 | Include = 5
|
1249 | Data = 6
|
1250 | Enum = 7
|
1251 |
|
1252 | _mod_def_str = {
|
1253 | 1: 'Global',
|
1254 | 2: 'Func',
|
1255 | 3: 'Class',
|
1256 | 4: 'Import',
|
1257 | 5: 'Include',
|
1258 | 6: 'Data',
|
1259 | 7: 'Enum',
|
1260 | }
|
1261 |
|
1262 | def mod_def_str(tag, dot=True):
|
1263 | # type: (int, bool) -> str
|
1264 | v = _mod_def_str[tag]
|
1265 | if dot:
|
1266 | return "mod_def.%s" % v
|
1267 | else:
|
1268 | return v
|
1269 |
|
1270 | class mod_def_t(pybase.CompoundObj):
|
1271 | def tag(self):
|
1272 | # type: () -> int
|
1273 | return self._type_tag
|
1274 | pass
|
1275 |
|
1276 | class mod_def__Import(mod_def_t):
|
1277 | _type_tag = 4
|
1278 | __slots__ = ()
|
1279 |
|
1280 | def __init__(self, ):
|
1281 | # type: () -> None
|
1282 | pass
|
1283 |
|
1284 | def PrettyTree(self, trav=None):
|
1285 | # type: (Optional[TraversalState]) -> hnode_t
|
1286 | trav = trav or TraversalState()
|
1287 | heap_id = id(self)
|
1288 | if heap_id in trav.seen:
|
1289 | return hnode.AlreadySeen(heap_id)
|
1290 | trav.seen[heap_id] = True
|
1291 | out_node = NewRecord('mod_def__Import')
|
1292 | L = out_node.fields
|
1293 |
|
1294 | return out_node
|
1295 |
|
1296 | def _AbbreviatedTree(self, trav=None):
|
1297 | # type: (Optional[TraversalState]) -> hnode_t
|
1298 | trav = trav or TraversalState()
|
1299 | heap_id = id(self)
|
1300 | if heap_id in trav.seen:
|
1301 | return hnode.AlreadySeen(heap_id)
|
1302 | trav.seen[heap_id] = True
|
1303 | out_node = NewRecord('mod_def__Import')
|
1304 | L = out_node.fields
|
1305 | return out_node
|
1306 |
|
1307 | def AbbreviatedTree(self, trav=None):
|
1308 | # type: (Optional[TraversalState]) -> hnode_t
|
1309 | return self._AbbreviatedTree(trav=trav)
|
1310 |
|
1311 | class mod_def__Data(mod_def_t):
|
1312 | _type_tag = 6
|
1313 | __slots__ = ()
|
1314 |
|
1315 | def __init__(self, ):
|
1316 | # type: () -> None
|
1317 | pass
|
1318 |
|
1319 | def PrettyTree(self, trav=None):
|
1320 | # type: (Optional[TraversalState]) -> hnode_t
|
1321 | trav = trav or TraversalState()
|
1322 | heap_id = id(self)
|
1323 | if heap_id in trav.seen:
|
1324 | return hnode.AlreadySeen(heap_id)
|
1325 | trav.seen[heap_id] = True
|
1326 | out_node = NewRecord('mod_def__Data')
|
1327 | L = out_node.fields
|
1328 |
|
1329 | return out_node
|
1330 |
|
1331 | def _AbbreviatedTree(self, trav=None):
|
1332 | # type: (Optional[TraversalState]) -> hnode_t
|
1333 | trav = trav or TraversalState()
|
1334 | heap_id = id(self)
|
1335 | if heap_id in trav.seen:
|
1336 | return hnode.AlreadySeen(heap_id)
|
1337 | trav.seen[heap_id] = True
|
1338 | out_node = NewRecord('mod_def__Data')
|
1339 | L = out_node.fields
|
1340 | return out_node
|
1341 |
|
1342 | def AbbreviatedTree(self, trav=None):
|
1343 | # type: (Optional[TraversalState]) -> hnode_t
|
1344 | return self._AbbreviatedTree(trav=trav)
|
1345 |
|
1346 | class mod_def__Enum(mod_def_t):
|
1347 | _type_tag = 7
|
1348 | __slots__ = ()
|
1349 |
|
1350 | def __init__(self, ):
|
1351 | # type: () -> None
|
1352 | pass
|
1353 |
|
1354 | def PrettyTree(self, trav=None):
|
1355 | # type: (Optional[TraversalState]) -> hnode_t
|
1356 | trav = trav or TraversalState()
|
1357 | heap_id = id(self)
|
1358 | if heap_id in trav.seen:
|
1359 | return hnode.AlreadySeen(heap_id)
|
1360 | trav.seen[heap_id] = True
|
1361 | out_node = NewRecord('mod_def__Enum')
|
1362 | L = out_node.fields
|
1363 |
|
1364 | return out_node
|
1365 |
|
1366 | def _AbbreviatedTree(self, trav=None):
|
1367 | # type: (Optional[TraversalState]) -> hnode_t
|
1368 | trav = trav or TraversalState()
|
1369 | heap_id = id(self)
|
1370 | if heap_id in trav.seen:
|
1371 | return hnode.AlreadySeen(heap_id)
|
1372 | trav.seen[heap_id] = True
|
1373 | out_node = NewRecord('mod_def__Enum')
|
1374 | L = out_node.fields
|
1375 | return out_node
|
1376 |
|
1377 | def AbbreviatedTree(self, trav=None):
|
1378 | # type: (Optional[TraversalState]) -> hnode_t
|
1379 | return self._AbbreviatedTree(trav=trav)
|
1380 |
|
1381 | class mod_def(object):
|
1382 | class Global(mod_def_t):
|
1383 | _type_tag = 1
|
1384 | __slots__ = ('name_type',)
|
1385 |
|
1386 | def __init__(self, name_type):
|
1387 | # type: (NameType) -> None
|
1388 | self.name_type = name_type
|
1389 |
|
1390 | @staticmethod
|
1391 | def CreateNull(alloc_lists=False):
|
1392 | # type: () -> mod_def.Global
|
1393 | return mod_def.Global(cast(NameType, None))
|
1394 |
|
1395 | def PrettyTree(self, trav=None):
|
1396 | # type: (Optional[TraversalState]) -> hnode_t
|
1397 | trav = trav or TraversalState()
|
1398 | heap_id = id(self)
|
1399 | if heap_id in trav.seen:
|
1400 | return hnode.AlreadySeen(heap_id)
|
1401 | trav.seen[heap_id] = True
|
1402 | out_node = NewRecord('mod_def.Global')
|
1403 | L = out_node.fields
|
1404 |
|
1405 | assert self.name_type is not None
|
1406 | x0 = self.name_type.PrettyTree(trav=trav)
|
1407 | L.append(Field('name_type', x0))
|
1408 |
|
1409 | return out_node
|
1410 |
|
1411 | def _AbbreviatedTree(self, trav=None):
|
1412 | # type: (Optional[TraversalState]) -> hnode_t
|
1413 | trav = trav or TraversalState()
|
1414 | heap_id = id(self)
|
1415 | if heap_id in trav.seen:
|
1416 | return hnode.AlreadySeen(heap_id)
|
1417 | trav.seen[heap_id] = True
|
1418 | out_node = NewRecord('mod_def.Global')
|
1419 | L = out_node.fields
|
1420 | assert self.name_type is not None
|
1421 | x0 = self.name_type.AbbreviatedTree(trav=trav)
|
1422 | L.append(Field('name_type', x0))
|
1423 |
|
1424 | return out_node
|
1425 |
|
1426 | def AbbreviatedTree(self, trav=None):
|
1427 | # type: (Optional[TraversalState]) -> hnode_t
|
1428 | return self._AbbreviatedTree(trav=trav)
|
1429 |
|
1430 | class Func(mod_def_t):
|
1431 | _type_tag = 2
|
1432 | __slots__ = ('name', 'sig', 'statements')
|
1433 |
|
1434 | def __init__(self, name, sig, statements):
|
1435 | # type: (str, Signature, List[stmt_t]) -> None
|
1436 | self.name = name
|
1437 | self.sig = sig
|
1438 | self.statements = statements
|
1439 |
|
1440 | @staticmethod
|
1441 | def CreateNull(alloc_lists=False):
|
1442 | # type: () -> mod_def.Func
|
1443 | return mod_def.Func('', cast(Signature, None), [] if alloc_lists else cast('List[stmt_t]', None))
|
1444 |
|
1445 | def PrettyTree(self, trav=None):
|
1446 | # type: (Optional[TraversalState]) -> hnode_t
|
1447 | trav = trav or TraversalState()
|
1448 | heap_id = id(self)
|
1449 | if heap_id in trav.seen:
|
1450 | return hnode.AlreadySeen(heap_id)
|
1451 | trav.seen[heap_id] = True
|
1452 | out_node = NewRecord('mod_def.Func')
|
1453 | L = out_node.fields
|
1454 |
|
1455 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1456 | L.append(Field('name', x0))
|
1457 |
|
1458 | assert self.sig is not None
|
1459 | x1 = self.sig.PrettyTree(trav=trav)
|
1460 | L.append(Field('sig', x1))
|
1461 |
|
1462 | if self.statements is not None: # List
|
1463 | x2 = hnode.Array([])
|
1464 | for i2 in self.statements:
|
1465 | h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
|
1466 | i2.PrettyTree(trav=trav))
|
1467 | x2.children.append(h)
|
1468 | L.append(Field('statements', x2))
|
1469 |
|
1470 | return out_node
|
1471 |
|
1472 | def _AbbreviatedTree(self, trav=None):
|
1473 | # type: (Optional[TraversalState]) -> hnode_t
|
1474 | trav = trav or TraversalState()
|
1475 | heap_id = id(self)
|
1476 | if heap_id in trav.seen:
|
1477 | return hnode.AlreadySeen(heap_id)
|
1478 | trav.seen[heap_id] = True
|
1479 | out_node = NewRecord('mod_def.Func')
|
1480 | L = out_node.fields
|
1481 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1482 | L.append(Field('name', x0))
|
1483 |
|
1484 | assert self.sig is not None
|
1485 | x1 = self.sig.AbbreviatedTree(trav=trav)
|
1486 | L.append(Field('sig', x1))
|
1487 |
|
1488 | if self.statements is not None: # List
|
1489 | x2 = hnode.Array([])
|
1490 | for i2 in self.statements:
|
1491 | h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
|
1492 | i2.AbbreviatedTree(trav=trav))
|
1493 | x2.children.append(h)
|
1494 | L.append(Field('statements', x2))
|
1495 |
|
1496 | return out_node
|
1497 |
|
1498 | def AbbreviatedTree(self, trav=None):
|
1499 | # type: (Optional[TraversalState]) -> hnode_t
|
1500 | return self._AbbreviatedTree(trav=trav)
|
1501 |
|
1502 | class Class(mod_def_t):
|
1503 | _type_tag = 3
|
1504 | __slots__ = ('name', 'defs')
|
1505 |
|
1506 | def __init__(self, name, defs):
|
1507 | # type: (str, List[class_def_t]) -> None
|
1508 | self.name = name
|
1509 | self.defs = defs
|
1510 |
|
1511 | @staticmethod
|
1512 | def CreateNull(alloc_lists=False):
|
1513 | # type: () -> mod_def.Class
|
1514 | return mod_def.Class('', [] if alloc_lists else cast('List[class_def_t]', None))
|
1515 |
|
1516 | def PrettyTree(self, trav=None):
|
1517 | # type: (Optional[TraversalState]) -> hnode_t
|
1518 | trav = trav or TraversalState()
|
1519 | heap_id = id(self)
|
1520 | if heap_id in trav.seen:
|
1521 | return hnode.AlreadySeen(heap_id)
|
1522 | trav.seen[heap_id] = True
|
1523 | out_node = NewRecord('mod_def.Class')
|
1524 | L = out_node.fields
|
1525 |
|
1526 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1527 | L.append(Field('name', x0))
|
1528 |
|
1529 | if self.defs is not None: # List
|
1530 | x1 = hnode.Array([])
|
1531 | for i1 in self.defs:
|
1532 | x1.children.append(hnode.Leaf(class_def_str(i1), color_e.TypeName))
|
1533 | L.append(Field('defs', x1))
|
1534 |
|
1535 | return out_node
|
1536 |
|
1537 | def _AbbreviatedTree(self, trav=None):
|
1538 | # type: (Optional[TraversalState]) -> hnode_t
|
1539 | trav = trav or TraversalState()
|
1540 | heap_id = id(self)
|
1541 | if heap_id in trav.seen:
|
1542 | return hnode.AlreadySeen(heap_id)
|
1543 | trav.seen[heap_id] = True
|
1544 | out_node = NewRecord('mod_def.Class')
|
1545 | L = out_node.fields
|
1546 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1547 | L.append(Field('name', x0))
|
1548 |
|
1549 | if self.defs is not None: # List
|
1550 | x1 = hnode.Array([])
|
1551 | for i1 in self.defs:
|
1552 | x1.children.append(hnode.Leaf(class_def_str(i1), color_e.TypeName))
|
1553 | L.append(Field('defs', x1))
|
1554 |
|
1555 | return out_node
|
1556 |
|
1557 | def AbbreviatedTree(self, trav=None):
|
1558 | # type: (Optional[TraversalState]) -> hnode_t
|
1559 | return self._AbbreviatedTree(trav=trav)
|
1560 |
|
1561 | Import = mod_def__Import()
|
1562 |
|
1563 | class Include(mod_def_t):
|
1564 | _type_tag = 5
|
1565 | __slots__ = ('path',)
|
1566 |
|
1567 | def __init__(self, path):
|
1568 | # type: (str) -> None
|
1569 | self.path = path
|
1570 |
|
1571 | @staticmethod
|
1572 | def CreateNull(alloc_lists=False):
|
1573 | # type: () -> mod_def.Include
|
1574 | return mod_def.Include('')
|
1575 |
|
1576 | def PrettyTree(self, trav=None):
|
1577 | # type: (Optional[TraversalState]) -> hnode_t
|
1578 | trav = trav or TraversalState()
|
1579 | heap_id = id(self)
|
1580 | if heap_id in trav.seen:
|
1581 | return hnode.AlreadySeen(heap_id)
|
1582 | trav.seen[heap_id] = True
|
1583 | out_node = NewRecord('mod_def.Include')
|
1584 | L = out_node.fields
|
1585 |
|
1586 | x0 = NewLeaf(self.path, color_e.StringConst)
|
1587 | L.append(Field('path', x0))
|
1588 |
|
1589 | return out_node
|
1590 |
|
1591 | def _AbbreviatedTree(self, trav=None):
|
1592 | # type: (Optional[TraversalState]) -> hnode_t
|
1593 | trav = trav or TraversalState()
|
1594 | heap_id = id(self)
|
1595 | if heap_id in trav.seen:
|
1596 | return hnode.AlreadySeen(heap_id)
|
1597 | trav.seen[heap_id] = True
|
1598 | out_node = NewRecord('mod_def.Include')
|
1599 | L = out_node.fields
|
1600 | x0 = NewLeaf(self.path, color_e.StringConst)
|
1601 | L.append(Field('path', x0))
|
1602 |
|
1603 | return out_node
|
1604 |
|
1605 | def AbbreviatedTree(self, trav=None):
|
1606 | # type: (Optional[TraversalState]) -> hnode_t
|
1607 | return self._AbbreviatedTree(trav=trav)
|
1608 |
|
1609 | Data = mod_def__Data()
|
1610 |
|
1611 | Enum = mod_def__Enum()
|
1612 |
|
1613 | pass
|
1614 |
|
1615 | class Token(pybase.CompoundObj):
|
1616 | _type_tag = 64
|
1617 | __slots__ = ('path', 'chunk', 'start', 'length')
|
1618 |
|
1619 | def __init__(self, path, chunk, start, length):
|
1620 | # type: (str, str, int, int) -> None
|
1621 | self.path = path
|
1622 | self.chunk = chunk
|
1623 | self.start = start
|
1624 | self.length = length
|
1625 |
|
1626 | @staticmethod
|
1627 | def CreateNull(alloc_lists=False):
|
1628 | # type: () -> Token
|
1629 | return Token('', '', -1, -1)
|
1630 |
|
1631 | def PrettyTree(self, trav=None):
|
1632 | # type: (Optional[TraversalState]) -> hnode_t
|
1633 | trav = trav or TraversalState()
|
1634 | heap_id = id(self)
|
1635 | if heap_id in trav.seen:
|
1636 | return hnode.AlreadySeen(heap_id)
|
1637 | trav.seen[heap_id] = True
|
1638 | out_node = NewRecord('Token')
|
1639 | L = out_node.fields
|
1640 |
|
1641 | x0 = NewLeaf(self.path, color_e.StringConst)
|
1642 | L.append(Field('path', x0))
|
1643 |
|
1644 | x1 = NewLeaf(self.chunk, color_e.StringConst)
|
1645 | L.append(Field('chunk', x1))
|
1646 |
|
1647 | x2 = hnode.Leaf(str(self.start), color_e.OtherConst)
|
1648 | L.append(Field('start', x2))
|
1649 |
|
1650 | x3 = hnode.Leaf(str(self.length), color_e.OtherConst)
|
1651 | L.append(Field('length', x3))
|
1652 |
|
1653 | return out_node
|
1654 |
|
1655 | def _AbbreviatedTree(self, trav=None):
|
1656 | # type: (Optional[TraversalState]) -> hnode_t
|
1657 | trav = trav or TraversalState()
|
1658 | heap_id = id(self)
|
1659 | if heap_id in trav.seen:
|
1660 | return hnode.AlreadySeen(heap_id)
|
1661 | trav.seen[heap_id] = True
|
1662 | out_node = NewRecord('Token')
|
1663 | L = out_node.fields
|
1664 | x0 = NewLeaf(self.path, color_e.StringConst)
|
1665 | L.append(Field('path', x0))
|
1666 |
|
1667 | x1 = NewLeaf(self.chunk, color_e.StringConst)
|
1668 | L.append(Field('chunk', x1))
|
1669 |
|
1670 | x2 = hnode.Leaf(str(self.start), color_e.OtherConst)
|
1671 | L.append(Field('start', x2))
|
1672 |
|
1673 | x3 = hnode.Leaf(str(self.length), color_e.OtherConst)
|
1674 | L.append(Field('length', x3))
|
1675 |
|
1676 | return out_node
|
1677 |
|
1678 | def AbbreviatedTree(self, trav=None):
|
1679 | # type: (Optional[TraversalState]) -> hnode_t
|
1680 | return self._AbbreviatedTree(trav=trav)
|
1681 |
|
1682 | class Bool(kexpr_t):
|
1683 | _type_tag = 65
|
1684 | __slots__ = ('b', 'loc')
|
1685 |
|
1686 | def __init__(self, b, loc):
|
1687 | # type: (bool, Token) -> None
|
1688 | self.b = b
|
1689 | self.loc = loc
|
1690 |
|
1691 | @staticmethod
|
1692 | def CreateNull(alloc_lists=False):
|
1693 | # type: () -> Bool
|
1694 | return Bool(False, cast(Token, None))
|
1695 |
|
1696 | def PrettyTree(self, trav=None):
|
1697 | # type: (Optional[TraversalState]) -> hnode_t
|
1698 | trav = trav or TraversalState()
|
1699 | heap_id = id(self)
|
1700 | if heap_id in trav.seen:
|
1701 | return hnode.AlreadySeen(heap_id)
|
1702 | trav.seen[heap_id] = True
|
1703 | out_node = NewRecord('Bool')
|
1704 | L = out_node.fields
|
1705 |
|
1706 | x0 = hnode.Leaf('T' if self.b else 'F', color_e.OtherConst)
|
1707 | L.append(Field('b', x0))
|
1708 |
|
1709 | assert self.loc is not None
|
1710 | x1 = self.loc.PrettyTree(trav=trav)
|
1711 | L.append(Field('loc', x1))
|
1712 |
|
1713 | return out_node
|
1714 |
|
1715 | def _AbbreviatedTree(self, trav=None):
|
1716 | # type: (Optional[TraversalState]) -> hnode_t
|
1717 | trav = trav or TraversalState()
|
1718 | heap_id = id(self)
|
1719 | if heap_id in trav.seen:
|
1720 | return hnode.AlreadySeen(heap_id)
|
1721 | trav.seen[heap_id] = True
|
1722 | out_node = NewRecord('Bool')
|
1723 | L = out_node.fields
|
1724 | x0 = hnode.Leaf('T' if self.b else 'F', color_e.OtherConst)
|
1725 | L.append(Field('b', x0))
|
1726 |
|
1727 | assert self.loc is not None
|
1728 | x1 = self.loc.AbbreviatedTree(trav=trav)
|
1729 | L.append(Field('loc', x1))
|
1730 |
|
1731 | return out_node
|
1732 |
|
1733 | def AbbreviatedTree(self, trav=None):
|
1734 | # type: (Optional[TraversalState]) -> hnode_t
|
1735 | return self._AbbreviatedTree(trav=trav)
|
1736 |
|
1737 | class Int(kexpr_t):
|
1738 | _type_tag = 66
|
1739 | __slots__ = ('i', 'loc')
|
1740 |
|
1741 | def __init__(self, i, loc):
|
1742 | # type: (int, Token) -> None
|
1743 | self.i = i
|
1744 | self.loc = loc
|
1745 |
|
1746 | @staticmethod
|
1747 | def CreateNull(alloc_lists=False):
|
1748 | # type: () -> Int
|
1749 | return Int(-1, cast(Token, None))
|
1750 |
|
1751 | def PrettyTree(self, trav=None):
|
1752 | # type: (Optional[TraversalState]) -> hnode_t
|
1753 | trav = trav or TraversalState()
|
1754 | heap_id = id(self)
|
1755 | if heap_id in trav.seen:
|
1756 | return hnode.AlreadySeen(heap_id)
|
1757 | trav.seen[heap_id] = True
|
1758 | out_node = NewRecord('Int')
|
1759 | L = out_node.fields
|
1760 |
|
1761 | x0 = hnode.Leaf(str(self.i), color_e.OtherConst)
|
1762 | L.append(Field('i', x0))
|
1763 |
|
1764 | assert self.loc is not None
|
1765 | x1 = self.loc.PrettyTree(trav=trav)
|
1766 | L.append(Field('loc', x1))
|
1767 |
|
1768 | return out_node
|
1769 |
|
1770 | def _AbbreviatedTree(self, trav=None):
|
1771 | # type: (Optional[TraversalState]) -> hnode_t
|
1772 | trav = trav or TraversalState()
|
1773 | heap_id = id(self)
|
1774 | if heap_id in trav.seen:
|
1775 | return hnode.AlreadySeen(heap_id)
|
1776 | trav.seen[heap_id] = True
|
1777 | out_node = NewRecord('Int')
|
1778 | L = out_node.fields
|
1779 | x0 = hnode.Leaf(str(self.i), color_e.OtherConst)
|
1780 | L.append(Field('i', x0))
|
1781 |
|
1782 | assert self.loc is not None
|
1783 | x1 = self.loc.AbbreviatedTree(trav=trav)
|
1784 | L.append(Field('loc', x1))
|
1785 |
|
1786 | return out_node
|
1787 |
|
1788 | def AbbreviatedTree(self, trav=None):
|
1789 | # type: (Optional[TraversalState]) -> hnode_t
|
1790 | return self._AbbreviatedTree(trav=trav)
|
1791 |
|
1792 | class Str(kexpr_t):
|
1793 | _type_tag = 67
|
1794 | __slots__ = ('s', 'loc')
|
1795 |
|
1796 | def __init__(self, s, loc):
|
1797 | # type: (str, Token) -> None
|
1798 | self.s = s
|
1799 | self.loc = loc
|
1800 |
|
1801 | @staticmethod
|
1802 | def CreateNull(alloc_lists=False):
|
1803 | # type: () -> Str
|
1804 | return Str('', cast(Token, None))
|
1805 |
|
1806 | def PrettyTree(self, trav=None):
|
1807 | # type: (Optional[TraversalState]) -> hnode_t
|
1808 | trav = trav or TraversalState()
|
1809 | heap_id = id(self)
|
1810 | if heap_id in trav.seen:
|
1811 | return hnode.AlreadySeen(heap_id)
|
1812 | trav.seen[heap_id] = True
|
1813 | out_node = NewRecord('Str')
|
1814 | L = out_node.fields
|
1815 |
|
1816 | x0 = NewLeaf(self.s, color_e.StringConst)
|
1817 | L.append(Field('s', x0))
|
1818 |
|
1819 | assert self.loc is not None
|
1820 | x1 = self.loc.PrettyTree(trav=trav)
|
1821 | L.append(Field('loc', x1))
|
1822 |
|
1823 | return out_node
|
1824 |
|
1825 | def _AbbreviatedTree(self, trav=None):
|
1826 | # type: (Optional[TraversalState]) -> hnode_t
|
1827 | trav = trav or TraversalState()
|
1828 | heap_id = id(self)
|
1829 | if heap_id in trav.seen:
|
1830 | return hnode.AlreadySeen(heap_id)
|
1831 | trav.seen[heap_id] = True
|
1832 | out_node = NewRecord('Str')
|
1833 | L = out_node.fields
|
1834 | x0 = NewLeaf(self.s, color_e.StringConst)
|
1835 | L.append(Field('s', x0))
|
1836 |
|
1837 | assert self.loc is not None
|
1838 | x1 = self.loc.AbbreviatedTree(trav=trav)
|
1839 | L.append(Field('loc', x1))
|
1840 |
|
1841 | return out_node
|
1842 |
|
1843 | def AbbreviatedTree(self, trav=None):
|
1844 | # type: (Optional[TraversalState]) -> hnode_t
|
1845 | return self._AbbreviatedTree(trav=trav)
|
1846 |
|
1847 | class MultiStr(kexpr_t):
|
1848 | _type_tag = 68
|
1849 | __slots__ = ('lines',)
|
1850 |
|
1851 | def __init__(self, lines):
|
1852 | # type: (List[Token]) -> None
|
1853 | self.lines = lines
|
1854 |
|
1855 | @staticmethod
|
1856 | def CreateNull(alloc_lists=False):
|
1857 | # type: () -> MultiStr
|
1858 | return MultiStr([] if alloc_lists else cast('List[Token]', None))
|
1859 |
|
1860 | def PrettyTree(self, trav=None):
|
1861 | # type: (Optional[TraversalState]) -> hnode_t
|
1862 | trav = trav or TraversalState()
|
1863 | heap_id = id(self)
|
1864 | if heap_id in trav.seen:
|
1865 | return hnode.AlreadySeen(heap_id)
|
1866 | trav.seen[heap_id] = True
|
1867 | out_node = NewRecord('MultiStr')
|
1868 | L = out_node.fields
|
1869 |
|
1870 | if self.lines is not None: # List
|
1871 | x0 = hnode.Array([])
|
1872 | for i0 in self.lines:
|
1873 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
1874 | i0.PrettyTree(trav=trav))
|
1875 | x0.children.append(h)
|
1876 | L.append(Field('lines', x0))
|
1877 |
|
1878 | return out_node
|
1879 |
|
1880 | def _AbbreviatedTree(self, trav=None):
|
1881 | # type: (Optional[TraversalState]) -> hnode_t
|
1882 | trav = trav or TraversalState()
|
1883 | heap_id = id(self)
|
1884 | if heap_id in trav.seen:
|
1885 | return hnode.AlreadySeen(heap_id)
|
1886 | trav.seen[heap_id] = True
|
1887 | out_node = NewRecord('MultiStr')
|
1888 | L = out_node.fields
|
1889 | if self.lines is not None: # List
|
1890 | x0 = hnode.Array([])
|
1891 | for i0 in self.lines:
|
1892 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
1893 | i0.AbbreviatedTree(trav=trav))
|
1894 | x0.children.append(h)
|
1895 | L.append(Field('lines', x0))
|
1896 |
|
1897 | return out_node
|
1898 |
|
1899 | def AbbreviatedTree(self, trav=None):
|
1900 | # type: (Optional[TraversalState]) -> hnode_t
|
1901 | return self._AbbreviatedTree(trav=trav)
|
1902 |
|
1903 | class Field_(pybase.CompoundObj):
|
1904 | _type_tag = 69
|
1905 | __slots__ = ('name', 'typ')
|
1906 |
|
1907 | def __init__(self, name, typ):
|
1908 | # type: (str, ktype_t) -> None
|
1909 | self.name = name
|
1910 | self.typ = typ
|
1911 |
|
1912 | @staticmethod
|
1913 | def CreateNull(alloc_lists=False):
|
1914 | # type: () -> Field_
|
1915 | return Field_('', cast(ktype_t, None))
|
1916 |
|
1917 | def PrettyTree(self, trav=None):
|
1918 | # type: (Optional[TraversalState]) -> hnode_t
|
1919 | trav = trav or TraversalState()
|
1920 | heap_id = id(self)
|
1921 | if heap_id in trav.seen:
|
1922 | return hnode.AlreadySeen(heap_id)
|
1923 | trav.seen[heap_id] = True
|
1924 | out_node = NewRecord('Field_')
|
1925 | L = out_node.fields
|
1926 |
|
1927 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1928 | L.append(Field('name', x0))
|
1929 |
|
1930 | assert self.typ is not None
|
1931 | x1 = self.typ.PrettyTree(trav=trav)
|
1932 | L.append(Field('typ', x1))
|
1933 |
|
1934 | return out_node
|
1935 |
|
1936 | def _AbbreviatedTree(self, trav=None):
|
1937 | # type: (Optional[TraversalState]) -> hnode_t
|
1938 | trav = trav or TraversalState()
|
1939 | heap_id = id(self)
|
1940 | if heap_id in trav.seen:
|
1941 | return hnode.AlreadySeen(heap_id)
|
1942 | trav.seen[heap_id] = True
|
1943 | out_node = NewRecord('Field_')
|
1944 | L = out_node.fields
|
1945 | x0 = NewLeaf(self.name, color_e.StringConst)
|
1946 | L.append(Field('name', x0))
|
1947 |
|
1948 | assert self.typ is not None
|
1949 | x1 = self.typ.AbbreviatedTree(trav=trav)
|
1950 | L.append(Field('typ', x1))
|
1951 |
|
1952 | return out_node
|
1953 |
|
1954 | def AbbreviatedTree(self, trav=None):
|
1955 | # type: (Optional[TraversalState]) -> hnode_t
|
1956 | return self._AbbreviatedTree(trav=trav)
|
1957 |
|
1958 | class variant(pybase.CompoundObj):
|
1959 | _type_tag = 70
|
1960 | __slots__ = ('fields',)
|
1961 |
|
1962 | def __init__(self, fields):
|
1963 | # type: (List[Field_]) -> None
|
1964 | self.fields = fields
|
1965 |
|
1966 | @staticmethod
|
1967 | def CreateNull(alloc_lists=False):
|
1968 | # type: () -> variant
|
1969 | return variant([] if alloc_lists else cast('List[Field_]', None))
|
1970 |
|
1971 | def PrettyTree(self, trav=None):
|
1972 | # type: (Optional[TraversalState]) -> hnode_t
|
1973 | trav = trav or TraversalState()
|
1974 | heap_id = id(self)
|
1975 | if heap_id in trav.seen:
|
1976 | return hnode.AlreadySeen(heap_id)
|
1977 | trav.seen[heap_id] = True
|
1978 | out_node = NewRecord('variant')
|
1979 | L = out_node.fields
|
1980 |
|
1981 | if self.fields is not None: # List
|
1982 | x0 = hnode.Array([])
|
1983 | for i0 in self.fields:
|
1984 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
1985 | i0.PrettyTree(trav=trav))
|
1986 | x0.children.append(h)
|
1987 | L.append(Field('fields', x0))
|
1988 |
|
1989 | return out_node
|
1990 |
|
1991 | def _AbbreviatedTree(self, trav=None):
|
1992 | # type: (Optional[TraversalState]) -> hnode_t
|
1993 | trav = trav or TraversalState()
|
1994 | heap_id = id(self)
|
1995 | if heap_id in trav.seen:
|
1996 | return hnode.AlreadySeen(heap_id)
|
1997 | trav.seen[heap_id] = True
|
1998 | out_node = NewRecord('variant')
|
1999 | L = out_node.fields
|
2000 | if self.fields is not None: # List
|
2001 | x0 = hnode.Array([])
|
2002 | for i0 in self.fields:
|
2003 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
2004 | i0.AbbreviatedTree(trav=trav))
|
2005 | x0.children.append(h)
|
2006 | L.append(Field('fields', x0))
|
2007 |
|
2008 | return out_node
|
2009 |
|
2010 | def AbbreviatedTree(self, trav=None):
|
2011 | # type: (Optional[TraversalState]) -> hnode_t
|
2012 | return self._AbbreviatedTree(trav=trav)
|
2013 |
|
2014 | class NameType(pybase.CompoundObj):
|
2015 | _type_tag = 71
|
2016 | __slots__ = ('name', 'typ')
|
2017 |
|
2018 | def __init__(self, name, typ):
|
2019 | # type: (str, ktype_t) -> None
|
2020 | self.name = name
|
2021 | self.typ = typ
|
2022 |
|
2023 | @staticmethod
|
2024 | def CreateNull(alloc_lists=False):
|
2025 | # type: () -> NameType
|
2026 | return NameType('', cast(ktype_t, None))
|
2027 |
|
2028 | def PrettyTree(self, trav=None):
|
2029 | # type: (Optional[TraversalState]) -> hnode_t
|
2030 | trav = trav or TraversalState()
|
2031 | heap_id = id(self)
|
2032 | if heap_id in trav.seen:
|
2033 | return hnode.AlreadySeen(heap_id)
|
2034 | trav.seen[heap_id] = True
|
2035 | out_node = NewRecord('NameType')
|
2036 | L = out_node.fields
|
2037 |
|
2038 | x0 = NewLeaf(self.name, color_e.StringConst)
|
2039 | L.append(Field('name', x0))
|
2040 |
|
2041 | assert self.typ is not None
|
2042 | x1 = self.typ.PrettyTree(trav=trav)
|
2043 | L.append(Field('typ', x1))
|
2044 |
|
2045 | return out_node
|
2046 |
|
2047 | def _AbbreviatedTree(self, trav=None):
|
2048 | # type: (Optional[TraversalState]) -> hnode_t
|
2049 | trav = trav or TraversalState()
|
2050 | heap_id = id(self)
|
2051 | if heap_id in trav.seen:
|
2052 | return hnode.AlreadySeen(heap_id)
|
2053 | trav.seen[heap_id] = True
|
2054 | out_node = NewRecord('NameType')
|
2055 | L = out_node.fields
|
2056 | x0 = NewLeaf(self.name, color_e.StringConst)
|
2057 | L.append(Field('name', x0))
|
2058 |
|
2059 | assert self.typ is not None
|
2060 | x1 = self.typ.AbbreviatedTree(trav=trav)
|
2061 | L.append(Field('typ', x1))
|
2062 |
|
2063 | return out_node
|
2064 |
|
2065 | def AbbreviatedTree(self, trav=None):
|
2066 | # type: (Optional[TraversalState]) -> hnode_t
|
2067 | return self._AbbreviatedTree(trav=trav)
|
2068 |
|
2069 | class Signature(pybase.CompoundObj):
|
2070 | _type_tag = 72
|
2071 | __slots__ = ('params', 'return_type')
|
2072 |
|
2073 | def __init__(self, params, return_type):
|
2074 | # type: (List[NameType], ktype_t) -> None
|
2075 | self.params = params
|
2076 | self.return_type = return_type
|
2077 |
|
2078 | @staticmethod
|
2079 | def CreateNull(alloc_lists=False):
|
2080 | # type: () -> Signature
|
2081 | return Signature([] if alloc_lists else cast('List[NameType]', None), cast(ktype_t, None))
|
2082 |
|
2083 | def PrettyTree(self, trav=None):
|
2084 | # type: (Optional[TraversalState]) -> hnode_t
|
2085 | trav = trav or TraversalState()
|
2086 | heap_id = id(self)
|
2087 | if heap_id in trav.seen:
|
2088 | return hnode.AlreadySeen(heap_id)
|
2089 | trav.seen[heap_id] = True
|
2090 | out_node = NewRecord('Signature')
|
2091 | L = out_node.fields
|
2092 |
|
2093 | if self.params is not None: # List
|
2094 | x0 = hnode.Array([])
|
2095 | for i0 in self.params:
|
2096 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
2097 | i0.PrettyTree(trav=trav))
|
2098 | x0.children.append(h)
|
2099 | L.append(Field('params', x0))
|
2100 |
|
2101 | assert self.return_type is not None
|
2102 | x1 = self.return_type.PrettyTree(trav=trav)
|
2103 | L.append(Field('return_type', x1))
|
2104 |
|
2105 | return out_node
|
2106 |
|
2107 | def _AbbreviatedTree(self, trav=None):
|
2108 | # type: (Optional[TraversalState]) -> hnode_t
|
2109 | trav = trav or TraversalState()
|
2110 | heap_id = id(self)
|
2111 | if heap_id in trav.seen:
|
2112 | return hnode.AlreadySeen(heap_id)
|
2113 | trav.seen[heap_id] = True
|
2114 | out_node = NewRecord('Signature')
|
2115 | L = out_node.fields
|
2116 | if self.params is not None: # List
|
2117 | x0 = hnode.Array([])
|
2118 | for i0 in self.params:
|
2119 | h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
|
2120 | i0.AbbreviatedTree(trav=trav))
|
2121 | x0.children.append(h)
|
2122 | L.append(Field('params', x0))
|
2123 |
|
2124 | assert self.return_type is not None
|
2125 | x1 = self.return_type.AbbreviatedTree(trav=trav)
|
2126 | L.append(Field('return_type', x1))
|
2127 |
|
2128 | return out_node
|
2129 |
|
2130 | def AbbreviatedTree(self, trav=None):
|
2131 | # type: (Optional[TraversalState]) -> hnode_t
|
2132 | return self._AbbreviatedTree(trav=trav)
|
2133 |
|
2134 | class Module(pybase.CompoundObj):
|
2135 | _type_tag = 73
|
2136 | __slots__ = ('name', 'defs')
|
2137 |
|
2138 | def __init__(self, name, defs):
|
2139 | # type: (str, List[mod_def_t]) -> None
|
2140 | self.name = name
|
2141 | self.defs = defs
|
2142 |
|
2143 | @staticmethod
|
2144 | def CreateNull(alloc_lists=False):
|
2145 | # type: () -> Module
|
2146 | return Module('', [] if alloc_lists else cast('List[mod_def_t]', None))
|
2147 |
|
2148 | def PrettyTree(self, trav=None):
|
2149 | # type: (Optional[TraversalState]) -> hnode_t
|
2150 | trav = trav or TraversalState()
|
2151 | heap_id = id(self)
|
2152 | if heap_id in trav.seen:
|
2153 | return hnode.AlreadySeen(heap_id)
|
2154 | trav.seen[heap_id] = True
|
2155 | out_node = NewRecord('Module')
|
2156 | L = out_node.fields
|
2157 |
|
2158 | x0 = NewLeaf(self.name, color_e.StringConst)
|
2159 | L.append(Field('name', x0))
|
2160 |
|
2161 | if self.defs is not None: # List
|
2162 | x1 = hnode.Array([])
|
2163 | for i1 in self.defs:
|
2164 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
2165 | i1.PrettyTree(trav=trav))
|
2166 | x1.children.append(h)
|
2167 | L.append(Field('defs', x1))
|
2168 |
|
2169 | return out_node
|
2170 |
|
2171 | def _AbbreviatedTree(self, trav=None):
|
2172 | # type: (Optional[TraversalState]) -> hnode_t
|
2173 | trav = trav or TraversalState()
|
2174 | heap_id = id(self)
|
2175 | if heap_id in trav.seen:
|
2176 | return hnode.AlreadySeen(heap_id)
|
2177 | trav.seen[heap_id] = True
|
2178 | out_node = NewRecord('Module')
|
2179 | L = out_node.fields
|
2180 | x0 = NewLeaf(self.name, color_e.StringConst)
|
2181 | L.append(Field('name', x0))
|
2182 |
|
2183 | if self.defs is not None: # List
|
2184 | x1 = hnode.Array([])
|
2185 | for i1 in self.defs:
|
2186 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
2187 | i1.AbbreviatedTree(trav=trav))
|
2188 | x1.children.append(h)
|
2189 | L.append(Field('defs', x1))
|
2190 |
|
2191 | return out_node
|
2192 |
|
2193 | def AbbreviatedTree(self, trav=None):
|
2194 | # type: (Optional[TraversalState]) -> hnode_t
|
2195 | return self._AbbreviatedTree(trav=trav)
|
2196 |
|
2197 | class Program(pybase.CompoundObj):
|
2198 | _type_tag = 74
|
2199 | __slots__ = ('main_module', 'modules')
|
2200 |
|
2201 | def __init__(self, main_module, modules):
|
2202 | # type: (str, List[Module]) -> None
|
2203 | self.main_module = main_module
|
2204 | self.modules = modules
|
2205 |
|
2206 | @staticmethod
|
2207 | def CreateNull(alloc_lists=False):
|
2208 | # type: () -> Program
|
2209 | return Program('', [] if alloc_lists else cast('List[Module]', None))
|
2210 |
|
2211 | def PrettyTree(self, trav=None):
|
2212 | # type: (Optional[TraversalState]) -> hnode_t
|
2213 | trav = trav or TraversalState()
|
2214 | heap_id = id(self)
|
2215 | if heap_id in trav.seen:
|
2216 | return hnode.AlreadySeen(heap_id)
|
2217 | trav.seen[heap_id] = True
|
2218 | out_node = NewRecord('Program')
|
2219 | L = out_node.fields
|
2220 |
|
2221 | x0 = NewLeaf(self.main_module, color_e.StringConst)
|
2222 | L.append(Field('main_module', x0))
|
2223 |
|
2224 | if self.modules is not None: # List
|
2225 | x1 = hnode.Array([])
|
2226 | for i1 in self.modules:
|
2227 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
2228 | i1.PrettyTree(trav=trav))
|
2229 | x1.children.append(h)
|
2230 | L.append(Field('modules', x1))
|
2231 |
|
2232 | return out_node
|
2233 |
|
2234 | def _AbbreviatedTree(self, trav=None):
|
2235 | # type: (Optional[TraversalState]) -> hnode_t
|
2236 | trav = trav or TraversalState()
|
2237 | heap_id = id(self)
|
2238 | if heap_id in trav.seen:
|
2239 | return hnode.AlreadySeen(heap_id)
|
2240 | trav.seen[heap_id] = True
|
2241 | out_node = NewRecord('Program')
|
2242 | L = out_node.fields
|
2243 | x0 = NewLeaf(self.main_module, color_e.StringConst)
|
2244 | L.append(Field('main_module', x0))
|
2245 |
|
2246 | if self.modules is not None: # List
|
2247 | x1 = hnode.Array([])
|
2248 | for i1 in self.modules:
|
2249 | h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
|
2250 | i1.AbbreviatedTree(trav=trav))
|
2251 | x1.children.append(h)
|
2252 | L.append(Field('modules', x1))
|
2253 |
|
2254 | return out_node
|
2255 |
|
2256 | def AbbreviatedTree(self, trav=None):
|
2257 | # type: (Optional[TraversalState]) -> hnode_t
|
2258 | return self._AbbreviatedTree(trav=trav)
|
2259 |
|