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

1343 lines, 952 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(bool do_abbrev, 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 = ToPretty(this->var_name);
31 L->append(Alloc<Field>(StrFromC("var_name"), x0));
32
33 if (this->rval) { // Optional
34 hnode_t* x1 = this->rval->PrettyTree(do_abbrev, seen);
35 L->append(Alloc<Field>(StrFromC("rval"), x1));
36 }
37
38 hnode_t* x2 = ToPretty(this->plus_eq);
39 L->append(Alloc<Field>(StrFromC("plus_eq"), x2));
40
41 hnode_t* x3 = this->blame_word->PrettyTree(do_abbrev, seen);
42 L->append(Alloc<Field>(StrFromC("blame_word"), x3));
43
44 return out_node;
45}
46
47
48hnode_t* ProcArgs::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
49 seen = seen ? seen : Alloc<Dict<int, bool>>();
50 int heap_id = ObjectId(this);
51 if (dict_contains(seen, heap_id)) {
52 return Alloc<hnode::AlreadySeen>(heap_id);
53 }
54 seen->set(heap_id, true);
55
56 hnode::Record* out_node = runtime::NewRecord(StrFromC("ProcArgs"));
57 List<Field*>* L = out_node->fields;
58
59 hnode_t* x0 = this->typed_args->PrettyTree(do_abbrev, seen);
60 L->append(Alloc<Field>(StrFromC("typed_args"), x0));
61
62 if (this->pos_args != nullptr) { // List
63 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
64 for (ListIter<value_asdl::value_t*> it(this->pos_args); !it.Done();
65 it.Next()) {
66 value_asdl::value_t* v_ = it.Value();
67 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
68 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
69 x1->children->append(h);
70 }
71 L->append(Alloc<Field>(StrFromC("pos_args"), x1));
72 }
73
74 if (this->named_args != nullptr) { // Dict
75 auto* unnamed = NewList<hnode_t*>();
76 auto* hdict = Alloc<hnode::Record>(kEmptyString, StrFromC("{"),
77 StrFromC("}"),
78 NewList<Field*>(), unnamed);
79 for (DictIter<BigStr*, value_asdl::value_t*> it(this->named_args);
80 !it.Done(); it.Next()) {
81 auto k = it.Key();
82 auto v = it.Value();
83 unnamed->append(ToPretty(k));
84 unnamed->append(v->PrettyTree(do_abbrev, seen));
85 }
86 L->append(Alloc<Field>(StrFromC("named_args"), hdict));
87 }
88
89 if (this->block_arg) { // Optional
90 hnode_t* x3 = this->block_arg->PrettyTree(do_abbrev, seen);
91 L->append(Alloc<Field>(StrFromC("block_arg"), x3));
92 }
93
94 return out_node;
95}
96
97BigStr* cmd_value_str(int tag, bool dot) {
98 char buf[32];
99 const char* v = nullptr;
100 switch (tag) {
101 case cmd_value_e::Argv:
102 v = "Argv"; break;
103 case cmd_value_e::Assign:
104 v = "Assign"; break;
105 default:
106 assert(0);
107 }
108 if (dot) {
109 snprintf(buf, 32, "cmd_value.%s", v);
110 return StrFromC(buf);
111 } else {
112 return StrFromC(v);
113 }
114}
115
116hnode_t* cmd_value__Argv::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
117 seen = seen ? seen : Alloc<Dict<int, bool>>();
118 int heap_id = ObjectId(this);
119 if (dict_contains(seen, heap_id)) {
120 return Alloc<hnode::AlreadySeen>(heap_id);
121 }
122 seen->set(heap_id, true);
123
124 hnode::Record* out_node = runtime::NewRecord(cmd_value_str(this->tag()));
125 List<Field*>* L = out_node->fields;
126
127 if (this->argv != nullptr) { // List
128 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
129 for (ListIter<BigStr*> it(this->argv); !it.Done(); it.Next()) {
130 BigStr* v_ = it.Value();
131 hnode_t* h = ToPretty(v_);
132 x0->children->append(h);
133 }
134 L->append(Alloc<Field>(StrFromC("argv"), x0));
135 }
136
137 if (this->arg_locs != nullptr) { // List
138 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
139 for (ListIter<syntax_asdl::CompoundWord*> it(this->arg_locs); !it.Done();
140 it.Next()) {
141 syntax_asdl::CompoundWord* v_ = it.Value();
142 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
143 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
144 x1->children->append(h);
145 }
146 L->append(Alloc<Field>(StrFromC("arg_locs"), x1));
147 }
148
149 hnode_t* x2 = ToPretty(this->is_last_cmd);
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(do_abbrev, 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(do_abbrev, 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(bool do_abbrev, 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 = ToPretty(this->builtin_id);
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 = ToPretty(v_);
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(do_abbrev, 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(do_abbrev, 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(bool do_abbrev, 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(do_abbrev, seen);
222 }
223 case cmd_value_e::Assign: {
224 cmd_value__Assign* obj = static_cast<cmd_value__Assign*>(this);
225 return obj->PrettyTree(do_abbrev, seen);
226 }
227 default:
228 assert(0);
229 }
230}
231
232hnode_t* Piece::PrettyTree(bool do_abbrev, 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 = ToPretty(this->s);
244 L->append(Alloc<Field>(StrFromC("s"), x0));
245
246 hnode_t* x1 = ToPretty(this->quoted);
247 L->append(Alloc<Field>(StrFromC("quoted"), x1));
248
249 hnode_t* x2 = ToPretty(this->do_split);
250 L->append(Alloc<Field>(StrFromC("do_split"), x2));
251
252 return out_node;
253}
254
255BigStr* part_value_str(int tag, bool dot) {
256 char buf[32];
257 const char* v = nullptr;
258 switch (tag) {
259 case part_value_e::String:
260 v = "String"; break;
261 case part_value_e::Array:
262 v = "Array"; break;
263 case part_value_e::ExtGlob:
264 v = "ExtGlob"; break;
265 default:
266 assert(0);
267 }
268 if (dot) {
269 snprintf(buf, 32, "part_value.%s", v);
270 return StrFromC(buf);
271 } else {
272 return StrFromC(v);
273 }
274}
275
276hnode_t* part_value__Array::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
277 seen = seen ? seen : Alloc<Dict<int, bool>>();
278 int heap_id = ObjectId(this);
279 if (dict_contains(seen, heap_id)) {
280 return Alloc<hnode::AlreadySeen>(heap_id);
281 }
282 seen->set(heap_id, true);
283
284 hnode::Record* out_node = runtime::NewRecord(part_value_str(this->tag()));
285 List<Field*>* L = out_node->fields;
286
287 if (this->strs != nullptr) { // List
288 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
289 for (ListIter<BigStr*> it(this->strs); !it.Done(); it.Next()) {
290 BigStr* v_ = it.Value();
291 hnode_t* h = ToPretty(v_);
292 x0->children->append(h);
293 }
294 L->append(Alloc<Field>(StrFromC("strs"), x0));
295 }
296
297 return out_node;
298}
299
300
301hnode_t* part_value__ExtGlob::PrettyTree(bool do_abbrev, Dict<int, bool>* seen)
302 {
303 seen = seen ? seen : Alloc<Dict<int, bool>>();
304 int heap_id = ObjectId(this);
305 if (dict_contains(seen, heap_id)) {
306 return Alloc<hnode::AlreadySeen>(heap_id);
307 }
308 seen->set(heap_id, true);
309
310 hnode::Record* out_node = runtime::NewRecord(part_value_str(this->tag()));
311 List<Field*>* L = out_node->fields;
312
313 if (this->part_vals != nullptr) { // List
314 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
315 for (ListIter<part_value_t*> it(this->part_vals); !it.Done(); it.Next()) {
316 part_value_t* v_ = it.Value();
317 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
318 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
319 x0->children->append(h);
320 }
321 L->append(Alloc<Field>(StrFromC("part_vals"), x0));
322 }
323
324 return out_node;
325}
326
327
328hnode_t* part_value_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
329 switch (this->tag()) {
330 case part_value_e::String: {
331 Piece* obj = static_cast<Piece*>(this);
332 return obj->PrettyTree(do_abbrev, seen);
333 }
334 case part_value_e::Array: {
335 part_value__Array* obj = static_cast<part_value__Array*>(this);
336 return obj->PrettyTree(do_abbrev, seen);
337 }
338 case part_value_e::ExtGlob: {
339 part_value__ExtGlob* obj = static_cast<part_value__ExtGlob*>(this);
340 return obj->PrettyTree(do_abbrev, seen);
341 }
342 default:
343 assert(0);
344 }
345}
346BigStr* coerced_str(coerced_e tag, bool dot) {
347 char buf[32];
348 const char* v = nullptr;
349 switch (tag) {
350 case coerced_e::Int:
351 v = "Int"; break;
352 case coerced_e::Float:
353 v = "Float"; break;
354 case coerced_e::Neither:
355 v = "Neither"; break;
356 default:
357 assert(0);
358 }
359 if (dot) {
360 snprintf(buf, 32, "coerced.%s", v);
361 return StrFromC(buf);
362 } else {
363 return StrFromC(v);
364 }
365}
366
367hnode_t* VarSubState::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
368 seen = seen ? seen : Alloc<Dict<int, bool>>();
369 int heap_id = ObjectId(this);
370 if (dict_contains(seen, heap_id)) {
371 return Alloc<hnode::AlreadySeen>(heap_id);
372 }
373 seen->set(heap_id, true);
374
375 hnode::Record* out_node = runtime::NewRecord(StrFromC("VarSubState"));
376 List<Field*>* L = out_node->fields;
377
378 hnode_t* x0 = ToPretty(this->join_array);
379 L->append(Alloc<Field>(StrFromC("join_array"), x0));
380
381 hnode_t* x1 = ToPretty(this->is_type_query);
382 L->append(Alloc<Field>(StrFromC("is_type_query"), x1));
383
384 hnode_t* x2 = ToPretty(this->has_test_op);
385 L->append(Alloc<Field>(StrFromC("has_test_op"), x2));
386
387 hnode_t* x3 = ToPretty(this->has_nullary_op);
388 L->append(Alloc<Field>(StrFromC("has_nullary_op"), x3));
389
390 return out_node;
391}
392
393
394hnode_t* Cell::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
395 seen = seen ? seen : Alloc<Dict<int, bool>>();
396 int heap_id = ObjectId(this);
397 if (dict_contains(seen, heap_id)) {
398 return Alloc<hnode::AlreadySeen>(heap_id);
399 }
400 seen->set(heap_id, true);
401
402 hnode::Record* out_node = runtime::NewRecord(StrFromC("Cell"));
403 List<Field*>* L = out_node->fields;
404
405 hnode_t* x0 = ToPretty(this->exported);
406 L->append(Alloc<Field>(StrFromC("exported"), x0));
407
408 hnode_t* x1 = ToPretty(this->readonly);
409 L->append(Alloc<Field>(StrFromC("readonly"), x1));
410
411 hnode_t* x2 = ToPretty(this->nameref);
412 L->append(Alloc<Field>(StrFromC("nameref"), x2));
413
414 hnode_t* x3 = this->val->PrettyTree(do_abbrev, seen);
415 L->append(Alloc<Field>(StrFromC("val"), x3));
416
417 return out_node;
418}
419
420BigStr* scope_str(scope_e tag, bool dot) {
421 char buf[32];
422 const char* v = nullptr;
423 switch (tag) {
424 case scope_e::Shopt:
425 v = "Shopt"; break;
426 case scope_e::Dynamic:
427 v = "Dynamic"; break;
428 case scope_e::LocalOrGlobal:
429 v = "LocalOrGlobal"; break;
430 case scope_e::LocalOnly:
431 v = "LocalOnly"; break;
432 case scope_e::GlobalOnly:
433 v = "GlobalOnly"; break;
434 default:
435 assert(0);
436 }
437 if (dot) {
438 snprintf(buf, 32, "scope.%s", v);
439 return StrFromC(buf);
440 } else {
441 return StrFromC(v);
442 }
443}
444BigStr* a_index_str(int tag, bool dot) {
445 char buf[32];
446 const char* v = nullptr;
447 switch (tag) {
448 case a_index_e::Str:
449 v = "Str"; break;
450 case a_index_e::Int:
451 v = "Int"; break;
452 default:
453 assert(0);
454 }
455 if (dot) {
456 snprintf(buf, 32, "a_index.%s", v);
457 return StrFromC(buf);
458 } else {
459 return StrFromC(v);
460 }
461}
462
463hnode_t* a_index__Str::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
464 seen = seen ? seen : Alloc<Dict<int, bool>>();
465 int heap_id = ObjectId(this);
466 if (dict_contains(seen, heap_id)) {
467 return Alloc<hnode::AlreadySeen>(heap_id);
468 }
469 seen->set(heap_id, true);
470
471 hnode::Record* out_node = runtime::NewRecord(a_index_str(this->tag()));
472 List<Field*>* L = out_node->fields;
473
474 hnode_t* x0 = ToPretty(this->s);
475 L->append(Alloc<Field>(StrFromC("s"), x0));
476
477 return out_node;
478}
479
480
481hnode_t* a_index__Int::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
482 seen = seen ? seen : Alloc<Dict<int, bool>>();
483 int heap_id = ObjectId(this);
484 if (dict_contains(seen, heap_id)) {
485 return Alloc<hnode::AlreadySeen>(heap_id);
486 }
487 seen->set(heap_id, true);
488
489 hnode::Record* out_node = runtime::NewRecord(a_index_str(this->tag()));
490 List<Field*>* L = out_node->fields;
491
492 hnode_t* x0 = ToPretty(this->i);
493 L->append(Alloc<Field>(StrFromC("i"), x0));
494
495 return out_node;
496}
497
498
499hnode_t* a_index_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
500 switch (this->tag()) {
501 case a_index_e::Str: {
502 a_index__Str* obj = static_cast<a_index__Str*>(this);
503 return obj->PrettyTree(do_abbrev, seen);
504 }
505 case a_index_e::Int: {
506 a_index__Int* obj = static_cast<a_index__Int*>(this);
507 return obj->PrettyTree(do_abbrev, seen);
508 }
509 default:
510 assert(0);
511 }
512}
513
514hnode_t* VTestPlace::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
515 seen = seen ? seen : Alloc<Dict<int, bool>>();
516 int heap_id = ObjectId(this);
517 if (dict_contains(seen, heap_id)) {
518 return Alloc<hnode::AlreadySeen>(heap_id);
519 }
520 seen->set(heap_id, true);
521
522 hnode::Record* out_node = runtime::NewRecord(StrFromC("VTestPlace"));
523 List<Field*>* L = out_node->fields;
524
525 if (this->name) { // Optional
526 hnode_t* x0 = ToPretty(this->name);
527 L->append(Alloc<Field>(StrFromC("name"), x0));
528 }
529
530 if (this->index) { // Optional
531 hnode_t* x1 = this->index->PrettyTree(do_abbrev, seen);
532 L->append(Alloc<Field>(StrFromC("index"), x1));
533 }
534
535 return out_node;
536}
537
538BigStr* redirect_arg_str(int tag, bool dot) {
539 char buf[32];
540 const char* v = nullptr;
541 switch (tag) {
542 case redirect_arg_e::Path:
543 v = "Path"; break;
544 case redirect_arg_e::CopyFd:
545 v = "CopyFd"; break;
546 case redirect_arg_e::MoveFd:
547 v = "MoveFd"; break;
548 case redirect_arg_e::CloseFd:
549 v = "CloseFd"; break;
550 case redirect_arg_e::HereDoc:
551 v = "HereDoc"; break;
552 default:
553 assert(0);
554 }
555 if (dot) {
556 snprintf(buf, 32, "redirect_arg.%s", v);
557 return StrFromC(buf);
558 } else {
559 return StrFromC(v);
560 }
561}
562
563redirect_arg__CloseFd* redirect_arg::CloseFd = &gredirect_arg__CloseFd.obj;
564
565GcGlobal<redirect_arg__CloseFd> gredirect_arg__CloseFd =
566 { ObjHeader::Global(redirect_arg_e::CloseFd) };
567
568hnode_t* redirect_arg__Path::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
569 seen = seen ? seen : Alloc<Dict<int, bool>>();
570 int heap_id = ObjectId(this);
571 if (dict_contains(seen, heap_id)) {
572 return Alloc<hnode::AlreadySeen>(heap_id);
573 }
574 seen->set(heap_id, true);
575
576 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
577 List<Field*>* L = out_node->fields;
578
579 hnode_t* x0 = ToPretty(this->filename);
580 L->append(Alloc<Field>(StrFromC("filename"), x0));
581
582 return out_node;
583}
584
585
586hnode_t* redirect_arg__CopyFd::PrettyTree(bool do_abbrev, Dict<int, bool>*
587 seen) {
588 seen = seen ? seen : Alloc<Dict<int, bool>>();
589 int heap_id = ObjectId(this);
590 if (dict_contains(seen, heap_id)) {
591 return Alloc<hnode::AlreadySeen>(heap_id);
592 }
593 seen->set(heap_id, true);
594
595 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
596 List<Field*>* L = out_node->fields;
597
598 hnode_t* x0 = ToPretty(this->target_fd);
599 L->append(Alloc<Field>(StrFromC("target_fd"), x0));
600
601 return out_node;
602}
603
604
605hnode_t* redirect_arg__MoveFd::PrettyTree(bool do_abbrev, Dict<int, bool>*
606 seen) {
607 seen = seen ? seen : Alloc<Dict<int, bool>>();
608 int heap_id = ObjectId(this);
609 if (dict_contains(seen, heap_id)) {
610 return Alloc<hnode::AlreadySeen>(heap_id);
611 }
612 seen->set(heap_id, true);
613
614 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
615 List<Field*>* L = out_node->fields;
616
617 hnode_t* x0 = ToPretty(this->target_fd);
618 L->append(Alloc<Field>(StrFromC("target_fd"), x0));
619
620 return out_node;
621}
622
623
624hnode_t* redirect_arg__CloseFd::PrettyTree(bool do_abbrev, Dict<int, bool>*
625 seen) {
626 seen = seen ? seen : Alloc<Dict<int, bool>>();
627 int heap_id = ObjectId(this);
628 if (dict_contains(seen, heap_id)) {
629 return Alloc<hnode::AlreadySeen>(heap_id);
630 }
631 seen->set(heap_id, true);
632
633 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
634 return out_node;
635}
636
637
638hnode_t* redirect_arg__HereDoc::PrettyTree(bool do_abbrev, Dict<int, bool>*
639 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 = ToPretty(this->body);
651 L->append(Alloc<Field>(StrFromC("body"), x0));
652
653 return out_node;
654}
655
656
657hnode_t* redirect_arg_t::PrettyTree(bool do_abbrev, 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(do_abbrev, seen);
662 }
663 case redirect_arg_e::CopyFd: {
664 redirect_arg__CopyFd* obj = static_cast<redirect_arg__CopyFd*>(this);
665 return obj->PrettyTree(do_abbrev, seen);
666 }
667 case redirect_arg_e::MoveFd: {
668 redirect_arg__MoveFd* obj = static_cast<redirect_arg__MoveFd*>(this);
669 return obj->PrettyTree(do_abbrev, seen);
670 }
671 case redirect_arg_e::CloseFd: {
672 redirect_arg__CloseFd* obj = static_cast<redirect_arg__CloseFd*>(this);
673 return obj->PrettyTree(do_abbrev, seen);
674 }
675 case redirect_arg_e::HereDoc: {
676 redirect_arg__HereDoc* obj = static_cast<redirect_arg__HereDoc*>(this);
677 return obj->PrettyTree(do_abbrev, seen);
678 }
679 default:
680 assert(0);
681 }
682}
683
684hnode_t* RedirValue::PrettyTree(bool do_abbrev, 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, false),
696 color_e::UserType);
697 L->append(Alloc<Field>(StrFromC("op_id"), x0));
698
699 hnode_t* x1 = this->op_loc->PrettyTree(do_abbrev, seen);
700 L->append(Alloc<Field>(StrFromC("op_loc"), x1));
701
702 hnode_t* x2 = this->loc->PrettyTree(do_abbrev, seen);
703 L->append(Alloc<Field>(StrFromC("loc"), x2));
704
705 hnode_t* x3 = this->arg->PrettyTree(do_abbrev, seen);
706 L->append(Alloc<Field>(StrFromC("arg"), x3));
707
708 return out_node;
709}
710
711
712hnode_t* StatusArray::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
713 seen = seen ? seen : Alloc<Dict<int, bool>>();
714 int heap_id = ObjectId(this);
715 if (dict_contains(seen, heap_id)) {
716 return Alloc<hnode::AlreadySeen>(heap_id);
717 }
718 seen->set(heap_id, true);
719
720 hnode::Record* out_node = runtime::NewRecord(StrFromC("StatusArray"));
721 List<Field*>* L = out_node->fields;
722
723 if (this->codes != nullptr) { // List
724 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
725 for (ListIter<int> it(this->codes); !it.Done(); it.Next()) {
726 int v_ = it.Value();
727 hnode_t* h = ToPretty(v_);
728 x0->children->append(h);
729 }
730 L->append(Alloc<Field>(StrFromC("codes"), x0));
731 }
732
733 if (this->locs != nullptr) { // List
734 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
735 for (ListIter<syntax_asdl::loc_t*> it(this->locs); !it.Done(); it.Next()) {
736 syntax_asdl::loc_t* v_ = it.Value();
737 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
738 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
739 x1->children->append(h);
740 }
741 L->append(Alloc<Field>(StrFromC("locs"), x1));
742 }
743
744 return out_node;
745}
746
747
748hnode_t* CommandStatus::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
749 seen = seen ? seen : Alloc<Dict<int, bool>>();
750 int heap_id = ObjectId(this);
751 if (dict_contains(seen, heap_id)) {
752 return Alloc<hnode::AlreadySeen>(heap_id);
753 }
754 seen->set(heap_id, true);
755
756 hnode::Record* out_node = runtime::NewRecord(StrFromC("CommandStatus"));
757 List<Field*>* L = out_node->fields;
758
759 hnode_t* x0 = ToPretty(this->check_errexit);
760 L->append(Alloc<Field>(StrFromC("check_errexit"), x0));
761
762 hnode_t* x1 = ToPretty(this->show_code);
763 L->append(Alloc<Field>(StrFromC("show_code"), x1));
764
765 hnode_t* x2 = ToPretty(this->pipe_negated);
766 L->append(Alloc<Field>(StrFromC("pipe_negated"), x2));
767
768 if (this->pipe_status != nullptr) { // List
769 hnode::Array* x3 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
770 for (ListIter<int> it(this->pipe_status); !it.Done(); it.Next()) {
771 int v_ = it.Value();
772 hnode_t* h = ToPretty(v_);
773 x3->children->append(h);
774 }
775 L->append(Alloc<Field>(StrFromC("pipe_status"), x3));
776 }
777
778 if (this->pipe_locs != nullptr) { // List
779 hnode::Array* x4 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
780 for (ListIter<syntax_asdl::loc_t*> it(this->pipe_locs); !it.Done();
781 it.Next()) {
782 syntax_asdl::loc_t* v_ = it.Value();
783 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
784 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
785 x4->children->append(h);
786 }
787 L->append(Alloc<Field>(StrFromC("pipe_locs"), x4));
788 }
789
790 return out_node;
791}
792
793BigStr* wait_status_str(int tag, bool dot) {
794 char buf[32];
795 const char* v = nullptr;
796 switch (tag) {
797 case wait_status_e::Proc:
798 v = "Proc"; break;
799 case wait_status_e::Pipeline:
800 v = "Pipeline"; break;
801 case wait_status_e::Cancelled:
802 v = "Cancelled"; break;
803 default:
804 assert(0);
805 }
806 if (dot) {
807 snprintf(buf, 32, "wait_status.%s", v);
808 return StrFromC(buf);
809 } else {
810 return StrFromC(v);
811 }
812}
813
814hnode_t* wait_status__Proc::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
815 seen = seen ? seen : Alloc<Dict<int, bool>>();
816 int heap_id = ObjectId(this);
817 if (dict_contains(seen, heap_id)) {
818 return Alloc<hnode::AlreadySeen>(heap_id);
819 }
820 seen->set(heap_id, true);
821
822 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
823 List<Field*>* L = out_node->fields;
824
825 hnode_t* x0 = ToPretty(this->code);
826 L->append(Alloc<Field>(StrFromC("code"), x0));
827
828 return out_node;
829}
830
831
832hnode_t* wait_status__Pipeline::PrettyTree(bool do_abbrev, Dict<int, bool>*
833 seen) {
834 seen = seen ? seen : Alloc<Dict<int, bool>>();
835 int heap_id = ObjectId(this);
836 if (dict_contains(seen, heap_id)) {
837 return Alloc<hnode::AlreadySeen>(heap_id);
838 }
839 seen->set(heap_id, true);
840
841 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
842 List<Field*>* L = out_node->fields;
843
844 if (this->codes != nullptr) { // List
845 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
846 for (ListIter<int> it(this->codes); !it.Done(); it.Next()) {
847 int v_ = it.Value();
848 hnode_t* h = ToPretty(v_);
849 x0->children->append(h);
850 }
851 L->append(Alloc<Field>(StrFromC("codes"), x0));
852 }
853
854 return out_node;
855}
856
857
858hnode_t* wait_status__Cancelled::PrettyTree(bool do_abbrev, Dict<int, bool>*
859 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 = ToPretty(this->sig_num);
871 L->append(Alloc<Field>(StrFromC("sig_num"), x0));
872
873 return out_node;
874}
875
876
877hnode_t* wait_status_t::PrettyTree(bool do_abbrev, 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(do_abbrev, seen);
882 }
883 case wait_status_e::Pipeline: {
884 wait_status__Pipeline* obj = static_cast<wait_status__Pipeline*>(this);
885 return obj->PrettyTree(do_abbrev, seen);
886 }
887 case wait_status_e::Cancelled: {
888 wait_status__Cancelled* obj = static_cast<wait_status__Cancelled*>(this);
889 return obj->PrettyTree(do_abbrev, 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* error_code_str(error_code_e tag, bool dot) {
1034 char buf[32];
1035 const char* v = nullptr;
1036 switch (tag) {
1037 case error_code_e::OK:
1038 v = "OK"; break;
1039 case error_code_e::IndexOutOfRange:
1040 v = "IndexOutOfRange"; break;
1041 default:
1042 assert(0);
1043 }
1044 if (dot) {
1045 snprintf(buf, 32, "error_code.%s", v);
1046 return StrFromC(buf);
1047 } else {
1048 return StrFromC(v);
1049 }
1050}
1051BigStr* flag_type_str(flag_type_e tag, bool dot) {
1052 char buf[32];
1053 const char* v = nullptr;
1054 switch (tag) {
1055 case flag_type_e::Bool:
1056 v = "Bool"; break;
1057 case flag_type_e::Int:
1058 v = "Int"; break;
1059 case flag_type_e::Float:
1060 v = "Float"; break;
1061 case flag_type_e::Str:
1062 v = "Str"; break;
1063 default:
1064 assert(0);
1065 }
1066 if (dot) {
1067 snprintf(buf, 32, "flag_type.%s", v);
1068 return StrFromC(buf);
1069 } else {
1070 return StrFromC(v);
1071 }
1072}
1073BigStr* trace_str(int tag, bool dot) {
1074 char buf[32];
1075 const char* v = nullptr;
1076 switch (tag) {
1077 case trace_e::External:
1078 v = "External"; break;
1079 case trace_e::CommandSub:
1080 v = "CommandSub"; break;
1081 case trace_e::ForkWait:
1082 v = "ForkWait"; break;
1083 case trace_e::Fork:
1084 v = "Fork"; break;
1085 case trace_e::PipelinePart:
1086 v = "PipelinePart"; break;
1087 case trace_e::ProcessSub:
1088 v = "ProcessSub"; break;
1089 case trace_e::HereDoc:
1090 v = "HereDoc"; break;
1091 default:
1092 assert(0);
1093 }
1094 if (dot) {
1095 snprintf(buf, 32, "trace.%s", v);
1096 return StrFromC(buf);
1097 } else {
1098 return StrFromC(v);
1099 }
1100}
1101
1102trace__CommandSub* trace::CommandSub = &gtrace__CommandSub.obj;
1103
1104GcGlobal<trace__CommandSub> gtrace__CommandSub =
1105 { ObjHeader::Global(trace_e::CommandSub) };
1106
1107trace__ForkWait* trace::ForkWait = &gtrace__ForkWait.obj;
1108
1109GcGlobal<trace__ForkWait> gtrace__ForkWait =
1110 { ObjHeader::Global(trace_e::ForkWait) };
1111
1112trace__Fork* trace::Fork = &gtrace__Fork.obj;
1113
1114GcGlobal<trace__Fork> gtrace__Fork =
1115 { ObjHeader::Global(trace_e::Fork) };
1116
1117trace__PipelinePart* trace::PipelinePart = &gtrace__PipelinePart.obj;
1118
1119GcGlobal<trace__PipelinePart> gtrace__PipelinePart =
1120 { ObjHeader::Global(trace_e::PipelinePart) };
1121
1122trace__ProcessSub* trace::ProcessSub = &gtrace__ProcessSub.obj;
1123
1124GcGlobal<trace__ProcessSub> gtrace__ProcessSub =
1125 { ObjHeader::Global(trace_e::ProcessSub) };
1126
1127trace__HereDoc* trace::HereDoc = &gtrace__HereDoc.obj;
1128
1129GcGlobal<trace__HereDoc> gtrace__HereDoc =
1130 { ObjHeader::Global(trace_e::HereDoc) };
1131
1132hnode_t* trace__External::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1133 seen = seen ? seen : Alloc<Dict<int, bool>>();
1134 int heap_id = ObjectId(this);
1135 if (dict_contains(seen, heap_id)) {
1136 return Alloc<hnode::AlreadySeen>(heap_id);
1137 }
1138 seen->set(heap_id, true);
1139
1140 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1141 List<Field*>* L = out_node->fields;
1142
1143 if (this->argv != nullptr) { // List
1144 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1145 for (ListIter<BigStr*> it(this->argv); !it.Done(); it.Next()) {
1146 BigStr* v_ = it.Value();
1147 hnode_t* h = ToPretty(v_);
1148 x0->children->append(h);
1149 }
1150 L->append(Alloc<Field>(StrFromC("argv"), x0));
1151 }
1152
1153 return out_node;
1154}
1155
1156
1157hnode_t* trace__CommandSub::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1158 seen = seen ? seen : Alloc<Dict<int, bool>>();
1159 int heap_id = ObjectId(this);
1160 if (dict_contains(seen, heap_id)) {
1161 return Alloc<hnode::AlreadySeen>(heap_id);
1162 }
1163 seen->set(heap_id, true);
1164
1165 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1166 return out_node;
1167}
1168
1169
1170hnode_t* trace__ForkWait::PrettyTree(bool do_abbrev, 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(trace_str(this->tag()));
1179 return out_node;
1180}
1181
1182
1183hnode_t* trace__Fork::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1184 seen = seen ? seen : Alloc<Dict<int, bool>>();
1185 int heap_id = ObjectId(this);
1186 if (dict_contains(seen, heap_id)) {
1187 return Alloc<hnode::AlreadySeen>(heap_id);
1188 }
1189 seen->set(heap_id, true);
1190
1191 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1192 return out_node;
1193}
1194
1195
1196hnode_t* trace__PipelinePart::PrettyTree(bool do_abbrev, Dict<int, bool>* seen)
1197 {
1198 seen = seen ? seen : Alloc<Dict<int, bool>>();
1199 int heap_id = ObjectId(this);
1200 if (dict_contains(seen, heap_id)) {
1201 return Alloc<hnode::AlreadySeen>(heap_id);
1202 }
1203 seen->set(heap_id, true);
1204
1205 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1206 return out_node;
1207}
1208
1209
1210hnode_t* trace__ProcessSub::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1211 seen = seen ? seen : Alloc<Dict<int, bool>>();
1212 int heap_id = ObjectId(this);
1213 if (dict_contains(seen, heap_id)) {
1214 return Alloc<hnode::AlreadySeen>(heap_id);
1215 }
1216 seen->set(heap_id, true);
1217
1218 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1219 return out_node;
1220}
1221
1222
1223hnode_t* trace__HereDoc::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1224 seen = seen ? seen : Alloc<Dict<int, bool>>();
1225 int heap_id = ObjectId(this);
1226 if (dict_contains(seen, heap_id)) {
1227 return Alloc<hnode::AlreadySeen>(heap_id);
1228 }
1229 seen->set(heap_id, true);
1230
1231 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1232 return out_node;
1233}
1234
1235
1236hnode_t* trace_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1237 switch (this->tag()) {
1238 case trace_e::External: {
1239 trace__External* obj = static_cast<trace__External*>(this);
1240 return obj->PrettyTree(do_abbrev, seen);
1241 }
1242 case trace_e::CommandSub: {
1243 trace__CommandSub* obj = static_cast<trace__CommandSub*>(this);
1244 return obj->PrettyTree(do_abbrev, seen);
1245 }
1246 case trace_e::ForkWait: {
1247 trace__ForkWait* obj = static_cast<trace__ForkWait*>(this);
1248 return obj->PrettyTree(do_abbrev, seen);
1249 }
1250 case trace_e::Fork: {
1251 trace__Fork* obj = static_cast<trace__Fork*>(this);
1252 return obj->PrettyTree(do_abbrev, seen);
1253 }
1254 case trace_e::PipelinePart: {
1255 trace__PipelinePart* obj = static_cast<trace__PipelinePart*>(this);
1256 return obj->PrettyTree(do_abbrev, seen);
1257 }
1258 case trace_e::ProcessSub: {
1259 trace__ProcessSub* obj = static_cast<trace__ProcessSub*>(this);
1260 return obj->PrettyTree(do_abbrev, seen);
1261 }
1262 case trace_e::HereDoc: {
1263 trace__HereDoc* obj = static_cast<trace__HereDoc*>(this);
1264 return obj->PrettyTree(do_abbrev, seen);
1265 }
1266 default:
1267 assert(0);
1268 }
1269}
1270BigStr* word_style_str(word_style_e tag, bool dot) {
1271 char buf[32];
1272 const char* v = nullptr;
1273 switch (tag) {
1274 case word_style_e::Expr:
1275 v = "Expr"; break;
1276 case word_style_e::Unquoted:
1277 v = "Unquoted"; break;
1278 case word_style_e::DQ:
1279 v = "DQ"; break;
1280 case word_style_e::SQ:
1281 v = "SQ"; break;
1282 default:
1283 assert(0);
1284 }
1285 if (dot) {
1286 snprintf(buf, 32, "word_style.%s", v);
1287 return StrFromC(buf);
1288 } else {
1289 return StrFromC(v);
1290 }
1291}
1292
1293hnode_t* HayNode::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1294 seen = seen ? seen : Alloc<Dict<int, bool>>();
1295 int heap_id = ObjectId(this);
1296 if (dict_contains(seen, heap_id)) {
1297 return Alloc<hnode::AlreadySeen>(heap_id);
1298 }
1299 seen->set(heap_id, true);
1300
1301 hnode::Record* out_node = runtime::NewRecord(StrFromC("HayNode"));
1302 List<Field*>* L = out_node->fields;
1303
1304 if (this->children != nullptr) { // Dict
1305 auto* unnamed = NewList<hnode_t*>();
1306 auto* hdict = Alloc<hnode::Record>(kEmptyString, StrFromC("{"),
1307 StrFromC("}"),
1308 NewList<Field*>(), unnamed);
1309 for (DictIter<BigStr*, HayNode*> it(this->children); !it.Done(); it.Next())
1310 {
1311 auto k = it.Key();
1312 auto v = it.Value();
1313 unnamed->append(ToPretty(k));
1314 unnamed->append(v->PrettyTree(do_abbrev, seen));
1315 }
1316 L->append(Alloc<Field>(StrFromC("children"), hdict));
1317 }
1318
1319 return out_node;
1320}
1321
1322BigStr* comp_action_str(comp_action_e tag, bool dot) {
1323 char buf[32];
1324 const char* v = nullptr;
1325 switch (tag) {
1326 case comp_action_e::Other:
1327 v = "Other"; break;
1328 case comp_action_e::FileSystem:
1329 v = "FileSystem"; break;
1330 case comp_action_e::BashFunc:
1331 v = "BashFunc"; break;
1332 default:
1333 assert(0);
1334 }
1335 if (dot) {
1336 snprintf(buf, 32, "comp_action.%s", v);
1337 return StrFromC(buf);
1338 } else {
1339 return StrFromC(v);
1340 }
1341}
1342
1343} // namespace runtime_asdl