OILS / _devbuild / gen / shared_variant_asdl.py View on Github | oilshell.org

651 lines, 465 significant
1from asdl import pybase
2from mycpp import mops
3from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
4
5
6from asdl import runtime # For runtime.NO_SPID
7from asdl.runtime import NewRecord, NewLeaf, TraversalState
8from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
9
10class expr_e(object):
11 Binary = 1
12 DoubleQuoted = 65
13
14_expr_str = {
15 1: 'Binary',
16 65: 'DoubleQuoted',
17}
18
19def expr_str(tag, dot=True):
20 # type: (int, bool) -> str
21 v = _expr_str[tag]
22 if dot:
23 return "expr.%s" % v
24 else:
25 return v
26
27class expr_t(pybase.CompoundObj):
28 def tag(self):
29 # type: () -> int
30 return self._type_tag
31 pass
32
33class expr(object):
34 class Binary(expr_t):
35 _type_tag = 1
36 __slots__ = ('left', 'right')
37
38 def __init__(self, left, right):
39 # type: (expr_t, expr_t) -> None
40 self.left = left
41 self.right = right
42
43 @staticmethod
44 def CreateNull(alloc_lists=False):
45 # type: () -> expr.Binary
46 return expr.Binary(cast(expr_t, None), cast(expr_t, None))
47
48 def PrettyTree(self, trav=None):
49 # type: (Optional[TraversalState]) -> hnode_t
50 trav = trav or TraversalState()
51 heap_id = id(self)
52 if heap_id in trav.seen:
53 return hnode.AlreadySeen(heap_id)
54 trav.seen[heap_id] = True
55 out_node = NewRecord('expr.Binary')
56 L = out_node.fields
57
58 assert self.left is not None
59 x0 = self.left.PrettyTree(trav=trav)
60 L.append(Field('left', x0))
61
62 assert self.right is not None
63 x1 = self.right.PrettyTree(trav=trav)
64 L.append(Field('right', x1))
65
66 return out_node
67
68 def _AbbreviatedTree(self, trav=None):
69 # type: (Optional[TraversalState]) -> hnode_t
70 trav = trav or TraversalState()
71 heap_id = id(self)
72 if heap_id in trav.seen:
73 return hnode.AlreadySeen(heap_id)
74 trav.seen[heap_id] = True
75 out_node = NewRecord('expr.Binary')
76 L = out_node.fields
77 assert self.left is not None
78 x0 = self.left.AbbreviatedTree(trav=trav)
79 L.append(Field('left', x0))
80
81 assert self.right is not None
82 x1 = self.right.AbbreviatedTree(trav=trav)
83 L.append(Field('right', x1))
84
85 return out_node
86
87 def AbbreviatedTree(self, trav=None):
88 # type: (Optional[TraversalState]) -> hnode_t
89 return self._AbbreviatedTree(trav=trav)
90
91 pass
92
93class tok_e(object):
94 Eof = 1
95 Token = 66
96
97_tok_str = {
98 1: 'Eof',
99 66: 'Token',
100}
101
102def tok_str(tag, dot=True):
103 # type: (int, bool) -> str
104 v = _tok_str[tag]
105 if dot:
106 return "tok.%s" % v
107 else:
108 return v
109
110class tok_t(pybase.CompoundObj):
111 def tag(self):
112 # type: () -> int
113 return self._type_tag
114 pass
115
116class tok__Eof(tok_t):
117 _type_tag = 1
118 __slots__ = ()
119
120 def __init__(self, ):
121 # type: () -> None
122 pass
123
124 def PrettyTree(self, trav=None):
125 # type: (Optional[TraversalState]) -> hnode_t
126 trav = trav or TraversalState()
127 heap_id = id(self)
128 if heap_id in trav.seen:
129 return hnode.AlreadySeen(heap_id)
130 trav.seen[heap_id] = True
131 out_node = NewRecord('tok__Eof')
132 L = out_node.fields
133
134 return out_node
135
136 def _AbbreviatedTree(self, trav=None):
137 # type: (Optional[TraversalState]) -> hnode_t
138 trav = trav or TraversalState()
139 heap_id = id(self)
140 if heap_id in trav.seen:
141 return hnode.AlreadySeen(heap_id)
142 trav.seen[heap_id] = True
143 out_node = NewRecord('tok__Eof')
144 L = out_node.fields
145 return out_node
146
147 def AbbreviatedTree(self, trav=None):
148 # type: (Optional[TraversalState]) -> hnode_t
149 return self._AbbreviatedTree(trav=trav)
150
151class tok(object):
152 Eof = tok__Eof()
153
154 pass
155
156class word_part_e(object):
157 Literal = 1
158 DoubleQuoted = 65
159
160_word_part_str = {
161 1: 'Literal',
162 65: 'DoubleQuoted',
163}
164
165def word_part_str(tag, dot=True):
166 # type: (int, bool) -> str
167 v = _word_part_str[tag]
168 if dot:
169 return "word_part.%s" % v
170 else:
171 return v
172
173class word_part_t(pybase.CompoundObj):
174 def tag(self):
175 # type: () -> int
176 return self._type_tag
177 pass
178
179class word_part(object):
180 class Literal(word_part_t):
181 _type_tag = 1
182 __slots__ = ('s',)
183
184 def __init__(self, s):
185 # type: (str) -> None
186 self.s = s
187
188 @staticmethod
189 def CreateNull(alloc_lists=False):
190 # type: () -> word_part.Literal
191 return word_part.Literal('')
192
193 def PrettyTree(self, trav=None):
194 # type: (Optional[TraversalState]) -> hnode_t
195 trav = trav or TraversalState()
196 heap_id = id(self)
197 if heap_id in trav.seen:
198 return hnode.AlreadySeen(heap_id)
199 trav.seen[heap_id] = True
200 out_node = NewRecord('word_part.Literal')
201 L = out_node.fields
202
203 x0 = NewLeaf(self.s, color_e.StringConst)
204 L.append(Field('s', x0))
205
206 return out_node
207
208 def _AbbreviatedTree(self, trav=None):
209 # type: (Optional[TraversalState]) -> hnode_t
210 trav = trav or TraversalState()
211 heap_id = id(self)
212 if heap_id in trav.seen:
213 return hnode.AlreadySeen(heap_id)
214 trav.seen[heap_id] = True
215 out_node = NewRecord('word_part.Literal')
216 L = out_node.fields
217 x0 = NewLeaf(self.s, color_e.StringConst)
218 L.append(Field('s', x0))
219
220 return out_node
221
222 def AbbreviatedTree(self, trav=None):
223 # type: (Optional[TraversalState]) -> hnode_t
224 return self._AbbreviatedTree(trav=trav)
225
226 pass
227
228class cflow_e(object):
229 Break = 1
230 Continue = 2
231 Return = 3
232
233_cflow_str = {
234 1: 'Break',
235 2: 'Continue',
236 3: 'Return',
237}
238
239def cflow_str(tag, dot=True):
240 # type: (int, bool) -> str
241 v = _cflow_str[tag]
242 if dot:
243 return "cflow.%s" % v
244 else:
245 return v
246
247class cflow_t(pybase.CompoundObj):
248 def tag(self):
249 # type: () -> int
250 return self._type_tag
251 pass
252
253class cflow__Break(cflow_t):
254 _type_tag = 1
255 __slots__ = ()
256
257 def __init__(self, ):
258 # type: () -> None
259 pass
260
261 def PrettyTree(self, trav=None):
262 # type: (Optional[TraversalState]) -> hnode_t
263 trav = trav or TraversalState()
264 heap_id = id(self)
265 if heap_id in trav.seen:
266 return hnode.AlreadySeen(heap_id)
267 trav.seen[heap_id] = True
268 out_node = NewRecord('cflow__Break')
269 L = out_node.fields
270
271 return out_node
272
273 def _AbbreviatedTree(self, trav=None):
274 # type: (Optional[TraversalState]) -> hnode_t
275 trav = trav or TraversalState()
276 heap_id = id(self)
277 if heap_id in trav.seen:
278 return hnode.AlreadySeen(heap_id)
279 trav.seen[heap_id] = True
280 out_node = NewRecord('cflow__Break')
281 L = out_node.fields
282 return out_node
283
284 def AbbreviatedTree(self, trav=None):
285 # type: (Optional[TraversalState]) -> hnode_t
286 return self._AbbreviatedTree(trav=trav)
287
288class cflow__Continue(cflow_t):
289 _type_tag = 2
290 __slots__ = ()
291
292 def __init__(self, ):
293 # type: () -> None
294 pass
295
296 def PrettyTree(self, trav=None):
297 # type: (Optional[TraversalState]) -> hnode_t
298 trav = trav or TraversalState()
299 heap_id = id(self)
300 if heap_id in trav.seen:
301 return hnode.AlreadySeen(heap_id)
302 trav.seen[heap_id] = True
303 out_node = NewRecord('cflow__Continue')
304 L = out_node.fields
305
306 return out_node
307
308 def _AbbreviatedTree(self, trav=None):
309 # type: (Optional[TraversalState]) -> hnode_t
310 trav = trav or TraversalState()
311 heap_id = id(self)
312 if heap_id in trav.seen:
313 return hnode.AlreadySeen(heap_id)
314 trav.seen[heap_id] = True
315 out_node = NewRecord('cflow__Continue')
316 L = out_node.fields
317 return out_node
318
319 def AbbreviatedTree(self, trav=None):
320 # type: (Optional[TraversalState]) -> hnode_t
321 return self._AbbreviatedTree(trav=trav)
322
323class cflow(object):
324 Break = cflow__Break()
325
326 Continue = cflow__Continue()
327
328 class Return(cflow_t):
329 _type_tag = 3
330 __slots__ = ('val',)
331
332 def __init__(self, val):
333 # type: (int) -> None
334 self.val = val
335
336 @staticmethod
337 def CreateNull(alloc_lists=False):
338 # type: () -> cflow.Return
339 return cflow.Return(-1)
340
341 def PrettyTree(self, trav=None):
342 # type: (Optional[TraversalState]) -> hnode_t
343 trav = trav or TraversalState()
344 heap_id = id(self)
345 if heap_id in trav.seen:
346 return hnode.AlreadySeen(heap_id)
347 trav.seen[heap_id] = True
348 out_node = NewRecord('cflow.Return')
349 L = out_node.fields
350
351 x0 = hnode.Leaf(str(self.val), color_e.OtherConst)
352 L.append(Field('val', x0))
353
354 return out_node
355
356 def _AbbreviatedTree(self, trav=None):
357 # type: (Optional[TraversalState]) -> hnode_t
358 trav = trav or TraversalState()
359 heap_id = id(self)
360 if heap_id in trav.seen:
361 return hnode.AlreadySeen(heap_id)
362 trav.seen[heap_id] = True
363 out_node = NewRecord('cflow.Return')
364 L = out_node.fields
365 x0 = hnode.Leaf(str(self.val), color_e.OtherConst)
366 L.append(Field('val', x0))
367
368 return out_node
369
370 def AbbreviatedTree(self, trav=None):
371 # type: (Optional[TraversalState]) -> hnode_t
372 return self._AbbreviatedTree(trav=trav)
373
374 pass
375
376class prod(pybase.CompoundObj):
377 _type_tag = 64
378 __slots__ = ('a', 'b')
379
380 def __init__(self, a, b):
381 # type: (str, str) -> None
382 self.a = a
383 self.b = b
384
385 @staticmethod
386 def CreateNull(alloc_lists=False):
387 # type: () -> prod
388 return prod('', '')
389
390 def PrettyTree(self, trav=None):
391 # type: (Optional[TraversalState]) -> hnode_t
392 trav = trav or TraversalState()
393 heap_id = id(self)
394 if heap_id in trav.seen:
395 return hnode.AlreadySeen(heap_id)
396 trav.seen[heap_id] = True
397 out_node = NewRecord('prod')
398 L = out_node.fields
399
400 x0 = NewLeaf(self.a, color_e.StringConst)
401 L.append(Field('a', x0))
402
403 x1 = NewLeaf(self.b, color_e.StringConst)
404 L.append(Field('b', x1))
405
406 return out_node
407
408 def _AbbreviatedTree(self, trav=None):
409 # type: (Optional[TraversalState]) -> hnode_t
410 trav = trav or TraversalState()
411 heap_id = id(self)
412 if heap_id in trav.seen:
413 return hnode.AlreadySeen(heap_id)
414 trav.seen[heap_id] = True
415 out_node = NewRecord('prod')
416 L = out_node.fields
417 x0 = NewLeaf(self.a, color_e.StringConst)
418 L.append(Field('a', x0))
419
420 x1 = NewLeaf(self.b, color_e.StringConst)
421 L.append(Field('b', x1))
422
423 return out_node
424
425 def AbbreviatedTree(self, trav=None):
426 # type: (Optional[TraversalState]) -> hnode_t
427 return self._AbbreviatedTree(trav=trav)
428
429class DoubleQuoted(expr_t, word_part_t):
430 _type_tag = 65
431 __slots__ = ('left', 'tokens')
432
433 def __init__(self, left, tokens):
434 # type: (int, List[str]) -> None
435 self.left = left
436 self.tokens = tokens
437
438 @staticmethod
439 def CreateNull(alloc_lists=False):
440 # type: () -> DoubleQuoted
441 return DoubleQuoted(-1, [] if alloc_lists else cast('List[str]', None))
442
443 def PrettyTree(self, trav=None):
444 # type: (Optional[TraversalState]) -> hnode_t
445 trav = trav or TraversalState()
446 heap_id = id(self)
447 if heap_id in trav.seen:
448 return hnode.AlreadySeen(heap_id)
449 trav.seen[heap_id] = True
450 out_node = NewRecord('DoubleQuoted')
451 L = out_node.fields
452
453 x0 = hnode.Leaf(str(self.left), color_e.OtherConst)
454 L.append(Field('left', x0))
455
456 if self.tokens is not None: # List
457 x1 = hnode.Array([])
458 for i1 in self.tokens:
459 x1.children.append(NewLeaf(i1, color_e.StringConst))
460 L.append(Field('tokens', x1))
461
462 return out_node
463
464 def _AbbreviatedTree(self, trav=None):
465 # type: (Optional[TraversalState]) -> hnode_t
466 trav = trav or TraversalState()
467 heap_id = id(self)
468 if heap_id in trav.seen:
469 return hnode.AlreadySeen(heap_id)
470 trav.seen[heap_id] = True
471 out_node = NewRecord('DoubleQuoted')
472 L = out_node.fields
473 x0 = hnode.Leaf(str(self.left), color_e.OtherConst)
474 L.append(Field('left', x0))
475
476 if self.tokens is not None: # List
477 x1 = hnode.Array([])
478 for i1 in self.tokens:
479 x1.children.append(NewLeaf(i1, color_e.StringConst))
480 L.append(Field('tokens', x1))
481
482 return out_node
483
484 def AbbreviatedTree(self, trav=None):
485 # type: (Optional[TraversalState]) -> hnode_t
486 return self._AbbreviatedTree(trav=trav)
487
488class Token(tok_t):
489 _type_tag = 66
490 __slots__ = ('id', 'val')
491
492 def __init__(self, id, val):
493 # type: (int, str) -> None
494 self.id = id
495 self.val = val
496
497 @staticmethod
498 def CreateNull(alloc_lists=False):
499 # type: () -> Token
500 return Token(-1, '')
501
502 def PrettyTree(self, trav=None):
503 # type: (Optional[TraversalState]) -> hnode_t
504 trav = trav or TraversalState()
505 heap_id = id(self)
506 if heap_id in trav.seen:
507 return hnode.AlreadySeen(heap_id)
508 trav.seen[heap_id] = True
509 out_node = NewRecord('Token')
510 L = out_node.fields
511
512 x0 = hnode.Leaf(str(self.id), color_e.OtherConst)
513 L.append(Field('id', x0))
514
515 x1 = NewLeaf(self.val, color_e.StringConst)
516 L.append(Field('val', x1))
517
518 return out_node
519
520 def _AbbreviatedTree(self, trav=None):
521 # type: (Optional[TraversalState]) -> hnode_t
522 trav = trav or TraversalState()
523 heap_id = id(self)
524 if heap_id in trav.seen:
525 return hnode.AlreadySeen(heap_id)
526 trav.seen[heap_id] = True
527 out_node = NewRecord('Token')
528 L = out_node.fields
529 x0 = hnode.Leaf(str(self.id), color_e.OtherConst)
530 L.append(Field('id', x0))
531
532 x1 = NewLeaf(self.val, color_e.StringConst)
533 L.append(Field('val', x1))
534
535 return out_node
536
537 def AbbreviatedTree(self, trav=None):
538 # type: (Optional[TraversalState]) -> hnode_t
539 return self._AbbreviatedTree(trav=trav)
540
541class tok_struct(pybase.CompoundObj):
542 _type_tag = 67
543 __slots__ = ('token', 'x')
544
545 def __init__(self, token, x):
546 # type: (tok_t, int) -> None
547 self.token = token
548 self.x = x
549
550 @staticmethod
551 def CreateNull(alloc_lists=False):
552 # type: () -> tok_struct
553 return tok_struct(cast(tok_t, None), -1)
554
555 def PrettyTree(self, trav=None):
556 # type: (Optional[TraversalState]) -> hnode_t
557 trav = trav or TraversalState()
558 heap_id = id(self)
559 if heap_id in trav.seen:
560 return hnode.AlreadySeen(heap_id)
561 trav.seen[heap_id] = True
562 out_node = NewRecord('tok_struct')
563 L = out_node.fields
564
565 assert self.token is not None
566 x0 = self.token.PrettyTree(trav=trav)
567 L.append(Field('token', x0))
568
569 x1 = hnode.Leaf(str(self.x), color_e.OtherConst)
570 L.append(Field('x', x1))
571
572 return out_node
573
574 def _AbbreviatedTree(self, trav=None):
575 # type: (Optional[TraversalState]) -> hnode_t
576 trav = trav or TraversalState()
577 heap_id = id(self)
578 if heap_id in trav.seen:
579 return hnode.AlreadySeen(heap_id)
580 trav.seen[heap_id] = True
581 out_node = NewRecord('tok_struct')
582 L = out_node.fields
583 assert self.token is not None
584 x0 = self.token.AbbreviatedTree(trav=trav)
585 L.append(Field('token', x0))
586
587 x1 = hnode.Leaf(str(self.x), color_e.OtherConst)
588 L.append(Field('x', x1))
589
590 return out_node
591
592 def AbbreviatedTree(self, trav=None):
593 # type: (Optional[TraversalState]) -> hnode_t
594 return self._AbbreviatedTree(trav=trav)
595
596class tok_array(pybase.CompoundObj):
597 _type_tag = 68
598 __slots__ = ('tokens',)
599
600 def __init__(self, tokens):
601 # type: (List[tok_t]) -> None
602 self.tokens = tokens
603
604 @staticmethod
605 def CreateNull(alloc_lists=False):
606 # type: () -> tok_array
607 return tok_array([] if alloc_lists else cast('List[tok_t]', None))
608
609 def PrettyTree(self, trav=None):
610 # type: (Optional[TraversalState]) -> hnode_t
611 trav = trav or TraversalState()
612 heap_id = id(self)
613 if heap_id in trav.seen:
614 return hnode.AlreadySeen(heap_id)
615 trav.seen[heap_id] = True
616 out_node = NewRecord('tok_array')
617 L = out_node.fields
618
619 if self.tokens is not None: # List
620 x0 = hnode.Array([])
621 for i0 in self.tokens:
622 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
623 i0.PrettyTree(trav=trav))
624 x0.children.append(h)
625 L.append(Field('tokens', x0))
626
627 return out_node
628
629 def _AbbreviatedTree(self, trav=None):
630 # type: (Optional[TraversalState]) -> hnode_t
631 trav = trav or TraversalState()
632 heap_id = id(self)
633 if heap_id in trav.seen:
634 return hnode.AlreadySeen(heap_id)
635 trav.seen[heap_id] = True
636 out_node = NewRecord('tok_array')
637 L = out_node.fields
638 if self.tokens is not None: # List
639 x0 = hnode.Array([])
640 for i0 in self.tokens:
641 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
642 i0.AbbreviatedTree(trav=trav))
643 x0.children.append(h)
644 L.append(Field('tokens', x0))
645
646 return out_node
647
648 def AbbreviatedTree(self, trav=None):
649 # type: (Optional[TraversalState]) -> hnode_t
650 return self._AbbreviatedTree(trav=trav)
651