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