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

1322 lines, 937 significant
1// _gen/core/runtime.asdl.cc is generated by asdl_main.py
2
3#include "_gen/core/runtime.asdl.h"
4#include <assert.h>
5#include "prebuilt/asdl/runtime.mycpp.h" // generated code uses wrappers here
6#include "_gen/frontend/syntax.asdl.h" // "use" in ASDL
7#include "_gen/core/value.asdl.h" // "use" in ASDL
8
9// Generated code uses these types
10using hnode_asdl::hnode;
11using hnode_asdl::Field;
12using hnode_asdl::color_e;
13
14using id_kind_asdl::Id_str;
15
16namespace runtime_asdl {
17
18
19hnode_t* AssignArg::PrettyTree(Dict<int, bool>* seen) {
20 seen = seen ? seen : Alloc<Dict<int, bool>>();
21 int heap_id = ObjectId(this);
22 if (dict_contains(seen, heap_id)) {
23 return Alloc<hnode::AlreadySeen>(heap_id);
24 }
25 seen->set(heap_id, true);
26
27 hnode::Record* out_node = runtime::NewRecord(StrFromC("AssignArg"));
28 List<Field*>* L = out_node->fields;
29
30 hnode_t* x0 = runtime::NewLeaf(this->var_name, color_e::StringConst);
31 L->append(Alloc<Field>(StrFromC("var_name"), x0));
32
33 if (this->rval) { // Optional
34 hnode_t* x1 = this->rval->PrettyTree(seen);
35 L->append(Alloc<Field>(StrFromC("rval"), x1));
36 }
37
38 hnode_t* x2 = Alloc<hnode::Leaf>(this->plus_eq ? runtime::TRUE_STR :
39 runtime::FALSE_STR, color_e::OtherConst);
40 L->append(Alloc<Field>(StrFromC("plus_eq"), x2));
41
42 hnode_t* x3 = this->blame_word->PrettyTree(seen);
43 L->append(Alloc<Field>(StrFromC("blame_word"), x3));
44
45 return out_node;
46}
47
48
49hnode_t* ProcArgs::PrettyTree(Dict<int, bool>* seen) {
50 seen = seen ? seen : Alloc<Dict<int, bool>>();
51 int heap_id = ObjectId(this);
52 if (dict_contains(seen, heap_id)) {
53 return Alloc<hnode::AlreadySeen>(heap_id);
54 }
55 seen->set(heap_id, true);
56
57 hnode::Record* out_node = runtime::NewRecord(StrFromC("ProcArgs"));
58 List<Field*>* L = out_node->fields;
59
60 hnode_t* x0 = this->typed_args->PrettyTree(seen);
61 L->append(Alloc<Field>(StrFromC("typed_args"), x0));
62
63 if (this->pos_args != nullptr) { // List
64 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
65 for (ListIter<value_asdl::value_t*> it(this->pos_args); !it.Done();
66 it.Next()) {
67 value_asdl::value_t* v_ = it.Value();
68 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
69 color_e::OtherConst) : v_->PrettyTree(seen);
70 x1->children->append(h);
71 }
72 L->append(Alloc<Field>(StrFromC("pos_args"), x1));
73 }
74
75 if (this->named_args) { // Dict
76 auto m = Alloc<hnode::Leaf>(StrFromC("Dict"), color_e::OtherConst);
77 hnode::Array* x2 = Alloc<hnode::Array>(NewList<hnode_t*>({m}));
78 for (DictIter<BigStr*, value_asdl::value_t*> it(this->named_args);
79 !it.Done(); it.Next()) {
80 auto k2 = it.Key();
81 auto v2 = it.Value();
82 x2->children->append(runtime::NewLeaf(k2, color_e::StringConst));
83 x2->children->append(v2->PrettyTree(seen));
84 }
85 L->append(Alloc<Field>(StrFromC ("named_args"), x2));
86 }
87
88 if (this->block_arg) { // Optional
89 hnode_t* x3 = this->block_arg->PrettyTree(seen);
90 L->append(Alloc<Field>(StrFromC("block_arg"), x3));
91 }
92
93 return out_node;
94}
95
96BigStr* cmd_value_str(int tag, bool dot) {
97 char buf[32];
98 const char* v = nullptr;
99 switch (tag) {
100 case cmd_value_e::Argv:
101 v = "Argv"; break;
102 case cmd_value_e::Assign:
103 v = "Assign"; break;
104 default:
105 assert(0);
106 }
107 if (dot) {
108 snprintf(buf, 32, "cmd_value.%s", v);
109 return StrFromC(buf);
110 } else {
111 return StrFromC(v);
112 }
113}
114
115hnode_t* cmd_value__Argv::PrettyTree(Dict<int, bool>* seen) {
116 seen = seen ? seen : Alloc<Dict<int, bool>>();
117 int heap_id = ObjectId(this);
118 if (dict_contains(seen, heap_id)) {
119 return Alloc<hnode::AlreadySeen>(heap_id);
120 }
121 seen->set(heap_id, true);
122
123 hnode::Record* out_node = runtime::NewRecord(cmd_value_str(this->tag()));
124 List<Field*>* L = out_node->fields;
125
126 if (this->argv != nullptr) { // List
127 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
128 for (ListIter<BigStr*> it(this->argv); !it.Done(); it.Next()) {
129 BigStr* v_ = it.Value();
130 hnode_t* h = runtime::NewLeaf(v_, color_e::StringConst);
131 x0->children->append(h);
132 }
133 L->append(Alloc<Field>(StrFromC("argv"), x0));
134 }
135
136 if (this->arg_locs != nullptr) { // List
137 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
138 for (ListIter<syntax_asdl::CompoundWord*> it(this->arg_locs); !it.Done();
139 it.Next()) {
140 syntax_asdl::CompoundWord* v_ = it.Value();
141 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
142 color_e::OtherConst) : v_->PrettyTree(seen);
143 x1->children->append(h);
144 }
145 L->append(Alloc<Field>(StrFromC("arg_locs"), x1));
146 }
147
148 hnode_t* x2 = Alloc<hnode::Leaf>(this->is_last_cmd ? runtime::TRUE_STR :
149 runtime::FALSE_STR, color_e::OtherConst);
150 L->append(Alloc<Field>(StrFromC("is_last_cmd"), x2));
151
152 if (this->self_obj) { // Optional
153 hnode_t* x3 = this->self_obj->PrettyTree(seen);
154 L->append(Alloc<Field>(StrFromC("self_obj"), x3));
155 }
156
157 if (this->proc_args) { // Optional
158 hnode_t* x4 = this->proc_args->PrettyTree(seen);
159 L->append(Alloc<Field>(StrFromC("proc_args"), x4));
160 }
161
162 return out_node;
163}
164
165
166hnode_t* cmd_value__Assign::PrettyTree(Dict<int, bool>* seen) {
167 seen = seen ? seen : Alloc<Dict<int, bool>>();
168 int heap_id = ObjectId(this);
169 if (dict_contains(seen, heap_id)) {
170 return Alloc<hnode::AlreadySeen>(heap_id);
171 }
172 seen->set(heap_id, true);
173
174 hnode::Record* out_node = runtime::NewRecord(cmd_value_str(this->tag()));
175 List<Field*>* L = out_node->fields;
176
177 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->builtin_id), color_e::OtherConst);
178 L->append(Alloc<Field>(StrFromC("builtin_id"), x0));
179
180 if (this->argv != nullptr) { // List
181 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
182 for (ListIter<BigStr*> it(this->argv); !it.Done(); it.Next()) {
183 BigStr* v_ = it.Value();
184 hnode_t* h = runtime::NewLeaf(v_, color_e::StringConst);
185 x1->children->append(h);
186 }
187 L->append(Alloc<Field>(StrFromC("argv"), x1));
188 }
189
190 if (this->arg_locs != nullptr) { // List
191 hnode::Array* x2 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
192 for (ListIter<syntax_asdl::CompoundWord*> it(this->arg_locs); !it.Done();
193 it.Next()) {
194 syntax_asdl::CompoundWord* v_ = it.Value();
195 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
196 color_e::OtherConst) : v_->PrettyTree(seen);
197 x2->children->append(h);
198 }
199 L->append(Alloc<Field>(StrFromC("arg_locs"), x2));
200 }
201
202 if (this->pairs != nullptr) { // List
203 hnode::Array* x3 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
204 for (ListIter<AssignArg*> it(this->pairs); !it.Done(); it.Next()) {
205 AssignArg* v_ = it.Value();
206 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
207 color_e::OtherConst) : v_->PrettyTree(seen);
208 x3->children->append(h);
209 }
210 L->append(Alloc<Field>(StrFromC("pairs"), x3));
211 }
212
213 return out_node;
214}
215
216
217hnode_t* cmd_value_t::PrettyTree(Dict<int, bool>* seen) {
218 switch (this->tag()) {
219 case cmd_value_e::Argv: {
220 cmd_value__Argv* obj = static_cast<cmd_value__Argv*>(this);
221 return obj->PrettyTree(seen);
222 }
223 case cmd_value_e::Assign: {
224 cmd_value__Assign* obj = static_cast<cmd_value__Assign*>(this);
225 return obj->PrettyTree(seen);
226 }
227 default:
228 assert(0);
229 }
230}
231
232hnode_t* Piece::PrettyTree(Dict<int, bool>* seen) {
233 seen = seen ? seen : Alloc<Dict<int, bool>>();
234 int heap_id = ObjectId(this);
235 if (dict_contains(seen, heap_id)) {
236 return Alloc<hnode::AlreadySeen>(heap_id);
237 }
238 seen->set(heap_id, true);
239
240 hnode::Record* out_node = runtime::NewRecord(StrFromC("Piece"));
241 List<Field*>* L = out_node->fields;
242
243 hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
244 L->append(Alloc<Field>(StrFromC("s"), x0));
245
246 hnode_t* x1 = Alloc<hnode::Leaf>(this->quoted ? runtime::TRUE_STR :
247 runtime::FALSE_STR, color_e::OtherConst);
248 L->append(Alloc<Field>(StrFromC("quoted"), x1));
249
250 hnode_t* x2 = Alloc<hnode::Leaf>(this->do_split ? runtime::TRUE_STR :
251 runtime::FALSE_STR, color_e::OtherConst);
252 L->append(Alloc<Field>(StrFromC("do_split"), x2));
253
254 return out_node;
255}
256
257BigStr* part_value_str(int tag, bool dot) {
258 char buf[32];
259 const char* v = nullptr;
260 switch (tag) {
261 case part_value_e::String:
262 v = "String"; break;
263 case part_value_e::Array:
264 v = "Array"; break;
265 case part_value_e::ExtGlob:
266 v = "ExtGlob"; break;
267 default:
268 assert(0);
269 }
270 if (dot) {
271 snprintf(buf, 32, "part_value.%s", v);
272 return StrFromC(buf);
273 } else {
274 return StrFromC(v);
275 }
276}
277
278hnode_t* part_value__Array::PrettyTree(Dict<int, bool>* seen) {
279 seen = seen ? seen : Alloc<Dict<int, bool>>();
280 int heap_id = ObjectId(this);
281 if (dict_contains(seen, heap_id)) {
282 return Alloc<hnode::AlreadySeen>(heap_id);
283 }
284 seen->set(heap_id, true);
285
286 hnode::Record* out_node = runtime::NewRecord(part_value_str(this->tag()));
287 List<Field*>* L = out_node->fields;
288
289 if (this->strs != nullptr) { // List
290 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
291 for (ListIter<BigStr*> it(this->strs); !it.Done(); it.Next()) {
292 BigStr* v_ = it.Value();
293 hnode_t* h = runtime::NewLeaf(v_, color_e::StringConst);
294 x0->children->append(h);
295 }
296 L->append(Alloc<Field>(StrFromC("strs"), x0));
297 }
298
299 return out_node;
300}
301
302
303hnode_t* part_value__ExtGlob::PrettyTree(Dict<int, bool>* seen) {
304 seen = seen ? seen : Alloc<Dict<int, bool>>();
305 int heap_id = ObjectId(this);
306 if (dict_contains(seen, heap_id)) {
307 return Alloc<hnode::AlreadySeen>(heap_id);
308 }
309 seen->set(heap_id, true);
310
311 hnode::Record* out_node = runtime::NewRecord(part_value_str(this->tag()));
312 List<Field*>* L = out_node->fields;
313
314 if (this->part_vals != nullptr) { // List
315 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
316 for (ListIter<part_value_t*> it(this->part_vals); !it.Done(); it.Next()) {
317 part_value_t* v_ = it.Value();
318 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
319 color_e::OtherConst) : v_->PrettyTree(seen);
320 x0->children->append(h);
321 }
322 L->append(Alloc<Field>(StrFromC("part_vals"), x0));
323 }
324
325 return out_node;
326}
327
328
329hnode_t* part_value_t::PrettyTree(Dict<int, bool>* seen) {
330 switch (this->tag()) {
331 case part_value_e::String: {
332 Piece* obj = static_cast<Piece*>(this);
333 return obj->PrettyTree(seen);
334 }
335 case part_value_e::Array: {
336 part_value__Array* obj = static_cast<part_value__Array*>(this);
337 return obj->PrettyTree(seen);
338 }
339 case part_value_e::ExtGlob: {
340 part_value__ExtGlob* obj = static_cast<part_value__ExtGlob*>(this);
341 return obj->PrettyTree(seen);
342 }
343 default:
344 assert(0);
345 }
346}
347BigStr* coerced_str(coerced_e tag, bool dot) {
348 char buf[32];
349 const char* v = nullptr;
350 switch (tag) {
351 case coerced_e::Int:
352 v = "Int"; break;
353 case coerced_e::Float:
354 v = "Float"; break;
355 case coerced_e::Neither:
356 v = "Neither"; break;
357 default:
358 assert(0);
359 }
360 if (dot) {
361 snprintf(buf, 32, "coerced.%s", v);
362 return StrFromC(buf);
363 } else {
364 return StrFromC(v);
365 }
366}
367
368hnode_t* VarSubState::PrettyTree(Dict<int, bool>* seen) {
369 seen = seen ? seen : Alloc<Dict<int, bool>>();
370 int heap_id = ObjectId(this);
371 if (dict_contains(seen, heap_id)) {
372 return Alloc<hnode::AlreadySeen>(heap_id);
373 }
374 seen->set(heap_id, true);
375
376 hnode::Record* out_node = runtime::NewRecord(StrFromC("VarSubState"));
377 List<Field*>* L = out_node->fields;
378
379 hnode_t* x0 = Alloc<hnode::Leaf>(this->join_array ? runtime::TRUE_STR :
380 runtime::FALSE_STR, color_e::OtherConst);
381 L->append(Alloc<Field>(StrFromC("join_array"), x0));
382
383 hnode_t* x1 = Alloc<hnode::Leaf>(this->is_type_query ? runtime::TRUE_STR :
384 runtime::FALSE_STR, color_e::OtherConst);
385 L->append(Alloc<Field>(StrFromC("is_type_query"), x1));
386
387 hnode_t* x2 = Alloc<hnode::Leaf>(this->has_test_op ? runtime::TRUE_STR :
388 runtime::FALSE_STR, color_e::OtherConst);
389 L->append(Alloc<Field>(StrFromC("has_test_op"), x2));
390
391 return out_node;
392}
393
394
395hnode_t* Cell::PrettyTree(Dict<int, bool>* seen) {
396 seen = seen ? seen : Alloc<Dict<int, bool>>();
397 int heap_id = ObjectId(this);
398 if (dict_contains(seen, heap_id)) {
399 return Alloc<hnode::AlreadySeen>(heap_id);
400 }
401 seen->set(heap_id, true);
402
403 hnode::Record* out_node = runtime::NewRecord(StrFromC("Cell"));
404 List<Field*>* L = out_node->fields;
405
406 hnode_t* x0 = Alloc<hnode::Leaf>(this->exported ? runtime::TRUE_STR :
407 runtime::FALSE_STR, color_e::OtherConst);
408 L->append(Alloc<Field>(StrFromC("exported"), x0));
409
410 hnode_t* x1 = Alloc<hnode::Leaf>(this->readonly ? runtime::TRUE_STR :
411 runtime::FALSE_STR, color_e::OtherConst);
412 L->append(Alloc<Field>(StrFromC("readonly"), x1));
413
414 hnode_t* x2 = Alloc<hnode::Leaf>(this->nameref ? runtime::TRUE_STR :
415 runtime::FALSE_STR, color_e::OtherConst);
416 L->append(Alloc<Field>(StrFromC("nameref"), x2));
417
418 hnode_t* x3 = this->val->PrettyTree(seen);
419 L->append(Alloc<Field>(StrFromC("val"), x3));
420
421 return out_node;
422}
423
424BigStr* scope_str(scope_e tag, bool dot) {
425 char buf[32];
426 const char* v = nullptr;
427 switch (tag) {
428 case scope_e::Shopt:
429 v = "Shopt"; break;
430 case scope_e::Dynamic:
431 v = "Dynamic"; break;
432 case scope_e::LocalOrGlobal:
433 v = "LocalOrGlobal"; break;
434 case scope_e::LocalOnly:
435 v = "LocalOnly"; break;
436 case scope_e::GlobalOnly:
437 v = "GlobalOnly"; break;
438 default:
439 assert(0);
440 }
441 if (dot) {
442 snprintf(buf, 32, "scope.%s", v);
443 return StrFromC(buf);
444 } else {
445 return StrFromC(v);
446 }
447}
448BigStr* a_index_str(int tag, bool dot) {
449 char buf[32];
450 const char* v = nullptr;
451 switch (tag) {
452 case a_index_e::Str:
453 v = "Str"; break;
454 case a_index_e::Int:
455 v = "Int"; break;
456 default:
457 assert(0);
458 }
459 if (dot) {
460 snprintf(buf, 32, "a_index.%s", v);
461 return StrFromC(buf);
462 } else {
463 return StrFromC(v);
464 }
465}
466
467hnode_t* a_index__Str::PrettyTree(Dict<int, bool>* seen) {
468 seen = seen ? seen : Alloc<Dict<int, bool>>();
469 int heap_id = ObjectId(this);
470 if (dict_contains(seen, heap_id)) {
471 return Alloc<hnode::AlreadySeen>(heap_id);
472 }
473 seen->set(heap_id, true);
474
475 hnode::Record* out_node = runtime::NewRecord(a_index_str(this->tag()));
476 List<Field*>* L = out_node->fields;
477
478 hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
479 L->append(Alloc<Field>(StrFromC("s"), x0));
480
481 return out_node;
482}
483
484
485hnode_t* a_index__Int::PrettyTree(Dict<int, bool>* seen) {
486 seen = seen ? seen : Alloc<Dict<int, bool>>();
487 int heap_id = ObjectId(this);
488 if (dict_contains(seen, heap_id)) {
489 return Alloc<hnode::AlreadySeen>(heap_id);
490 }
491 seen->set(heap_id, true);
492
493 hnode::Record* out_node = runtime::NewRecord(a_index_str(this->tag()));
494 List<Field*>* L = out_node->fields;
495
496 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->i), color_e::OtherConst);
497 L->append(Alloc<Field>(StrFromC("i"), x0));
498
499 return out_node;
500}
501
502
503hnode_t* a_index_t::PrettyTree(Dict<int, bool>* seen) {
504 switch (this->tag()) {
505 case a_index_e::Str: {
506 a_index__Str* obj = static_cast<a_index__Str*>(this);
507 return obj->PrettyTree(seen);
508 }
509 case a_index_e::Int: {
510 a_index__Int* obj = static_cast<a_index__Int*>(this);
511 return obj->PrettyTree(seen);
512 }
513 default:
514 assert(0);
515 }
516}
517
518hnode_t* VTestPlace::PrettyTree(Dict<int, bool>* seen) {
519 seen = seen ? seen : Alloc<Dict<int, bool>>();
520 int heap_id = ObjectId(this);
521 if (dict_contains(seen, heap_id)) {
522 return Alloc<hnode::AlreadySeen>(heap_id);
523 }
524 seen->set(heap_id, true);
525
526 hnode::Record* out_node = runtime::NewRecord(StrFromC("VTestPlace"));
527 List<Field*>* L = out_node->fields;
528
529 if (this->name) { // Optional
530 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
531 L->append(Alloc<Field>(StrFromC("name"), x0));
532 }
533
534 if (this->index) { // Optional
535 hnode_t* x1 = this->index->PrettyTree(seen);
536 L->append(Alloc<Field>(StrFromC("index"), x1));
537 }
538
539 return out_node;
540}
541
542BigStr* redirect_arg_str(int tag, bool dot) {
543 char buf[32];
544 const char* v = nullptr;
545 switch (tag) {
546 case redirect_arg_e::Path:
547 v = "Path"; break;
548 case redirect_arg_e::CopyFd:
549 v = "CopyFd"; break;
550 case redirect_arg_e::MoveFd:
551 v = "MoveFd"; break;
552 case redirect_arg_e::CloseFd:
553 v = "CloseFd"; break;
554 case redirect_arg_e::HereDoc:
555 v = "HereDoc"; break;
556 default:
557 assert(0);
558 }
559 if (dot) {
560 snprintf(buf, 32, "redirect_arg.%s", v);
561 return StrFromC(buf);
562 } else {
563 return StrFromC(v);
564 }
565}
566
567redirect_arg__CloseFd* redirect_arg::CloseFd = &gredirect_arg__CloseFd.obj;
568
569GcGlobal<redirect_arg__CloseFd> gredirect_arg__CloseFd =
570 { ObjHeader::Global(redirect_arg_e::CloseFd) };
571
572hnode_t* redirect_arg__Path::PrettyTree(Dict<int, bool>* seen) {
573 seen = seen ? seen : Alloc<Dict<int, bool>>();
574 int heap_id = ObjectId(this);
575 if (dict_contains(seen, heap_id)) {
576 return Alloc<hnode::AlreadySeen>(heap_id);
577 }
578 seen->set(heap_id, true);
579
580 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
581 List<Field*>* L = out_node->fields;
582
583 hnode_t* x0 = runtime::NewLeaf(this->filename, color_e::StringConst);
584 L->append(Alloc<Field>(StrFromC("filename"), x0));
585
586 return out_node;
587}
588
589
590hnode_t* redirect_arg__CopyFd::PrettyTree(Dict<int, bool>* seen) {
591 seen = seen ? seen : Alloc<Dict<int, bool>>();
592 int heap_id = ObjectId(this);
593 if (dict_contains(seen, heap_id)) {
594 return Alloc<hnode::AlreadySeen>(heap_id);
595 }
596 seen->set(heap_id, true);
597
598 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
599 List<Field*>* L = out_node->fields;
600
601 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->target_fd), color_e::OtherConst);
602 L->append(Alloc<Field>(StrFromC("target_fd"), x0));
603
604 return out_node;
605}
606
607
608hnode_t* redirect_arg__MoveFd::PrettyTree(Dict<int, bool>* seen) {
609 seen = seen ? seen : Alloc<Dict<int, bool>>();
610 int heap_id = ObjectId(this);
611 if (dict_contains(seen, heap_id)) {
612 return Alloc<hnode::AlreadySeen>(heap_id);
613 }
614 seen->set(heap_id, true);
615
616 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
617 List<Field*>* L = out_node->fields;
618
619 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->target_fd), color_e::OtherConst);
620 L->append(Alloc<Field>(StrFromC("target_fd"), x0));
621
622 return out_node;
623}
624
625
626hnode_t* redirect_arg__CloseFd::PrettyTree(Dict<int, bool>* seen) {
627 seen = seen ? seen : Alloc<Dict<int, bool>>();
628 int heap_id = ObjectId(this);
629 if (dict_contains(seen, heap_id)) {
630 return Alloc<hnode::AlreadySeen>(heap_id);
631 }
632 seen->set(heap_id, true);
633
634 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
635 return out_node;
636}
637
638
639hnode_t* redirect_arg__HereDoc::PrettyTree(Dict<int, bool>* seen) {
640 seen = seen ? seen : Alloc<Dict<int, bool>>();
641 int heap_id = ObjectId(this);
642 if (dict_contains(seen, heap_id)) {
643 return Alloc<hnode::AlreadySeen>(heap_id);
644 }
645 seen->set(heap_id, true);
646
647 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
648 List<Field*>* L = out_node->fields;
649
650 hnode_t* x0 = runtime::NewLeaf(this->body, color_e::StringConst);
651 L->append(Alloc<Field>(StrFromC("body"), x0));
652
653 return out_node;
654}
655
656
657hnode_t* redirect_arg_t::PrettyTree(Dict<int, bool>* seen) {
658 switch (this->tag()) {
659 case redirect_arg_e::Path: {
660 redirect_arg__Path* obj = static_cast<redirect_arg__Path*>(this);
661 return obj->PrettyTree(seen);
662 }
663 case redirect_arg_e::CopyFd: {
664 redirect_arg__CopyFd* obj = static_cast<redirect_arg__CopyFd*>(this);
665 return obj->PrettyTree(seen);
666 }
667 case redirect_arg_e::MoveFd: {
668 redirect_arg__MoveFd* obj = static_cast<redirect_arg__MoveFd*>(this);
669 return obj->PrettyTree(seen);
670 }
671 case redirect_arg_e::CloseFd: {
672 redirect_arg__CloseFd* obj = static_cast<redirect_arg__CloseFd*>(this);
673 return obj->PrettyTree(seen);
674 }
675 case redirect_arg_e::HereDoc: {
676 redirect_arg__HereDoc* obj = static_cast<redirect_arg__HereDoc*>(this);
677 return obj->PrettyTree(seen);
678 }
679 default:
680 assert(0);
681 }
682}
683
684hnode_t* RedirValue::PrettyTree(Dict<int, bool>* seen) {
685 seen = seen ? seen : Alloc<Dict<int, bool>>();
686 int heap_id = ObjectId(this);
687 if (dict_contains(seen, heap_id)) {
688 return Alloc<hnode::AlreadySeen>(heap_id);
689 }
690 seen->set(heap_id, true);
691
692 hnode::Record* out_node = runtime::NewRecord(StrFromC("RedirValue"));
693 List<Field*>* L = out_node->fields;
694
695 hnode_t* x0 = Alloc<hnode::Leaf>(Id_str(this->op_id), color_e::UserType);
696 L->append(Alloc<Field>(StrFromC("op_id"), x0));
697
698 hnode_t* x1 = this->op_loc->PrettyTree(seen);
699 L->append(Alloc<Field>(StrFromC("op_loc"), x1));
700
701 hnode_t* x2 = this->loc->PrettyTree(seen);
702 L->append(Alloc<Field>(StrFromC("loc"), x2));
703
704 hnode_t* x3 = this->arg->PrettyTree(seen);
705 L->append(Alloc<Field>(StrFromC("arg"), x3));
706
707 return out_node;
708}
709
710
711hnode_t* StatusArray::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
719 hnode::Record* out_node = runtime::NewRecord(StrFromC("StatusArray"));
720 List<Field*>* L = out_node->fields;
721
722 if (this->codes != nullptr) { // List
723 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
724 for (ListIter<int> it(this->codes); !it.Done(); it.Next()) {
725 int v_ = it.Value();
726 hnode_t* h = Alloc<hnode::Leaf>(str(v_), color_e::OtherConst);
727 x0->children->append(h);
728 }
729 L->append(Alloc<Field>(StrFromC("codes"), x0));
730 }
731
732 if (this->locs != nullptr) { // List
733 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
734 for (ListIter<syntax_asdl::loc_t*> it(this->locs); !it.Done(); it.Next()) {
735 syntax_asdl::loc_t* v_ = it.Value();
736 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
737 color_e::OtherConst) : v_->PrettyTree(seen);
738 x1->children->append(h);
739 }
740 L->append(Alloc<Field>(StrFromC("locs"), x1));
741 }
742
743 return out_node;
744}
745
746
747hnode_t* CommandStatus::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
755 hnode::Record* out_node = runtime::NewRecord(StrFromC("CommandStatus"));
756 List<Field*>* L = out_node->fields;
757
758 hnode_t* x0 = Alloc<hnode::Leaf>(this->check_errexit ? runtime::TRUE_STR :
759 runtime::FALSE_STR, color_e::OtherConst);
760 L->append(Alloc<Field>(StrFromC("check_errexit"), x0));
761
762 hnode_t* x1 = Alloc<hnode::Leaf>(this->show_code ? runtime::TRUE_STR :
763 runtime::FALSE_STR, color_e::OtherConst);
764 L->append(Alloc<Field>(StrFromC("show_code"), x1));
765
766 hnode_t* x2 = Alloc<hnode::Leaf>(this->pipe_negated ? runtime::TRUE_STR :
767 runtime::FALSE_STR, color_e::OtherConst);
768 L->append(Alloc<Field>(StrFromC("pipe_negated"), x2));
769
770 if (this->pipe_status != nullptr) { // List
771 hnode::Array* x3 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
772 for (ListIter<int> it(this->pipe_status); !it.Done(); it.Next()) {
773 int v_ = it.Value();
774 hnode_t* h = Alloc<hnode::Leaf>(str(v_), color_e::OtherConst);
775 x3->children->append(h);
776 }
777 L->append(Alloc<Field>(StrFromC("pipe_status"), x3));
778 }
779
780 if (this->pipe_locs != nullptr) { // List
781 hnode::Array* x4 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
782 for (ListIter<syntax_asdl::loc_t*> it(this->pipe_locs); !it.Done();
783 it.Next()) {
784 syntax_asdl::loc_t* v_ = it.Value();
785 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
786 color_e::OtherConst) : v_->PrettyTree(seen);
787 x4->children->append(h);
788 }
789 L->append(Alloc<Field>(StrFromC("pipe_locs"), x4));
790 }
791
792 return out_node;
793}
794
795BigStr* wait_status_str(int tag, bool dot) {
796 char buf[32];
797 const char* v = nullptr;
798 switch (tag) {
799 case wait_status_e::Proc:
800 v = "Proc"; break;
801 case wait_status_e::Pipeline:
802 v = "Pipeline"; break;
803 case wait_status_e::Cancelled:
804 v = "Cancelled"; break;
805 default:
806 assert(0);
807 }
808 if (dot) {
809 snprintf(buf, 32, "wait_status.%s", v);
810 return StrFromC(buf);
811 } else {
812 return StrFromC(v);
813 }
814}
815
816hnode_t* wait_status__Proc::PrettyTree(Dict<int, bool>* seen) {
817 seen = seen ? seen : Alloc<Dict<int, bool>>();
818 int heap_id = ObjectId(this);
819 if (dict_contains(seen, heap_id)) {
820 return Alloc<hnode::AlreadySeen>(heap_id);
821 }
822 seen->set(heap_id, true);
823
824 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
825 List<Field*>* L = out_node->fields;
826
827 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->code), color_e::OtherConst);
828 L->append(Alloc<Field>(StrFromC("code"), x0));
829
830 return out_node;
831}
832
833
834hnode_t* wait_status__Pipeline::PrettyTree(Dict<int, bool>* seen) {
835 seen = seen ? seen : Alloc<Dict<int, bool>>();
836 int heap_id = ObjectId(this);
837 if (dict_contains(seen, heap_id)) {
838 return Alloc<hnode::AlreadySeen>(heap_id);
839 }
840 seen->set(heap_id, true);
841
842 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
843 List<Field*>* L = out_node->fields;
844
845 if (this->codes != nullptr) { // List
846 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
847 for (ListIter<int> it(this->codes); !it.Done(); it.Next()) {
848 int v_ = it.Value();
849 hnode_t* h = Alloc<hnode::Leaf>(str(v_), color_e::OtherConst);
850 x0->children->append(h);
851 }
852 L->append(Alloc<Field>(StrFromC("codes"), x0));
853 }
854
855 return out_node;
856}
857
858
859hnode_t* wait_status__Cancelled::PrettyTree(Dict<int, bool>* seen) {
860 seen = seen ? seen : Alloc<Dict<int, bool>>();
861 int heap_id = ObjectId(this);
862 if (dict_contains(seen, heap_id)) {
863 return Alloc<hnode::AlreadySeen>(heap_id);
864 }
865 seen->set(heap_id, true);
866
867 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
868 List<Field*>* L = out_node->fields;
869
870 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->sig_num), color_e::OtherConst);
871 L->append(Alloc<Field>(StrFromC("sig_num"), x0));
872
873 return out_node;
874}
875
876
877hnode_t* wait_status_t::PrettyTree(Dict<int, bool>* seen) {
878 switch (this->tag()) {
879 case wait_status_e::Proc: {
880 wait_status__Proc* obj = static_cast<wait_status__Proc*>(this);
881 return obj->PrettyTree(seen);
882 }
883 case wait_status_e::Pipeline: {
884 wait_status__Pipeline* obj = static_cast<wait_status__Pipeline*>(this);
885 return obj->PrettyTree(seen);
886 }
887 case wait_status_e::Cancelled: {
888 wait_status__Cancelled* obj = static_cast<wait_status__Cancelled*>(this);
889 return obj->PrettyTree(seen);
890 }
891 default:
892 assert(0);
893 }
894}
895BigStr* flow_str(flow_e tag, bool dot) {
896 char buf[32];
897 const char* v = nullptr;
898 switch (tag) {
899 case flow_e::Nothing:
900 v = "Nothing"; break;
901 case flow_e::Break:
902 v = "Break"; break;
903 case flow_e::Raise:
904 v = "Raise"; break;
905 default:
906 assert(0);
907 }
908 if (dot) {
909 snprintf(buf, 32, "flow.%s", v);
910 return StrFromC(buf);
911 } else {
912 return StrFromC(v);
913 }
914}
915BigStr* span_str(span_e tag, bool dot) {
916 char buf[32];
917 const char* v = nullptr;
918 switch (tag) {
919 case span_e::Black:
920 v = "Black"; break;
921 case span_e::Delim:
922 v = "Delim"; break;
923 case span_e::Backslash:
924 v = "Backslash"; break;
925 default:
926 assert(0);
927 }
928 if (dot) {
929 snprintf(buf, 32, "span.%s", v);
930 return StrFromC(buf);
931 } else {
932 return StrFromC(v);
933 }
934}
935BigStr* emit_str(int tag, bool dot) {
936 char buf[32];
937 const char* v = nullptr;
938 switch (tag) {
939 case emit_i::Part:
940 v = "Part"; break;
941 case emit_i::Delim:
942 v = "Delim"; break;
943 case emit_i::Empty:
944 v = "Empty"; break;
945 case emit_i::Escape:
946 v = "Escape"; break;
947 case emit_i::Nothing:
948 v = "Nothing"; break;
949 default:
950 assert(0);
951 }
952 if (dot) {
953 snprintf(buf, 32, "emit.%s", v);
954 return StrFromC(buf);
955 } else {
956 return StrFromC(v);
957 }
958}
959BigStr* state_str(int tag, bool dot) {
960 char buf[32];
961 const char* v = nullptr;
962 switch (tag) {
963 case state_i::Invalid:
964 v = "Invalid"; break;
965 case state_i::Start:
966 v = "Start"; break;
967 case state_i::DE_White1:
968 v = "DE_White1"; break;
969 case state_i::DE_Gray:
970 v = "DE_Gray"; break;
971 case state_i::DE_White2:
972 v = "DE_White2"; break;
973 case state_i::Black:
974 v = "Black"; break;
975 case state_i::Backslash:
976 v = "Backslash"; break;
977 case state_i::Done:
978 v = "Done"; break;
979 default:
980 assert(0);
981 }
982 if (dot) {
983 snprintf(buf, 32, "state.%s", v);
984 return StrFromC(buf);
985 } else {
986 return StrFromC(v);
987 }
988}
989BigStr* char_kind_str(int tag, bool dot) {
990 char buf[32];
991 const char* v = nullptr;
992 switch (tag) {
993 case char_kind_i::DE_White:
994 v = "DE_White"; break;
995 case char_kind_i::DE_Gray:
996 v = "DE_Gray"; break;
997 case char_kind_i::Black:
998 v = "Black"; break;
999 case char_kind_i::Backslash:
1000 v = "Backslash"; break;
1001 case char_kind_i::Sentinel:
1002 v = "Sentinel"; break;
1003 default:
1004 assert(0);
1005 }
1006 if (dot) {
1007 snprintf(buf, 32, "char_kind.%s", v);
1008 return StrFromC(buf);
1009 } else {
1010 return StrFromC(v);
1011 }
1012}
1013BigStr* job_state_str(job_state_e tag, bool dot) {
1014 char buf[32];
1015 const char* v = nullptr;
1016 switch (tag) {
1017 case job_state_e::Running:
1018 v = "Running"; break;
1019 case job_state_e::Done:
1020 v = "Done"; break;
1021 case job_state_e::Stopped:
1022 v = "Stopped"; break;
1023 default:
1024 assert(0);
1025 }
1026 if (dot) {
1027 snprintf(buf, 32, "job_state.%s", v);
1028 return StrFromC(buf);
1029 } else {
1030 return StrFromC(v);
1031 }
1032}
1033BigStr* flag_type_str(flag_type_e tag, bool dot) {
1034 char buf[32];
1035 const char* v = nullptr;
1036 switch (tag) {
1037 case flag_type_e::Bool:
1038 v = "Bool"; break;
1039 case flag_type_e::Int:
1040 v = "Int"; break;
1041 case flag_type_e::Float:
1042 v = "Float"; break;
1043 case flag_type_e::Str:
1044 v = "Str"; break;
1045 default:
1046 assert(0);
1047 }
1048 if (dot) {
1049 snprintf(buf, 32, "flag_type.%s", v);
1050 return StrFromC(buf);
1051 } else {
1052 return StrFromC(v);
1053 }
1054}
1055BigStr* trace_str(int tag, bool dot) {
1056 char buf[32];
1057 const char* v = nullptr;
1058 switch (tag) {
1059 case trace_e::External:
1060 v = "External"; break;
1061 case trace_e::CommandSub:
1062 v = "CommandSub"; break;
1063 case trace_e::ForkWait:
1064 v = "ForkWait"; break;
1065 case trace_e::Fork:
1066 v = "Fork"; break;
1067 case trace_e::PipelinePart:
1068 v = "PipelinePart"; break;
1069 case trace_e::ProcessSub:
1070 v = "ProcessSub"; break;
1071 case trace_e::HereDoc:
1072 v = "HereDoc"; break;
1073 default:
1074 assert(0);
1075 }
1076 if (dot) {
1077 snprintf(buf, 32, "trace.%s", v);
1078 return StrFromC(buf);
1079 } else {
1080 return StrFromC(v);
1081 }
1082}
1083
1084trace__CommandSub* trace::CommandSub = &gtrace__CommandSub.obj;
1085
1086GcGlobal<trace__CommandSub> gtrace__CommandSub =
1087 { ObjHeader::Global(trace_e::CommandSub) };
1088
1089trace__ForkWait* trace::ForkWait = &gtrace__ForkWait.obj;
1090
1091GcGlobal<trace__ForkWait> gtrace__ForkWait =
1092 { ObjHeader::Global(trace_e::ForkWait) };
1093
1094trace__Fork* trace::Fork = &gtrace__Fork.obj;
1095
1096GcGlobal<trace__Fork> gtrace__Fork =
1097 { ObjHeader::Global(trace_e::Fork) };
1098
1099trace__PipelinePart* trace::PipelinePart = &gtrace__PipelinePart.obj;
1100
1101GcGlobal<trace__PipelinePart> gtrace__PipelinePart =
1102 { ObjHeader::Global(trace_e::PipelinePart) };
1103
1104trace__ProcessSub* trace::ProcessSub = &gtrace__ProcessSub.obj;
1105
1106GcGlobal<trace__ProcessSub> gtrace__ProcessSub =
1107 { ObjHeader::Global(trace_e::ProcessSub) };
1108
1109trace__HereDoc* trace::HereDoc = &gtrace__HereDoc.obj;
1110
1111GcGlobal<trace__HereDoc> gtrace__HereDoc =
1112 { ObjHeader::Global(trace_e::HereDoc) };
1113
1114hnode_t* trace__External::PrettyTree(Dict<int, bool>* seen) {
1115 seen = seen ? seen : Alloc<Dict<int, bool>>();
1116 int heap_id = ObjectId(this);
1117 if (dict_contains(seen, heap_id)) {
1118 return Alloc<hnode::AlreadySeen>(heap_id);
1119 }
1120 seen->set(heap_id, true);
1121
1122 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1123 List<Field*>* L = out_node->fields;
1124
1125 if (this->argv != nullptr) { // List
1126 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1127 for (ListIter<BigStr*> it(this->argv); !it.Done(); it.Next()) {
1128 BigStr* v_ = it.Value();
1129 hnode_t* h = runtime::NewLeaf(v_, color_e::StringConst);
1130 x0->children->append(h);
1131 }
1132 L->append(Alloc<Field>(StrFromC("argv"), x0));
1133 }
1134
1135 return out_node;
1136}
1137
1138
1139hnode_t* trace__CommandSub::PrettyTree(Dict<int, bool>* seen) {
1140 seen = seen ? seen : Alloc<Dict<int, bool>>();
1141 int heap_id = ObjectId(this);
1142 if (dict_contains(seen, heap_id)) {
1143 return Alloc<hnode::AlreadySeen>(heap_id);
1144 }
1145 seen->set(heap_id, true);
1146
1147 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1148 return out_node;
1149}
1150
1151
1152hnode_t* trace__ForkWait::PrettyTree(Dict<int, bool>* seen) {
1153 seen = seen ? seen : Alloc<Dict<int, bool>>();
1154 int heap_id = ObjectId(this);
1155 if (dict_contains(seen, heap_id)) {
1156 return Alloc<hnode::AlreadySeen>(heap_id);
1157 }
1158 seen->set(heap_id, true);
1159
1160 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1161 return out_node;
1162}
1163
1164
1165hnode_t* trace__Fork::PrettyTree(Dict<int, bool>* seen) {
1166 seen = seen ? seen : Alloc<Dict<int, bool>>();
1167 int heap_id = ObjectId(this);
1168 if (dict_contains(seen, heap_id)) {
1169 return Alloc<hnode::AlreadySeen>(heap_id);
1170 }
1171 seen->set(heap_id, true);
1172
1173 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1174 return out_node;
1175}
1176
1177
1178hnode_t* trace__PipelinePart::PrettyTree(Dict<int, bool>* seen) {
1179 seen = seen ? seen : Alloc<Dict<int, bool>>();
1180 int heap_id = ObjectId(this);
1181 if (dict_contains(seen, heap_id)) {
1182 return Alloc<hnode::AlreadySeen>(heap_id);
1183 }
1184 seen->set(heap_id, true);
1185
1186 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1187 return out_node;
1188}
1189
1190
1191hnode_t* trace__ProcessSub::PrettyTree(Dict<int, bool>* seen) {
1192 seen = seen ? seen : Alloc<Dict<int, bool>>();
1193 int heap_id = ObjectId(this);
1194 if (dict_contains(seen, heap_id)) {
1195 return Alloc<hnode::AlreadySeen>(heap_id);
1196 }
1197 seen->set(heap_id, true);
1198
1199 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1200 return out_node;
1201}
1202
1203
1204hnode_t* trace__HereDoc::PrettyTree(Dict<int, bool>* seen) {
1205 seen = seen ? seen : Alloc<Dict<int, bool>>();
1206 int heap_id = ObjectId(this);
1207 if (dict_contains(seen, heap_id)) {
1208 return Alloc<hnode::AlreadySeen>(heap_id);
1209 }
1210 seen->set(heap_id, true);
1211
1212 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1213 return out_node;
1214}
1215
1216
1217hnode_t* trace_t::PrettyTree(Dict<int, bool>* seen) {
1218 switch (this->tag()) {
1219 case trace_e::External: {
1220 trace__External* obj = static_cast<trace__External*>(this);
1221 return obj->PrettyTree(seen);
1222 }
1223 case trace_e::CommandSub: {
1224 trace__CommandSub* obj = static_cast<trace__CommandSub*>(this);
1225 return obj->PrettyTree(seen);
1226 }
1227 case trace_e::ForkWait: {
1228 trace__ForkWait* obj = static_cast<trace__ForkWait*>(this);
1229 return obj->PrettyTree(seen);
1230 }
1231 case trace_e::Fork: {
1232 trace__Fork* obj = static_cast<trace__Fork*>(this);
1233 return obj->PrettyTree(seen);
1234 }
1235 case trace_e::PipelinePart: {
1236 trace__PipelinePart* obj = static_cast<trace__PipelinePart*>(this);
1237 return obj->PrettyTree(seen);
1238 }
1239 case trace_e::ProcessSub: {
1240 trace__ProcessSub* obj = static_cast<trace__ProcessSub*>(this);
1241 return obj->PrettyTree(seen);
1242 }
1243 case trace_e::HereDoc: {
1244 trace__HereDoc* obj = static_cast<trace__HereDoc*>(this);
1245 return obj->PrettyTree(seen);
1246 }
1247 default:
1248 assert(0);
1249 }
1250}
1251BigStr* word_style_str(word_style_e tag, bool dot) {
1252 char buf[32];
1253 const char* v = nullptr;
1254 switch (tag) {
1255 case word_style_e::Expr:
1256 v = "Expr"; break;
1257 case word_style_e::Unquoted:
1258 v = "Unquoted"; break;
1259 case word_style_e::DQ:
1260 v = "DQ"; break;
1261 case word_style_e::SQ:
1262 v = "SQ"; break;
1263 default:
1264 assert(0);
1265 }
1266 if (dot) {
1267 snprintf(buf, 32, "word_style.%s", v);
1268 return StrFromC(buf);
1269 } else {
1270 return StrFromC(v);
1271 }
1272}
1273
1274hnode_t* HayNode::PrettyTree(Dict<int, bool>* seen) {
1275 seen = seen ? seen : Alloc<Dict<int, bool>>();
1276 int heap_id = ObjectId(this);
1277 if (dict_contains(seen, heap_id)) {
1278 return Alloc<hnode::AlreadySeen>(heap_id);
1279 }
1280 seen->set(heap_id, true);
1281
1282 hnode::Record* out_node = runtime::NewRecord(StrFromC("HayNode"));
1283 List<Field*>* L = out_node->fields;
1284
1285 if (this->children) { // Dict
1286 auto m = Alloc<hnode::Leaf>(StrFromC("Dict"), color_e::OtherConst);
1287 hnode::Array* x0 = Alloc<hnode::Array>(NewList<hnode_t*>({m}));
1288 for (DictIter<BigStr*, HayNode*> it(this->children); !it.Done(); it.Next())
1289 {
1290 auto k0 = it.Key();
1291 auto v0 = it.Value();
1292 x0->children->append(runtime::NewLeaf(k0, color_e::StringConst));
1293 x0->children->append(v0->PrettyTree(seen));
1294 }
1295 L->append(Alloc<Field>(StrFromC ("children"), x0));
1296 }
1297
1298 return out_node;
1299}
1300
1301BigStr* comp_action_str(comp_action_e tag, bool dot) {
1302 char buf[32];
1303 const char* v = nullptr;
1304 switch (tag) {
1305 case comp_action_e::Other:
1306 v = "Other"; break;
1307 case comp_action_e::FileSystem:
1308 v = "FileSystem"; break;
1309 case comp_action_e::BashFunc:
1310 v = "BashFunc"; break;
1311 default:
1312 assert(0);
1313 }
1314 if (dot) {
1315 snprintf(buf, 32, "comp_action.%s", v);
1316 return StrFromC(buf);
1317 } else {
1318 return StrFromC(v);
1319 }
1320}
1321
1322} // namespace runtime_asdl