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

277 lines, 194 significant
1from asdl import pybase
2from mycpp import mops
3from typing import Optional, List, Tuple, Dict, Any, cast, TYPE_CHECKING
4
5
6from asdl import runtime # For runtime.NO_SPID
7from asdl.runtime import NewRecord, NewLeaf, TraversalState
8from _devbuild.gen.hnode_asdl import color_e, hnode, hnode_e, hnode_t, Field
9
10class value_e(object):
11 Str = 1
12 Array = 2
13
14_value_str = {
15 1: 'Str',
16 2: 'Array',
17}
18
19def value_str(tag, dot=True):
20 # type: (int, bool) -> str
21 v = _value_str[tag]
22 if dot:
23 return "value.%s" % v
24 else:
25 return v
26
27class value_t(pybase.CompoundObj):
28 def tag(self):
29 # type: () -> int
30 return self._type_tag
31 pass
32
33class value__Str(value_t):
34 _type_tag = 1
35 __slots__ = ()
36
37 def __init__(self, ):
38 # type: () -> None
39 pass
40
41 def PrettyTree(self, trav=None):
42 # type: (Optional[TraversalState]) -> hnode_t
43 trav = trav or TraversalState()
44 heap_id = id(self)
45 if heap_id in trav.seen:
46 return hnode.AlreadySeen(heap_id)
47 trav.seen[heap_id] = True
48 out_node = NewRecord('value__Str')
49 L = out_node.fields
50
51 return out_node
52
53 def _AbbreviatedTree(self, trav=None):
54 # type: (Optional[TraversalState]) -> hnode_t
55 trav = trav or TraversalState()
56 heap_id = id(self)
57 if heap_id in trav.seen:
58 return hnode.AlreadySeen(heap_id)
59 trav.seen[heap_id] = True
60 out_node = NewRecord('value__Str')
61 L = out_node.fields
62 return out_node
63
64 def AbbreviatedTree(self, trav=None):
65 # type: (Optional[TraversalState]) -> hnode_t
66 return self._AbbreviatedTree(trav=trav)
67
68class value(object):
69 Str = value__Str()
70
71 class Array(value_t):
72 _type_tag = 2
73 __slots__ = ('a',)
74
75 def __init__(self, a):
76 # type: (int) -> None
77 self.a = a
78
79 @staticmethod
80 def CreateNull(alloc_lists=False):
81 # type: () -> value.Array
82 return value.Array(-1)
83
84 def PrettyTree(self, trav=None):
85 # type: (Optional[TraversalState]) -> hnode_t
86 trav = trav or TraversalState()
87 heap_id = id(self)
88 if heap_id in trav.seen:
89 return hnode.AlreadySeen(heap_id)
90 trav.seen[heap_id] = True
91 out_node = NewRecord('value.Array')
92 L = out_node.fields
93
94 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
95 L.append(Field('a', x0))
96
97 return out_node
98
99 def _AbbreviatedTree(self, trav=None):
100 # type: (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 out_node = NewRecord('value.Array')
107 L = out_node.fields
108 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
109 L.append(Field('a', x0))
110
111 return out_node
112
113 def AbbreviatedTree(self, trav=None):
114 # type: (Optional[TraversalState]) -> hnode_t
115 return self._AbbreviatedTree(trav=trav)
116
117 pass
118
119class t2(pybase.CompoundObj):
120 _type_tag = 64
121 __slots__ = ('a', 'b')
122
123 def __init__(self, a, b):
124 # type: (int, int) -> None
125 self.a = a
126 self.b = b
127
128 @staticmethod
129 def CreateNull(alloc_lists=False):
130 # type: () -> t2
131 return t2(-1, -1)
132
133 def PrettyTree(self, trav=None):
134 # type: (Optional[TraversalState]) -> hnode_t
135 trav = trav or TraversalState()
136 heap_id = id(self)
137 if heap_id in trav.seen:
138 return hnode.AlreadySeen(heap_id)
139 trav.seen[heap_id] = True
140 out_node = NewRecord('t2')
141 L = out_node.fields
142
143 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
144 L.append(Field('a', x0))
145
146 x1 = hnode.Leaf(str(self.b), color_e.OtherConst)
147 L.append(Field('b', x1))
148
149 return out_node
150
151 def _AbbreviatedTree(self, trav=None):
152 # type: (Optional[TraversalState]) -> hnode_t
153 trav = trav or TraversalState()
154 heap_id = id(self)
155 if heap_id in trav.seen:
156 return hnode.AlreadySeen(heap_id)
157 trav.seen[heap_id] = True
158 out_node = NewRecord('t2')
159 L = out_node.fields
160 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
161 L.append(Field('a', x0))
162
163 x1 = hnode.Leaf(str(self.b), color_e.OtherConst)
164 L.append(Field('b', x1))
165
166 return out_node
167
168 def AbbreviatedTree(self, trav=None):
169 # type: (Optional[TraversalState]) -> hnode_t
170 return self._AbbreviatedTree(trav=trav)
171
172class t3(pybase.CompoundObj):
173 _type_tag = 65
174 __slots__ = ('a', 'b')
175
176 def __init__(self, a, b):
177 # type: (int, int) -> None
178 self.a = a
179 self.b = b
180
181 @staticmethod
182 def CreateNull(alloc_lists=False):
183 # type: () -> t3
184 return t3(-1, -1)
185
186 def PrettyTree(self, trav=None):
187 # type: (Optional[TraversalState]) -> hnode_t
188 trav = trav or TraversalState()
189 heap_id = id(self)
190 if heap_id in trav.seen:
191 return hnode.AlreadySeen(heap_id)
192 trav.seen[heap_id] = True
193 out_node = NewRecord('t3')
194 L = out_node.fields
195
196 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
197 L.append(Field('a', x0))
198
199 x1 = hnode.Leaf(str(self.b), color_e.OtherConst)
200 L.append(Field('b', x1))
201
202 return out_node
203
204 def _AbbreviatedTree(self, trav=None):
205 # type: (Optional[TraversalState]) -> hnode_t
206 trav = trav or TraversalState()
207 heap_id = id(self)
208 if heap_id in trav.seen:
209 return hnode.AlreadySeen(heap_id)
210 trav.seen[heap_id] = True
211 out_node = NewRecord('t3')
212 L = out_node.fields
213 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
214 L.append(Field('a', x0))
215
216 x1 = hnode.Leaf(str(self.b), color_e.OtherConst)
217 L.append(Field('b', x1))
218
219 return out_node
220
221 def AbbreviatedTree(self, trav=None):
222 # type: (Optional[TraversalState]) -> hnode_t
223 return self._AbbreviatedTree(trav=trav)
224
225class t4(pybase.CompoundObj):
226 _type_tag = 66
227 __slots__ = ('a', 'b')
228
229 def __init__(self, a, b):
230 # type: (int, int) -> None
231 self.a = a
232 self.b = b
233
234 @staticmethod
235 def CreateNull(alloc_lists=False):
236 # type: () -> t4
237 return t4(-1, -1)
238
239 def PrettyTree(self, trav=None):
240 # type: (Optional[TraversalState]) -> hnode_t
241 trav = trav or TraversalState()
242 heap_id = id(self)
243 if heap_id in trav.seen:
244 return hnode.AlreadySeen(heap_id)
245 trav.seen[heap_id] = True
246 out_node = NewRecord('t4')
247 L = out_node.fields
248
249 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
250 L.append(Field('a', x0))
251
252 x1 = hnode.Leaf(str(self.b), color_e.OtherConst)
253 L.append(Field('b', x1))
254
255 return out_node
256
257 def _AbbreviatedTree(self, trav=None):
258 # type: (Optional[TraversalState]) -> hnode_t
259 trav = trav or TraversalState()
260 heap_id = id(self)
261 if heap_id in trav.seen:
262 return hnode.AlreadySeen(heap_id)
263 trav.seen[heap_id] = True
264 out_node = NewRecord('t4')
265 L = out_node.fields
266 x0 = hnode.Leaf(str(self.a), color_e.OtherConst)
267 L.append(Field('a', x0))
268
269 x1 = hnode.Leaf(str(self.b), color_e.OtherConst)
270 L.append(Field('b', x1))
271
272 return out_node
273
274 def AbbreviatedTree(self, trav=None):
275 # type: (Optional[TraversalState]) -> hnode_t
276 return self._AbbreviatedTree(trav=trav)
277