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

442 lines, 303 significant
1from asdl import pybase
2from mycpp import mops
3from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
4
5from asdl import runtime # For runtime.NO_SPID
6from asdl.runtime import NewRecord, NewLeaf, TraversalState
7from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
8
9class expr_e(object):
10 Binary = 1
11 DoubleQuoted = 65
12
13_expr_str = {
14 1: 'Binary',
15 65: 'DoubleQuoted',
16}
17
18def expr_str(tag, dot=True):
19 # type: (int, bool) -> str
20 v = _expr_str[tag]
21 if dot:
22 return "expr.%s" % v
23 else:
24 return v
25
26class expr_t(pybase.CompoundObj):
27 def tag(self):
28 # type: () -> int
29 return self._type_tag
30
31class expr(object):
32 class Binary(expr_t):
33 _type_tag = 1
34 __slots__ = ('left', 'right')
35
36 def __init__(self, left, right):
37 # type: (expr_t, expr_t) -> None
38 self.left = left
39 self.right = right
40
41 @staticmethod
42 def CreateNull(alloc_lists=False):
43 # type: () -> expr.Binary
44 return expr.Binary(cast('expr_t', None), cast('expr_t', None))
45
46 def PrettyTree(self, do_abbrev, trav=None):
47 # type: (bool, Optional[TraversalState]) -> hnode_t
48 trav = trav or TraversalState()
49 heap_id = id(self)
50 if heap_id in trav.seen:
51 return hnode.AlreadySeen(heap_id)
52 trav.seen[heap_id] = True
53
54 out_node = NewRecord('expr.Binary')
55 L = out_node.fields
56
57 assert self.left is not None
58 x0 = self.left.PrettyTree(do_abbrev, trav=trav)
59 L.append(Field('left', x0))
60
61 assert self.right is not None
62 x1 = self.right.PrettyTree(do_abbrev, trav=trav)
63 L.append(Field('right', x1))
64
65 return out_node
66
67 pass
68
69class tok_e(object):
70 Eof = 1
71 Token = 66
72
73_tok_str = {
74 1: 'Eof',
75 66: 'Token',
76}
77
78def tok_str(tag, dot=True):
79 # type: (int, bool) -> str
80 v = _tok_str[tag]
81 if dot:
82 return "tok.%s" % v
83 else:
84 return v
85
86class tok_t(pybase.CompoundObj):
87 def tag(self):
88 # type: () -> int
89 return self._type_tag
90
91class tok__Eof(tok_t):
92 _type_tag = 1
93 __slots__ = ()
94
95 def __init__(self, ):
96 # type: () -> None
97 pass
98
99 def PrettyTree(self, do_abbrev, trav=None):
100 # type: (bool, Optional[TraversalState]) -> hnode_t
101 trav = trav or TraversalState()
102 heap_id = id(self)
103 if heap_id in trav.seen:
104 return hnode.AlreadySeen(heap_id)
105 trav.seen[heap_id] = True
106
107 out_node = NewRecord('tok.Eof')
108 L = out_node.fields
109
110 return out_node
111
112class tok(object):
113 Eof = tok__Eof()
114
115 pass
116
117class word_part_e(object):
118 Literal = 1
119 DoubleQuoted = 65
120
121_word_part_str = {
122 1: 'Literal',
123 65: 'DoubleQuoted',
124}
125
126def word_part_str(tag, dot=True):
127 # type: (int, bool) -> str
128 v = _word_part_str[tag]
129 if dot:
130 return "word_part.%s" % v
131 else:
132 return v
133
134class word_part_t(pybase.CompoundObj):
135 def tag(self):
136 # type: () -> int
137 return self._type_tag
138
139class word_part(object):
140 class Literal(word_part_t):
141 _type_tag = 1
142 __slots__ = ('s',)
143
144 def __init__(self, s):
145 # type: (str) -> None
146 self.s = s
147
148 @staticmethod
149 def CreateNull(alloc_lists=False):
150 # type: () -> word_part.Literal
151 return word_part.Literal('')
152
153 def PrettyTree(self, do_abbrev, trav=None):
154 # type: (bool, Optional[TraversalState]) -> hnode_t
155 trav = trav or TraversalState()
156 heap_id = id(self)
157 if heap_id in trav.seen:
158 return hnode.AlreadySeen(heap_id)
159 trav.seen[heap_id] = True
160
161 out_node = NewRecord('word_part.Literal')
162 L = out_node.fields
163
164 x0 = NewLeaf(self.s, color_e.StringConst)
165 L.append(Field('s', x0))
166
167 return out_node
168
169 pass
170
171class cflow_e(object):
172 Break = 1
173 Continue = 2
174 Return = 3
175
176_cflow_str = {
177 1: 'Break',
178 2: 'Continue',
179 3: 'Return',
180}
181
182def cflow_str(tag, dot=True):
183 # type: (int, bool) -> str
184 v = _cflow_str[tag]
185 if dot:
186 return "cflow.%s" % v
187 else:
188 return v
189
190class cflow_t(pybase.CompoundObj):
191 def tag(self):
192 # type: () -> int
193 return self._type_tag
194
195class cflow__Break(cflow_t):
196 _type_tag = 1
197 __slots__ = ()
198
199 def __init__(self, ):
200 # type: () -> None
201 pass
202
203 def PrettyTree(self, do_abbrev, trav=None):
204 # type: (bool, Optional[TraversalState]) -> hnode_t
205 trav = trav or TraversalState()
206 heap_id = id(self)
207 if heap_id in trav.seen:
208 return hnode.AlreadySeen(heap_id)
209 trav.seen[heap_id] = True
210
211 out_node = NewRecord('cflow.Break')
212 L = out_node.fields
213
214 return out_node
215
216class cflow__Continue(cflow_t):
217 _type_tag = 2
218 __slots__ = ()
219
220 def __init__(self, ):
221 # type: () -> None
222 pass
223
224 def PrettyTree(self, do_abbrev, trav=None):
225 # type: (bool, Optional[TraversalState]) -> hnode_t
226 trav = trav or TraversalState()
227 heap_id = id(self)
228 if heap_id in trav.seen:
229 return hnode.AlreadySeen(heap_id)
230 trav.seen[heap_id] = True
231
232 out_node = NewRecord('cflow.Continue')
233 L = out_node.fields
234
235 return out_node
236
237class cflow(object):
238 Break = cflow__Break()
239
240 Continue = cflow__Continue()
241
242 class Return(cflow_t):
243 _type_tag = 3
244 __slots__ = ('val',)
245
246 def __init__(self, val):
247 # type: (int) -> None
248 self.val = val
249
250 @staticmethod
251 def CreateNull(alloc_lists=False):
252 # type: () -> cflow.Return
253 return cflow.Return(-1)
254
255 def PrettyTree(self, do_abbrev, trav=None):
256 # type: (bool, Optional[TraversalState]) -> hnode_t
257 trav = trav or TraversalState()
258 heap_id = id(self)
259 if heap_id in trav.seen:
260 return hnode.AlreadySeen(heap_id)
261 trav.seen[heap_id] = True
262
263 out_node = NewRecord('cflow.Return')
264 L = out_node.fields
265
266 x0 = hnode.Leaf(str(self.val), color_e.OtherConst)
267 L.append(Field('val', x0))
268
269 return out_node
270
271 pass
272
273class prod(pybase.CompoundObj):
274 _type_tag = 64
275 __slots__ = ('a', 'b')
276
277 def __init__(self, a, b):
278 # type: (str, str) -> None
279 self.a = a
280 self.b = b
281
282 @staticmethod
283 def CreateNull(alloc_lists=False):
284 # type: () -> prod
285 return prod('', '')
286
287 def PrettyTree(self, do_abbrev, trav=None):
288 # type: (bool, Optional[TraversalState]) -> hnode_t
289 trav = trav or TraversalState()
290 heap_id = id(self)
291 if heap_id in trav.seen:
292 return hnode.AlreadySeen(heap_id)
293 trav.seen[heap_id] = True
294
295 out_node = NewRecord('prod')
296 L = out_node.fields
297
298 x0 = NewLeaf(self.a, color_e.StringConst)
299 L.append(Field('a', x0))
300
301 x1 = NewLeaf(self.b, color_e.StringConst)
302 L.append(Field('b', x1))
303
304 return out_node
305
306class DoubleQuoted(expr_t, word_part_t):
307 _type_tag = 65
308 __slots__ = ('left', 'tokens')
309
310 def __init__(self, left, tokens):
311 # type: (int, List[str]) -> None
312 self.left = left
313 self.tokens = tokens
314
315 @staticmethod
316 def CreateNull(alloc_lists=False):
317 # type: () -> DoubleQuoted
318 return DoubleQuoted(-1, [] if alloc_lists else cast('List[str]', None))
319
320 def PrettyTree(self, do_abbrev, trav=None):
321 # type: (bool, Optional[TraversalState]) -> hnode_t
322 trav = trav or TraversalState()
323 heap_id = id(self)
324 if heap_id in trav.seen:
325 return hnode.AlreadySeen(heap_id)
326 trav.seen[heap_id] = True
327
328 out_node = NewRecord('DoubleQuoted')
329 L = out_node.fields
330
331 x0 = hnode.Leaf(str(self.left), color_e.OtherConst)
332 L.append(Field('left', x0))
333
334 if self.tokens is not None: # List
335 x1 = hnode.Array([])
336 for i1 in self.tokens:
337 x1.children.append(NewLeaf(i1, color_e.StringConst))
338 L.append(Field('tokens', x1))
339
340 return out_node
341
342class Token(tok_t):
343 _type_tag = 66
344 __slots__ = ('id', 'val')
345
346 def __init__(self, id, val):
347 # type: (int, str) -> None
348 self.id = id
349 self.val = val
350
351 @staticmethod
352 def CreateNull(alloc_lists=False):
353 # type: () -> Token
354 return Token(-1, '')
355
356 def PrettyTree(self, do_abbrev, trav=None):
357 # type: (bool, Optional[TraversalState]) -> hnode_t
358 trav = trav or TraversalState()
359 heap_id = id(self)
360 if heap_id in trav.seen:
361 return hnode.AlreadySeen(heap_id)
362 trav.seen[heap_id] = True
363
364 out_node = NewRecord('Token')
365 L = out_node.fields
366
367 x0 = hnode.Leaf(str(self.id), color_e.OtherConst)
368 L.append(Field('id', x0))
369
370 x1 = NewLeaf(self.val, color_e.StringConst)
371 L.append(Field('val', x1))
372
373 return out_node
374
375class tok_struct(pybase.CompoundObj):
376 _type_tag = 67
377 __slots__ = ('token', 'x')
378
379 def __init__(self, token, x):
380 # type: (tok_t, int) -> None
381 self.token = token
382 self.x = x
383
384 @staticmethod
385 def CreateNull(alloc_lists=False):
386 # type: () -> tok_struct
387 return tok_struct(cast('tok_t', None), -1)
388
389 def PrettyTree(self, do_abbrev, trav=None):
390 # type: (bool, Optional[TraversalState]) -> hnode_t
391 trav = trav or TraversalState()
392 heap_id = id(self)
393 if heap_id in trav.seen:
394 return hnode.AlreadySeen(heap_id)
395 trav.seen[heap_id] = True
396
397 out_node = NewRecord('tok_struct')
398 L = out_node.fields
399
400 assert self.token is not None
401 x0 = self.token.PrettyTree(do_abbrev, trav=trav)
402 L.append(Field('token', x0))
403
404 x1 = hnode.Leaf(str(self.x), color_e.OtherConst)
405 L.append(Field('x', x1))
406
407 return out_node
408
409class tok_array(pybase.CompoundObj):
410 _type_tag = 68
411 __slots__ = ('tokens',)
412
413 def __init__(self, tokens):
414 # type: (List[tok_t]) -> None
415 self.tokens = tokens
416
417 @staticmethod
418 def CreateNull(alloc_lists=False):
419 # type: () -> tok_array
420 return tok_array([] if alloc_lists else cast('List[tok_t]', None))
421
422 def PrettyTree(self, do_abbrev, trav=None):
423 # type: (bool, Optional[TraversalState]) -> hnode_t
424 trav = trav or TraversalState()
425 heap_id = id(self)
426 if heap_id in trav.seen:
427 return hnode.AlreadySeen(heap_id)
428 trav.seen[heap_id] = True
429
430 out_node = NewRecord('tok_array')
431 L = out_node.fields
432
433 if self.tokens is not None: # List
434 x0 = hnode.Array([])
435 for i0 in self.tokens:
436 h = (hnode.Leaf("_", color_e.OtherConst) if i0 is None else
437 i0.PrettyTree(do_abbrev, trav=trav))
438 x0.children.append(h)
439 L.append(Field('tokens', x0))
440
441 return out_node
442