OILS / _gen / yaks / yaks.asdl.cc View on Github | oilshell.org

1187 lines, 826 significant
1// _gen/yaks/yaks.asdl.cc is generated by asdl_main.py
2
3#include "_gen/yaks/yaks.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
8using hnode_asdl::hnode;
9using hnode_asdl::Field;
10using hnode_asdl::color_e;
11
12
13namespace yaks_asdl {
14
15
16hnode_t* Token::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("Token"));
24 List<Field*>* L = out_node->fields;
25
26 hnode_t* x0 = runtime::NewLeaf(this->path, color_e::StringConst);
27 L->append(Alloc<Field>(StrFromC("path"), x0));
28
29 hnode_t* x1 = runtime::NewLeaf(this->chunk, color_e::StringConst);
30 L->append(Alloc<Field>(StrFromC("chunk"), x1));
31
32 hnode_t* x2 = Alloc<hnode::Leaf>(str(this->start), color_e::OtherConst);
33 L->append(Alloc<Field>(StrFromC("start"), x2));
34
35 hnode_t* x3 = Alloc<hnode::Leaf>(str(this->length), color_e::OtherConst);
36 L->append(Alloc<Field>(StrFromC("length"), x3));
37
38 return out_node;
39}
40
41
42hnode_t* Bool::PrettyTree(Dict<int, bool>* seen) {
43 seen = seen ? seen : Alloc<Dict<int, bool>>();
44 int heap_id = ObjectId(this);
45 if (dict_contains(seen, heap_id)) {
46 return Alloc<hnode::AlreadySeen>(heap_id);
47 }
48 seen->set(heap_id, true);
49 hnode::Record* out_node = runtime::NewRecord(StrFromC("Bool"));
50 List<Field*>* L = out_node->fields;
51
52 hnode_t* x0 = Alloc<hnode::Leaf>(this->b ? runtime::TRUE_STR :
53 runtime::FALSE_STR, color_e::OtherConst);
54 L->append(Alloc<Field>(StrFromC("b"), x0));
55
56 hnode_t* x1 = this->loc->PrettyTree(seen);
57 L->append(Alloc<Field>(StrFromC("loc"), x1));
58
59 return out_node;
60}
61
62
63hnode_t* Int::PrettyTree(Dict<int, bool>* seen) {
64 seen = seen ? seen : Alloc<Dict<int, bool>>();
65 int heap_id = ObjectId(this);
66 if (dict_contains(seen, heap_id)) {
67 return Alloc<hnode::AlreadySeen>(heap_id);
68 }
69 seen->set(heap_id, true);
70 hnode::Record* out_node = runtime::NewRecord(StrFromC("Int"));
71 List<Field*>* L = out_node->fields;
72
73 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->i), color_e::OtherConst);
74 L->append(Alloc<Field>(StrFromC("i"), x0));
75
76 hnode_t* x1 = this->loc->PrettyTree(seen);
77 L->append(Alloc<Field>(StrFromC("loc"), x1));
78
79 return out_node;
80}
81
82
83hnode_t* Str::PrettyTree(Dict<int, bool>* seen) {
84 seen = seen ? seen : Alloc<Dict<int, bool>>();
85 int heap_id = ObjectId(this);
86 if (dict_contains(seen, heap_id)) {
87 return Alloc<hnode::AlreadySeen>(heap_id);
88 }
89 seen->set(heap_id, true);
90 hnode::Record* out_node = runtime::NewRecord(StrFromC("Str"));
91 List<Field*>* L = out_node->fields;
92
93 hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
94 L->append(Alloc<Field>(StrFromC("s"), x0));
95
96 hnode_t* x1 = this->loc->PrettyTree(seen);
97 L->append(Alloc<Field>(StrFromC("loc"), x1));
98
99 return out_node;
100}
101
102
103hnode_t* MultiStr::PrettyTree(Dict<int, bool>* seen) {
104 seen = seen ? seen : Alloc<Dict<int, bool>>();
105 int heap_id = ObjectId(this);
106 if (dict_contains(seen, heap_id)) {
107 return Alloc<hnode::AlreadySeen>(heap_id);
108 }
109 seen->set(heap_id, true);
110 hnode::Record* out_node = runtime::NewRecord(StrFromC("MultiStr"));
111 List<Field*>* L = out_node->fields;
112
113 if (this->lines != nullptr) { // List
114 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
115 for (ListIter<Token*> it(this->lines); !it.Done(); it.Next()) {
116 Token* i0 = it.Value();
117 hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
118 color_e::OtherConst) : i0->PrettyTree(seen);
119 x0->children->append(h);
120 }
121 L->append(Alloc<Field>(StrFromC("lines"), x0));
122 }
123
124 return out_node;
125}
126
127BigStr* op_str(op_e tag, bool dot) {
128 char buf[32];
129 const char* v = nullptr;
130 switch (tag) {
131 case op_e::Plus:
132 v = "Plus"; break;
133 case op_e::Minus:
134 v = "Minus"; break;
135 default:
136 assert(0);
137 }
138 if (dot) {
139 snprintf(buf, 32, "op.%s", v);
140 return StrFromC(buf);
141 } else {
142 return StrFromC(v);
143 }
144}
145BigStr* kexpr_str(int tag, bool dot) {
146 char buf[32];
147 const char* v = nullptr;
148 switch (tag) {
149 case kexpr_e::Bool:
150 v = "Bool"; break;
151 case kexpr_e::Int:
152 v = "Int"; break;
153 case kexpr_e::Str:
154 v = "Str"; break;
155 case kexpr_e::MultiStr:
156 v = "MultiStr"; break;
157 case kexpr_e::Unary:
158 v = "Unary"; break;
159 case kexpr_e::Binary:
160 v = "Binary"; break;
161 case kexpr_e::Ternary:
162 v = "Ternary"; break;
163 case kexpr_e::Call:
164 v = "Call"; break;
165 default:
166 assert(0);
167 }
168 if (dot) {
169 snprintf(buf, 32, "kexpr.%s", v);
170 return StrFromC(buf);
171 } else {
172 return StrFromC(v);
173 }
174}
175
176hnode_t* kexpr__Unary::PrettyTree(Dict<int, bool>* seen) {
177 seen = seen ? seen : Alloc<Dict<int, bool>>();
178 int heap_id = ObjectId(this);
179 if (dict_contains(seen, heap_id)) {
180 return Alloc<hnode::AlreadySeen>(heap_id);
181 }
182 seen->set(heap_id, true);
183 hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
184 List<Field*>* L = out_node->fields;
185
186 hnode_t* x0 = this->op->PrettyTree(seen);
187 L->append(Alloc<Field>(StrFromC("op"), x0));
188
189 hnode_t* x1 = this->child->PrettyTree(seen);
190 L->append(Alloc<Field>(StrFromC("child"), x1));
191
192 return out_node;
193}
194
195
196hnode_t* kexpr__Binary::PrettyTree(Dict<int, bool>* seen) {
197 seen = seen ? seen : Alloc<Dict<int, bool>>();
198 int heap_id = ObjectId(this);
199 if (dict_contains(seen, heap_id)) {
200 return Alloc<hnode::AlreadySeen>(heap_id);
201 }
202 seen->set(heap_id, true);
203 hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
204 List<Field*>* L = out_node->fields;
205
206 hnode_t* x0 = this->op->PrettyTree(seen);
207 L->append(Alloc<Field>(StrFromC("op"), x0));
208
209 hnode_t* x1 = this->left->PrettyTree(seen);
210 L->append(Alloc<Field>(StrFromC("left"), x1));
211
212 hnode_t* x2 = this->right->PrettyTree(seen);
213 L->append(Alloc<Field>(StrFromC("right"), x2));
214
215 return out_node;
216}
217
218
219hnode_t* kexpr__Ternary::PrettyTree(Dict<int, bool>* seen) {
220 seen = seen ? seen : Alloc<Dict<int, bool>>();
221 int heap_id = ObjectId(this);
222 if (dict_contains(seen, heap_id)) {
223 return Alloc<hnode::AlreadySeen>(heap_id);
224 }
225 seen->set(heap_id, true);
226 hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
227 List<Field*>* L = out_node->fields;
228
229 hnode_t* x0 = this->op->PrettyTree(seen);
230 L->append(Alloc<Field>(StrFromC("op"), x0));
231
232 hnode_t* x1 = this->left->PrettyTree(seen);
233 L->append(Alloc<Field>(StrFromC("left"), x1));
234
235 hnode_t* x2 = this->cond->PrettyTree(seen);
236 L->append(Alloc<Field>(StrFromC("cond"), x2));
237
238 hnode_t* x3 = this->right->PrettyTree(seen);
239 L->append(Alloc<Field>(StrFromC("right"), x3));
240
241 return out_node;
242}
243
244
245hnode_t* kexpr__Call::PrettyTree(Dict<int, bool>* seen) {
246 seen = seen ? seen : Alloc<Dict<int, bool>>();
247 int heap_id = ObjectId(this);
248 if (dict_contains(seen, heap_id)) {
249 return Alloc<hnode::AlreadySeen>(heap_id);
250 }
251 seen->set(heap_id, true);
252 hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
253 List<Field*>* L = out_node->fields;
254
255 hnode_t* x0 = this->f->PrettyTree(seen);
256 L->append(Alloc<Field>(StrFromC("f"), x0));
257
258 if (this->args != nullptr) { // List
259 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
260 for (ListIter<kexpr_t*> it(this->args); !it.Done(); it.Next()) {
261 kexpr_t* i1 = it.Value();
262 hnode_t* h = (i1 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
263 color_e::OtherConst) : i1->PrettyTree(seen);
264 x1->children->append(h);
265 }
266 L->append(Alloc<Field>(StrFromC("args"), x1));
267 }
268
269 return out_node;
270}
271
272
273hnode_t* kexpr_t::PrettyTree(Dict<int, bool>* seen) {
274 switch (this->tag()) {
275 case kexpr_e::Bool: {
276 Bool* obj = static_cast<Bool*>(this);
277 return obj->PrettyTree(seen);
278 }
279 case kexpr_e::Int: {
280 Int* obj = static_cast<Int*>(this);
281 return obj->PrettyTree(seen);
282 }
283 case kexpr_e::Str: {
284 Str* obj = static_cast<Str*>(this);
285 return obj->PrettyTree(seen);
286 }
287 case kexpr_e::MultiStr: {
288 MultiStr* obj = static_cast<MultiStr*>(this);
289 return obj->PrettyTree(seen);
290 }
291 case kexpr_e::Unary: {
292 kexpr__Unary* obj = static_cast<kexpr__Unary*>(this);
293 return obj->PrettyTree(seen);
294 }
295 case kexpr_e::Binary: {
296 kexpr__Binary* obj = static_cast<kexpr__Binary*>(this);
297 return obj->PrettyTree(seen);
298 }
299 case kexpr_e::Ternary: {
300 kexpr__Ternary* obj = static_cast<kexpr__Ternary*>(this);
301 return obj->PrettyTree(seen);
302 }
303 case kexpr_e::Call: {
304 kexpr__Call* obj = static_cast<kexpr__Call*>(this);
305 return obj->PrettyTree(seen);
306 }
307 default:
308 assert(0);
309 }
310}
311
312hnode_t* Field_::PrettyTree(Dict<int, bool>* seen) {
313 seen = seen ? seen : Alloc<Dict<int, bool>>();
314 int heap_id = ObjectId(this);
315 if (dict_contains(seen, heap_id)) {
316 return Alloc<hnode::AlreadySeen>(heap_id);
317 }
318 seen->set(heap_id, true);
319 hnode::Record* out_node = runtime::NewRecord(StrFromC("Field_"));
320 List<Field*>* L = out_node->fields;
321
322 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
323 L->append(Alloc<Field>(StrFromC("name"), x0));
324
325 hnode_t* x1 = this->typ->PrettyTree(seen);
326 L->append(Alloc<Field>(StrFromC("typ"), x1));
327
328 return out_node;
329}
330
331
332hnode_t* variant::PrettyTree(Dict<int, bool>* seen) {
333 seen = seen ? seen : Alloc<Dict<int, bool>>();
334 int heap_id = ObjectId(this);
335 if (dict_contains(seen, heap_id)) {
336 return Alloc<hnode::AlreadySeen>(heap_id);
337 }
338 seen->set(heap_id, true);
339 hnode::Record* out_node = runtime::NewRecord(StrFromC("variant"));
340 List<Field*>* L = out_node->fields;
341
342 if (this->fields != nullptr) { // List
343 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
344 for (ListIter<Field_*> it(this->fields); !it.Done(); it.Next()) {
345 Field_* i0 = it.Value();
346 hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
347 color_e::OtherConst) : i0->PrettyTree(seen);
348 x0->children->append(h);
349 }
350 L->append(Alloc<Field>(StrFromC("fields"), x0));
351 }
352
353 return out_node;
354}
355
356BigStr* ktype_str(int tag, bool dot) {
357 char buf[32];
358 const char* v = nullptr;
359 switch (tag) {
360 case ktype_e::Bool:
361 v = "Bool"; break;
362 case ktype_e::Int:
363 v = "Int"; break;
364 case ktype_e::Str:
365 v = "Str"; break;
366 case ktype_e::List:
367 v = "List"; break;
368 case ktype_e::Dict:
369 v = "Dict"; break;
370 case ktype_e::Class:
371 v = "Class"; break;
372 case ktype_e::Data:
373 v = "Data"; break;
374 case ktype_e::Enum:
375 v = "Enum"; break;
376 default:
377 assert(0);
378 }
379 if (dot) {
380 snprintf(buf, 32, "ktype.%s", v);
381 return StrFromC(buf);
382 } else {
383 return StrFromC(v);
384 }
385}
386
387ktype__Bool* ktype::Bool = &gktype__Bool.obj;
388
389GcGlobal<ktype__Bool> gktype__Bool =
390 { ObjHeader::Global(ktype_e::Bool) };
391
392ktype__Int* ktype::Int = &gktype__Int.obj;
393
394GcGlobal<ktype__Int> gktype__Int =
395 { ObjHeader::Global(ktype_e::Int) };
396
397ktype__Str* ktype::Str = &gktype__Str.obj;
398
399GcGlobal<ktype__Str> gktype__Str =
400 { ObjHeader::Global(ktype_e::Str) };
401
402hnode_t* ktype__Bool::PrettyTree(Dict<int, bool>* seen) {
403 seen = seen ? seen : Alloc<Dict<int, bool>>();
404 int heap_id = ObjectId(this);
405 if (dict_contains(seen, heap_id)) {
406 return Alloc<hnode::AlreadySeen>(heap_id);
407 }
408 seen->set(heap_id, true);
409 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
410 return out_node;
411}
412
413
414hnode_t* ktype__Int::PrettyTree(Dict<int, bool>* seen) {
415 seen = seen ? seen : Alloc<Dict<int, bool>>();
416 int heap_id = ObjectId(this);
417 if (dict_contains(seen, heap_id)) {
418 return Alloc<hnode::AlreadySeen>(heap_id);
419 }
420 seen->set(heap_id, true);
421 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
422 return out_node;
423}
424
425
426hnode_t* ktype__Str::PrettyTree(Dict<int, bool>* seen) {
427 seen = seen ? seen : Alloc<Dict<int, bool>>();
428 int heap_id = ObjectId(this);
429 if (dict_contains(seen, heap_id)) {
430 return Alloc<hnode::AlreadySeen>(heap_id);
431 }
432 seen->set(heap_id, true);
433 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
434 return out_node;
435}
436
437
438hnode_t* ktype__List::PrettyTree(Dict<int, bool>* seen) {
439 seen = seen ? seen : Alloc<Dict<int, bool>>();
440 int heap_id = ObjectId(this);
441 if (dict_contains(seen, heap_id)) {
442 return Alloc<hnode::AlreadySeen>(heap_id);
443 }
444 seen->set(heap_id, true);
445 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
446 List<Field*>* L = out_node->fields;
447
448 hnode_t* x0 = this->T->PrettyTree(seen);
449 L->append(Alloc<Field>(StrFromC("T"), x0));
450
451 return out_node;
452}
453
454
455hnode_t* ktype__Dict::PrettyTree(Dict<int, bool>* seen) {
456 seen = seen ? seen : Alloc<Dict<int, bool>>();
457 int heap_id = ObjectId(this);
458 if (dict_contains(seen, heap_id)) {
459 return Alloc<hnode::AlreadySeen>(heap_id);
460 }
461 seen->set(heap_id, true);
462 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
463 List<Field*>* L = out_node->fields;
464
465 hnode_t* x0 = this->K->PrettyTree(seen);
466 L->append(Alloc<Field>(StrFromC("K"), x0));
467
468 hnode_t* x1 = this->V->PrettyTree(seen);
469 L->append(Alloc<Field>(StrFromC("V"), x1));
470
471 return out_node;
472}
473
474
475hnode_t* ktype__Class::PrettyTree(Dict<int, bool>* seen) {
476 seen = seen ? seen : Alloc<Dict<int, bool>>();
477 int heap_id = ObjectId(this);
478 if (dict_contains(seen, heap_id)) {
479 return Alloc<hnode::AlreadySeen>(heap_id);
480 }
481 seen->set(heap_id, true);
482 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
483 List<Field*>* L = out_node->fields;
484
485 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
486 L->append(Alloc<Field>(StrFromC("name"), x0));
487
488 return out_node;
489}
490
491
492hnode_t* ktype__Data::PrettyTree(Dict<int, bool>* seen) {
493 seen = seen ? seen : Alloc<Dict<int, bool>>();
494 int heap_id = ObjectId(this);
495 if (dict_contains(seen, heap_id)) {
496 return Alloc<hnode::AlreadySeen>(heap_id);
497 }
498 seen->set(heap_id, true);
499 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
500 List<Field*>* L = out_node->fields;
501
502 if (this->fields != nullptr) { // List
503 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
504 for (ListIter<Field_*> it(this->fields); !it.Done(); it.Next()) {
505 Field_* i0 = it.Value();
506 hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
507 color_e::OtherConst) : i0->PrettyTree(seen);
508 x0->children->append(h);
509 }
510 L->append(Alloc<Field>(StrFromC("fields"), x0));
511 }
512
513 return out_node;
514}
515
516
517hnode_t* ktype__Enum::PrettyTree(Dict<int, bool>* seen) {
518 seen = seen ? seen : Alloc<Dict<int, bool>>();
519 int heap_id = ObjectId(this);
520 if (dict_contains(seen, heap_id)) {
521 return Alloc<hnode::AlreadySeen>(heap_id);
522 }
523 seen->set(heap_id, true);
524 hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
525 List<Field*>* L = out_node->fields;
526
527 if (this->variants != nullptr) { // List
528 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
529 for (ListIter<variant*> it(this->variants); !it.Done(); it.Next()) {
530 variant* i0 = it.Value();
531 hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
532 color_e::OtherConst) : i0->PrettyTree(seen);
533 x0->children->append(h);
534 }
535 L->append(Alloc<Field>(StrFromC("variants"), x0));
536 }
537
538 return out_node;
539}
540
541
542hnode_t* ktype_t::PrettyTree(Dict<int, bool>* seen) {
543 switch (this->tag()) {
544 case ktype_e::Bool: {
545 ktype__Bool* obj = static_cast<ktype__Bool*>(this);
546 return obj->PrettyTree(seen);
547 }
548 case ktype_e::Int: {
549 ktype__Int* obj = static_cast<ktype__Int*>(this);
550 return obj->PrettyTree(seen);
551 }
552 case ktype_e::Str: {
553 ktype__Str* obj = static_cast<ktype__Str*>(this);
554 return obj->PrettyTree(seen);
555 }
556 case ktype_e::List: {
557 ktype__List* obj = static_cast<ktype__List*>(this);
558 return obj->PrettyTree(seen);
559 }
560 case ktype_e::Dict: {
561 ktype__Dict* obj = static_cast<ktype__Dict*>(this);
562 return obj->PrettyTree(seen);
563 }
564 case ktype_e::Class: {
565 ktype__Class* obj = static_cast<ktype__Class*>(this);
566 return obj->PrettyTree(seen);
567 }
568 case ktype_e::Data: {
569 ktype__Data* obj = static_cast<ktype__Data*>(this);
570 return obj->PrettyTree(seen);
571 }
572 case ktype_e::Enum: {
573 ktype__Enum* obj = static_cast<ktype__Enum*>(this);
574 return obj->PrettyTree(seen);
575 }
576 default:
577 assert(0);
578 }
579}
580
581hnode_t* NameType::PrettyTree(Dict<int, bool>* seen) {
582 seen = seen ? seen : Alloc<Dict<int, bool>>();
583 int heap_id = ObjectId(this);
584 if (dict_contains(seen, heap_id)) {
585 return Alloc<hnode::AlreadySeen>(heap_id);
586 }
587 seen->set(heap_id, true);
588 hnode::Record* out_node = runtime::NewRecord(StrFromC("NameType"));
589 List<Field*>* L = out_node->fields;
590
591 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
592 L->append(Alloc<Field>(StrFromC("name"), x0));
593
594 hnode_t* x1 = this->typ->PrettyTree(seen);
595 L->append(Alloc<Field>(StrFromC("typ"), x1));
596
597 return out_node;
598}
599
600BigStr* stmt_str(int tag, bool dot) {
601 char buf[32];
602 const char* v = nullptr;
603 switch (tag) {
604 case stmt_e::VarDecl:
605 v = "VarDecl"; break;
606 case stmt_e::PlaceMutation:
607 v = "PlaceMutation"; break;
608 case stmt_e::If:
609 v = "If"; break;
610 case stmt_e::Switch:
611 v = "Switch"; break;
612 case stmt_e::For:
613 v = "For"; break;
614 case stmt_e::While:
615 v = "While"; break;
616 case stmt_e::Break:
617 v = "Break"; break;
618 case stmt_e::Continue:
619 v = "Continue"; break;
620 case stmt_e::Return:
621 v = "Return"; break;
622 case stmt_e::Try:
623 v = "Try"; break;
624 case stmt_e::With:
625 v = "With"; break;
626 default:
627 assert(0);
628 }
629 if (dot) {
630 snprintf(buf, 32, "stmt.%s", v);
631 return StrFromC(buf);
632 } else {
633 return StrFromC(v);
634 }
635}
636
637stmt__If* stmt::If = &gstmt__If.obj;
638
639GcGlobal<stmt__If> gstmt__If =
640 { ObjHeader::Global(stmt_e::If) };
641
642stmt__Switch* stmt::Switch = &gstmt__Switch.obj;
643
644GcGlobal<stmt__Switch> gstmt__Switch =
645 { ObjHeader::Global(stmt_e::Switch) };
646
647stmt__For* stmt::For = &gstmt__For.obj;
648
649GcGlobal<stmt__For> gstmt__For =
650 { ObjHeader::Global(stmt_e::For) };
651
652stmt__While* stmt::While = &gstmt__While.obj;
653
654GcGlobal<stmt__While> gstmt__While =
655 { ObjHeader::Global(stmt_e::While) };
656
657stmt__Break* stmt::Break = &gstmt__Break.obj;
658
659GcGlobal<stmt__Break> gstmt__Break =
660 { ObjHeader::Global(stmt_e::Break) };
661
662stmt__Continue* stmt::Continue = &gstmt__Continue.obj;
663
664GcGlobal<stmt__Continue> gstmt__Continue =
665 { ObjHeader::Global(stmt_e::Continue) };
666
667stmt__Try* stmt::Try = &gstmt__Try.obj;
668
669GcGlobal<stmt__Try> gstmt__Try =
670 { ObjHeader::Global(stmt_e::Try) };
671
672stmt__With* stmt::With = &gstmt__With.obj;
673
674GcGlobal<stmt__With> gstmt__With =
675 { ObjHeader::Global(stmt_e::With) };
676
677hnode_t* stmt__VarDecl::PrettyTree(Dict<int, bool>* seen) {
678 seen = seen ? seen : Alloc<Dict<int, bool>>();
679 int heap_id = ObjectId(this);
680 if (dict_contains(seen, heap_id)) {
681 return Alloc<hnode::AlreadySeen>(heap_id);
682 }
683 seen->set(heap_id, true);
684 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
685 List<Field*>* L = out_node->fields;
686
687 hnode_t* x0 = this->keyword->PrettyTree(seen);
688 L->append(Alloc<Field>(StrFromC("keyword"), x0));
689
690 return out_node;
691}
692
693
694hnode_t* stmt__PlaceMutation::PrettyTree(Dict<int, bool>* seen) {
695 seen = seen ? seen : Alloc<Dict<int, bool>>();
696 int heap_id = ObjectId(this);
697 if (dict_contains(seen, heap_id)) {
698 return Alloc<hnode::AlreadySeen>(heap_id);
699 }
700 seen->set(heap_id, true);
701 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
702 List<Field*>* L = out_node->fields;
703
704 hnode_t* x0 = this->keyword->PrettyTree(seen);
705 L->append(Alloc<Field>(StrFromC("keyword"), x0));
706
707 return out_node;
708}
709
710
711hnode_t* stmt__If::PrettyTree(Dict<int, bool>* seen) {
712 seen = seen ? seen : Alloc<Dict<int, bool>>();
713 int heap_id = ObjectId(this);
714 if (dict_contains(seen, heap_id)) {
715 return Alloc<hnode::AlreadySeen>(heap_id);
716 }
717 seen->set(heap_id, true);
718 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
719 return out_node;
720}
721
722
723hnode_t* stmt__Switch::PrettyTree(Dict<int, bool>* seen) {
724 seen = seen ? seen : Alloc<Dict<int, bool>>();
725 int heap_id = ObjectId(this);
726 if (dict_contains(seen, heap_id)) {
727 return Alloc<hnode::AlreadySeen>(heap_id);
728 }
729 seen->set(heap_id, true);
730 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
731 return out_node;
732}
733
734
735hnode_t* stmt__For::PrettyTree(Dict<int, bool>* seen) {
736 seen = seen ? seen : Alloc<Dict<int, bool>>();
737 int heap_id = ObjectId(this);
738 if (dict_contains(seen, heap_id)) {
739 return Alloc<hnode::AlreadySeen>(heap_id);
740 }
741 seen->set(heap_id, true);
742 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
743 return out_node;
744}
745
746
747hnode_t* stmt__While::PrettyTree(Dict<int, bool>* seen) {
748 seen = seen ? seen : Alloc<Dict<int, bool>>();
749 int heap_id = ObjectId(this);
750 if (dict_contains(seen, heap_id)) {
751 return Alloc<hnode::AlreadySeen>(heap_id);
752 }
753 seen->set(heap_id, true);
754 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
755 return out_node;
756}
757
758
759hnode_t* stmt__Break::PrettyTree(Dict<int, bool>* seen) {
760 seen = seen ? seen : Alloc<Dict<int, bool>>();
761 int heap_id = ObjectId(this);
762 if (dict_contains(seen, heap_id)) {
763 return Alloc<hnode::AlreadySeen>(heap_id);
764 }
765 seen->set(heap_id, true);
766 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
767 return out_node;
768}
769
770
771hnode_t* stmt__Continue::PrettyTree(Dict<int, bool>* seen) {
772 seen = seen ? seen : Alloc<Dict<int, bool>>();
773 int heap_id = ObjectId(this);
774 if (dict_contains(seen, heap_id)) {
775 return Alloc<hnode::AlreadySeen>(heap_id);
776 }
777 seen->set(heap_id, true);
778 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
779 return out_node;
780}
781
782
783hnode_t* stmt__Return::PrettyTree(Dict<int, bool>* seen) {
784 seen = seen ? seen : Alloc<Dict<int, bool>>();
785 int heap_id = ObjectId(this);
786 if (dict_contains(seen, heap_id)) {
787 return Alloc<hnode::AlreadySeen>(heap_id);
788 }
789 seen->set(heap_id, true);
790 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
791 List<Field*>* L = out_node->fields;
792
793 hnode_t* x0 = this->e->PrettyTree(seen);
794 L->append(Alloc<Field>(StrFromC("e"), x0));
795
796 return out_node;
797}
798
799
800hnode_t* stmt__Try::PrettyTree(Dict<int, bool>* seen) {
801 seen = seen ? seen : Alloc<Dict<int, bool>>();
802 int heap_id = ObjectId(this);
803 if (dict_contains(seen, heap_id)) {
804 return Alloc<hnode::AlreadySeen>(heap_id);
805 }
806 seen->set(heap_id, true);
807 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
808 return out_node;
809}
810
811
812hnode_t* stmt__With::PrettyTree(Dict<int, bool>* seen) {
813 seen = seen ? seen : Alloc<Dict<int, bool>>();
814 int heap_id = ObjectId(this);
815 if (dict_contains(seen, heap_id)) {
816 return Alloc<hnode::AlreadySeen>(heap_id);
817 }
818 seen->set(heap_id, true);
819 hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
820 return out_node;
821}
822
823
824hnode_t* stmt_t::PrettyTree(Dict<int, bool>* seen) {
825 switch (this->tag()) {
826 case stmt_e::VarDecl: {
827 stmt__VarDecl* obj = static_cast<stmt__VarDecl*>(this);
828 return obj->PrettyTree(seen);
829 }
830 case stmt_e::PlaceMutation: {
831 stmt__PlaceMutation* obj = static_cast<stmt__PlaceMutation*>(this);
832 return obj->PrettyTree(seen);
833 }
834 case stmt_e::If: {
835 stmt__If* obj = static_cast<stmt__If*>(this);
836 return obj->PrettyTree(seen);
837 }
838 case stmt_e::Switch: {
839 stmt__Switch* obj = static_cast<stmt__Switch*>(this);
840 return obj->PrettyTree(seen);
841 }
842 case stmt_e::For: {
843 stmt__For* obj = static_cast<stmt__For*>(this);
844 return obj->PrettyTree(seen);
845 }
846 case stmt_e::While: {
847 stmt__While* obj = static_cast<stmt__While*>(this);
848 return obj->PrettyTree(seen);
849 }
850 case stmt_e::Break: {
851 stmt__Break* obj = static_cast<stmt__Break*>(this);
852 return obj->PrettyTree(seen);
853 }
854 case stmt_e::Continue: {
855 stmt__Continue* obj = static_cast<stmt__Continue*>(this);
856 return obj->PrettyTree(seen);
857 }
858 case stmt_e::Return: {
859 stmt__Return* obj = static_cast<stmt__Return*>(this);
860 return obj->PrettyTree(seen);
861 }
862 case stmt_e::Try: {
863 stmt__Try* obj = static_cast<stmt__Try*>(this);
864 return obj->PrettyTree(seen);
865 }
866 case stmt_e::With: {
867 stmt__With* obj = static_cast<stmt__With*>(this);
868 return obj->PrettyTree(seen);
869 }
870 default:
871 assert(0);
872 }
873}
874BigStr* class_def_str(class_def_e tag, bool dot) {
875 char buf[32];
876 const char* v = nullptr;
877 switch (tag) {
878 case class_def_e::Constructor:
879 v = "Constructor"; break;
880 case class_def_e::Destructor:
881 v = "Destructor"; break;
882 case class_def_e::Method:
883 v = "Method"; break;
884 case class_def_e::Field:
885 v = "Field"; break;
886 default:
887 assert(0);
888 }
889 if (dot) {
890 snprintf(buf, 32, "class_def.%s", v);
891 return StrFromC(buf);
892 } else {
893 return StrFromC(v);
894 }
895}
896
897hnode_t* Signature::PrettyTree(Dict<int, bool>* seen) {
898 seen = seen ? seen : Alloc<Dict<int, bool>>();
899 int heap_id = ObjectId(this);
900 if (dict_contains(seen, heap_id)) {
901 return Alloc<hnode::AlreadySeen>(heap_id);
902 }
903 seen->set(heap_id, true);
904 hnode::Record* out_node = runtime::NewRecord(StrFromC("Signature"));
905 List<Field*>* L = out_node->fields;
906
907 if (this->params != nullptr) { // List
908 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
909 for (ListIter<NameType*> it(this->params); !it.Done(); it.Next()) {
910 NameType* i0 = it.Value();
911 hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
912 color_e::OtherConst) : i0->PrettyTree(seen);
913 x0->children->append(h);
914 }
915 L->append(Alloc<Field>(StrFromC("params"), x0));
916 }
917
918 hnode_t* x1 = this->return_type->PrettyTree(seen);
919 L->append(Alloc<Field>(StrFromC("return_type"), x1));
920
921 return out_node;
922}
923
924BigStr* mod_def_str(int tag, bool dot) {
925 char buf[32];
926 const char* v = nullptr;
927 switch (tag) {
928 case mod_def_e::Global:
929 v = "Global"; break;
930 case mod_def_e::Func:
931 v = "Func"; break;
932 case mod_def_e::Class:
933 v = "Class"; break;
934 case mod_def_e::Import:
935 v = "Import"; break;
936 case mod_def_e::Include:
937 v = "Include"; break;
938 case mod_def_e::Data:
939 v = "Data"; break;
940 case mod_def_e::Enum:
941 v = "Enum"; break;
942 default:
943 assert(0);
944 }
945 if (dot) {
946 snprintf(buf, 32, "mod_def.%s", v);
947 return StrFromC(buf);
948 } else {
949 return StrFromC(v);
950 }
951}
952
953mod_def__Import* mod_def::Import = &gmod_def__Import.obj;
954
955GcGlobal<mod_def__Import> gmod_def__Import =
956 { ObjHeader::Global(mod_def_e::Import) };
957
958mod_def__Data* mod_def::Data = &gmod_def__Data.obj;
959
960GcGlobal<mod_def__Data> gmod_def__Data =
961 { ObjHeader::Global(mod_def_e::Data) };
962
963mod_def__Enum* mod_def::Enum = &gmod_def__Enum.obj;
964
965GcGlobal<mod_def__Enum> gmod_def__Enum =
966 { ObjHeader::Global(mod_def_e::Enum) };
967
968hnode_t* mod_def__Global::PrettyTree(Dict<int, bool>* seen) {
969 seen = seen ? seen : Alloc<Dict<int, bool>>();
970 int heap_id = ObjectId(this);
971 if (dict_contains(seen, heap_id)) {
972 return Alloc<hnode::AlreadySeen>(heap_id);
973 }
974 seen->set(heap_id, true);
975 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
976 List<Field*>* L = out_node->fields;
977
978 hnode_t* x0 = this->name_type->PrettyTree(seen);
979 L->append(Alloc<Field>(StrFromC("name_type"), x0));
980
981 return out_node;
982}
983
984
985hnode_t* mod_def__Func::PrettyTree(Dict<int, bool>* seen) {
986 seen = seen ? seen : Alloc<Dict<int, bool>>();
987 int heap_id = ObjectId(this);
988 if (dict_contains(seen, heap_id)) {
989 return Alloc<hnode::AlreadySeen>(heap_id);
990 }
991 seen->set(heap_id, true);
992 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
993 List<Field*>* L = out_node->fields;
994
995 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
996 L->append(Alloc<Field>(StrFromC("name"), x0));
997
998 hnode_t* x1 = this->sig->PrettyTree(seen);
999 L->append(Alloc<Field>(StrFromC("sig"), x1));
1000
1001 if (this->statements != nullptr) { // List
1002 hnode::Array* x2 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1003 for (ListIter<stmt_t*> it(this->statements); !it.Done(); it.Next()) {
1004 stmt_t* i2 = it.Value();
1005 hnode_t* h = (i2 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
1006 color_e::OtherConst) : i2->PrettyTree(seen);
1007 x2->children->append(h);
1008 }
1009 L->append(Alloc<Field>(StrFromC("statements"), x2));
1010 }
1011
1012 return out_node;
1013}
1014
1015
1016hnode_t* mod_def__Class::PrettyTree(Dict<int, bool>* seen) {
1017 seen = seen ? seen : Alloc<Dict<int, bool>>();
1018 int heap_id = ObjectId(this);
1019 if (dict_contains(seen, heap_id)) {
1020 return Alloc<hnode::AlreadySeen>(heap_id);
1021 }
1022 seen->set(heap_id, true);
1023 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
1024 List<Field*>* L = out_node->fields;
1025
1026 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
1027 L->append(Alloc<Field>(StrFromC("name"), x0));
1028
1029 if (this->defs != nullptr) { // List
1030 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1031 for (ListIter<class_def_t> it(this->defs); !it.Done(); it.Next()) {
1032 class_def_t i1 = it.Value();
1033 x1->children->append(Alloc<hnode::Leaf>(class_def_str(i1),
1034 color_e::TypeName));
1035 }
1036 L->append(Alloc<Field>(StrFromC("defs"), x1));
1037 }
1038
1039 return out_node;
1040}
1041
1042
1043hnode_t* mod_def__Import::PrettyTree(Dict<int, bool>* seen) {
1044 seen = seen ? seen : Alloc<Dict<int, bool>>();
1045 int heap_id = ObjectId(this);
1046 if (dict_contains(seen, heap_id)) {
1047 return Alloc<hnode::AlreadySeen>(heap_id);
1048 }
1049 seen->set(heap_id, true);
1050 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
1051 return out_node;
1052}
1053
1054
1055hnode_t* mod_def__Include::PrettyTree(Dict<int, bool>* seen) {
1056 seen = seen ? seen : Alloc<Dict<int, bool>>();
1057 int heap_id = ObjectId(this);
1058 if (dict_contains(seen, heap_id)) {
1059 return Alloc<hnode::AlreadySeen>(heap_id);
1060 }
1061 seen->set(heap_id, true);
1062 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
1063 List<Field*>* L = out_node->fields;
1064
1065 hnode_t* x0 = runtime::NewLeaf(this->path, color_e::StringConst);
1066 L->append(Alloc<Field>(StrFromC("path"), x0));
1067
1068 return out_node;
1069}
1070
1071
1072hnode_t* mod_def__Data::PrettyTree(Dict<int, bool>* seen) {
1073 seen = seen ? seen : Alloc<Dict<int, bool>>();
1074 int heap_id = ObjectId(this);
1075 if (dict_contains(seen, heap_id)) {
1076 return Alloc<hnode::AlreadySeen>(heap_id);
1077 }
1078 seen->set(heap_id, true);
1079 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
1080 return out_node;
1081}
1082
1083
1084hnode_t* mod_def__Enum::PrettyTree(Dict<int, bool>* seen) {
1085 seen = seen ? seen : Alloc<Dict<int, bool>>();
1086 int heap_id = ObjectId(this);
1087 if (dict_contains(seen, heap_id)) {
1088 return Alloc<hnode::AlreadySeen>(heap_id);
1089 }
1090 seen->set(heap_id, true);
1091 hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
1092 return out_node;
1093}
1094
1095
1096hnode_t* mod_def_t::PrettyTree(Dict<int, bool>* seen) {
1097 switch (this->tag()) {
1098 case mod_def_e::Global: {
1099 mod_def__Global* obj = static_cast<mod_def__Global*>(this);
1100 return obj->PrettyTree(seen);
1101 }
1102 case mod_def_e::Func: {
1103 mod_def__Func* obj = static_cast<mod_def__Func*>(this);
1104 return obj->PrettyTree(seen);
1105 }
1106 case mod_def_e::Class: {
1107 mod_def__Class* obj = static_cast<mod_def__Class*>(this);
1108 return obj->PrettyTree(seen);
1109 }
1110 case mod_def_e::Import: {
1111 mod_def__Import* obj = static_cast<mod_def__Import*>(this);
1112 return obj->PrettyTree(seen);
1113 }
1114 case mod_def_e::Include: {
1115 mod_def__Include* obj = static_cast<mod_def__Include*>(this);
1116 return obj->PrettyTree(seen);
1117 }
1118 case mod_def_e::Data: {
1119 mod_def__Data* obj = static_cast<mod_def__Data*>(this);
1120 return obj->PrettyTree(seen);
1121 }
1122 case mod_def_e::Enum: {
1123 mod_def__Enum* obj = static_cast<mod_def__Enum*>(this);
1124 return obj->PrettyTree(seen);
1125 }
1126 default:
1127 assert(0);
1128 }
1129}
1130
1131hnode_t* Module::PrettyTree(Dict<int, bool>* seen) {
1132 seen = seen ? seen : Alloc<Dict<int, bool>>();
1133 int heap_id = ObjectId(this);
1134 if (dict_contains(seen, heap_id)) {
1135 return Alloc<hnode::AlreadySeen>(heap_id);
1136 }
1137 seen->set(heap_id, true);
1138 hnode::Record* out_node = runtime::NewRecord(StrFromC("Module"));
1139 List<Field*>* L = out_node->fields;
1140
1141 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
1142 L->append(Alloc<Field>(StrFromC("name"), x0));
1143
1144 if (this->defs != nullptr) { // List
1145 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1146 for (ListIter<mod_def_t*> it(this->defs); !it.Done(); it.Next()) {
1147 mod_def_t* i1 = it.Value();
1148 hnode_t* h = (i1 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
1149 color_e::OtherConst) : i1->PrettyTree(seen);
1150 x1->children->append(h);
1151 }
1152 L->append(Alloc<Field>(StrFromC("defs"), x1));
1153 }
1154
1155 return out_node;
1156}
1157
1158
1159hnode_t* Program::PrettyTree(Dict<int, bool>* seen) {
1160 seen = seen ? seen : Alloc<Dict<int, bool>>();
1161 int heap_id = ObjectId(this);
1162 if (dict_contains(seen, heap_id)) {
1163 return Alloc<hnode::AlreadySeen>(heap_id);
1164 }
1165 seen->set(heap_id, true);
1166 hnode::Record* out_node = runtime::NewRecord(StrFromC("Program"));
1167 List<Field*>* L = out_node->fields;
1168
1169 hnode_t* x0 = runtime::NewLeaf(this->main_module, color_e::StringConst);
1170 L->append(Alloc<Field>(StrFromC("main_module"), x0));
1171
1172 if (this->modules != nullptr) { // List
1173 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1174 for (ListIter<Module*> it(this->modules); !it.Done(); it.Next()) {
1175 Module* i1 = it.Value();
1176 hnode_t* h = (i1 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
1177 color_e::OtherConst) : i1->PrettyTree(seen);
1178 x1->children->append(h);
1179 }
1180 L->append(Alloc<Field>(StrFromC("modules"), x1));
1181 }
1182
1183 return out_node;
1184}
1185
1186
1187} // namespace yaks_asdl