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