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

2078 lines, 1523 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, word_t, command_t, CompoundWord, DoubleQuoted, ArgList, re_t, redir_loc_t, proc_sig_t, LiteralBlock, Func
7 from _devbuild.gen.value_asdl import value_t
8
9from _devbuild.gen.id_kind_asdl import Id_t
10from _devbuild.gen.id_kind_asdl import Id_str
11
12
13from asdl import runtime # For runtime.NO_SPID
14from asdl.runtime import NewRecord, NewLeaf, TraversalState
15from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
16
17class cmd_value_e(object):
18 Argv = 1
19 Assign = 2
20
21_cmd_value_str = {
22 1: 'Argv',
23 2: 'Assign',
24}
25
26def cmd_value_str(tag, dot=True):
27 # type: (int, bool) -> str
28 v = _cmd_value_str[tag]
29 if dot:
30 return "cmd_value.%s" % v
31 else:
32 return v
33
34class cmd_value_t(pybase.CompoundObj):
35 def tag(self):
36 # type: () -> int
37 return self._type_tag
38 pass
39
40class cmd_value(object):
41 class Argv(cmd_value_t):
42 _type_tag = 1
43 __slots__ = ('argv', 'arg_locs', 'typed_args', 'pos_args', 'named_args',
44 'block_arg')
45
46 def __init__(self, argv, arg_locs, typed_args, pos_args, named_args,
47 block_arg):
48 # type: (List[str], List[CompoundWord], Optional[ArgList], Optional[List[value_t]], Optional[Dict[str, value_t]], Optional[value_t]) -> None
49 self.argv = argv
50 self.arg_locs = arg_locs
51 self.typed_args = typed_args
52 self.pos_args = pos_args
53 self.named_args = named_args
54 self.block_arg = block_arg
55
56 @staticmethod
57 def CreateNull(alloc_lists=False):
58 # type: () -> cmd_value.Argv
59 return cmd_value.Argv([] if alloc_lists else cast('List[str]', None), [] if alloc_lists else cast('List[CompoundWord]', None), cast('Optional[ArgList]', None), cast('Optional[List[value_t]]', None), cast('Optional[Dict[str, value_t]]', None), cast('Optional[value_t]', None))
60
61 def PrettyTree(self, trav=None):
62 # type: (Optional[TraversalState]) -> hnode_t
63 trav = trav or TraversalState()
64 heap_id = id(self)
65 if heap_id in trav.seen:
66 return hnode.AlreadySeen(heap_id)
67 trav.seen[heap_id] = True
68 out_node = NewRecord('cmd_value.Argv')
69 L = out_node.fields
70
71 if self.argv is not None: # List
72 x0 = hnode.Array([])
73 for i0 in self.argv:
74 x0.children.append(NewLeaf(i0, color_e.StringConst))
75 L.append(Field('argv', x0))
76
77 if self.arg_locs is not None: # List
78 x1 = hnode.Array([])
79 for i1 in self.arg_locs:
80 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
81 i1.PrettyTree(trav=trav))
82 x1.children.append(h)
83 L.append(Field('arg_locs', x1))
84
85 if self.typed_args is not None: # Optional
86 x2 = self.typed_args.PrettyTree(trav=trav)
87 L.append(Field('typed_args', x2))
88
89 if self.pos_args is not None: # List
90 x3 = hnode.Array([])
91 for i3 in self.pos_args:
92 h = (hnode.Leaf("_", color_e.OtherConst) if i3 is None else
93 i3.PrettyTree(trav=trav))
94 x3.children.append(h)
95 L.append(Field('pos_args', x3))
96
97 if self.named_args is not None: # Dict
98 m = hnode.Leaf("Dict", color_e.OtherConst)
99 x4 = hnode.Array([m])
100 for k4, v4 in self.named_args.iteritems():
101 x4.children.append(NewLeaf(k4, color_e.StringConst))
102 x4.children.append(v4.PrettyTree(trav=trav))
103 L.append(Field('named_args', x4))
104
105 if self.block_arg is not None: # Optional
106 x5 = self.block_arg.PrettyTree(trav=trav)
107 L.append(Field('block_arg', x5))
108
109 return out_node
110
111 def _AbbreviatedTree(self, trav=None):
112 # type: (Optional[TraversalState]) -> hnode_t
113 trav = trav or TraversalState()
114 heap_id = id(self)
115 if heap_id in trav.seen:
116 return hnode.AlreadySeen(heap_id)
117 trav.seen[heap_id] = True
118 out_node = NewRecord('cmd_value.Argv')
119 L = out_node.fields
120 if self.argv is not None: # List
121 x0 = hnode.Array([])
122 for i0 in self.argv:
123 x0.children.append(NewLeaf(i0, color_e.StringConst))
124 L.append(Field('argv', x0))
125
126 if self.arg_locs is not None: # List
127 x1 = hnode.Array([])
128 for i1 in self.arg_locs:
129 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
130 i1.AbbreviatedTree(trav=trav))
131 x1.children.append(h)
132 L.append(Field('arg_locs', x1))
133
134 if self.typed_args is not None: # Optional
135 x2 = self.typed_args.AbbreviatedTree(trav=trav)
136 L.append(Field('typed_args', x2))
137
138 if self.pos_args is not None: # List
139 x3 = hnode.Array([])
140 for i3 in self.pos_args:
141 h = (hnode.Leaf("_", color_e.OtherConst) if i3 is None else
142 i3.AbbreviatedTree(trav=trav))
143 x3.children.append(h)
144 L.append(Field('pos_args', x3))
145
146 if self.named_args is not None: # Dict
147 m = hnode.Leaf("Dict", color_e.OtherConst)
148 x4 = hnode.Array([m])
149 for k4, v4 in self.named_args.iteritems():
150 x4.children.append(NewLeaf(k4, color_e.StringConst))
151 x4.children.append(v4.AbbreviatedTree(trav=trav))
152 L.append(Field('named_args', x4))
153
154 if self.block_arg is not None: # Optional
155 x5 = self.block_arg.AbbreviatedTree(trav=trav)
156 L.append(Field('block_arg', x5))
157
158 return out_node
159
160 def AbbreviatedTree(self, trav=None):
161 # type: (Optional[TraversalState]) -> hnode_t
162 return self._AbbreviatedTree(trav=trav)
163
164 class Assign(cmd_value_t):
165 _type_tag = 2
166 __slots__ = ('builtin_id', 'argv', 'arg_locs', 'pairs')
167
168 def __init__(self, builtin_id, argv, arg_locs, pairs):
169 # type: (int, List[str], List[CompoundWord], List[AssignArg]) -> None
170 self.builtin_id = builtin_id
171 self.argv = argv
172 self.arg_locs = arg_locs
173 self.pairs = pairs
174
175 @staticmethod
176 def CreateNull(alloc_lists=False):
177 # type: () -> cmd_value.Assign
178 return cmd_value.Assign(-1, [] if alloc_lists else cast('List[str]', None), [] if alloc_lists else cast('List[CompoundWord]', None), [] if alloc_lists else cast('List[AssignArg]', None))
179
180 def PrettyTree(self, trav=None):
181 # type: (Optional[TraversalState]) -> hnode_t
182 trav = trav or TraversalState()
183 heap_id = id(self)
184 if heap_id in trav.seen:
185 return hnode.AlreadySeen(heap_id)
186 trav.seen[heap_id] = True
187 out_node = NewRecord('cmd_value.Assign')
188 L = out_node.fields
189
190 x0 = hnode.Leaf(str(self.builtin_id), color_e.OtherConst)
191 L.append(Field('builtin_id', x0))
192
193 if self.argv is not None: # List
194 x1 = hnode.Array([])
195 for i1 in self.argv:
196 x1.children.append(NewLeaf(i1, color_e.StringConst))
197 L.append(Field('argv', x1))
198
199 if self.arg_locs is not None: # List
200 x2 = hnode.Array([])
201 for i2 in self.arg_locs:
202 h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
203 i2.PrettyTree(trav=trav))
204 x2.children.append(h)
205 L.append(Field('arg_locs', x2))
206
207 if self.pairs is not None: # List
208 x3 = hnode.Array([])
209 for i3 in self.pairs:
210 h = (hnode.Leaf("_", color_e.OtherConst) if i3 is None else
211 i3.PrettyTree(trav=trav))
212 x3.children.append(h)
213 L.append(Field('pairs', x3))
214
215 return out_node
216
217 def _AbbreviatedTree(self, trav=None):
218 # type: (Optional[TraversalState]) -> hnode_t
219 trav = trav or TraversalState()
220 heap_id = id(self)
221 if heap_id in trav.seen:
222 return hnode.AlreadySeen(heap_id)
223 trav.seen[heap_id] = True
224 out_node = NewRecord('cmd_value.Assign')
225 L = out_node.fields
226 x0 = hnode.Leaf(str(self.builtin_id), color_e.OtherConst)
227 L.append(Field('builtin_id', x0))
228
229 if self.argv is not None: # List
230 x1 = hnode.Array([])
231 for i1 in self.argv:
232 x1.children.append(NewLeaf(i1, color_e.StringConst))
233 L.append(Field('argv', x1))
234
235 if self.arg_locs is not None: # List
236 x2 = hnode.Array([])
237 for i2 in self.arg_locs:
238 h = (hnode.Leaf("_", color_e.OtherConst) if i2 is None else
239 i2.AbbreviatedTree(trav=trav))
240 x2.children.append(h)
241 L.append(Field('arg_locs', x2))
242
243 if self.pairs is not None: # List
244 x3 = hnode.Array([])
245 for i3 in self.pairs:
246 h = (hnode.Leaf("_", color_e.OtherConst) if i3 is None else
247 i3.AbbreviatedTree(trav=trav))
248 x3.children.append(h)
249 L.append(Field('pairs', x3))
250
251 return out_node
252
253 def AbbreviatedTree(self, trav=None):
254 # type: (Optional[TraversalState]) -> hnode_t
255 return self._AbbreviatedTree(trav=trav)
256
257 pass
258
259class part_value_e(object):
260 String = 65
261 Array = 2
262 ExtGlob = 3
263
264_part_value_str = {
265 2: 'Array',
266 3: 'ExtGlob',
267 65: 'String',
268}
269
270def part_value_str(tag, dot=True):
271 # type: (int, bool) -> str
272 v = _part_value_str[tag]
273 if dot:
274 return "part_value.%s" % v
275 else:
276 return v
277
278class part_value_t(pybase.CompoundObj):
279 def tag(self):
280 # type: () -> int
281 return self._type_tag
282 pass
283
284class part_value(object):
285 class Array(part_value_t):
286 _type_tag = 2
287 __slots__ = ('strs',)
288
289 def __init__(self, strs):
290 # type: (List[str]) -> None
291 self.strs = strs
292
293 @staticmethod
294 def CreateNull(alloc_lists=False):
295 # type: () -> part_value.Array
296 return part_value.Array([] if alloc_lists else cast('List[str]', None))
297
298 def PrettyTree(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('part_value.Array')
306 L = out_node.fields
307
308 if self.strs is not None: # List
309 x0 = hnode.Array([])
310 for i0 in self.strs:
311 x0.children.append(NewLeaf(i0, color_e.StringConst))
312 L.append(Field('strs', x0))
313
314 return out_node
315
316 def _AbbreviatedTree(self, trav=None):
317 # type: (Optional[TraversalState]) -> hnode_t
318 trav = trav or TraversalState()
319 heap_id = id(self)
320 if heap_id in trav.seen:
321 return hnode.AlreadySeen(heap_id)
322 trav.seen[heap_id] = True
323 out_node = NewRecord('part_value.Array')
324 L = out_node.fields
325 if self.strs is not None: # List
326 x0 = hnode.Array([])
327 for i0 in self.strs:
328 x0.children.append(NewLeaf(i0, color_e.StringConst))
329 L.append(Field('strs', x0))
330
331 return out_node
332
333 def AbbreviatedTree(self, trav=None):
334 # type: (Optional[TraversalState]) -> hnode_t
335 return self._AbbreviatedTree(trav=trav)
336
337 class ExtGlob(part_value_t):
338 _type_tag = 3
339 __slots__ = ('part_vals',)
340
341 def __init__(self, part_vals):
342 # type: (List[part_value_t]) -> None
343 self.part_vals = part_vals
344
345 @staticmethod
346 def CreateNull(alloc_lists=False):
347 # type: () -> part_value.ExtGlob
348 return part_value.ExtGlob([] if alloc_lists else cast('List[part_value_t]', None))
349
350 def PrettyTree(self, trav=None):
351 # type: (Optional[TraversalState]) -> hnode_t
352 trav = trav or TraversalState()
353 heap_id = id(self)
354 if heap_id in trav.seen:
355 return hnode.AlreadySeen(heap_id)
356 trav.seen[heap_id] = True
357 out_node = NewRecord('part_value.ExtGlob')
358 L = out_node.fields
359
360 if self.part_vals is not None: # List
361 x0 = hnode.Array([])
362 for i0 in self.part_vals:
363 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
364 i0.PrettyTree(trav=trav))
365 x0.children.append(h)
366 L.append(Field('part_vals', x0))
367
368 return out_node
369
370 def _AbbreviatedTree(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('part_value.ExtGlob')
378 L = out_node.fields
379 if self.part_vals is not None: # List
380 x0 = hnode.Array([])
381 for i0 in self.part_vals:
382 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
383 i0.AbbreviatedTree(trav=trav))
384 x0.children.append(h)
385 L.append(Field('part_vals', x0))
386
387 return out_node
388
389 def AbbreviatedTree(self, trav=None):
390 # type: (Optional[TraversalState]) -> hnode_t
391 return self._AbbreviatedTree(trav=trav)
392
393 pass
394
395class coerced_t(pybase.SimpleObj):
396 pass
397
398class coerced_e(object):
399 Int = coerced_t(1)
400 Float = coerced_t(2)
401 Neither = coerced_t(3)
402
403_coerced_str = {
404 1: 'coerced.Int',
405 2: 'coerced.Float',
406 3: 'coerced.Neither',
407}
408
409def coerced_str(val):
410 # type: (coerced_t) -> str
411 return _coerced_str[val]
412
413class scope_t(pybase.SimpleObj):
414 pass
415
416class scope_e(object):
417 Shopt = scope_t(1)
418 Dynamic = scope_t(2)
419 LocalOrGlobal = scope_t(3)
420 LocalOnly = scope_t(4)
421 GlobalOnly = scope_t(5)
422
423_scope_str = {
424 1: 'scope.Shopt',
425 2: 'scope.Dynamic',
426 3: 'scope.LocalOrGlobal',
427 4: 'scope.LocalOnly',
428 5: 'scope.GlobalOnly',
429}
430
431def scope_str(val):
432 # type: (scope_t) -> str
433 return _scope_str[val]
434
435class a_index_e(object):
436 Str = 1
437 Int = 2
438
439_a_index_str = {
440 1: 'Str',
441 2: 'Int',
442}
443
444def a_index_str(tag, dot=True):
445 # type: (int, bool) -> str
446 v = _a_index_str[tag]
447 if dot:
448 return "a_index.%s" % v
449 else:
450 return v
451
452class a_index_t(pybase.CompoundObj):
453 def tag(self):
454 # type: () -> int
455 return self._type_tag
456 pass
457
458class a_index(object):
459 class Str(a_index_t):
460 _type_tag = 1
461 __slots__ = ('s',)
462
463 def __init__(self, s):
464 # type: (str) -> None
465 self.s = s
466
467 @staticmethod
468 def CreateNull(alloc_lists=False):
469 # type: () -> a_index.Str
470 return a_index.Str('')
471
472 def PrettyTree(self, trav=None):
473 # type: (Optional[TraversalState]) -> hnode_t
474 trav = trav or TraversalState()
475 heap_id = id(self)
476 if heap_id in trav.seen:
477 return hnode.AlreadySeen(heap_id)
478 trav.seen[heap_id] = True
479 out_node = NewRecord('a_index.Str')
480 L = out_node.fields
481
482 x0 = NewLeaf(self.s, color_e.StringConst)
483 L.append(Field('s', x0))
484
485 return out_node
486
487 def _AbbreviatedTree(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('a_index.Str')
495 L = out_node.fields
496 x0 = NewLeaf(self.s, color_e.StringConst)
497 L.append(Field('s', x0))
498
499 return out_node
500
501 def AbbreviatedTree(self, trav=None):
502 # type: (Optional[TraversalState]) -> hnode_t
503 return self._AbbreviatedTree(trav=trav)
504
505 class Int(a_index_t):
506 _type_tag = 2
507 __slots__ = ('i',)
508
509 def __init__(self, i):
510 # type: (int) -> None
511 self.i = i
512
513 @staticmethod
514 def CreateNull(alloc_lists=False):
515 # type: () -> a_index.Int
516 return a_index.Int(-1)
517
518 def PrettyTree(self, trav=None):
519 # type: (Optional[TraversalState]) -> hnode_t
520 trav = trav or TraversalState()
521 heap_id = id(self)
522 if heap_id in trav.seen:
523 return hnode.AlreadySeen(heap_id)
524 trav.seen[heap_id] = True
525 out_node = NewRecord('a_index.Int')
526 L = out_node.fields
527
528 x0 = hnode.Leaf(str(self.i), color_e.OtherConst)
529 L.append(Field('i', x0))
530
531 return out_node
532
533 def _AbbreviatedTree(self, trav=None):
534 # type: (Optional[TraversalState]) -> hnode_t
535 trav = trav or TraversalState()
536 heap_id = id(self)
537 if heap_id in trav.seen:
538 return hnode.AlreadySeen(heap_id)
539 trav.seen[heap_id] = True
540 out_node = NewRecord('a_index.Int')
541 L = out_node.fields
542 x0 = hnode.Leaf(str(self.i), color_e.OtherConst)
543 L.append(Field('i', x0))
544
545 return out_node
546
547 def AbbreviatedTree(self, trav=None):
548 # type: (Optional[TraversalState]) -> hnode_t
549 return self._AbbreviatedTree(trav=trav)
550
551 pass
552
553class redirect_arg_e(object):
554 Path = 1
555 CopyFd = 2
556 MoveFd = 3
557 CloseFd = 4
558 HereDoc = 5
559
560_redirect_arg_str = {
561 1: 'Path',
562 2: 'CopyFd',
563 3: 'MoveFd',
564 4: 'CloseFd',
565 5: 'HereDoc',
566}
567
568def redirect_arg_str(tag, dot=True):
569 # type: (int, bool) -> str
570 v = _redirect_arg_str[tag]
571 if dot:
572 return "redirect_arg.%s" % v
573 else:
574 return v
575
576class redirect_arg_t(pybase.CompoundObj):
577 def tag(self):
578 # type: () -> int
579 return self._type_tag
580 pass
581
582class redirect_arg__CloseFd(redirect_arg_t):
583 _type_tag = 4
584 __slots__ = ()
585
586 def __init__(self, ):
587 # type: () -> None
588 pass
589
590 def PrettyTree(self, trav=None):
591 # type: (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 out_node = NewRecord('redirect_arg__CloseFd')
598 L = out_node.fields
599
600 return out_node
601
602 def _AbbreviatedTree(self, trav=None):
603 # type: (Optional[TraversalState]) -> hnode_t
604 trav = trav or TraversalState()
605 heap_id = id(self)
606 if heap_id in trav.seen:
607 return hnode.AlreadySeen(heap_id)
608 trav.seen[heap_id] = True
609 out_node = NewRecord('redirect_arg__CloseFd')
610 L = out_node.fields
611 return out_node
612
613 def AbbreviatedTree(self, trav=None):
614 # type: (Optional[TraversalState]) -> hnode_t
615 return self._AbbreviatedTree(trav=trav)
616
617class redirect_arg(object):
618 class Path(redirect_arg_t):
619 _type_tag = 1
620 __slots__ = ('filename',)
621
622 def __init__(self, filename):
623 # type: (str) -> None
624 self.filename = filename
625
626 @staticmethod
627 def CreateNull(alloc_lists=False):
628 # type: () -> redirect_arg.Path
629 return redirect_arg.Path('')
630
631 def PrettyTree(self, trav=None):
632 # type: (Optional[TraversalState]) -> hnode_t
633 trav = trav or TraversalState()
634 heap_id = id(self)
635 if heap_id in trav.seen:
636 return hnode.AlreadySeen(heap_id)
637 trav.seen[heap_id] = True
638 out_node = NewRecord('redirect_arg.Path')
639 L = out_node.fields
640
641 x0 = NewLeaf(self.filename, color_e.StringConst)
642 L.append(Field('filename', x0))
643
644 return out_node
645
646 def _AbbreviatedTree(self, trav=None):
647 # type: (Optional[TraversalState]) -> hnode_t
648 trav = trav or TraversalState()
649 heap_id = id(self)
650 if heap_id in trav.seen:
651 return hnode.AlreadySeen(heap_id)
652 trav.seen[heap_id] = True
653 out_node = NewRecord('redirect_arg.Path')
654 L = out_node.fields
655 x0 = NewLeaf(self.filename, color_e.StringConst)
656 L.append(Field('filename', x0))
657
658 return out_node
659
660 def AbbreviatedTree(self, trav=None):
661 # type: (Optional[TraversalState]) -> hnode_t
662 return self._AbbreviatedTree(trav=trav)
663
664 class CopyFd(redirect_arg_t):
665 _type_tag = 2
666 __slots__ = ('target_fd',)
667
668 def __init__(self, target_fd):
669 # type: (int) -> None
670 self.target_fd = target_fd
671
672 @staticmethod
673 def CreateNull(alloc_lists=False):
674 # type: () -> redirect_arg.CopyFd
675 return redirect_arg.CopyFd(-1)
676
677 def PrettyTree(self, trav=None):
678 # type: (Optional[TraversalState]) -> hnode_t
679 trav = trav or TraversalState()
680 heap_id = id(self)
681 if heap_id in trav.seen:
682 return hnode.AlreadySeen(heap_id)
683 trav.seen[heap_id] = True
684 out_node = NewRecord('redirect_arg.CopyFd')
685 L = out_node.fields
686
687 x0 = hnode.Leaf(str(self.target_fd), color_e.OtherConst)
688 L.append(Field('target_fd', x0))
689
690 return out_node
691
692 def _AbbreviatedTree(self, trav=None):
693 # type: (Optional[TraversalState]) -> hnode_t
694 trav = trav or TraversalState()
695 heap_id = id(self)
696 if heap_id in trav.seen:
697 return hnode.AlreadySeen(heap_id)
698 trav.seen[heap_id] = True
699 out_node = NewRecord('redirect_arg.CopyFd')
700 L = out_node.fields
701 x0 = hnode.Leaf(str(self.target_fd), color_e.OtherConst)
702 L.append(Field('target_fd', x0))
703
704 return out_node
705
706 def AbbreviatedTree(self, trav=None):
707 # type: (Optional[TraversalState]) -> hnode_t
708 return self._AbbreviatedTree(trav=trav)
709
710 class MoveFd(redirect_arg_t):
711 _type_tag = 3
712 __slots__ = ('target_fd',)
713
714 def __init__(self, target_fd):
715 # type: (int) -> None
716 self.target_fd = target_fd
717
718 @staticmethod
719 def CreateNull(alloc_lists=False):
720 # type: () -> redirect_arg.MoveFd
721 return redirect_arg.MoveFd(-1)
722
723 def PrettyTree(self, trav=None):
724 # type: (Optional[TraversalState]) -> hnode_t
725 trav = trav or TraversalState()
726 heap_id = id(self)
727 if heap_id in trav.seen:
728 return hnode.AlreadySeen(heap_id)
729 trav.seen[heap_id] = True
730 out_node = NewRecord('redirect_arg.MoveFd')
731 L = out_node.fields
732
733 x0 = hnode.Leaf(str(self.target_fd), color_e.OtherConst)
734 L.append(Field('target_fd', x0))
735
736 return out_node
737
738 def _AbbreviatedTree(self, trav=None):
739 # type: (Optional[TraversalState]) -> hnode_t
740 trav = trav or TraversalState()
741 heap_id = id(self)
742 if heap_id in trav.seen:
743 return hnode.AlreadySeen(heap_id)
744 trav.seen[heap_id] = True
745 out_node = NewRecord('redirect_arg.MoveFd')
746 L = out_node.fields
747 x0 = hnode.Leaf(str(self.target_fd), color_e.OtherConst)
748 L.append(Field('target_fd', x0))
749
750 return out_node
751
752 def AbbreviatedTree(self, trav=None):
753 # type: (Optional[TraversalState]) -> hnode_t
754 return self._AbbreviatedTree(trav=trav)
755
756 CloseFd = redirect_arg__CloseFd()
757
758 class HereDoc(redirect_arg_t):
759 _type_tag = 5
760 __slots__ = ('body',)
761
762 def __init__(self, body):
763 # type: (str) -> None
764 self.body = body
765
766 @staticmethod
767 def CreateNull(alloc_lists=False):
768 # type: () -> redirect_arg.HereDoc
769 return redirect_arg.HereDoc('')
770
771 def PrettyTree(self, trav=None):
772 # type: (Optional[TraversalState]) -> hnode_t
773 trav = trav or TraversalState()
774 heap_id = id(self)
775 if heap_id in trav.seen:
776 return hnode.AlreadySeen(heap_id)
777 trav.seen[heap_id] = True
778 out_node = NewRecord('redirect_arg.HereDoc')
779 L = out_node.fields
780
781 x0 = NewLeaf(self.body, color_e.StringConst)
782 L.append(Field('body', x0))
783
784 return out_node
785
786 def _AbbreviatedTree(self, trav=None):
787 # type: (Optional[TraversalState]) -> hnode_t
788 trav = trav or TraversalState()
789 heap_id = id(self)
790 if heap_id in trav.seen:
791 return hnode.AlreadySeen(heap_id)
792 trav.seen[heap_id] = True
793 out_node = NewRecord('redirect_arg.HereDoc')
794 L = out_node.fields
795 x0 = NewLeaf(self.body, color_e.StringConst)
796 L.append(Field('body', x0))
797
798 return out_node
799
800 def AbbreviatedTree(self, trav=None):
801 # type: (Optional[TraversalState]) -> hnode_t
802 return self._AbbreviatedTree(trav=trav)
803
804 pass
805
806class wait_status_e(object):
807 Proc = 1
808 Pipeline = 2
809 Cancelled = 3
810
811_wait_status_str = {
812 1: 'Proc',
813 2: 'Pipeline',
814 3: 'Cancelled',
815}
816
817def wait_status_str(tag, dot=True):
818 # type: (int, bool) -> str
819 v = _wait_status_str[tag]
820 if dot:
821 return "wait_status.%s" % v
822 else:
823 return v
824
825class wait_status_t(pybase.CompoundObj):
826 def tag(self):
827 # type: () -> int
828 return self._type_tag
829 pass
830
831class wait_status(object):
832 class Proc(wait_status_t):
833 _type_tag = 1
834 __slots__ = ('code',)
835
836 def __init__(self, code):
837 # type: (int) -> None
838 self.code = code
839
840 @staticmethod
841 def CreateNull(alloc_lists=False):
842 # type: () -> wait_status.Proc
843 return wait_status.Proc(-1)
844
845 def PrettyTree(self, trav=None):
846 # type: (Optional[TraversalState]) -> hnode_t
847 trav = trav or TraversalState()
848 heap_id = id(self)
849 if heap_id in trav.seen:
850 return hnode.AlreadySeen(heap_id)
851 trav.seen[heap_id] = True
852 out_node = NewRecord('wait_status.Proc')
853 L = out_node.fields
854
855 x0 = hnode.Leaf(str(self.code), color_e.OtherConst)
856 L.append(Field('code', x0))
857
858 return out_node
859
860 def _AbbreviatedTree(self, trav=None):
861 # type: (Optional[TraversalState]) -> hnode_t
862 trav = trav or TraversalState()
863 heap_id = id(self)
864 if heap_id in trav.seen:
865 return hnode.AlreadySeen(heap_id)
866 trav.seen[heap_id] = True
867 out_node = NewRecord('wait_status.Proc')
868 L = out_node.fields
869 x0 = hnode.Leaf(str(self.code), color_e.OtherConst)
870 L.append(Field('code', x0))
871
872 return out_node
873
874 def AbbreviatedTree(self, trav=None):
875 # type: (Optional[TraversalState]) -> hnode_t
876 return self._AbbreviatedTree(trav=trav)
877
878 class Pipeline(wait_status_t):
879 _type_tag = 2
880 __slots__ = ('codes',)
881
882 def __init__(self, codes):
883 # type: (List[int]) -> None
884 self.codes = codes
885
886 @staticmethod
887 def CreateNull(alloc_lists=False):
888 # type: () -> wait_status.Pipeline
889 return wait_status.Pipeline([] if alloc_lists else cast('List[int]', None))
890
891 def PrettyTree(self, trav=None):
892 # type: (Optional[TraversalState]) -> hnode_t
893 trav = trav or TraversalState()
894 heap_id = id(self)
895 if heap_id in trav.seen:
896 return hnode.AlreadySeen(heap_id)
897 trav.seen[heap_id] = True
898 out_node = NewRecord('wait_status.Pipeline')
899 L = out_node.fields
900
901 if self.codes is not None: # List
902 x0 = hnode.Array([])
903 for i0 in self.codes:
904 x0.children.append(hnode.Leaf(str(i0), color_e.OtherConst))
905 L.append(Field('codes', x0))
906
907 return out_node
908
909 def _AbbreviatedTree(self, trav=None):
910 # type: (Optional[TraversalState]) -> hnode_t
911 trav = trav or TraversalState()
912 heap_id = id(self)
913 if heap_id in trav.seen:
914 return hnode.AlreadySeen(heap_id)
915 trav.seen[heap_id] = True
916 out_node = NewRecord('wait_status.Pipeline')
917 L = out_node.fields
918 if self.codes is not None: # List
919 x0 = hnode.Array([])
920 for i0 in self.codes:
921 x0.children.append(hnode.Leaf(str(i0), color_e.OtherConst))
922 L.append(Field('codes', x0))
923
924 return out_node
925
926 def AbbreviatedTree(self, trav=None):
927 # type: (Optional[TraversalState]) -> hnode_t
928 return self._AbbreviatedTree(trav=trav)
929
930 class Cancelled(wait_status_t):
931 _type_tag = 3
932 __slots__ = ('sig_num',)
933
934 def __init__(self, sig_num):
935 # type: (int) -> None
936 self.sig_num = sig_num
937
938 @staticmethod
939 def CreateNull(alloc_lists=False):
940 # type: () -> wait_status.Cancelled
941 return wait_status.Cancelled(-1)
942
943 def PrettyTree(self, trav=None):
944 # type: (Optional[TraversalState]) -> hnode_t
945 trav = trav or TraversalState()
946 heap_id = id(self)
947 if heap_id in trav.seen:
948 return hnode.AlreadySeen(heap_id)
949 trav.seen[heap_id] = True
950 out_node = NewRecord('wait_status.Cancelled')
951 L = out_node.fields
952
953 x0 = hnode.Leaf(str(self.sig_num), color_e.OtherConst)
954 L.append(Field('sig_num', x0))
955
956 return out_node
957
958 def _AbbreviatedTree(self, trav=None):
959 # type: (Optional[TraversalState]) -> hnode_t
960 trav = trav or TraversalState()
961 heap_id = id(self)
962 if heap_id in trav.seen:
963 return hnode.AlreadySeen(heap_id)
964 trav.seen[heap_id] = True
965 out_node = NewRecord('wait_status.Cancelled')
966 L = out_node.fields
967 x0 = hnode.Leaf(str(self.sig_num), color_e.OtherConst)
968 L.append(Field('sig_num', x0))
969
970 return out_node
971
972 def AbbreviatedTree(self, trav=None):
973 # type: (Optional[TraversalState]) -> hnode_t
974 return self._AbbreviatedTree(trav=trav)
975
976 pass
977
978class flow_t(pybase.SimpleObj):
979 pass
980
981class flow_e(object):
982 Nothing = flow_t(1)
983 Break = flow_t(2)
984 Raise = flow_t(3)
985
986_flow_str = {
987 1: 'flow.Nothing',
988 2: 'flow.Break',
989 3: 'flow.Raise',
990}
991
992def flow_str(val):
993 # type: (flow_t) -> str
994 return _flow_str[val]
995
996class span_t(pybase.SimpleObj):
997 pass
998
999class span_e(object):
1000 Black = span_t(1)
1001 Delim = span_t(2)
1002 Backslash = span_t(3)
1003
1004_span_str = {
1005 1: 'span.Black',
1006 2: 'span.Delim',
1007 3: 'span.Backslash',
1008}
1009
1010def span_str(val):
1011 # type: (span_t) -> str
1012 return _span_str[val]
1013
1014emit_t = int # type alias for integer
1015
1016class emit_i(object):
1017 Part = 1
1018 Delim = 2
1019 Empty = 3
1020 Escape = 4
1021 Nothing = 5
1022 ARRAY_SIZE = 6
1023
1024_emit_str = {
1025 1: 'emit.Part',
1026 2: 'emit.Delim',
1027 3: 'emit.Empty',
1028 4: 'emit.Escape',
1029 5: 'emit.Nothing',
1030}
1031
1032def emit_str(val):
1033 # type: (emit_t) -> str
1034 return _emit_str[val]
1035
1036state_t = int # type alias for integer
1037
1038class state_i(object):
1039 Invalid = 1
1040 Start = 2
1041 DE_White1 = 3
1042 DE_Gray = 4
1043 DE_White2 = 5
1044 Black = 6
1045 Backslash = 7
1046 Done = 8
1047 ARRAY_SIZE = 9
1048
1049_state_str = {
1050 1: 'state.Invalid',
1051 2: 'state.Start',
1052 3: 'state.DE_White1',
1053 4: 'state.DE_Gray',
1054 5: 'state.DE_White2',
1055 6: 'state.Black',
1056 7: 'state.Backslash',
1057 8: 'state.Done',
1058}
1059
1060def state_str(val):
1061 # type: (state_t) -> str
1062 return _state_str[val]
1063
1064char_kind_t = int # type alias for integer
1065
1066class char_kind_i(object):
1067 DE_White = 1
1068 DE_Gray = 2
1069 Black = 3
1070 Backslash = 4
1071 Sentinel = 5
1072 ARRAY_SIZE = 6
1073
1074_char_kind_str = {
1075 1: 'char_kind.DE_White',
1076 2: 'char_kind.DE_Gray',
1077 3: 'char_kind.Black',
1078 4: 'char_kind.Backslash',
1079 5: 'char_kind.Sentinel',
1080}
1081
1082def char_kind_str(val):
1083 # type: (char_kind_t) -> str
1084 return _char_kind_str[val]
1085
1086class job_state_t(pybase.SimpleObj):
1087 pass
1088
1089class job_state_e(object):
1090 Running = job_state_t(1)
1091 Done = job_state_t(2)
1092 Stopped = job_state_t(3)
1093
1094_job_state_str = {
1095 1: 'job_state.Running',
1096 2: 'job_state.Done',
1097 3: 'job_state.Stopped',
1098}
1099
1100def job_state_str(val):
1101 # type: (job_state_t) -> str
1102 return _job_state_str[val]
1103
1104class flag_type_t(pybase.SimpleObj):
1105 pass
1106
1107class flag_type_e(object):
1108 Bool = flag_type_t(1)
1109 Int = flag_type_t(2)
1110 Float = flag_type_t(3)
1111 Str = flag_type_t(4)
1112
1113_flag_type_str = {
1114 1: 'flag_type.Bool',
1115 2: 'flag_type.Int',
1116 3: 'flag_type.Float',
1117 4: 'flag_type.Str',
1118}
1119
1120def flag_type_str(val):
1121 # type: (flag_type_t) -> str
1122 return _flag_type_str[val]
1123
1124class trace_e(object):
1125 External = 1
1126 CommandSub = 2
1127 ForkWait = 3
1128 Fork = 4
1129 PipelinePart = 5
1130 ProcessSub = 6
1131 HereDoc = 7
1132
1133_trace_str = {
1134 1: 'External',
1135 2: 'CommandSub',
1136 3: 'ForkWait',
1137 4: 'Fork',
1138 5: 'PipelinePart',
1139 6: 'ProcessSub',
1140 7: 'HereDoc',
1141}
1142
1143def trace_str(tag, dot=True):
1144 # type: (int, bool) -> str
1145 v = _trace_str[tag]
1146 if dot:
1147 return "trace.%s" % v
1148 else:
1149 return v
1150
1151class trace_t(pybase.CompoundObj):
1152 def tag(self):
1153 # type: () -> int
1154 return self._type_tag
1155 pass
1156
1157class trace__CommandSub(trace_t):
1158 _type_tag = 2
1159 __slots__ = ()
1160
1161 def __init__(self, ):
1162 # type: () -> None
1163 pass
1164
1165 def PrettyTree(self, trav=None):
1166 # type: (Optional[TraversalState]) -> hnode_t
1167 trav = trav or TraversalState()
1168 heap_id = id(self)
1169 if heap_id in trav.seen:
1170 return hnode.AlreadySeen(heap_id)
1171 trav.seen[heap_id] = True
1172 out_node = NewRecord('trace__CommandSub')
1173 L = out_node.fields
1174
1175 return out_node
1176
1177 def _AbbreviatedTree(self, trav=None):
1178 # type: (Optional[TraversalState]) -> hnode_t
1179 trav = trav or TraversalState()
1180 heap_id = id(self)
1181 if heap_id in trav.seen:
1182 return hnode.AlreadySeen(heap_id)
1183 trav.seen[heap_id] = True
1184 out_node = NewRecord('trace__CommandSub')
1185 L = out_node.fields
1186 return out_node
1187
1188 def AbbreviatedTree(self, trav=None):
1189 # type: (Optional[TraversalState]) -> hnode_t
1190 return self._AbbreviatedTree(trav=trav)
1191
1192class trace__ForkWait(trace_t):
1193 _type_tag = 3
1194 __slots__ = ()
1195
1196 def __init__(self, ):
1197 # type: () -> None
1198 pass
1199
1200 def PrettyTree(self, trav=None):
1201 # type: (Optional[TraversalState]) -> hnode_t
1202 trav = trav or TraversalState()
1203 heap_id = id(self)
1204 if heap_id in trav.seen:
1205 return hnode.AlreadySeen(heap_id)
1206 trav.seen[heap_id] = True
1207 out_node = NewRecord('trace__ForkWait')
1208 L = out_node.fields
1209
1210 return out_node
1211
1212 def _AbbreviatedTree(self, trav=None):
1213 # type: (Optional[TraversalState]) -> hnode_t
1214 trav = trav or TraversalState()
1215 heap_id = id(self)
1216 if heap_id in trav.seen:
1217 return hnode.AlreadySeen(heap_id)
1218 trav.seen[heap_id] = True
1219 out_node = NewRecord('trace__ForkWait')
1220 L = out_node.fields
1221 return out_node
1222
1223 def AbbreviatedTree(self, trav=None):
1224 # type: (Optional[TraversalState]) -> hnode_t
1225 return self._AbbreviatedTree(trav=trav)
1226
1227class trace__Fork(trace_t):
1228 _type_tag = 4
1229 __slots__ = ()
1230
1231 def __init__(self, ):
1232 # type: () -> None
1233 pass
1234
1235 def PrettyTree(self, trav=None):
1236 # type: (Optional[TraversalState]) -> hnode_t
1237 trav = trav or TraversalState()
1238 heap_id = id(self)
1239 if heap_id in trav.seen:
1240 return hnode.AlreadySeen(heap_id)
1241 trav.seen[heap_id] = True
1242 out_node = NewRecord('trace__Fork')
1243 L = out_node.fields
1244
1245 return out_node
1246
1247 def _AbbreviatedTree(self, trav=None):
1248 # type: (Optional[TraversalState]) -> hnode_t
1249 trav = trav or TraversalState()
1250 heap_id = id(self)
1251 if heap_id in trav.seen:
1252 return hnode.AlreadySeen(heap_id)
1253 trav.seen[heap_id] = True
1254 out_node = NewRecord('trace__Fork')
1255 L = out_node.fields
1256 return out_node
1257
1258 def AbbreviatedTree(self, trav=None):
1259 # type: (Optional[TraversalState]) -> hnode_t
1260 return self._AbbreviatedTree(trav=trav)
1261
1262class trace__PipelinePart(trace_t):
1263 _type_tag = 5
1264 __slots__ = ()
1265
1266 def __init__(self, ):
1267 # type: () -> None
1268 pass
1269
1270 def PrettyTree(self, trav=None):
1271 # type: (Optional[TraversalState]) -> hnode_t
1272 trav = trav or TraversalState()
1273 heap_id = id(self)
1274 if heap_id in trav.seen:
1275 return hnode.AlreadySeen(heap_id)
1276 trav.seen[heap_id] = True
1277 out_node = NewRecord('trace__PipelinePart')
1278 L = out_node.fields
1279
1280 return out_node
1281
1282 def _AbbreviatedTree(self, trav=None):
1283 # type: (Optional[TraversalState]) -> hnode_t
1284 trav = trav or TraversalState()
1285 heap_id = id(self)
1286 if heap_id in trav.seen:
1287 return hnode.AlreadySeen(heap_id)
1288 trav.seen[heap_id] = True
1289 out_node = NewRecord('trace__PipelinePart')
1290 L = out_node.fields
1291 return out_node
1292
1293 def AbbreviatedTree(self, trav=None):
1294 # type: (Optional[TraversalState]) -> hnode_t
1295 return self._AbbreviatedTree(trav=trav)
1296
1297class trace__ProcessSub(trace_t):
1298 _type_tag = 6
1299 __slots__ = ()
1300
1301 def __init__(self, ):
1302 # type: () -> None
1303 pass
1304
1305 def PrettyTree(self, trav=None):
1306 # type: (Optional[TraversalState]) -> hnode_t
1307 trav = trav or TraversalState()
1308 heap_id = id(self)
1309 if heap_id in trav.seen:
1310 return hnode.AlreadySeen(heap_id)
1311 trav.seen[heap_id] = True
1312 out_node = NewRecord('trace__ProcessSub')
1313 L = out_node.fields
1314
1315 return out_node
1316
1317 def _AbbreviatedTree(self, trav=None):
1318 # type: (Optional[TraversalState]) -> hnode_t
1319 trav = trav or TraversalState()
1320 heap_id = id(self)
1321 if heap_id in trav.seen:
1322 return hnode.AlreadySeen(heap_id)
1323 trav.seen[heap_id] = True
1324 out_node = NewRecord('trace__ProcessSub')
1325 L = out_node.fields
1326 return out_node
1327
1328 def AbbreviatedTree(self, trav=None):
1329 # type: (Optional[TraversalState]) -> hnode_t
1330 return self._AbbreviatedTree(trav=trav)
1331
1332class trace__HereDoc(trace_t):
1333 _type_tag = 7
1334 __slots__ = ()
1335
1336 def __init__(self, ):
1337 # type: () -> None
1338 pass
1339
1340 def PrettyTree(self, trav=None):
1341 # type: (Optional[TraversalState]) -> hnode_t
1342 trav = trav or TraversalState()
1343 heap_id = id(self)
1344 if heap_id in trav.seen:
1345 return hnode.AlreadySeen(heap_id)
1346 trav.seen[heap_id] = True
1347 out_node = NewRecord('trace__HereDoc')
1348 L = out_node.fields
1349
1350 return out_node
1351
1352 def _AbbreviatedTree(self, trav=None):
1353 # type: (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 out_node = NewRecord('trace__HereDoc')
1360 L = out_node.fields
1361 return out_node
1362
1363 def AbbreviatedTree(self, trav=None):
1364 # type: (Optional[TraversalState]) -> hnode_t
1365 return self._AbbreviatedTree(trav=trav)
1366
1367class trace(object):
1368 class External(trace_t):
1369 _type_tag = 1
1370 __slots__ = ('argv',)
1371
1372 def __init__(self, argv):
1373 # type: (List[str]) -> None
1374 self.argv = argv
1375
1376 @staticmethod
1377 def CreateNull(alloc_lists=False):
1378 # type: () -> trace.External
1379 return trace.External([] if alloc_lists else cast('List[str]', None))
1380
1381 def PrettyTree(self, trav=None):
1382 # type: (Optional[TraversalState]) -> hnode_t
1383 trav = trav or TraversalState()
1384 heap_id = id(self)
1385 if heap_id in trav.seen:
1386 return hnode.AlreadySeen(heap_id)
1387 trav.seen[heap_id] = True
1388 out_node = NewRecord('trace.External')
1389 L = out_node.fields
1390
1391 if self.argv is not None: # List
1392 x0 = hnode.Array([])
1393 for i0 in self.argv:
1394 x0.children.append(NewLeaf(i0, color_e.StringConst))
1395 L.append(Field('argv', x0))
1396
1397 return out_node
1398
1399 def _AbbreviatedTree(self, trav=None):
1400 # type: (Optional[TraversalState]) -> hnode_t
1401 trav = trav or TraversalState()
1402 heap_id = id(self)
1403 if heap_id in trav.seen:
1404 return hnode.AlreadySeen(heap_id)
1405 trav.seen[heap_id] = True
1406 out_node = NewRecord('trace.External')
1407 L = out_node.fields
1408 if self.argv is not None: # List
1409 x0 = hnode.Array([])
1410 for i0 in self.argv:
1411 x0.children.append(NewLeaf(i0, color_e.StringConst))
1412 L.append(Field('argv', x0))
1413
1414 return out_node
1415
1416 def AbbreviatedTree(self, trav=None):
1417 # type: (Optional[TraversalState]) -> hnode_t
1418 return self._AbbreviatedTree(trav=trav)
1419
1420 CommandSub = trace__CommandSub()
1421
1422 ForkWait = trace__ForkWait()
1423
1424 Fork = trace__Fork()
1425
1426 PipelinePart = trace__PipelinePart()
1427
1428 ProcessSub = trace__ProcessSub()
1429
1430 HereDoc = trace__HereDoc()
1431
1432 pass
1433
1434class word_style_t(pybase.SimpleObj):
1435 pass
1436
1437class word_style_e(object):
1438 Expr = word_style_t(1)
1439 Unquoted = word_style_t(2)
1440 DQ = word_style_t(3)
1441 SQ = word_style_t(4)
1442
1443_word_style_str = {
1444 1: 'word_style.Expr',
1445 2: 'word_style.Unquoted',
1446 3: 'word_style.DQ',
1447 4: 'word_style.SQ',
1448}
1449
1450def word_style_str(val):
1451 # type: (word_style_t) -> str
1452 return _word_style_str[val]
1453
1454class comp_action_t(pybase.SimpleObj):
1455 pass
1456
1457class comp_action_e(object):
1458 Other = comp_action_t(1)
1459 FileSystem = comp_action_t(2)
1460 BashFunc = comp_action_t(3)
1461
1462_comp_action_str = {
1463 1: 'comp_action.Other',
1464 2: 'comp_action.FileSystem',
1465 3: 'comp_action.BashFunc',
1466}
1467
1468def comp_action_str(val):
1469 # type: (comp_action_t) -> str
1470 return _comp_action_str[val]
1471
1472class AssignArg(pybase.CompoundObj):
1473 _type_tag = 64
1474 __slots__ = ('var_name', 'rval', 'plus_eq', 'blame_word')
1475
1476 def __init__(self, var_name, rval, plus_eq, blame_word):
1477 # type: (str, Optional[value_t], bool, CompoundWord) -> None
1478 self.var_name = var_name
1479 self.rval = rval
1480 self.plus_eq = plus_eq
1481 self.blame_word = blame_word
1482
1483 @staticmethod
1484 def CreateNull(alloc_lists=False):
1485 # type: () -> AssignArg
1486 return AssignArg('', cast('Optional[value_t]', None), False, cast(CompoundWord, None))
1487
1488 def PrettyTree(self, trav=None):
1489 # type: (Optional[TraversalState]) -> hnode_t
1490 trav = trav or TraversalState()
1491 heap_id = id(self)
1492 if heap_id in trav.seen:
1493 return hnode.AlreadySeen(heap_id)
1494 trav.seen[heap_id] = True
1495 out_node = NewRecord('AssignArg')
1496 L = out_node.fields
1497
1498 x0 = NewLeaf(self.var_name, color_e.StringConst)
1499 L.append(Field('var_name', x0))
1500
1501 if self.rval is not None: # Optional
1502 x1 = self.rval.PrettyTree(trav=trav)
1503 L.append(Field('rval', x1))
1504
1505 x2 = hnode.Leaf('T' if self.plus_eq else 'F', color_e.OtherConst)
1506 L.append(Field('plus_eq', x2))
1507
1508 assert self.blame_word is not None
1509 x3 = self.blame_word.PrettyTree(trav=trav)
1510 L.append(Field('blame_word', x3))
1511
1512 return out_node
1513
1514 def _AbbreviatedTree(self, trav=None):
1515 # type: (Optional[TraversalState]) -> hnode_t
1516 trav = trav or TraversalState()
1517 heap_id = id(self)
1518 if heap_id in trav.seen:
1519 return hnode.AlreadySeen(heap_id)
1520 trav.seen[heap_id] = True
1521 out_node = NewRecord('AssignArg')
1522 L = out_node.fields
1523 x0 = NewLeaf(self.var_name, color_e.StringConst)
1524 L.append(Field('var_name', x0))
1525
1526 if self.rval is not None: # Optional
1527 x1 = self.rval.AbbreviatedTree(trav=trav)
1528 L.append(Field('rval', x1))
1529
1530 x2 = hnode.Leaf('T' if self.plus_eq else 'F', color_e.OtherConst)
1531 L.append(Field('plus_eq', x2))
1532
1533 assert self.blame_word is not None
1534 x3 = self.blame_word.AbbreviatedTree(trav=trav)
1535 L.append(Field('blame_word', x3))
1536
1537 return out_node
1538
1539 def AbbreviatedTree(self, trav=None):
1540 # type: (Optional[TraversalState]) -> hnode_t
1541 return self._AbbreviatedTree(trav=trav)
1542
1543class Piece(part_value_t):
1544 _type_tag = 65
1545 __slots__ = ('s', 'quoted', 'do_split')
1546
1547 def __init__(self, s, quoted, do_split):
1548 # type: (str, bool, bool) -> None
1549 self.s = s
1550 self.quoted = quoted
1551 self.do_split = do_split
1552
1553 @staticmethod
1554 def CreateNull(alloc_lists=False):
1555 # type: () -> Piece
1556 return Piece('', False, False)
1557
1558 def PrettyTree(self, trav=None):
1559 # type: (Optional[TraversalState]) -> hnode_t
1560 trav = trav or TraversalState()
1561 heap_id = id(self)
1562 if heap_id in trav.seen:
1563 return hnode.AlreadySeen(heap_id)
1564 trav.seen[heap_id] = True
1565 out_node = NewRecord('Piece')
1566 L = out_node.fields
1567
1568 x0 = NewLeaf(self.s, color_e.StringConst)
1569 L.append(Field('s', x0))
1570
1571 x1 = hnode.Leaf('T' if self.quoted else 'F', color_e.OtherConst)
1572 L.append(Field('quoted', x1))
1573
1574 x2 = hnode.Leaf('T' if self.do_split else 'F', color_e.OtherConst)
1575 L.append(Field('do_split', x2))
1576
1577 return out_node
1578
1579 def _AbbreviatedTree(self, trav=None):
1580 # type: (Optional[TraversalState]) -> hnode_t
1581 trav = trav or TraversalState()
1582 heap_id = id(self)
1583 if heap_id in trav.seen:
1584 return hnode.AlreadySeen(heap_id)
1585 trav.seen[heap_id] = True
1586 out_node = NewRecord('Piece')
1587 L = out_node.fields
1588 x0 = NewLeaf(self.s, color_e.StringConst)
1589 L.append(Field('s', x0))
1590
1591 x1 = hnode.Leaf('T' if self.quoted else 'F', color_e.OtherConst)
1592 L.append(Field('quoted', x1))
1593
1594 x2 = hnode.Leaf('T' if self.do_split else 'F', color_e.OtherConst)
1595 L.append(Field('do_split', x2))
1596
1597 return out_node
1598
1599 def AbbreviatedTree(self, trav=None):
1600 # type: (Optional[TraversalState]) -> hnode_t
1601 return self._AbbreviatedTree(trav=trav)
1602
1603class VarSubState(pybase.CompoundObj):
1604 _type_tag = 66
1605 __slots__ = ('join_array', 'is_type_query', 'has_test_op')
1606
1607 def __init__(self, join_array, is_type_query, has_test_op):
1608 # type: (bool, bool, bool) -> None
1609 self.join_array = join_array
1610 self.is_type_query = is_type_query
1611 self.has_test_op = has_test_op
1612
1613 @staticmethod
1614 def CreateNull(alloc_lists=False):
1615 # type: () -> VarSubState
1616 return VarSubState(False, False, False)
1617
1618 def PrettyTree(self, trav=None):
1619 # type: (Optional[TraversalState]) -> hnode_t
1620 trav = trav or TraversalState()
1621 heap_id = id(self)
1622 if heap_id in trav.seen:
1623 return hnode.AlreadySeen(heap_id)
1624 trav.seen[heap_id] = True
1625 out_node = NewRecord('VarSubState')
1626 L = out_node.fields
1627
1628 x0 = hnode.Leaf('T' if self.join_array else 'F', color_e.OtherConst)
1629 L.append(Field('join_array', x0))
1630
1631 x1 = hnode.Leaf('T' if self.is_type_query else 'F', color_e.OtherConst)
1632 L.append(Field('is_type_query', x1))
1633
1634 x2 = hnode.Leaf('T' if self.has_test_op else 'F', color_e.OtherConst)
1635 L.append(Field('has_test_op', x2))
1636
1637 return out_node
1638
1639 def _AbbreviatedTree(self, trav=None):
1640 # type: (Optional[TraversalState]) -> hnode_t
1641 trav = trav or TraversalState()
1642 heap_id = id(self)
1643 if heap_id in trav.seen:
1644 return hnode.AlreadySeen(heap_id)
1645 trav.seen[heap_id] = True
1646 out_node = NewRecord('VarSubState')
1647 L = out_node.fields
1648 x0 = hnode.Leaf('T' if self.join_array else 'F', color_e.OtherConst)
1649 L.append(Field('join_array', x0))
1650
1651 x1 = hnode.Leaf('T' if self.is_type_query else 'F', color_e.OtherConst)
1652 L.append(Field('is_type_query', x1))
1653
1654 x2 = hnode.Leaf('T' if self.has_test_op else 'F', color_e.OtherConst)
1655 L.append(Field('has_test_op', x2))
1656
1657 return out_node
1658
1659 def AbbreviatedTree(self, trav=None):
1660 # type: (Optional[TraversalState]) -> hnode_t
1661 return self._AbbreviatedTree(trav=trav)
1662
1663class Cell(pybase.CompoundObj):
1664 _type_tag = 67
1665 __slots__ = ('exported', 'readonly', 'nameref', 'val')
1666
1667 def __init__(self, exported, readonly, nameref, val):
1668 # type: (bool, bool, bool, value_t) -> None
1669 self.exported = exported
1670 self.readonly = readonly
1671 self.nameref = nameref
1672 self.val = val
1673
1674 @staticmethod
1675 def CreateNull(alloc_lists=False):
1676 # type: () -> Cell
1677 return Cell(False, False, False, cast(value_t, None))
1678
1679 def PrettyTree(self, trav=None):
1680 # type: (Optional[TraversalState]) -> hnode_t
1681 trav = trav or TraversalState()
1682 heap_id = id(self)
1683 if heap_id in trav.seen:
1684 return hnode.AlreadySeen(heap_id)
1685 trav.seen[heap_id] = True
1686 out_node = NewRecord('Cell')
1687 L = out_node.fields
1688
1689 x0 = hnode.Leaf('T' if self.exported else 'F', color_e.OtherConst)
1690 L.append(Field('exported', x0))
1691
1692 x1 = hnode.Leaf('T' if self.readonly else 'F', color_e.OtherConst)
1693 L.append(Field('readonly', x1))
1694
1695 x2 = hnode.Leaf('T' if self.nameref else 'F', color_e.OtherConst)
1696 L.append(Field('nameref', x2))
1697
1698 assert self.val is not None
1699 x3 = self.val.PrettyTree(trav=trav)
1700 L.append(Field('val', x3))
1701
1702 return out_node
1703
1704 def _AbbreviatedTree(self, trav=None):
1705 # type: (Optional[TraversalState]) -> hnode_t
1706 trav = trav or TraversalState()
1707 heap_id = id(self)
1708 if heap_id in trav.seen:
1709 return hnode.AlreadySeen(heap_id)
1710 trav.seen[heap_id] = True
1711 out_node = NewRecord('Cell')
1712 L = out_node.fields
1713 x0 = hnode.Leaf('T' if self.exported else 'F', color_e.OtherConst)
1714 L.append(Field('exported', x0))
1715
1716 x1 = hnode.Leaf('T' if self.readonly else 'F', color_e.OtherConst)
1717 L.append(Field('readonly', x1))
1718
1719 x2 = hnode.Leaf('T' if self.nameref else 'F', color_e.OtherConst)
1720 L.append(Field('nameref', x2))
1721
1722 assert self.val is not None
1723 x3 = self.val.AbbreviatedTree(trav=trav)
1724 L.append(Field('val', x3))
1725
1726 return out_node
1727
1728 def AbbreviatedTree(self, trav=None):
1729 # type: (Optional[TraversalState]) -> hnode_t
1730 return self._AbbreviatedTree(trav=trav)
1731
1732class VTestPlace(pybase.CompoundObj):
1733 _type_tag = 68
1734 __slots__ = ('name', 'index')
1735
1736 def __init__(self, name, index):
1737 # type: (Optional[str], Optional[a_index_t]) -> None
1738 self.name = name
1739 self.index = index
1740
1741 @staticmethod
1742 def CreateNull(alloc_lists=False):
1743 # type: () -> VTestPlace
1744 return VTestPlace(cast('Optional[str]', None), cast('Optional[a_index_t]', None))
1745
1746 def PrettyTree(self, trav=None):
1747 # type: (Optional[TraversalState]) -> hnode_t
1748 trav = trav or TraversalState()
1749 heap_id = id(self)
1750 if heap_id in trav.seen:
1751 return hnode.AlreadySeen(heap_id)
1752 trav.seen[heap_id] = True
1753 out_node = NewRecord('VTestPlace')
1754 L = out_node.fields
1755
1756 if self.name is not None: # Optional
1757 x0 = NewLeaf(self.name, color_e.StringConst)
1758 L.append(Field('name', x0))
1759
1760 if self.index is not None: # Optional
1761 x1 = self.index.PrettyTree(trav=trav)
1762 L.append(Field('index', x1))
1763
1764 return out_node
1765
1766 def _AbbreviatedTree(self, trav=None):
1767 # type: (Optional[TraversalState]) -> hnode_t
1768 trav = trav or TraversalState()
1769 heap_id = id(self)
1770 if heap_id in trav.seen:
1771 return hnode.AlreadySeen(heap_id)
1772 trav.seen[heap_id] = True
1773 out_node = NewRecord('VTestPlace')
1774 L = out_node.fields
1775 if self.name is not None: # Optional
1776 x0 = NewLeaf(self.name, color_e.StringConst)
1777 L.append(Field('name', x0))
1778
1779 if self.index is not None: # Optional
1780 x1 = self.index.AbbreviatedTree(trav=trav)
1781 L.append(Field('index', x1))
1782
1783 return out_node
1784
1785 def AbbreviatedTree(self, trav=None):
1786 # type: (Optional[TraversalState]) -> hnode_t
1787 return self._AbbreviatedTree(trav=trav)
1788
1789class RedirValue(pybase.CompoundObj):
1790 _type_tag = 69
1791 __slots__ = ('op_id', 'op_loc', 'loc', 'arg')
1792
1793 def __init__(self, op_id, op_loc, loc, arg):
1794 # type: (Id_t, loc_t, redir_loc_t, redirect_arg_t) -> None
1795 self.op_id = op_id
1796 self.op_loc = op_loc
1797 self.loc = loc
1798 self.arg = arg
1799
1800 @staticmethod
1801 def CreateNull(alloc_lists=False):
1802 # type: () -> RedirValue
1803 return RedirValue(-1, cast(loc_t, None), cast(redir_loc_t, None), cast(redirect_arg_t, None))
1804
1805 def PrettyTree(self, trav=None):
1806 # type: (Optional[TraversalState]) -> hnode_t
1807 trav = trav or TraversalState()
1808 heap_id = id(self)
1809 if heap_id in trav.seen:
1810 return hnode.AlreadySeen(heap_id)
1811 trav.seen[heap_id] = True
1812 out_node = NewRecord('RedirValue')
1813 L = out_node.fields
1814
1815 x0 = hnode.Leaf(Id_str(self.op_id), color_e.UserType)
1816 L.append(Field('op_id', x0))
1817
1818 assert self.op_loc is not None
1819 x1 = self.op_loc.PrettyTree(trav=trav)
1820 L.append(Field('op_loc', x1))
1821
1822 assert self.loc is not None
1823 x2 = self.loc.PrettyTree(trav=trav)
1824 L.append(Field('loc', x2))
1825
1826 assert self.arg is not None
1827 x3 = self.arg.PrettyTree(trav=trav)
1828 L.append(Field('arg', x3))
1829
1830 return out_node
1831
1832 def _AbbreviatedTree(self, trav=None):
1833 # type: (Optional[TraversalState]) -> hnode_t
1834 trav = trav or TraversalState()
1835 heap_id = id(self)
1836 if heap_id in trav.seen:
1837 return hnode.AlreadySeen(heap_id)
1838 trav.seen[heap_id] = True
1839 out_node = NewRecord('RedirValue')
1840 L = out_node.fields
1841 x0 = hnode.Leaf(Id_str(self.op_id), color_e.UserType)
1842 L.append(Field('op_id', x0))
1843
1844 assert self.op_loc is not None
1845 x1 = self.op_loc.AbbreviatedTree(trav=trav)
1846 L.append(Field('op_loc', x1))
1847
1848 assert self.loc is not None
1849 x2 = self.loc.AbbreviatedTree(trav=trav)
1850 L.append(Field('loc', x2))
1851
1852 assert self.arg is not None
1853 x3 = self.arg.AbbreviatedTree(trav=trav)
1854 L.append(Field('arg', x3))
1855
1856 return out_node
1857
1858 def AbbreviatedTree(self, trav=None):
1859 # type: (Optional[TraversalState]) -> hnode_t
1860 return self._AbbreviatedTree(trav=trav)
1861
1862class StatusArray(pybase.CompoundObj):
1863 _type_tag = 70
1864 __slots__ = ('codes', 'locs')
1865
1866 def __init__(self, codes, locs):
1867 # type: (Optional[List[int]], Optional[List[loc_t]]) -> None
1868 self.codes = codes
1869 self.locs = locs
1870
1871 @staticmethod
1872 def CreateNull(alloc_lists=False):
1873 # type: () -> StatusArray
1874 return StatusArray(cast('Optional[List[int]]', None), cast('Optional[List[loc_t]]', None))
1875
1876 def PrettyTree(self, trav=None):
1877 # type: (Optional[TraversalState]) -> hnode_t
1878 trav = trav or TraversalState()
1879 heap_id = id(self)
1880 if heap_id in trav.seen:
1881 return hnode.AlreadySeen(heap_id)
1882 trav.seen[heap_id] = True
1883 out_node = NewRecord('StatusArray')
1884 L = out_node.fields
1885
1886 if self.codes is not None: # List
1887 x0 = hnode.Array([])
1888 for i0 in self.codes:
1889 x0.children.append(hnode.Leaf(str(i0), color_e.OtherConst))
1890 L.append(Field('codes', x0))
1891
1892 if self.locs is not None: # List
1893 x1 = hnode.Array([])
1894 for i1 in self.locs:
1895 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
1896 i1.PrettyTree(trav=trav))
1897 x1.children.append(h)
1898 L.append(Field('locs', x1))
1899
1900 return out_node
1901
1902 def _AbbreviatedTree(self, trav=None):
1903 # type: (Optional[TraversalState]) -> hnode_t
1904 trav = trav or TraversalState()
1905 heap_id = id(self)
1906 if heap_id in trav.seen:
1907 return hnode.AlreadySeen(heap_id)
1908 trav.seen[heap_id] = True
1909 out_node = NewRecord('StatusArray')
1910 L = out_node.fields
1911 if self.codes is not None: # List
1912 x0 = hnode.Array([])
1913 for i0 in self.codes:
1914 x0.children.append(hnode.Leaf(str(i0), color_e.OtherConst))
1915 L.append(Field('codes', x0))
1916
1917 if self.locs is not None: # List
1918 x1 = hnode.Array([])
1919 for i1 in self.locs:
1920 h = (hnode.Leaf("_", color_e.OtherConst) if i1 is None else
1921 i1.AbbreviatedTree(trav=trav))
1922 x1.children.append(h)
1923 L.append(Field('locs', x1))
1924
1925 return out_node
1926
1927 def AbbreviatedTree(self, trav=None):
1928 # type: (Optional[TraversalState]) -> hnode_t
1929 return self._AbbreviatedTree(trav=trav)
1930
1931class CommandStatus(pybase.CompoundObj):
1932 _type_tag = 71
1933 __slots__ = ('check_errexit', 'show_code', 'pipe_negated', 'pipe_status',
1934 'pipe_locs')
1935
1936 def __init__(self, check_errexit, show_code, pipe_negated, pipe_status,
1937 pipe_locs):
1938 # type: (bool, bool, bool, Optional[List[int]], Optional[List[loc_t]]) -> None
1939 self.check_errexit = check_errexit
1940 self.show_code = show_code
1941 self.pipe_negated = pipe_negated
1942 self.pipe_status = pipe_status
1943 self.pipe_locs = pipe_locs
1944
1945 @staticmethod
1946 def CreateNull(alloc_lists=False):
1947 # type: () -> CommandStatus
1948 return CommandStatus(False, False, False, cast('Optional[List[int]]', None), cast('Optional[List[loc_t]]', None))
1949
1950 def PrettyTree(self, trav=None):
1951 # type: (Optional[TraversalState]) -> hnode_t
1952 trav = trav or TraversalState()
1953 heap_id = id(self)
1954 if heap_id in trav.seen:
1955 return hnode.AlreadySeen(heap_id)
1956 trav.seen[heap_id] = True
1957 out_node = NewRecord('CommandStatus')
1958 L = out_node.fields
1959
1960 x0 = hnode.Leaf('T' if self.check_errexit else 'F', color_e.OtherConst)
1961 L.append(Field('check_errexit', x0))
1962
1963 x1 = hnode.Leaf('T' if self.show_code else 'F', color_e.OtherConst)
1964 L.append(Field('show_code', x1))
1965
1966 x2 = hnode.Leaf('T' if self.pipe_negated else 'F', color_e.OtherConst)
1967 L.append(Field('pipe_negated', x2))
1968
1969 if self.pipe_status is not None: # List
1970 x3 = hnode.Array([])
1971 for i3 in self.pipe_status:
1972 x3.children.append(hnode.Leaf(str(i3), color_e.OtherConst))
1973 L.append(Field('pipe_status', x3))
1974
1975 if self.pipe_locs is not None: # List
1976 x4 = hnode.Array([])
1977 for i4 in self.pipe_locs:
1978 h = (hnode.Leaf("_", color_e.OtherConst) if i4 is None else
1979 i4.PrettyTree(trav=trav))
1980 x4.children.append(h)
1981 L.append(Field('pipe_locs', x4))
1982
1983 return out_node
1984
1985 def _AbbreviatedTree(self, trav=None):
1986 # type: (Optional[TraversalState]) -> hnode_t
1987 trav = trav or TraversalState()
1988 heap_id = id(self)
1989 if heap_id in trav.seen:
1990 return hnode.AlreadySeen(heap_id)
1991 trav.seen[heap_id] = True
1992 out_node = NewRecord('CommandStatus')
1993 L = out_node.fields
1994 x0 = hnode.Leaf('T' if self.check_errexit else 'F', color_e.OtherConst)
1995 L.append(Field('check_errexit', x0))
1996
1997 x1 = hnode.Leaf('T' if self.show_code else 'F', color_e.OtherConst)
1998 L.append(Field('show_code', x1))
1999
2000 x2 = hnode.Leaf('T' if self.pipe_negated else 'F', color_e.OtherConst)
2001 L.append(Field('pipe_negated', x2))
2002
2003 if self.pipe_status is not None: # List
2004 x3 = hnode.Array([])
2005 for i3 in self.pipe_status:
2006 x3.children.append(hnode.Leaf(str(i3), color_e.OtherConst))
2007 L.append(Field('pipe_status', x3))
2008
2009 if self.pipe_locs is not None: # List
2010 x4 = hnode.Array([])
2011 for i4 in self.pipe_locs:
2012 h = (hnode.Leaf("_", color_e.OtherConst) if i4 is None else
2013 i4.AbbreviatedTree(trav=trav))
2014 x4.children.append(h)
2015 L.append(Field('pipe_locs', x4))
2016
2017 return out_node
2018
2019 def AbbreviatedTree(self, trav=None):
2020 # type: (Optional[TraversalState]) -> hnode_t
2021 return self._AbbreviatedTree(trav=trav)
2022
2023class HayNode(pybase.CompoundObj):
2024 _type_tag = 72
2025 __slots__ = ('children',)
2026
2027 def __init__(self, children):
2028 # type: (Dict[str, HayNode]) -> None
2029 self.children = children
2030
2031 @staticmethod
2032 def CreateNull(alloc_lists=False):
2033 # type: () -> HayNode
2034 return HayNode(cast('Dict[str, HayNode]', None))
2035
2036 def PrettyTree(self, trav=None):
2037 # type: (Optional[TraversalState]) -> hnode_t
2038 trav = trav or TraversalState()
2039 heap_id = id(self)
2040 if heap_id in trav.seen:
2041 return hnode.AlreadySeen(heap_id)
2042 trav.seen[heap_id] = True
2043 out_node = NewRecord('HayNode')
2044 L = out_node.fields
2045
2046 if self.children is not None: # Dict
2047 m = hnode.Leaf("Dict", color_e.OtherConst)
2048 x0 = hnode.Array([m])
2049 for k0, v0 in self.children.iteritems():
2050 x0.children.append(NewLeaf(k0, color_e.StringConst))
2051 x0.children.append(v0.PrettyTree(trav=trav))
2052 L.append(Field('children', x0))
2053
2054 return out_node
2055
2056 def _AbbreviatedTree(self, trav=None):
2057 # type: (Optional[TraversalState]) -> hnode_t
2058 trav = trav or TraversalState()
2059 heap_id = id(self)
2060 if heap_id in trav.seen:
2061 return hnode.AlreadySeen(heap_id)
2062 trav.seen[heap_id] = True
2063 out_node = NewRecord('HayNode')
2064 L = out_node.fields
2065 if self.children is not None: # Dict
2066 m = hnode.Leaf("Dict", color_e.OtherConst)
2067 x0 = hnode.Array([m])
2068 for k0, v0 in self.children.iteritems():
2069 x0.children.append(NewLeaf(k0, color_e.StringConst))
2070 x0.children.append(v0.AbbreviatedTree(trav=trav))
2071 L.append(Field('children', x0))
2072
2073 return out_node
2074
2075 def AbbreviatedTree(self, trav=None):
2076 # type: (Optional[TraversalState]) -> hnode_t
2077 return self._AbbreviatedTree(trav=trav)
2078