1 | // _gen/asdl/examples/shared_variant.asdl.cc is generated by asdl_main.py
|
2 |
|
3 | #include "_gen/asdl/examples/shared_variant.asdl.h"
|
4 | #include <assert.h>
|
5 | #include "prebuilt/asdl/runtime.mycpp.h" // generated code uses wrappers here
|
6 |
|
7 | // Generated code uses these types
|
8 | using hnode_asdl::hnode;
|
9 | using hnode_asdl::Field;
|
10 | using hnode_asdl::color_e;
|
11 |
|
12 |
|
13 | namespace shared_variant_asdl {
|
14 |
|
15 |
|
16 | hnode_t* prod::PrettyTree(Dict<int, bool>* seen) {
|
17 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
18 | int heap_id = ObjectId(this);
|
19 | if (dict_contains(seen, heap_id)) {
|
20 | return Alloc<hnode::AlreadySeen>(heap_id);
|
21 | }
|
22 | seen->set(heap_id, true);
|
23 | hnode::Record* out_node = runtime::NewRecord(StrFromC("prod"));
|
24 | List<Field*>* L = out_node->fields;
|
25 |
|
26 | hnode_t* x0 = runtime::NewLeaf(this->a, color_e::StringConst);
|
27 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
28 |
|
29 | hnode_t* x1 = runtime::NewLeaf(this->b, color_e::StringConst);
|
30 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
31 |
|
32 | return out_node;
|
33 | }
|
34 |
|
35 |
|
36 | hnode_t* DoubleQuoted::PrettyTree(Dict<int, bool>* seen) {
|
37 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
38 | int heap_id = ObjectId(this);
|
39 | if (dict_contains(seen, heap_id)) {
|
40 | return Alloc<hnode::AlreadySeen>(heap_id);
|
41 | }
|
42 | seen->set(heap_id, true);
|
43 | hnode::Record* out_node = runtime::NewRecord(StrFromC("DoubleQuoted"));
|
44 | List<Field*>* L = out_node->fields;
|
45 |
|
46 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->left), color_e::OtherConst);
|
47 | L->append(Alloc<Field>(StrFromC("left"), x0));
|
48 |
|
49 | if (this->tokens != nullptr) { // List
|
50 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
51 | for (ListIter<BigStr*> it(this->tokens); !it.Done(); it.Next()) {
|
52 | BigStr* i1 = it.Value();
|
53 | hnode_t* h = runtime::NewLeaf(i1, color_e::StringConst);
|
54 | x1->children->append(h);
|
55 | }
|
56 | L->append(Alloc<Field>(StrFromC("tokens"), x1));
|
57 | }
|
58 |
|
59 | return out_node;
|
60 | }
|
61 |
|
62 | BigStr* expr_str(int tag, bool dot) {
|
63 | char buf[32];
|
64 | const char* v = nullptr;
|
65 | switch (tag) {
|
66 | case expr_e::Binary:
|
67 | v = "Binary"; break;
|
68 | case expr_e::DoubleQuoted:
|
69 | v = "DoubleQuoted"; break;
|
70 | default:
|
71 | assert(0);
|
72 | }
|
73 | if (dot) {
|
74 | snprintf(buf, 32, "expr.%s", v);
|
75 | return StrFromC(buf);
|
76 | } else {
|
77 | return StrFromC(v);
|
78 | }
|
79 | }
|
80 |
|
81 | hnode_t* expr__Binary::PrettyTree(Dict<int, bool>* seen) {
|
82 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
83 | int heap_id = ObjectId(this);
|
84 | if (dict_contains(seen, heap_id)) {
|
85 | return Alloc<hnode::AlreadySeen>(heap_id);
|
86 | }
|
87 | seen->set(heap_id, true);
|
88 | hnode::Record* out_node = runtime::NewRecord(expr_str(this->tag()));
|
89 | List<Field*>* L = out_node->fields;
|
90 |
|
91 | hnode_t* x0 = this->left->PrettyTree(seen);
|
92 | L->append(Alloc<Field>(StrFromC("left"), x0));
|
93 |
|
94 | hnode_t* x1 = this->right->PrettyTree(seen);
|
95 | L->append(Alloc<Field>(StrFromC("right"), x1));
|
96 |
|
97 | return out_node;
|
98 | }
|
99 |
|
100 |
|
101 | hnode_t* expr_t::PrettyTree(Dict<int, bool>* seen) {
|
102 | switch (this->tag()) {
|
103 | case expr_e::Binary: {
|
104 | expr__Binary* obj = static_cast<expr__Binary*>(this);
|
105 | return obj->PrettyTree(seen);
|
106 | }
|
107 | case expr_e::DoubleQuoted: {
|
108 | DoubleQuoted* obj = static_cast<DoubleQuoted*>(this);
|
109 | return obj->PrettyTree(seen);
|
110 | }
|
111 | default:
|
112 | assert(0);
|
113 | }
|
114 | }
|
115 |
|
116 | hnode_t* Token::PrettyTree(Dict<int, bool>* seen) {
|
117 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
118 | int heap_id = ObjectId(this);
|
119 | if (dict_contains(seen, heap_id)) {
|
120 | return Alloc<hnode::AlreadySeen>(heap_id);
|
121 | }
|
122 | seen->set(heap_id, true);
|
123 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Token"));
|
124 | List<Field*>* L = out_node->fields;
|
125 |
|
126 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->id), color_e::OtherConst);
|
127 | L->append(Alloc<Field>(StrFromC("id"), x0));
|
128 |
|
129 | hnode_t* x1 = runtime::NewLeaf(this->val, color_e::StringConst);
|
130 | L->append(Alloc<Field>(StrFromC("val"), x1));
|
131 |
|
132 | return out_node;
|
133 | }
|
134 |
|
135 | BigStr* tok_str(int tag, bool dot) {
|
136 | char buf[32];
|
137 | const char* v = nullptr;
|
138 | switch (tag) {
|
139 | case tok_e::Eof:
|
140 | v = "Eof"; break;
|
141 | case tok_e::Token:
|
142 | v = "Token"; break;
|
143 | default:
|
144 | assert(0);
|
145 | }
|
146 | if (dot) {
|
147 | snprintf(buf, 32, "tok.%s", v);
|
148 | return StrFromC(buf);
|
149 | } else {
|
150 | return StrFromC(v);
|
151 | }
|
152 | }
|
153 |
|
154 | tok__Eof* tok::Eof = >ok__Eof.obj;
|
155 |
|
156 | GcGlobal<tok__Eof> gtok__Eof =
|
157 | { ObjHeader::Global(tok_e::Eof) };
|
158 |
|
159 | hnode_t* tok__Eof::PrettyTree(Dict<int, bool>* seen) {
|
160 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
161 | int heap_id = ObjectId(this);
|
162 | if (dict_contains(seen, heap_id)) {
|
163 | return Alloc<hnode::AlreadySeen>(heap_id);
|
164 | }
|
165 | seen->set(heap_id, true);
|
166 | hnode::Record* out_node = runtime::NewRecord(tok_str(this->tag()));
|
167 | return out_node;
|
168 | }
|
169 |
|
170 |
|
171 | hnode_t* tok_t::PrettyTree(Dict<int, bool>* seen) {
|
172 | switch (this->tag()) {
|
173 | case tok_e::Eof: {
|
174 | tok__Eof* obj = static_cast<tok__Eof*>(this);
|
175 | return obj->PrettyTree(seen);
|
176 | }
|
177 | case tok_e::Token: {
|
178 | Token* obj = static_cast<Token*>(this);
|
179 | return obj->PrettyTree(seen);
|
180 | }
|
181 | default:
|
182 | assert(0);
|
183 | }
|
184 | }
|
185 |
|
186 | hnode_t* tok_struct::PrettyTree(Dict<int, bool>* seen) {
|
187 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
188 | int heap_id = ObjectId(this);
|
189 | if (dict_contains(seen, heap_id)) {
|
190 | return Alloc<hnode::AlreadySeen>(heap_id);
|
191 | }
|
192 | seen->set(heap_id, true);
|
193 | hnode::Record* out_node = runtime::NewRecord(StrFromC("tok_struct"));
|
194 | List<Field*>* L = out_node->fields;
|
195 |
|
196 | hnode_t* x0 = this->token->PrettyTree(seen);
|
197 | L->append(Alloc<Field>(StrFromC("token"), x0));
|
198 |
|
199 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->x), color_e::OtherConst);
|
200 | L->append(Alloc<Field>(StrFromC("x"), x1));
|
201 |
|
202 | return out_node;
|
203 | }
|
204 |
|
205 |
|
206 | hnode_t* tok_array::PrettyTree(Dict<int, bool>* seen) {
|
207 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
208 | int heap_id = ObjectId(this);
|
209 | if (dict_contains(seen, heap_id)) {
|
210 | return Alloc<hnode::AlreadySeen>(heap_id);
|
211 | }
|
212 | seen->set(heap_id, true);
|
213 | hnode::Record* out_node = runtime::NewRecord(StrFromC("tok_array"));
|
214 | List<Field*>* L = out_node->fields;
|
215 |
|
216 | if (this->tokens != nullptr) { // List
|
217 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
218 | for (ListIter<tok_t*> it(this->tokens); !it.Done(); it.Next()) {
|
219 | tok_t* i0 = it.Value();
|
220 | hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
221 | color_e::OtherConst) : i0->PrettyTree(seen);
|
222 | x0->children->append(h);
|
223 | }
|
224 | L->append(Alloc<Field>(StrFromC("tokens"), x0));
|
225 | }
|
226 |
|
227 | return out_node;
|
228 | }
|
229 |
|
230 | BigStr* word_part_str(int tag, bool dot) {
|
231 | char buf[32];
|
232 | const char* v = nullptr;
|
233 | switch (tag) {
|
234 | case word_part_e::Literal:
|
235 | v = "Literal"; break;
|
236 | case word_part_e::DoubleQuoted:
|
237 | v = "DoubleQuoted"; break;
|
238 | default:
|
239 | assert(0);
|
240 | }
|
241 | if (dot) {
|
242 | snprintf(buf, 32, "word_part.%s", v);
|
243 | return StrFromC(buf);
|
244 | } else {
|
245 | return StrFromC(v);
|
246 | }
|
247 | }
|
248 |
|
249 | hnode_t* word_part__Literal::PrettyTree(Dict<int, bool>* seen) {
|
250 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
251 | int heap_id = ObjectId(this);
|
252 | if (dict_contains(seen, heap_id)) {
|
253 | return Alloc<hnode::AlreadySeen>(heap_id);
|
254 | }
|
255 | seen->set(heap_id, true);
|
256 | hnode::Record* out_node = runtime::NewRecord(word_part_str(this->tag()));
|
257 | List<Field*>* L = out_node->fields;
|
258 |
|
259 | hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
|
260 | L->append(Alloc<Field>(StrFromC("s"), x0));
|
261 |
|
262 | return out_node;
|
263 | }
|
264 |
|
265 |
|
266 | hnode_t* word_part_t::PrettyTree(Dict<int, bool>* seen) {
|
267 | switch (this->tag()) {
|
268 | case word_part_e::Literal: {
|
269 | word_part__Literal* obj = static_cast<word_part__Literal*>(this);
|
270 | return obj->PrettyTree(seen);
|
271 | }
|
272 | case word_part_e::DoubleQuoted: {
|
273 | DoubleQuoted* obj = static_cast<DoubleQuoted*>(this);
|
274 | return obj->PrettyTree(seen);
|
275 | }
|
276 | default:
|
277 | assert(0);
|
278 | }
|
279 | }
|
280 | BigStr* cflow_str(int tag, bool dot) {
|
281 | char buf[32];
|
282 | const char* v = nullptr;
|
283 | switch (tag) {
|
284 | case cflow_e::Break:
|
285 | v = "Break"; break;
|
286 | case cflow_e::Continue:
|
287 | v = "Continue"; break;
|
288 | case cflow_e::Return:
|
289 | v = "Return"; break;
|
290 | default:
|
291 | assert(0);
|
292 | }
|
293 | if (dot) {
|
294 | snprintf(buf, 32, "cflow.%s", v);
|
295 | return StrFromC(buf);
|
296 | } else {
|
297 | return StrFromC(v);
|
298 | }
|
299 | }
|
300 |
|
301 | cflow__Break* cflow::Break = &gcflow__Break.obj;
|
302 |
|
303 | GcGlobal<cflow__Break> gcflow__Break =
|
304 | { ObjHeader::Global(cflow_e::Break) };
|
305 |
|
306 | cflow__Continue* cflow::Continue = &gcflow__Continue.obj;
|
307 |
|
308 | GcGlobal<cflow__Continue> gcflow__Continue =
|
309 | { ObjHeader::Global(cflow_e::Continue) };
|
310 |
|
311 | hnode_t* cflow__Break::PrettyTree(Dict<int, bool>* seen) {
|
312 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
313 | int heap_id = ObjectId(this);
|
314 | if (dict_contains(seen, heap_id)) {
|
315 | return Alloc<hnode::AlreadySeen>(heap_id);
|
316 | }
|
317 | seen->set(heap_id, true);
|
318 | hnode::Record* out_node = runtime::NewRecord(cflow_str(this->tag()));
|
319 | return out_node;
|
320 | }
|
321 |
|
322 |
|
323 | hnode_t* cflow__Continue::PrettyTree(Dict<int, bool>* seen) {
|
324 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
325 | int heap_id = ObjectId(this);
|
326 | if (dict_contains(seen, heap_id)) {
|
327 | return Alloc<hnode::AlreadySeen>(heap_id);
|
328 | }
|
329 | seen->set(heap_id, true);
|
330 | hnode::Record* out_node = runtime::NewRecord(cflow_str(this->tag()));
|
331 | return out_node;
|
332 | }
|
333 |
|
334 |
|
335 | hnode_t* cflow__Return::PrettyTree(Dict<int, bool>* seen) {
|
336 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
337 | int heap_id = ObjectId(this);
|
338 | if (dict_contains(seen, heap_id)) {
|
339 | return Alloc<hnode::AlreadySeen>(heap_id);
|
340 | }
|
341 | seen->set(heap_id, true);
|
342 | hnode::Record* out_node = runtime::NewRecord(cflow_str(this->tag()));
|
343 | List<Field*>* L = out_node->fields;
|
344 |
|
345 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->val), color_e::OtherConst);
|
346 | L->append(Alloc<Field>(StrFromC("val"), x0));
|
347 |
|
348 | return out_node;
|
349 | }
|
350 |
|
351 |
|
352 | hnode_t* cflow_t::PrettyTree(Dict<int, bool>* seen) {
|
353 | switch (this->tag()) {
|
354 | case cflow_e::Break: {
|
355 | cflow__Break* obj = static_cast<cflow__Break*>(this);
|
356 | return obj->PrettyTree(seen);
|
357 | }
|
358 | case cflow_e::Continue: {
|
359 | cflow__Continue* obj = static_cast<cflow__Continue*>(this);
|
360 | return obj->PrettyTree(seen);
|
361 | }
|
362 | case cflow_e::Return: {
|
363 | cflow__Return* obj = static_cast<cflow__Return*>(this);
|
364 | return obj->PrettyTree(seen);
|
365 | }
|
366 | default:
|
367 | assert(0);
|
368 | }
|
369 | }
|
370 |
|
371 | } // namespace shared_variant_asdl
|