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

1625 lines, 1163 significant
1from asdl import pybase
2from mycpp import mops
3from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
4
5if TYPE_CHECKING:
6 from _devbuild.gen.syntax_asdl import loc_t, Token, expr_t, command_t, DoubleQuoted, re_t, proc_sig_t, Func, NameType, EggexFlag, BraceGroup, SourceLine
7 from _devbuild.gen.runtime_asdl import Cell
8
9from asdl import runtime # For runtime.NO_SPID
10from asdl.runtime import NewRecord, NewLeaf, TraversalState
11from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
12
13class y_lvalue_e(object):
14 Local = 66
15 Container = 2
16
17_y_lvalue_str = {
18 2: 'Container',
19 66: 'Local',
20}
21
22def y_lvalue_str(tag, dot=True):
23 # type: (int, bool) -> str
24 v = _y_lvalue_str[tag]
25 if dot:
26 return "y_lvalue.%s" % v
27 else:
28 return v
29
30class y_lvalue_t(pybase.CompoundObj):
31 def tag(self):
32 # type: () -> int
33 return self._type_tag
34
35class y_lvalue(object):
36 class Container(y_lvalue_t):
37 _type_tag = 2
38 __slots__ = ('obj', 'index')
39
40 def __init__(self, obj, index):
41 # type: (value_t, value_t) -> None
42 self.obj = obj
43 self.index = index
44
45 @staticmethod
46 def CreateNull(alloc_lists=False):
47 # type: () -> y_lvalue.Container
48 return y_lvalue.Container(cast('value_t', None), cast('value_t', None))
49
50 def PrettyTree(self, do_abbrev, trav=None):
51 # type: (bool, Optional[TraversalState]) -> hnode_t
52 trav = trav or TraversalState()
53 heap_id = id(self)
54 if heap_id in trav.seen:
55 return hnode.AlreadySeen(heap_id)
56 trav.seen[heap_id] = True
57
58 out_node = NewRecord('y_lvalue.Container')
59 L = out_node.fields
60
61 assert self.obj is not None
62 x0 = self.obj.PrettyTree(do_abbrev, trav=trav)
63 L.append(Field('obj', x0))
64
65 assert self.index is not None
66 x1 = self.index.PrettyTree(do_abbrev, trav=trav)
67 L.append(Field('index', x1))
68
69 return out_node
70
71 pass
72
73class sh_lvalue_e(object):
74 Var = 66
75 Indexed = 2
76 Keyed = 3
77
78_sh_lvalue_str = {
79 2: 'Indexed',
80 3: 'Keyed',
81 66: 'Var',
82}
83
84def sh_lvalue_str(tag, dot=True):
85 # type: (int, bool) -> str
86 v = _sh_lvalue_str[tag]
87 if dot:
88 return "sh_lvalue.%s" % v
89 else:
90 return v
91
92class sh_lvalue_t(pybase.CompoundObj):
93 def tag(self):
94 # type: () -> int
95 return self._type_tag
96
97class sh_lvalue(object):
98 class Indexed(sh_lvalue_t):
99 _type_tag = 2
100 __slots__ = ('name', 'index', 'blame_loc')
101
102 def __init__(self, name, index, blame_loc):
103 # type: (str, int, loc_t) -> None
104 self.name = name
105 self.index = index
106 self.blame_loc = blame_loc
107
108 @staticmethod
109 def CreateNull(alloc_lists=False):
110 # type: () -> sh_lvalue.Indexed
111 return sh_lvalue.Indexed('', -1, cast('loc_t', None))
112
113 def PrettyTree(self, do_abbrev, trav=None):
114 # type: (bool, Optional[TraversalState]) -> hnode_t
115 trav = trav or TraversalState()
116 heap_id = id(self)
117 if heap_id in trav.seen:
118 return hnode.AlreadySeen(heap_id)
119 trav.seen[heap_id] = True
120
121 out_node = NewRecord('sh_lvalue.Indexed')
122 L = out_node.fields
123
124 x0 = NewLeaf(self.name, color_e.StringConst)
125 L.append(Field('name', x0))
126
127 x1 = hnode.Leaf(str(self.index), color_e.OtherConst)
128 L.append(Field('index', x1))
129
130 assert self.blame_loc is not None
131 x2 = self.blame_loc.PrettyTree(do_abbrev, trav=trav)
132 L.append(Field('blame_loc', x2))
133
134 return out_node
135
136 class Keyed(sh_lvalue_t):
137 _type_tag = 3
138 __slots__ = ('name', 'key', 'blame_loc')
139
140 def __init__(self, name, key, blame_loc):
141 # type: (str, str, loc_t) -> None
142 self.name = name
143 self.key = key
144 self.blame_loc = blame_loc
145
146 @staticmethod
147 def CreateNull(alloc_lists=False):
148 # type: () -> sh_lvalue.Keyed
149 return sh_lvalue.Keyed('', '', cast('loc_t', None))
150
151 def PrettyTree(self, do_abbrev, trav=None):
152 # type: (bool, Optional[TraversalState]) -> hnode_t
153 trav = trav or TraversalState()
154 heap_id = id(self)
155 if heap_id in trav.seen:
156 return hnode.AlreadySeen(heap_id)
157 trav.seen[heap_id] = True
158
159 out_node = NewRecord('sh_lvalue.Keyed')
160 L = out_node.fields
161
162 x0 = NewLeaf(self.name, color_e.StringConst)
163 L.append(Field('name', x0))
164
165 x1 = NewLeaf(self.key, color_e.StringConst)
166 L.append(Field('key', x1))
167
168 assert self.blame_loc is not None
169 x2 = self.blame_loc.PrettyTree(do_abbrev, trav=trav)
170 L.append(Field('blame_loc', x2))
171
172 return out_node
173
174 pass
175
176class eggex_ops_e(object):
177 No = 1
178 Yes = 2
179
180_eggex_ops_str = {
181 1: 'No',
182 2: 'Yes',
183}
184
185def eggex_ops_str(tag, dot=True):
186 # type: (int, bool) -> str
187 v = _eggex_ops_str[tag]
188 if dot:
189 return "eggex_ops.%s" % v
190 else:
191 return v
192
193class eggex_ops_t(pybase.CompoundObj):
194 def tag(self):
195 # type: () -> int
196 return self._type_tag
197
198class eggex_ops__No(eggex_ops_t):
199 _type_tag = 1
200 __slots__ = ()
201
202 def __init__(self, ):
203 # type: () -> None
204 pass
205
206 def PrettyTree(self, do_abbrev, trav=None):
207 # type: (bool, Optional[TraversalState]) -> hnode_t
208 trav = trav or TraversalState()
209 heap_id = id(self)
210 if heap_id in trav.seen:
211 return hnode.AlreadySeen(heap_id)
212 trav.seen[heap_id] = True
213
214 out_node = NewRecord('eggex_ops.No')
215 L = out_node.fields
216
217 return out_node
218
219class eggex_ops(object):
220 No = eggex_ops__No()
221
222 class Yes(eggex_ops_t):
223 _type_tag = 2
224 __slots__ = ('convert_funcs', 'convert_toks', 'capture_names')
225
226 def __init__(self, convert_funcs, convert_toks, capture_names):
227 # type: (List[Optional[value_t]], List[Optional[Token]], List[Optional[str]]) -> None
228 self.convert_funcs = convert_funcs
229 self.convert_toks = convert_toks
230 self.capture_names = capture_names
231
232 @staticmethod
233 def CreateNull(alloc_lists=False):
234 # type: () -> eggex_ops.Yes
235 return eggex_ops.Yes([] if alloc_lists else cast('List[Optional[value_t]]', None), [] if alloc_lists else cast('List[Optional[Token]]', None), [] if alloc_lists else cast('List[Optional[str]]', None))
236
237 def PrettyTree(self, do_abbrev, trav=None):
238 # type: (bool, Optional[TraversalState]) -> hnode_t
239 trav = trav or TraversalState()
240 heap_id = id(self)
241 if heap_id in trav.seen:
242 return hnode.AlreadySeen(heap_id)
243 trav.seen[heap_id] = True
244
245 out_node = NewRecord('eggex_ops.Yes')
246 L = out_node.fields
247
248 if self.convert_funcs is not None: # List
249 x0 = hnode.Array([])
250 for i0 in self.convert_funcs:
251 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
252 i0.PrettyTree(do_abbrev, trav=trav))
253 x0.children.append(h)
254 L.append(Field('convert_funcs', x0))
255
256 if self.convert_toks is not None: # List
257 x1 = hnode.Array([])
258 for i1 in self.convert_toks:
259 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
260 i1.PrettyTree(do_abbrev, trav=trav))
261 x1.children.append(h)
262 L.append(Field('convert_toks', x1))
263
264 if self.capture_names is not None: # List
265 x2 = hnode.Array([])
266 for i2 in self.capture_names:
267 x2.children.append(NewLeaf(i2, color_e.StringConst))
268 L.append(Field('capture_names', x2))
269
270 return out_node
271
272 pass
273
274class regex_match_e(object):
275 No = 1
276 Yes = 67
277
278_regex_match_str = {
279 1: 'No',
280 67: 'Yes',
281}
282
283def regex_match_str(tag, dot=True):
284 # type: (int, bool) -> str
285 v = _regex_match_str[tag]
286 if dot:
287 return "regex_match.%s" % v
288 else:
289 return v
290
291class regex_match_t(pybase.CompoundObj):
292 def tag(self):
293 # type: () -> int
294 return self._type_tag
295
296class regex_match__No(regex_match_t):
297 _type_tag = 1
298 __slots__ = ()
299
300 def __init__(self, ):
301 # type: () -> None
302 pass
303
304 def PrettyTree(self, do_abbrev, trav=None):
305 # type: (bool, Optional[TraversalState]) -> hnode_t
306 trav = trav or TraversalState()
307 heap_id = id(self)
308 if heap_id in trav.seen:
309 return hnode.AlreadySeen(heap_id)
310 trav.seen[heap_id] = True
311
312 out_node = NewRecord('regex_match.No')
313 L = out_node.fields
314
315 return out_node
316
317class regex_match(object):
318 No = regex_match__No()
319
320 pass
321
322class cmd_frag_e(object):
323 LiteralBlock = 68
324 Expr = 2
325
326_cmd_frag_str = {
327 2: 'Expr',
328 68: 'LiteralBlock',
329}
330
331def cmd_frag_str(tag, dot=True):
332 # type: (int, bool) -> str
333 v = _cmd_frag_str[tag]
334 if dot:
335 return "cmd_frag.%s" % v
336 else:
337 return v
338
339class cmd_frag_t(pybase.CompoundObj):
340 def tag(self):
341 # type: () -> int
342 return self._type_tag
343
344class cmd_frag(object):
345 class Expr(cmd_frag_t):
346 _type_tag = 2
347 __slots__ = ('c',)
348
349 def __init__(self, c):
350 # type: (command_t) -> None
351 self.c = c
352
353 @staticmethod
354 def CreateNull(alloc_lists=False):
355 # type: () -> cmd_frag.Expr
356 return cmd_frag.Expr(cast('command_t', None))
357
358 def PrettyTree(self, do_abbrev, trav=None):
359 # type: (bool, Optional[TraversalState]) -> hnode_t
360 trav = trav or TraversalState()
361 heap_id = id(self)
362 if heap_id in trav.seen:
363 return hnode.AlreadySeen(heap_id)
364 trav.seen[heap_id] = True
365
366 out_node = NewRecord('cmd_frag.Expr')
367 L = out_node.fields
368
369 assert self.c is not None
370 x0 = self.c.PrettyTree(do_abbrev, trav=trav)
371 L.append(Field('c', x0))
372
373 return out_node
374
375 pass
376
377class value_e(object):
378 Interrupted = 1
379 Stdin = 2
380 Slice = 3
381 Undef = 4
382 Str = 5
383 BashArray = 6
384 SparseArray = 7
385 BashAssoc = 8
386 Null = 9
387 Bool = 10
388 Int = 11
389 Float = 12
390 List = 13
391 Dict = 14
392 Obj = 69
393 Range = 16
394 Eggex = 17
395 Match = 67
396 Place = 19
397 Frame = 20
398 BoundFunc = 21
399 BuiltinFunc = 22
400 Func = 23
401 BuiltinProc = 24
402 Proc = 25
403 Expr = 26
404 CommandFrag = 27
405 Command = 28
406
407_value_str = {
408 1: 'Interrupted',
409 2: 'Stdin',
410 3: 'Slice',
411 4: 'Undef',
412 5: 'Str',
413 6: 'BashArray',
414 7: 'SparseArray',
415 8: 'BashAssoc',
416 9: 'Null',
417 10: 'Bool',
418 11: 'Int',
419 12: 'Float',
420 13: 'List',
421 14: 'Dict',
422 16: 'Range',
423 17: 'Eggex',
424 19: 'Place',
425 20: 'Frame',
426 21: 'BoundFunc',
427 22: 'BuiltinFunc',
428 23: 'Func',
429 24: 'BuiltinProc',
430 25: 'Proc',
431 26: 'Expr',
432 27: 'CommandFrag',
433 28: 'Command',
434 67: 'Match',
435 69: 'Obj',
436}
437
438def value_str(tag, dot=True):
439 # type: (int, bool) -> str
440 v = _value_str[tag]
441 if dot:
442 return "value.%s" % v
443 else:
444 return v
445
446class value_t(pybase.CompoundObj):
447 def tag(self):
448 # type: () -> int
449 return self._type_tag
450
451class value__Interrupted(value_t):
452 _type_tag = 1
453 __slots__ = ()
454
455 def __init__(self, ):
456 # type: () -> None
457 pass
458
459 def PrettyTree(self, do_abbrev, trav=None):
460 # type: (bool, Optional[TraversalState]) -> hnode_t
461 trav = trav or TraversalState()
462 heap_id = id(self)
463 if heap_id in trav.seen:
464 return hnode.AlreadySeen(heap_id)
465 trav.seen[heap_id] = True
466
467 out_node = NewRecord('value.Interrupted')
468 L = out_node.fields
469
470 return out_node
471
472class value__Stdin(value_t):
473 _type_tag = 2
474 __slots__ = ()
475
476 def __init__(self, ):
477 # type: () -> None
478 pass
479
480 def PrettyTree(self, do_abbrev, trav=None):
481 # type: (bool, Optional[TraversalState]) -> hnode_t
482 trav = trav or TraversalState()
483 heap_id = id(self)
484 if heap_id in trav.seen:
485 return hnode.AlreadySeen(heap_id)
486 trav.seen[heap_id] = True
487
488 out_node = NewRecord('value.Stdin')
489 L = out_node.fields
490
491 return out_node
492
493class value__Undef(value_t):
494 _type_tag = 4
495 __slots__ = ()
496
497 def __init__(self, ):
498 # type: () -> None
499 pass
500
501 def PrettyTree(self, do_abbrev, trav=None):
502 # type: (bool, Optional[TraversalState]) -> hnode_t
503 trav = trav or TraversalState()
504 heap_id = id(self)
505 if heap_id in trav.seen:
506 return hnode.AlreadySeen(heap_id)
507 trav.seen[heap_id] = True
508
509 out_node = NewRecord('value.Undef')
510 L = out_node.fields
511
512 return out_node
513
514class value__Null(value_t):
515 _type_tag = 9
516 __slots__ = ()
517
518 def __init__(self, ):
519 # type: () -> None
520 pass
521
522 def PrettyTree(self, do_abbrev, trav=None):
523 # type: (bool, Optional[TraversalState]) -> hnode_t
524 trav = trav or TraversalState()
525 heap_id = id(self)
526 if heap_id in trav.seen:
527 return hnode.AlreadySeen(heap_id)
528 trav.seen[heap_id] = True
529
530 out_node = NewRecord('value.Null')
531 L = out_node.fields
532
533 return out_node
534
535class value(object):
536 Interrupted = value__Interrupted()
537
538 Stdin = value__Stdin()
539
540 class Slice(value_t):
541 _type_tag = 3
542 __slots__ = ('lower', 'upper')
543
544 def __init__(self, lower, upper):
545 # type: (Optional[IntBox], Optional[IntBox]) -> None
546 self.lower = lower
547 self.upper = upper
548
549 @staticmethod
550 def CreateNull(alloc_lists=False):
551 # type: () -> value.Slice
552 return value.Slice(cast('Optional[IntBox]', None), cast('Optional[IntBox]', None))
553
554 def PrettyTree(self, do_abbrev, trav=None):
555 # type: (bool, Optional[TraversalState]) -> hnode_t
556 trav = trav or TraversalState()
557 heap_id = id(self)
558 if heap_id in trav.seen:
559 return hnode.AlreadySeen(heap_id)
560 trav.seen[heap_id] = True
561
562 out_node = NewRecord('value.Slice')
563 L = out_node.fields
564
565 if self.lower is not None: # Optional
566 x0 = self.lower.PrettyTree(do_abbrev, trav=trav)
567 L.append(Field('lower', x0))
568
569 if self.upper is not None: # Optional
570 x1 = self.upper.PrettyTree(do_abbrev, trav=trav)
571 L.append(Field('upper', x1))
572
573 return out_node
574
575 Undef = value__Undef()
576
577 class Str(value_t):
578 _type_tag = 5
579 __slots__ = ('s',)
580
581 def __init__(self, s):
582 # type: (str) -> None
583 self.s = s
584
585 @staticmethod
586 def CreateNull(alloc_lists=False):
587 # type: () -> value.Str
588 return value.Str('')
589
590 def PrettyTree(self, do_abbrev, trav=None):
591 # type: (bool, Optional[TraversalState]) -> hnode_t
592 trav = trav or TraversalState()
593 heap_id = id(self)
594 if heap_id in trav.seen:
595 return hnode.AlreadySeen(heap_id)
596 trav.seen[heap_id] = True
597
598 out_node = NewRecord('value.Str')
599 L = out_node.fields
600
601 x0 = NewLeaf(self.s, color_e.StringConst)
602 L.append(Field('s', x0))
603
604 return out_node
605
606 class BashArray(value_t):
607 _type_tag = 6
608 __slots__ = ('strs',)
609
610 def __init__(self, strs):
611 # type: (List[str]) -> None
612 self.strs = strs
613
614 @staticmethod
615 def CreateNull(alloc_lists=False):
616 # type: () -> value.BashArray
617 return value.BashArray([] if alloc_lists else cast('List[str]', None))
618
619 def PrettyTree(self, do_abbrev, trav=None):
620 # type: (bool, Optional[TraversalState]) -> hnode_t
621 trav = trav or TraversalState()
622 heap_id = id(self)
623 if heap_id in trav.seen:
624 return hnode.AlreadySeen(heap_id)
625 trav.seen[heap_id] = True
626
627 out_node = NewRecord('value.BashArray')
628 L = out_node.fields
629
630 if self.strs is not None: # List
631 x0 = hnode.Array([])
632 for i0 in self.strs:
633 x0.children.append(NewLeaf(i0, color_e.StringConst))
634 L.append(Field('strs', x0))
635
636 return out_node
637
638 class SparseArray(value_t):
639 _type_tag = 7
640 __slots__ = ('d', 'max_index')
641
642 def __init__(self, d, max_index):
643 # type: (Dict[mops.BigInt, str], mops.BigInt) -> None
644 self.d = d
645 self.max_index = max_index
646
647 @staticmethod
648 def CreateNull(alloc_lists=False):
649 # type: () -> value.SparseArray
650 return value.SparseArray(cast('Dict[mops.BigInt, str]', None), mops.BigInt(-1))
651
652 def PrettyTree(self, do_abbrev, trav=None):
653 # type: (bool, Optional[TraversalState]) -> hnode_t
654 trav = trav or TraversalState()
655 heap_id = id(self)
656 if heap_id in trav.seen:
657 return hnode.AlreadySeen(heap_id)
658 trav.seen[heap_id] = True
659
660 out_node = NewRecord('value.SparseArray')
661 L = out_node.fields
662
663 if self.d is not None: # Dict
664 unnamed0 = [] # type: List[hnode_t]
665 x0 = hnode.Record("", "{", "}", [], unnamed0)
666 for k0, v0 in self.d.iteritems():
667 unnamed0.append(hnode.Leaf(mops.ToStr(k0), color_e.OtherConst))
668 unnamed0.append(NewLeaf(v0, color_e.StringConst))
669 L.append(Field('d', x0))
670
671 x1 = hnode.Leaf(mops.ToStr(self.max_index), color_e.OtherConst)
672 L.append(Field('max_index', x1))
673
674 return out_node
675
676 class BashAssoc(value_t):
677 _type_tag = 8
678 __slots__ = ('d',)
679
680 def __init__(self, d):
681 # type: (Dict[str, str]) -> None
682 self.d = d
683
684 @staticmethod
685 def CreateNull(alloc_lists=False):
686 # type: () -> value.BashAssoc
687 return value.BashAssoc(cast('Dict[str, str]', None))
688
689 def PrettyTree(self, do_abbrev, trav=None):
690 # type: (bool, Optional[TraversalState]) -> hnode_t
691 trav = trav or TraversalState()
692 heap_id = id(self)
693 if heap_id in trav.seen:
694 return hnode.AlreadySeen(heap_id)
695 trav.seen[heap_id] = True
696
697 out_node = NewRecord('value.BashAssoc')
698 L = out_node.fields
699
700 if self.d is not None: # Dict
701 unnamed0 = [] # type: List[hnode_t]
702 x0 = hnode.Record("", "{", "}", [], unnamed0)
703 for k0, v0 in self.d.iteritems():
704 unnamed0.append(NewLeaf(k0, color_e.StringConst))
705 unnamed0.append(NewLeaf(v0, color_e.StringConst))
706 L.append(Field('d', x0))
707
708 return out_node
709
710 Null = value__Null()
711
712 class Bool(value_t):
713 _type_tag = 10
714 __slots__ = ('b',)
715
716 def __init__(self, b):
717 # type: (bool) -> None
718 self.b = b
719
720 @staticmethod
721 def CreateNull(alloc_lists=False):
722 # type: () -> value.Bool
723 return value.Bool(False)
724
725 def PrettyTree(self, do_abbrev, trav=None):
726 # type: (bool, Optional[TraversalState]) -> hnode_t
727 trav = trav or TraversalState()
728 heap_id = id(self)
729 if heap_id in trav.seen:
730 return hnode.AlreadySeen(heap_id)
731 trav.seen[heap_id] = True
732
733 out_node = NewRecord('value.Bool')
734 L = out_node.fields
735
736 x0 = hnode.Leaf('T' if self.b else 'F', color_e.OtherConst)
737 L.append(Field('b', x0))
738
739 return out_node
740
741 class Int(value_t):
742 _type_tag = 11
743 __slots__ = ('i',)
744
745 def __init__(self, i):
746 # type: (mops.BigInt) -> None
747 self.i = i
748
749 @staticmethod
750 def CreateNull(alloc_lists=False):
751 # type: () -> value.Int
752 return value.Int(mops.BigInt(-1))
753
754 def PrettyTree(self, do_abbrev, trav=None):
755 # type: (bool, Optional[TraversalState]) -> hnode_t
756 trav = trav or TraversalState()
757 heap_id = id(self)
758 if heap_id in trav.seen:
759 return hnode.AlreadySeen(heap_id)
760 trav.seen[heap_id] = True
761
762 out_node = NewRecord('value.Int')
763 L = out_node.fields
764
765 x0 = hnode.Leaf(mops.ToStr(self.i), color_e.OtherConst)
766 L.append(Field('i', x0))
767
768 return out_node
769
770 class Float(value_t):
771 _type_tag = 12
772 __slots__ = ('f',)
773
774 def __init__(self, f):
775 # type: (float) -> None
776 self.f = f
777
778 @staticmethod
779 def CreateNull(alloc_lists=False):
780 # type: () -> value.Float
781 return value.Float(0.0)
782
783 def PrettyTree(self, do_abbrev, trav=None):
784 # type: (bool, Optional[TraversalState]) -> hnode_t
785 trav = trav or TraversalState()
786 heap_id = id(self)
787 if heap_id in trav.seen:
788 return hnode.AlreadySeen(heap_id)
789 trav.seen[heap_id] = True
790
791 out_node = NewRecord('value.Float')
792 L = out_node.fields
793
794 x0 = hnode.Leaf(str(self.f), color_e.OtherConst)
795 L.append(Field('f', x0))
796
797 return out_node
798
799 class List(value_t):
800 _type_tag = 13
801 __slots__ = ('items',)
802
803 def __init__(self, items):
804 # type: (List[value_t]) -> None
805 self.items = items
806
807 @staticmethod
808 def CreateNull(alloc_lists=False):
809 # type: () -> value.List
810 return value.List([] if alloc_lists else cast('List[value_t]', None))
811
812 def PrettyTree(self, do_abbrev, trav=None):
813 # type: (bool, Optional[TraversalState]) -> hnode_t
814 trav = trav or TraversalState()
815 heap_id = id(self)
816 if heap_id in trav.seen:
817 return hnode.AlreadySeen(heap_id)
818 trav.seen[heap_id] = True
819
820 out_node = NewRecord('value.List')
821 L = out_node.fields
822
823 if self.items is not None: # List
824 x0 = hnode.Array([])
825 for i0 in self.items:
826 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
827 i0.PrettyTree(do_abbrev, trav=trav))
828 x0.children.append(h)
829 L.append(Field('items', x0))
830
831 return out_node
832
833 class Dict(value_t):
834 _type_tag = 14
835 __slots__ = ('d',)
836
837 def __init__(self, d):
838 # type: (Dict[str, value_t]) -> None
839 self.d = d
840
841 @staticmethod
842 def CreateNull(alloc_lists=False):
843 # type: () -> value.Dict
844 return value.Dict(cast('Dict[str, value_t]', None))
845
846 def PrettyTree(self, do_abbrev, trav=None):
847 # type: (bool, Optional[TraversalState]) -> hnode_t
848 trav = trav or TraversalState()
849 heap_id = id(self)
850 if heap_id in trav.seen:
851 return hnode.AlreadySeen(heap_id)
852 trav.seen[heap_id] = True
853
854 out_node = NewRecord('value.Dict')
855 L = out_node.fields
856
857 if self.d is not None: # Dict
858 unnamed0 = [] # type: List[hnode_t]
859 x0 = hnode.Record("", "{", "}", [], unnamed0)
860 for k0, v0 in self.d.iteritems():
861 unnamed0.append(NewLeaf(k0, color_e.StringConst))
862 unnamed0.append(v0.PrettyTree(do_abbrev, trav=trav))
863 L.append(Field('d', x0))
864
865 return out_node
866
867 class Range(value_t):
868 _type_tag = 16
869 __slots__ = ('lower', 'upper')
870
871 def __init__(self, lower, upper):
872 # type: (int, int) -> None
873 self.lower = lower
874 self.upper = upper
875
876 @staticmethod
877 def CreateNull(alloc_lists=False):
878 # type: () -> value.Range
879 return value.Range(-1, -1)
880
881 def PrettyTree(self, do_abbrev, trav=None):
882 # type: (bool, Optional[TraversalState]) -> hnode_t
883 trav = trav or TraversalState()
884 heap_id = id(self)
885 if heap_id in trav.seen:
886 return hnode.AlreadySeen(heap_id)
887 trav.seen[heap_id] = True
888
889 out_node = NewRecord('value.Range')
890 L = out_node.fields
891
892 x0 = hnode.Leaf(str(self.lower), color_e.OtherConst)
893 L.append(Field('lower', x0))
894
895 x1 = hnode.Leaf(str(self.upper), color_e.OtherConst)
896 L.append(Field('upper', x1))
897
898 return out_node
899
900 class Eggex(value_t):
901 _type_tag = 17
902 __slots__ = ('spliced', 'canonical_flags', 'convert_funcs', 'convert_toks',
903 'as_ere', 'capture_names')
904
905 def __init__(self, spliced, canonical_flags, convert_funcs, convert_toks,
906 as_ere, capture_names):
907 # type: (re_t, str, List[Optional[value_t]], List[Optional[Token]], Optional[str], List[Optional[str]]) -> None
908 self.spliced = spliced
909 self.canonical_flags = canonical_flags
910 self.convert_funcs = convert_funcs
911 self.convert_toks = convert_toks
912 self.as_ere = as_ere
913 self.capture_names = capture_names
914
915 @staticmethod
916 def CreateNull(alloc_lists=False):
917 # type: () -> value.Eggex
918 return value.Eggex(cast('re_t', None), '', [] if alloc_lists else cast('List[Optional[value_t]]', None), [] if alloc_lists else cast('List[Optional[Token]]', None), cast('Optional[str]', None), [] if alloc_lists else cast('List[Optional[str]]', None))
919
920 def PrettyTree(self, do_abbrev, trav=None):
921 # type: (bool, Optional[TraversalState]) -> hnode_t
922 trav = trav or TraversalState()
923 heap_id = id(self)
924 if heap_id in trav.seen:
925 return hnode.AlreadySeen(heap_id)
926 trav.seen[heap_id] = True
927
928 out_node = NewRecord('value.Eggex')
929 L = out_node.fields
930
931 assert self.spliced is not None
932 x0 = self.spliced.PrettyTree(do_abbrev, trav=trav)
933 L.append(Field('spliced', x0))
934
935 x1 = NewLeaf(self.canonical_flags, color_e.StringConst)
936 L.append(Field('canonical_flags', x1))
937
938 if self.convert_funcs is not None: # List
939 x2 = hnode.Array([])
940 for i2 in self.convert_funcs:
941 h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
942 i2.PrettyTree(do_abbrev, trav=trav))
943 x2.children.append(h)
944 L.append(Field('convert_funcs', x2))
945
946 if self.convert_toks is not None: # List
947 x3 = hnode.Array([])
948 for i3 in self.convert_toks:
949 h = (hnode.Leaf("_", color_e.OtherConst) if i3 is None else
950 i3.PrettyTree(do_abbrev, trav=trav))
951 x3.children.append(h)
952 L.append(Field('convert_toks', x3))
953
954 if self.as_ere is not None: # Optional
955 x4 = NewLeaf(self.as_ere, color_e.StringConst)
956 L.append(Field('as_ere', x4))
957
958 if self.capture_names is not None: # List
959 x5 = hnode.Array([])
960 for i5 in self.capture_names:
961 x5.children.append(NewLeaf(i5, color_e.StringConst))
962 L.append(Field('capture_names', x5))
963
964 return out_node
965
966 class Place(value_t):
967 _type_tag = 19
968 __slots__ = ('lval', 'frame')
969
970 def __init__(self, lval, frame):
971 # type: (y_lvalue_t, Dict[str, Cell]) -> None
972 self.lval = lval
973 self.frame = frame
974
975 @staticmethod
976 def CreateNull(alloc_lists=False):
977 # type: () -> value.Place
978 return value.Place(cast('y_lvalue_t', None), cast('Dict[str, Cell]', None))
979
980 def PrettyTree(self, do_abbrev, trav=None):
981 # type: (bool, Optional[TraversalState]) -> hnode_t
982 trav = trav or TraversalState()
983 heap_id = id(self)
984 if heap_id in trav.seen:
985 return hnode.AlreadySeen(heap_id)
986 trav.seen[heap_id] = True
987
988 out_node = NewRecord('value.Place')
989 L = out_node.fields
990
991 assert self.lval is not None
992 x0 = self.lval.PrettyTree(do_abbrev, trav=trav)
993 L.append(Field('lval', x0))
994
995 if self.frame is not None: # Dict
996 unnamed1 = [] # type: List[hnode_t]
997 x1 = hnode.Record("", "{", "}", [], unnamed1)
998 for k1, v1 in self.frame.iteritems():
999 unnamed1.append(NewLeaf(k1, color_e.StringConst))
1000 unnamed1.append(v1.PrettyTree(do_abbrev, trav=trav))
1001 L.append(Field('frame', x1))
1002
1003 return out_node
1004
1005 class Frame(value_t):
1006 _type_tag = 20
1007 __slots__ = ('frame',)
1008
1009 def __init__(self, frame):
1010 # type: (Dict[str, Cell]) -> None
1011 self.frame = frame
1012
1013 @staticmethod
1014 def CreateNull(alloc_lists=False):
1015 # type: () -> value.Frame
1016 return value.Frame(cast('Dict[str, Cell]', None))
1017
1018 def PrettyTree(self, do_abbrev, trav=None):
1019 # type: (bool, Optional[TraversalState]) -> hnode_t
1020 trav = trav or TraversalState()
1021 heap_id = id(self)
1022 if heap_id in trav.seen:
1023 return hnode.AlreadySeen(heap_id)
1024 trav.seen[heap_id] = True
1025
1026 out_node = NewRecord('value.Frame')
1027 L = out_node.fields
1028
1029 if self.frame is not None: # Dict
1030 unnamed0 = [] # type: List[hnode_t]
1031 x0 = hnode.Record("", "{", "}", [], unnamed0)
1032 for k0, v0 in self.frame.iteritems():
1033 unnamed0.append(NewLeaf(k0, color_e.StringConst))
1034 unnamed0.append(v0.PrettyTree(do_abbrev, trav=trav))
1035 L.append(Field('frame', x0))
1036
1037 return out_node
1038
1039 class BoundFunc(value_t):
1040 _type_tag = 21
1041 __slots__ = ('me', 'func')
1042
1043 def __init__(self, me, func):
1044 # type: (value_t, value_t) -> None
1045 self.me = me
1046 self.func = func
1047
1048 @staticmethod
1049 def CreateNull(alloc_lists=False):
1050 # type: () -> value.BoundFunc
1051 return value.BoundFunc(cast('value_t', None), cast('value_t', None))
1052
1053 def PrettyTree(self, do_abbrev, trav=None):
1054 # type: (bool, Optional[TraversalState]) -> hnode_t
1055 trav = trav or TraversalState()
1056 heap_id = id(self)
1057 if heap_id in trav.seen:
1058 return hnode.AlreadySeen(heap_id)
1059 trav.seen[heap_id] = True
1060
1061 out_node = NewRecord('value.BoundFunc')
1062 L = out_node.fields
1063
1064 assert self.me is not None
1065 x0 = self.me.PrettyTree(do_abbrev, trav=trav)
1066 L.append(Field('me', x0))
1067
1068 assert self.func is not None
1069 x1 = self.func.PrettyTree(do_abbrev, trav=trav)
1070 L.append(Field('func', x1))
1071
1072 return out_node
1073
1074 class BuiltinFunc(value_t):
1075 _type_tag = 22
1076 __slots__ = ('callable',)
1077
1078 def __init__(self, callable):
1079 # type: (Any) -> None
1080 self.callable = callable
1081
1082 @staticmethod
1083 def CreateNull(alloc_lists=False):
1084 # type: () -> value.BuiltinFunc
1085 return value.BuiltinFunc(cast('Any', None))
1086
1087 def PrettyTree(self, do_abbrev, trav=None):
1088 # type: (bool, Optional[TraversalState]) -> hnode_t
1089 trav = trav or TraversalState()
1090 heap_id = id(self)
1091 if heap_id in trav.seen:
1092 return hnode.AlreadySeen(heap_id)
1093 trav.seen[heap_id] = True
1094
1095 out_node = NewRecord('value.BuiltinFunc')
1096 L = out_node.fields
1097
1098 x0 = NewLeaf(str(self.callable), color_e.External)
1099 L.append(Field('callable', x0))
1100
1101 return out_node
1102
1103 class Func(value_t):
1104 _type_tag = 23
1105 __slots__ = ('name', 'parsed', 'pos_defaults', 'named_defaults',
1106 'module_frame')
1107
1108 def __init__(self, name, parsed, pos_defaults, named_defaults,
1109 module_frame):
1110 # type: (str, Func, List[value_t], Dict[str, value_t], Dict[str, Cell]) -> None
1111 self.name = name
1112 self.parsed = parsed
1113 self.pos_defaults = pos_defaults
1114 self.named_defaults = named_defaults
1115 self.module_frame = module_frame
1116
1117 @staticmethod
1118 def CreateNull(alloc_lists=False):
1119 # type: () -> value.Func
1120 return value.Func('', cast('Func', None), [] if alloc_lists else cast('List[value_t]', None), cast('Dict[str, value_t]', None), cast('Dict[str, Cell]', None))
1121
1122 def PrettyTree(self, do_abbrev, trav=None):
1123 # type: (bool, 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
1130 out_node = NewRecord('value.Func')
1131 L = out_node.fields
1132
1133 x0 = NewLeaf(self.name, color_e.StringConst)
1134 L.append(Field('name', x0))
1135
1136 assert self.parsed is not None
1137 x1 = self.parsed.PrettyTree(do_abbrev, trav=trav)
1138 L.append(Field('parsed', x1))
1139
1140 if self.pos_defaults is not None: # List
1141 x2 = hnode.Array([])
1142 for i2 in self.pos_defaults:
1143 h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
1144 i2.PrettyTree(do_abbrev, trav=trav))
1145 x2.children.append(h)
1146 L.append(Field('pos_defaults', x2))
1147
1148 if self.named_defaults is not None: # Dict
1149 unnamed3 = [] # type: List[hnode_t]
1150 x3 = hnode.Record("", "{", "}", [], unnamed3)
1151 for k3, v3 in self.named_defaults.iteritems():
1152 unnamed3.append(NewLeaf(k3, color_e.StringConst))
1153 unnamed3.append(v3.PrettyTree(do_abbrev, trav=trav))
1154 L.append(Field('named_defaults', x3))
1155
1156 if self.module_frame is not None: # Dict
1157 unnamed4 = [] # type: List[hnode_t]
1158 x4 = hnode.Record("", "{", "}", [], unnamed4)
1159 for k4, v4 in self.module_frame.iteritems():
1160 unnamed4.append(NewLeaf(k4, color_e.StringConst))
1161 unnamed4.append(v4.PrettyTree(do_abbrev, trav=trav))
1162 L.append(Field('module_frame', x4))
1163
1164 return out_node
1165
1166 class BuiltinProc(value_t):
1167 _type_tag = 24
1168 __slots__ = ('builtin',)
1169
1170 def __init__(self, builtin):
1171 # type: (Any) -> None
1172 self.builtin = builtin
1173
1174 @staticmethod
1175 def CreateNull(alloc_lists=False):
1176 # type: () -> value.BuiltinProc
1177 return value.BuiltinProc(cast('Any', None))
1178
1179 def PrettyTree(self, do_abbrev, trav=None):
1180 # type: (bool, Optional[TraversalState]) -> hnode_t
1181 trav = trav or TraversalState()
1182 heap_id = id(self)
1183 if heap_id in trav.seen:
1184 return hnode.AlreadySeen(heap_id)
1185 trav.seen[heap_id] = True
1186
1187 out_node = NewRecord('value.BuiltinProc')
1188 L = out_node.fields
1189
1190 x0 = NewLeaf(str(self.builtin), color_e.External)
1191 L.append(Field('builtin', x0))
1192
1193 return out_node
1194
1195 class Proc(value_t):
1196 _type_tag = 25
1197 __slots__ = ('name', 'name_tok', 'sig', 'body', 'defaults', 'sh_compat',
1198 'module_frame')
1199
1200 def __init__(self, name, name_tok, sig, body, defaults, sh_compat,
1201 module_frame):
1202 # type: (str, Token, proc_sig_t, command_t, Optional[ProcDefaults], bool, Dict[str, Cell]) -> None
1203 self.name = name
1204 self.name_tok = name_tok
1205 self.sig = sig
1206 self.body = body
1207 self.defaults = defaults
1208 self.sh_compat = sh_compat
1209 self.module_frame = module_frame
1210
1211 @staticmethod
1212 def CreateNull(alloc_lists=False):
1213 # type: () -> value.Proc
1214 return value.Proc('', cast('Token', None), cast('proc_sig_t', None), cast('command_t', None), cast('Optional[ProcDefaults]', None), False, cast('Dict[str, Cell]', None))
1215
1216 def PrettyTree(self, do_abbrev, trav=None):
1217 # type: (bool, Optional[TraversalState]) -> hnode_t
1218 trav = trav or TraversalState()
1219 heap_id = id(self)
1220 if heap_id in trav.seen:
1221 return hnode.AlreadySeen(heap_id)
1222 trav.seen[heap_id] = True
1223
1224 out_node = NewRecord('value.Proc')
1225 L = out_node.fields
1226
1227 x0 = NewLeaf(self.name, color_e.StringConst)
1228 L.append(Field('name', x0))
1229
1230 assert self.name_tok is not None
1231 x1 = self.name_tok.PrettyTree(do_abbrev, trav=trav)
1232 L.append(Field('name_tok', x1))
1233
1234 assert self.sig is not None
1235 x2 = self.sig.PrettyTree(do_abbrev, trav=trav)
1236 L.append(Field('sig', x2))
1237
1238 assert self.body is not None
1239 x3 = self.body.PrettyTree(do_abbrev, trav=trav)
1240 L.append(Field('body', x3))
1241
1242 if self.defaults is not None: # Optional
1243 x4 = self.defaults.PrettyTree(do_abbrev, trav=trav)
1244 L.append(Field('defaults', x4))
1245
1246 x5 = hnode.Leaf('T' if self.sh_compat else 'F', color_e.OtherConst)
1247 L.append(Field('sh_compat', x5))
1248
1249 if self.module_frame is not None: # Dict
1250 unnamed6 = [] # type: List[hnode_t]
1251 x6 = hnode.Record("", "{", "}", [], unnamed6)
1252 for k6, v6 in self.module_frame.iteritems():
1253 unnamed6.append(NewLeaf(k6, color_e.StringConst))
1254 unnamed6.append(v6.PrettyTree(do_abbrev, trav=trav))
1255 L.append(Field('module_frame', x6))
1256
1257 return out_node
1258
1259 class Expr(value_t):
1260 _type_tag = 26
1261 __slots__ = ('e', 'captured_frame', 'module_frame')
1262
1263 def __init__(self, e, captured_frame, module_frame):
1264 # type: (expr_t, Dict[str, Cell], Dict[str, Cell]) -> None
1265 self.e = e
1266 self.captured_frame = captured_frame
1267 self.module_frame = module_frame
1268
1269 @staticmethod
1270 def CreateNull(alloc_lists=False):
1271 # type: () -> value.Expr
1272 return value.Expr(cast('expr_t', None), cast('Dict[str, Cell]', None), cast('Dict[str, Cell]', None))
1273
1274 def PrettyTree(self, do_abbrev, trav=None):
1275 # type: (bool, Optional[TraversalState]) -> hnode_t
1276 trav = trav or TraversalState()
1277 heap_id = id(self)
1278 if heap_id in trav.seen:
1279 return hnode.AlreadySeen(heap_id)
1280 trav.seen[heap_id] = True
1281
1282 out_node = NewRecord('value.Expr')
1283 L = out_node.fields
1284
1285 assert self.e is not None
1286 x0 = self.e.PrettyTree(do_abbrev, trav=trav)
1287 L.append(Field('e', x0))
1288
1289 if self.captured_frame is not None: # Dict
1290 unnamed1 = [] # type: List[hnode_t]
1291 x1 = hnode.Record("", "{", "}", [], unnamed1)
1292 for k1, v1 in self.captured_frame.iteritems():
1293 unnamed1.append(NewLeaf(k1, color_e.StringConst))
1294 unnamed1.append(v1.PrettyTree(do_abbrev, trav=trav))
1295 L.append(Field('captured_frame', x1))
1296
1297 if self.module_frame is not None: # Dict
1298 unnamed2 = [] # type: List[hnode_t]
1299 x2 = hnode.Record("", "{", "}", [], unnamed2)
1300 for k2, v2 in self.module_frame.iteritems():
1301 unnamed2.append(NewLeaf(k2, color_e.StringConst))
1302 unnamed2.append(v2.PrettyTree(do_abbrev, trav=trav))
1303 L.append(Field('module_frame', x2))
1304
1305 return out_node
1306
1307 class CommandFrag(value_t):
1308 _type_tag = 27
1309 __slots__ = ('c',)
1310
1311 def __init__(self, c):
1312 # type: (command_t) -> None
1313 self.c = c
1314
1315 @staticmethod
1316 def CreateNull(alloc_lists=False):
1317 # type: () -> value.CommandFrag
1318 return value.CommandFrag(cast('command_t', None))
1319
1320 def PrettyTree(self, do_abbrev, trav=None):
1321 # type: (bool, Optional[TraversalState]) -> hnode_t
1322 trav = trav or TraversalState()
1323 heap_id = id(self)
1324 if heap_id in trav.seen:
1325 return hnode.AlreadySeen(heap_id)
1326 trav.seen[heap_id] = True
1327
1328 out_node = NewRecord('value.CommandFrag')
1329 L = out_node.fields
1330
1331 assert self.c is not None
1332 x0 = self.c.PrettyTree(do_abbrev, trav=trav)
1333 L.append(Field('c', x0))
1334
1335 return out_node
1336
1337 class Command(value_t):
1338 _type_tag = 28
1339 __slots__ = ('frag', 'captured_frame', 'module_frame')
1340
1341 def __init__(self, frag, captured_frame, module_frame):
1342 # type: (cmd_frag_t, Dict[str, Cell], Dict[str, Cell]) -> None
1343 self.frag = frag
1344 self.captured_frame = captured_frame
1345 self.module_frame = module_frame
1346
1347 @staticmethod
1348 def CreateNull(alloc_lists=False):
1349 # type: () -> value.Command
1350 return value.Command(cast('cmd_frag_t', None), cast('Dict[str, Cell]', None), cast('Dict[str, Cell]', None))
1351
1352 def PrettyTree(self, do_abbrev, trav=None):
1353 # type: (bool, Optional[TraversalState]) -> hnode_t
1354 trav = trav or TraversalState()
1355 heap_id = id(self)
1356 if heap_id in trav.seen:
1357 return hnode.AlreadySeen(heap_id)
1358 trav.seen[heap_id] = True
1359
1360 out_node = NewRecord('value.Command')
1361 L = out_node.fields
1362
1363 assert self.frag is not None
1364 x0 = self.frag.PrettyTree(do_abbrev, trav=trav)
1365 L.append(Field('frag', x0))
1366
1367 if self.captured_frame is not None: # Dict
1368 unnamed1 = [] # type: List[hnode_t]
1369 x1 = hnode.Record("", "{", "}", [], unnamed1)
1370 for k1, v1 in self.captured_frame.iteritems():
1371 unnamed1.append(NewLeaf(k1, color_e.StringConst))
1372 unnamed1.append(v1.PrettyTree(do_abbrev, trav=trav))
1373 L.append(Field('captured_frame', x1))
1374
1375 if self.module_frame is not None: # Dict
1376 unnamed2 = [] # type: List[hnode_t]
1377 x2 = hnode.Record("", "{", "}", [], unnamed2)
1378 for k2, v2 in self.module_frame.iteritems():
1379 unnamed2.append(NewLeaf(k2, color_e.StringConst))
1380 unnamed2.append(v2.PrettyTree(do_abbrev, trav=trav))
1381 L.append(Field('module_frame', x2))
1382
1383 return out_node
1384
1385 pass
1386
1387class IntBox(pybase.CompoundObj):
1388 _type_tag = 64
1389 __slots__ = ('i',)
1390
1391 def __init__(self, i):
1392 # type: (int) -> None
1393 self.i = i
1394
1395 @staticmethod
1396 def CreateNull(alloc_lists=False):
1397 # type: () -> IntBox
1398 return IntBox(-1)
1399
1400 def PrettyTree(self, do_abbrev, trav=None):
1401 # type: (bool, Optional[TraversalState]) -> hnode_t
1402 trav = trav or TraversalState()
1403 heap_id = id(self)
1404 if heap_id in trav.seen:
1405 return hnode.AlreadySeen(heap_id)
1406 trav.seen[heap_id] = True
1407
1408 out_node = NewRecord('IntBox')
1409 L = out_node.fields
1410
1411 x0 = hnode.Leaf(str(self.i), color_e.OtherConst)
1412 L.append(Field('i', x0))
1413
1414 return out_node
1415
1416class ProcDefaults(pybase.CompoundObj):
1417 _type_tag = 65
1418 __slots__ = ('for_word', 'for_typed', 'for_named', 'for_block')
1419
1420 def __init__(self, for_word, for_typed, for_named, for_block):
1421 # type: (Optional[List[value_t]], Optional[List[value_t]], Optional[Dict[str, value_t]], Optional[value_t]) -> None
1422 self.for_word = for_word
1423 self.for_typed = for_typed
1424 self.for_named = for_named
1425 self.for_block = for_block
1426
1427 @staticmethod
1428 def CreateNull(alloc_lists=False):
1429 # type: () -> ProcDefaults
1430 return ProcDefaults(cast('Optional[List[value_t]]', None), cast('Optional[List[value_t]]', None), cast('Optional[Dict[str, value_t]]', None), cast('Optional[value_t]', None))
1431
1432 def PrettyTree(self, do_abbrev, trav=None):
1433 # type: (bool, Optional[TraversalState]) -> hnode_t
1434 trav = trav or TraversalState()
1435 heap_id = id(self)
1436 if heap_id in trav.seen:
1437 return hnode.AlreadySeen(heap_id)
1438 trav.seen[heap_id] = True
1439
1440 out_node = NewRecord('ProcDefaults')
1441 L = out_node.fields
1442
1443 if self.for_word is not None: # List
1444 x0 = hnode.Array([])
1445 for i0 in self.for_word:
1446 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
1447 i0.PrettyTree(do_abbrev, trav=trav))
1448 x0.children.append(h)
1449 L.append(Field('for_word', x0))
1450
1451 if self.for_typed is not None: # List
1452 x1 = hnode.Array([])
1453 for i1 in self.for_typed:
1454 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
1455 i1.PrettyTree(do_abbrev, trav=trav))
1456 x1.children.append(h)
1457 L.append(Field('for_typed', x1))
1458
1459 if self.for_named is not None: # Dict
1460 unnamed2 = [] # type: List[hnode_t]
1461 x2 = hnode.Record("", "{", "}", [], unnamed2)
1462 for k2, v2 in self.for_named.iteritems():
1463 unnamed2.append(NewLeaf(k2, color_e.StringConst))
1464 unnamed2.append(v2.PrettyTree(do_abbrev, trav=trav))
1465 L.append(Field('for_named', x2))
1466
1467 if self.for_block is not None: # Optional
1468 x3 = self.for_block.PrettyTree(do_abbrev, trav=trav)
1469 L.append(Field('for_block', x3))
1470
1471 return out_node
1472
1473class LeftName(y_lvalue_t, sh_lvalue_t):
1474 _type_tag = 66
1475 __slots__ = ('name', 'blame_loc')
1476
1477 def __init__(self, name, blame_loc):
1478 # type: (str, loc_t) -> None
1479 self.name = name
1480 self.blame_loc = blame_loc
1481
1482 @staticmethod
1483 def CreateNull(alloc_lists=False):
1484 # type: () -> LeftName
1485 return LeftName('', cast('loc_t', None))
1486
1487 def PrettyTree(self, do_abbrev, trav=None):
1488 # type: (bool, Optional[TraversalState]) -> hnode_t
1489 trav = trav or TraversalState()
1490 heap_id = id(self)
1491 if heap_id in trav.seen:
1492 return hnode.AlreadySeen(heap_id)
1493 trav.seen[heap_id] = True
1494
1495 out_node = NewRecord('LeftName')
1496 L = out_node.fields
1497
1498 x0 = NewLeaf(self.name, color_e.StringConst)
1499 L.append(Field('name', x0))
1500
1501 assert self.blame_loc is not None
1502 x1 = self.blame_loc.PrettyTree(do_abbrev, trav=trav)
1503 L.append(Field('blame_loc', x1))
1504
1505 return out_node
1506
1507class RegexMatch(regex_match_t, value_t):
1508 _type_tag = 67
1509 __slots__ = ('s', 'indices', 'ops')
1510
1511 def __init__(self, s, indices, ops):
1512 # type: (str, List[int], eggex_ops_t) -> None
1513 self.s = s
1514 self.indices = indices
1515 self.ops = ops
1516
1517 @staticmethod
1518 def CreateNull(alloc_lists=False):
1519 # type: () -> RegexMatch
1520 return RegexMatch('', [] if alloc_lists else cast('List[int]', None), cast('eggex_ops_t', None))
1521
1522 def PrettyTree(self, do_abbrev, trav=None):
1523 # type: (bool, Optional[TraversalState]) -> hnode_t
1524 trav = trav or TraversalState()
1525 heap_id = id(self)
1526 if heap_id in trav.seen:
1527 return hnode.AlreadySeen(heap_id)
1528 trav.seen[heap_id] = True
1529
1530 out_node = NewRecord('RegexMatch')
1531 L = out_node.fields
1532
1533 x0 = NewLeaf(self.s, color_e.StringConst)
1534 L.append(Field('s', x0))
1535
1536 if self.indices is not None: # List
1537 x1 = hnode.Array([])
1538 for i1 in self.indices:
1539 x1.children.append(hnode.Leaf(str(i1), color_e.OtherConst))
1540 L.append(Field('indices', x1))
1541
1542 assert self.ops is not None
1543 x2 = self.ops.PrettyTree(do_abbrev, trav=trav)
1544 L.append(Field('ops', x2))
1545
1546 return out_node
1547
1548class LiteralBlock(cmd_frag_t):
1549 _type_tag = 68
1550 __slots__ = ('brace_group', 'lines')
1551
1552 def __init__(self, brace_group, lines):
1553 # type: (BraceGroup, List[SourceLine]) -> None
1554 self.brace_group = brace_group
1555 self.lines = lines
1556
1557 @staticmethod
1558 def CreateNull(alloc_lists=False):
1559 # type: () -> LiteralBlock
1560 return LiteralBlock(cast('BraceGroup', None), [] if alloc_lists else cast('List[SourceLine]', None))
1561
1562 def PrettyTree(self, do_abbrev, trav=None):
1563 # type: (bool, Optional[TraversalState]) -> hnode_t
1564 trav = trav or TraversalState()
1565 heap_id = id(self)
1566 if heap_id in trav.seen:
1567 return hnode.AlreadySeen(heap_id)
1568 trav.seen[heap_id] = True
1569
1570 out_node = NewRecord('LiteralBlock')
1571 L = out_node.fields
1572
1573 assert self.brace_group is not None
1574 x0 = self.brace_group.PrettyTree(do_abbrev, trav=trav)
1575 L.append(Field('brace_group', x0))
1576
1577 if self.lines is not None: # List
1578 x1 = hnode.Array([])
1579 for i1 in self.lines:
1580 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
1581 i1.PrettyTree(do_abbrev, trav=trav))
1582 x1.children.append(h)
1583 L.append(Field('lines', x1))
1584
1585 return out_node
1586
1587class Obj(value_t):
1588 _type_tag = 69
1589 __slots__ = ('prototype', 'd')
1590
1591 def __init__(self, prototype, d):
1592 # type: (Optional[Obj], Dict[str, value_t]) -> None
1593 self.prototype = prototype
1594 self.d = d
1595
1596 @staticmethod
1597 def CreateNull(alloc_lists=False):
1598 # type: () -> Obj
1599 return Obj(cast('Optional[Obj]', None), cast('Dict[str, value_t]', None))
1600
1601 def PrettyTree(self, do_abbrev, trav=None):
1602 # type: (bool, Optional[TraversalState]) -> hnode_t
1603 trav = trav or TraversalState()
1604 heap_id = id(self)
1605 if heap_id in trav.seen:
1606 return hnode.AlreadySeen(heap_id)
1607 trav.seen[heap_id] = True
1608
1609 out_node = NewRecord('Obj')
1610 L = out_node.fields
1611
1612 if self.prototype is not None: # Optional
1613 x0 = self.prototype.PrettyTree(do_abbrev, trav=trav)
1614 L.append(Field('prototype', x0))
1615
1616 if self.d is not None: # Dict
1617 unnamed1 = [] # type: List[hnode_t]
1618 x1 = hnode.Record("", "{", "}", [], unnamed1)
1619 for k1, v1 in self.d.iteritems():
1620 unnamed1.append(NewLeaf(k1, color_e.StringConst))
1621 unnamed1.append(v1.PrettyTree(do_abbrev, trav=trav))
1622 L.append(Field('d', x1))
1623
1624 return out_node
1625