OILS / _gen / core / runtime.asdl.cc View on Github | oils.pub

1340 lines, 950 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 = this->h_value->PrettyTree(do_abbrev, seen);
382 L->append(Alloc<Field>(StrFromC("h_value"), x1));
383
384 hnode_t* x2 = this->array_ref->PrettyTree(do_abbrev, seen);
385 L->append(Alloc<Field>(StrFromC("array_ref"), x2));
386
387 return out_node;
388}
389
390
391hnode_t* Cell::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
392 seen = seen ? seen : Alloc<Dict<int, bool>>();
393 int heap_id = ObjectId(this);
394 if (dict_contains(seen, heap_id)) {
395 return Alloc<hnode::AlreadySeen>(heap_id);
396 }
397 seen->set(heap_id, true);
398
399 hnode::Record* out_node = runtime::NewRecord(StrFromC("Cell"));
400 List<Field*>* L = out_node->fields;
401
402 hnode_t* x0 = ToPretty(this->exported);
403 L->append(Alloc<Field>(StrFromC("exported"), x0));
404
405 hnode_t* x1 = ToPretty(this->readonly);
406 L->append(Alloc<Field>(StrFromC("readonly"), x1));
407
408 hnode_t* x2 = ToPretty(this->nameref);
409 L->append(Alloc<Field>(StrFromC("nameref"), x2));
410
411 hnode_t* x3 = this->val->PrettyTree(do_abbrev, seen);
412 L->append(Alloc<Field>(StrFromC("val"), x3));
413
414 return out_node;
415}
416
417BigStr* scope_str(scope_e tag, bool dot) {
418 char buf[32];
419 const char* v = nullptr;
420 switch (tag) {
421 case scope_e::Shopt:
422 v = "Shopt"; break;
423 case scope_e::Dynamic:
424 v = "Dynamic"; break;
425 case scope_e::LocalOrGlobal:
426 v = "LocalOrGlobal"; break;
427 case scope_e::LocalOnly:
428 v = "LocalOnly"; break;
429 case scope_e::GlobalOnly:
430 v = "GlobalOnly"; break;
431 default:
432 assert(0);
433 }
434 if (dot) {
435 snprintf(buf, 32, "scope.%s", v);
436 return StrFromC(buf);
437 } else {
438 return StrFromC(v);
439 }
440}
441BigStr* a_index_str(int tag, bool dot) {
442 char buf[32];
443 const char* v = nullptr;
444 switch (tag) {
445 case a_index_e::Str:
446 v = "Str"; break;
447 case a_index_e::Int:
448 v = "Int"; break;
449 default:
450 assert(0);
451 }
452 if (dot) {
453 snprintf(buf, 32, "a_index.%s", v);
454 return StrFromC(buf);
455 } else {
456 return StrFromC(v);
457 }
458}
459
460hnode_t* a_index__Str::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
461 seen = seen ? seen : Alloc<Dict<int, bool>>();
462 int heap_id = ObjectId(this);
463 if (dict_contains(seen, heap_id)) {
464 return Alloc<hnode::AlreadySeen>(heap_id);
465 }
466 seen->set(heap_id, true);
467
468 hnode::Record* out_node = runtime::NewRecord(a_index_str(this->tag()));
469 List<Field*>* L = out_node->fields;
470
471 hnode_t* x0 = ToPretty(this->s);
472 L->append(Alloc<Field>(StrFromC("s"), x0));
473
474 return out_node;
475}
476
477
478hnode_t* a_index__Int::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
479 seen = seen ? seen : Alloc<Dict<int, bool>>();
480 int heap_id = ObjectId(this);
481 if (dict_contains(seen, heap_id)) {
482 return Alloc<hnode::AlreadySeen>(heap_id);
483 }
484 seen->set(heap_id, true);
485
486 hnode::Record* out_node = runtime::NewRecord(a_index_str(this->tag()));
487 List<Field*>* L = out_node->fields;
488
489 hnode_t* x0 = ToPretty(this->i);
490 L->append(Alloc<Field>(StrFromC("i"), x0));
491
492 return out_node;
493}
494
495
496hnode_t* a_index_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
497 switch (this->tag()) {
498 case a_index_e::Str: {
499 a_index__Str* obj = static_cast<a_index__Str*>(this);
500 return obj->PrettyTree(do_abbrev, seen);
501 }
502 case a_index_e::Int: {
503 a_index__Int* obj = static_cast<a_index__Int*>(this);
504 return obj->PrettyTree(do_abbrev, seen);
505 }
506 default:
507 assert(0);
508 }
509}
510
511hnode_t* VTestPlace::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
512 seen = seen ? seen : Alloc<Dict<int, bool>>();
513 int heap_id = ObjectId(this);
514 if (dict_contains(seen, heap_id)) {
515 return Alloc<hnode::AlreadySeen>(heap_id);
516 }
517 seen->set(heap_id, true);
518
519 hnode::Record* out_node = runtime::NewRecord(StrFromC("VTestPlace"));
520 List<Field*>* L = out_node->fields;
521
522 if (this->name) { // Optional
523 hnode_t* x0 = ToPretty(this->name);
524 L->append(Alloc<Field>(StrFromC("name"), x0));
525 }
526
527 if (this->index) { // Optional
528 hnode_t* x1 = this->index->PrettyTree(do_abbrev, seen);
529 L->append(Alloc<Field>(StrFromC("index"), x1));
530 }
531
532 return out_node;
533}
534
535BigStr* redirect_arg_str(int tag, bool dot) {
536 char buf[32];
537 const char* v = nullptr;
538 switch (tag) {
539 case redirect_arg_e::Path:
540 v = "Path"; break;
541 case redirect_arg_e::CopyFd:
542 v = "CopyFd"; break;
543 case redirect_arg_e::MoveFd:
544 v = "MoveFd"; break;
545 case redirect_arg_e::CloseFd:
546 v = "CloseFd"; break;
547 case redirect_arg_e::HereDoc:
548 v = "HereDoc"; break;
549 default:
550 assert(0);
551 }
552 if (dot) {
553 snprintf(buf, 32, "redirect_arg.%s", v);
554 return StrFromC(buf);
555 } else {
556 return StrFromC(v);
557 }
558}
559
560redirect_arg__CloseFd* redirect_arg::CloseFd = &gredirect_arg__CloseFd.obj;
561
562GcGlobal<redirect_arg__CloseFd> gredirect_arg__CloseFd =
563 { ObjHeader::Global(redirect_arg_e::CloseFd) };
564
565hnode_t* redirect_arg__Path::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
566 seen = seen ? seen : Alloc<Dict<int, bool>>();
567 int heap_id = ObjectId(this);
568 if (dict_contains(seen, heap_id)) {
569 return Alloc<hnode::AlreadySeen>(heap_id);
570 }
571 seen->set(heap_id, true);
572
573 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
574 List<Field*>* L = out_node->fields;
575
576 hnode_t* x0 = ToPretty(this->filename);
577 L->append(Alloc<Field>(StrFromC("filename"), x0));
578
579 return out_node;
580}
581
582
583hnode_t* redirect_arg__CopyFd::PrettyTree(bool do_abbrev, Dict<int, bool>*
584 seen) {
585 seen = seen ? seen : Alloc<Dict<int, bool>>();
586 int heap_id = ObjectId(this);
587 if (dict_contains(seen, heap_id)) {
588 return Alloc<hnode::AlreadySeen>(heap_id);
589 }
590 seen->set(heap_id, true);
591
592 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
593 List<Field*>* L = out_node->fields;
594
595 hnode_t* x0 = ToPretty(this->target_fd);
596 L->append(Alloc<Field>(StrFromC("target_fd"), x0));
597
598 return out_node;
599}
600
601
602hnode_t* redirect_arg__MoveFd::PrettyTree(bool do_abbrev, Dict<int, bool>*
603 seen) {
604 seen = seen ? seen : Alloc<Dict<int, bool>>();
605 int heap_id = ObjectId(this);
606 if (dict_contains(seen, heap_id)) {
607 return Alloc<hnode::AlreadySeen>(heap_id);
608 }
609 seen->set(heap_id, true);
610
611 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
612 List<Field*>* L = out_node->fields;
613
614 hnode_t* x0 = ToPretty(this->target_fd);
615 L->append(Alloc<Field>(StrFromC("target_fd"), x0));
616
617 return out_node;
618}
619
620
621hnode_t* redirect_arg__CloseFd::PrettyTree(bool do_abbrev, Dict<int, bool>*
622 seen) {
623 seen = seen ? seen : Alloc<Dict<int, bool>>();
624 int heap_id = ObjectId(this);
625 if (dict_contains(seen, heap_id)) {
626 return Alloc<hnode::AlreadySeen>(heap_id);
627 }
628 seen->set(heap_id, true);
629
630 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
631 return out_node;
632}
633
634
635hnode_t* redirect_arg__HereDoc::PrettyTree(bool do_abbrev, Dict<int, bool>*
636 seen) {
637 seen = seen ? seen : Alloc<Dict<int, bool>>();
638 int heap_id = ObjectId(this);
639 if (dict_contains(seen, heap_id)) {
640 return Alloc<hnode::AlreadySeen>(heap_id);
641 }
642 seen->set(heap_id, true);
643
644 hnode::Record* out_node = runtime::NewRecord(redirect_arg_str(this->tag()));
645 List<Field*>* L = out_node->fields;
646
647 hnode_t* x0 = ToPretty(this->body);
648 L->append(Alloc<Field>(StrFromC("body"), x0));
649
650 return out_node;
651}
652
653
654hnode_t* redirect_arg_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
655 switch (this->tag()) {
656 case redirect_arg_e::Path: {
657 redirect_arg__Path* obj = static_cast<redirect_arg__Path*>(this);
658 return obj->PrettyTree(do_abbrev, seen);
659 }
660 case redirect_arg_e::CopyFd: {
661 redirect_arg__CopyFd* obj = static_cast<redirect_arg__CopyFd*>(this);
662 return obj->PrettyTree(do_abbrev, seen);
663 }
664 case redirect_arg_e::MoveFd: {
665 redirect_arg__MoveFd* obj = static_cast<redirect_arg__MoveFd*>(this);
666 return obj->PrettyTree(do_abbrev, seen);
667 }
668 case redirect_arg_e::CloseFd: {
669 redirect_arg__CloseFd* obj = static_cast<redirect_arg__CloseFd*>(this);
670 return obj->PrettyTree(do_abbrev, seen);
671 }
672 case redirect_arg_e::HereDoc: {
673 redirect_arg__HereDoc* obj = static_cast<redirect_arg__HereDoc*>(this);
674 return obj->PrettyTree(do_abbrev, seen);
675 }
676 default:
677 assert(0);
678 }
679}
680
681hnode_t* RedirValue::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
682 seen = seen ? seen : Alloc<Dict<int, bool>>();
683 int heap_id = ObjectId(this);
684 if (dict_contains(seen, heap_id)) {
685 return Alloc<hnode::AlreadySeen>(heap_id);
686 }
687 seen->set(heap_id, true);
688
689 hnode::Record* out_node = runtime::NewRecord(StrFromC("RedirValue"));
690 List<Field*>* L = out_node->fields;
691
692 hnode_t* x0 = Alloc<hnode::Leaf>(Id_str(this->op_id, false),
693 color_e::UserType);
694 L->append(Alloc<Field>(StrFromC("op_id"), x0));
695
696 hnode_t* x1 = this->op_loc->PrettyTree(do_abbrev, seen);
697 L->append(Alloc<Field>(StrFromC("op_loc"), x1));
698
699 hnode_t* x2 = this->loc->PrettyTree(do_abbrev, seen);
700 L->append(Alloc<Field>(StrFromC("loc"), x2));
701
702 hnode_t* x3 = this->arg->PrettyTree(do_abbrev, seen);
703 L->append(Alloc<Field>(StrFromC("arg"), x3));
704
705 return out_node;
706}
707
708
709hnode_t* StatusArray::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
710 seen = seen ? seen : Alloc<Dict<int, bool>>();
711 int heap_id = ObjectId(this);
712 if (dict_contains(seen, heap_id)) {
713 return Alloc<hnode::AlreadySeen>(heap_id);
714 }
715 seen->set(heap_id, true);
716
717 hnode::Record* out_node = runtime::NewRecord(StrFromC("StatusArray"));
718 List<Field*>* L = out_node->fields;
719
720 if (this->codes != nullptr) { // List
721 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
722 for (ListIter<int> it(this->codes); !it.Done(); it.Next()) {
723 int v_ = it.Value();
724 hnode_t* h = ToPretty(v_);
725 x0->children->append(h);
726 }
727 L->append(Alloc<Field>(StrFromC("codes"), x0));
728 }
729
730 if (this->locs != nullptr) { // List
731 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
732 for (ListIter<syntax_asdl::loc_t*> it(this->locs); !it.Done(); it.Next()) {
733 syntax_asdl::loc_t* v_ = it.Value();
734 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
735 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
736 x1->children->append(h);
737 }
738 L->append(Alloc<Field>(StrFromC("locs"), x1));
739 }
740
741 return out_node;
742}
743
744
745hnode_t* CommandStatus::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
746 seen = seen ? seen : Alloc<Dict<int, bool>>();
747 int heap_id = ObjectId(this);
748 if (dict_contains(seen, heap_id)) {
749 return Alloc<hnode::AlreadySeen>(heap_id);
750 }
751 seen->set(heap_id, true);
752
753 hnode::Record* out_node = runtime::NewRecord(StrFromC("CommandStatus"));
754 List<Field*>* L = out_node->fields;
755
756 hnode_t* x0 = ToPretty(this->check_errexit);
757 L->append(Alloc<Field>(StrFromC("check_errexit"), x0));
758
759 hnode_t* x1 = ToPretty(this->show_code);
760 L->append(Alloc<Field>(StrFromC("show_code"), x1));
761
762 hnode_t* x2 = ToPretty(this->pipe_negated);
763 L->append(Alloc<Field>(StrFromC("pipe_negated"), x2));
764
765 if (this->pipe_status != nullptr) { // List
766 hnode::Array* x3 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
767 for (ListIter<int> it(this->pipe_status); !it.Done(); it.Next()) {
768 int v_ = it.Value();
769 hnode_t* h = ToPretty(v_);
770 x3->children->append(h);
771 }
772 L->append(Alloc<Field>(StrFromC("pipe_status"), x3));
773 }
774
775 if (this->pipe_locs != nullptr) { // List
776 hnode::Array* x4 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
777 for (ListIter<syntax_asdl::loc_t*> it(this->pipe_locs); !it.Done();
778 it.Next()) {
779 syntax_asdl::loc_t* v_ = it.Value();
780 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
781 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
782 x4->children->append(h);
783 }
784 L->append(Alloc<Field>(StrFromC("pipe_locs"), x4));
785 }
786
787 return out_node;
788}
789
790BigStr* wait_status_str(int tag, bool dot) {
791 char buf[32];
792 const char* v = nullptr;
793 switch (tag) {
794 case wait_status_e::Proc:
795 v = "Proc"; break;
796 case wait_status_e::Pipeline:
797 v = "Pipeline"; break;
798 case wait_status_e::Cancelled:
799 v = "Cancelled"; break;
800 default:
801 assert(0);
802 }
803 if (dot) {
804 snprintf(buf, 32, "wait_status.%s", v);
805 return StrFromC(buf);
806 } else {
807 return StrFromC(v);
808 }
809}
810
811hnode_t* wait_status__Proc::PrettyTree(bool do_abbrev, 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(wait_status_str(this->tag()));
820 List<Field*>* L = out_node->fields;
821
822 hnode_t* x0 = ToPretty(this->code);
823 L->append(Alloc<Field>(StrFromC("code"), x0));
824
825 return out_node;
826}
827
828
829hnode_t* wait_status__Pipeline::PrettyTree(bool do_abbrev, Dict<int, bool>*
830 seen) {
831 seen = seen ? seen : Alloc<Dict<int, bool>>();
832 int heap_id = ObjectId(this);
833 if (dict_contains(seen, heap_id)) {
834 return Alloc<hnode::AlreadySeen>(heap_id);
835 }
836 seen->set(heap_id, true);
837
838 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
839 List<Field*>* L = out_node->fields;
840
841 if (this->codes != nullptr) { // List
842 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
843 for (ListIter<int> it(this->codes); !it.Done(); it.Next()) {
844 int v_ = it.Value();
845 hnode_t* h = ToPretty(v_);
846 x0->children->append(h);
847 }
848 L->append(Alloc<Field>(StrFromC("codes"), x0));
849 }
850
851 return out_node;
852}
853
854
855hnode_t* wait_status__Cancelled::PrettyTree(bool do_abbrev, Dict<int, bool>*
856 seen) {
857 seen = seen ? seen : Alloc<Dict<int, bool>>();
858 int heap_id = ObjectId(this);
859 if (dict_contains(seen, heap_id)) {
860 return Alloc<hnode::AlreadySeen>(heap_id);
861 }
862 seen->set(heap_id, true);
863
864 hnode::Record* out_node = runtime::NewRecord(wait_status_str(this->tag()));
865 List<Field*>* L = out_node->fields;
866
867 hnode_t* x0 = ToPretty(this->sig_num);
868 L->append(Alloc<Field>(StrFromC("sig_num"), x0));
869
870 return out_node;
871}
872
873
874hnode_t* wait_status_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
875 switch (this->tag()) {
876 case wait_status_e::Proc: {
877 wait_status__Proc* obj = static_cast<wait_status__Proc*>(this);
878 return obj->PrettyTree(do_abbrev, seen);
879 }
880 case wait_status_e::Pipeline: {
881 wait_status__Pipeline* obj = static_cast<wait_status__Pipeline*>(this);
882 return obj->PrettyTree(do_abbrev, seen);
883 }
884 case wait_status_e::Cancelled: {
885 wait_status__Cancelled* obj = static_cast<wait_status__Cancelled*>(this);
886 return obj->PrettyTree(do_abbrev, seen);
887 }
888 default:
889 assert(0);
890 }
891}
892BigStr* flow_str(flow_e tag, bool dot) {
893 char buf[32];
894 const char* v = nullptr;
895 switch (tag) {
896 case flow_e::Nothing:
897 v = "Nothing"; break;
898 case flow_e::Break:
899 v = "Break"; break;
900 case flow_e::Raise:
901 v = "Raise"; break;
902 default:
903 assert(0);
904 }
905 if (dot) {
906 snprintf(buf, 32, "flow.%s", v);
907 return StrFromC(buf);
908 } else {
909 return StrFromC(v);
910 }
911}
912BigStr* span_str(span_e tag, bool dot) {
913 char buf[32];
914 const char* v = nullptr;
915 switch (tag) {
916 case span_e::Black:
917 v = "Black"; break;
918 case span_e::Delim:
919 v = "Delim"; break;
920 case span_e::Backslash:
921 v = "Backslash"; break;
922 default:
923 assert(0);
924 }
925 if (dot) {
926 snprintf(buf, 32, "span.%s", v);
927 return StrFromC(buf);
928 } else {
929 return StrFromC(v);
930 }
931}
932BigStr* emit_str(int tag, bool dot) {
933 char buf[32];
934 const char* v = nullptr;
935 switch (tag) {
936 case emit_i::Part:
937 v = "Part"; break;
938 case emit_i::Delim:
939 v = "Delim"; break;
940 case emit_i::Empty:
941 v = "Empty"; break;
942 case emit_i::Escape:
943 v = "Escape"; break;
944 case emit_i::Nothing:
945 v = "Nothing"; break;
946 default:
947 assert(0);
948 }
949 if (dot) {
950 snprintf(buf, 32, "emit.%s", v);
951 return StrFromC(buf);
952 } else {
953 return StrFromC(v);
954 }
955}
956BigStr* state_str(int tag, bool dot) {
957 char buf[32];
958 const char* v = nullptr;
959 switch (tag) {
960 case state_i::Invalid:
961 v = "Invalid"; break;
962 case state_i::Start:
963 v = "Start"; break;
964 case state_i::DE_White1:
965 v = "DE_White1"; break;
966 case state_i::DE_Gray:
967 v = "DE_Gray"; break;
968 case state_i::DE_White2:
969 v = "DE_White2"; break;
970 case state_i::Black:
971 v = "Black"; break;
972 case state_i::Backslash:
973 v = "Backslash"; break;
974 case state_i::Done:
975 v = "Done"; break;
976 default:
977 assert(0);
978 }
979 if (dot) {
980 snprintf(buf, 32, "state.%s", v);
981 return StrFromC(buf);
982 } else {
983 return StrFromC(v);
984 }
985}
986BigStr* char_kind_str(int tag, bool dot) {
987 char buf[32];
988 const char* v = nullptr;
989 switch (tag) {
990 case char_kind_i::DE_White:
991 v = "DE_White"; break;
992 case char_kind_i::DE_Gray:
993 v = "DE_Gray"; break;
994 case char_kind_i::Black:
995 v = "Black"; break;
996 case char_kind_i::Backslash:
997 v = "Backslash"; break;
998 case char_kind_i::Sentinel:
999 v = "Sentinel"; break;
1000 default:
1001 assert(0);
1002 }
1003 if (dot) {
1004 snprintf(buf, 32, "char_kind.%s", v);
1005 return StrFromC(buf);
1006 } else {
1007 return StrFromC(v);
1008 }
1009}
1010BigStr* job_state_str(job_state_e tag, bool dot) {
1011 char buf[32];
1012 const char* v = nullptr;
1013 switch (tag) {
1014 case job_state_e::Running:
1015 v = "Running"; break;
1016 case job_state_e::Done:
1017 v = "Done"; break;
1018 case job_state_e::Stopped:
1019 v = "Stopped"; break;
1020 default:
1021 assert(0);
1022 }
1023 if (dot) {
1024 snprintf(buf, 32, "job_state.%s", v);
1025 return StrFromC(buf);
1026 } else {
1027 return StrFromC(v);
1028 }
1029}
1030BigStr* error_code_str(error_code_e tag, bool dot) {
1031 char buf[32];
1032 const char* v = nullptr;
1033 switch (tag) {
1034 case error_code_e::OK:
1035 v = "OK"; break;
1036 case error_code_e::IndexOutOfRange:
1037 v = "IndexOutOfRange"; break;
1038 default:
1039 assert(0);
1040 }
1041 if (dot) {
1042 snprintf(buf, 32, "error_code.%s", v);
1043 return StrFromC(buf);
1044 } else {
1045 return StrFromC(v);
1046 }
1047}
1048BigStr* flag_type_str(flag_type_e tag, bool dot) {
1049 char buf[32];
1050 const char* v = nullptr;
1051 switch (tag) {
1052 case flag_type_e::Bool:
1053 v = "Bool"; break;
1054 case flag_type_e::Int:
1055 v = "Int"; break;
1056 case flag_type_e::Float:
1057 v = "Float"; break;
1058 case flag_type_e::Str:
1059 v = "Str"; break;
1060 default:
1061 assert(0);
1062 }
1063 if (dot) {
1064 snprintf(buf, 32, "flag_type.%s", v);
1065 return StrFromC(buf);
1066 } else {
1067 return StrFromC(v);
1068 }
1069}
1070BigStr* trace_str(int tag, bool dot) {
1071 char buf[32];
1072 const char* v = nullptr;
1073 switch (tag) {
1074 case trace_e::External:
1075 v = "External"; break;
1076 case trace_e::CommandSub:
1077 v = "CommandSub"; break;
1078 case trace_e::ForkWait:
1079 v = "ForkWait"; break;
1080 case trace_e::Fork:
1081 v = "Fork"; break;
1082 case trace_e::PipelinePart:
1083 v = "PipelinePart"; break;
1084 case trace_e::ProcessSub:
1085 v = "ProcessSub"; break;
1086 case trace_e::HereDoc:
1087 v = "HereDoc"; break;
1088 default:
1089 assert(0);
1090 }
1091 if (dot) {
1092 snprintf(buf, 32, "trace.%s", v);
1093 return StrFromC(buf);
1094 } else {
1095 return StrFromC(v);
1096 }
1097}
1098
1099trace__CommandSub* trace::CommandSub = &gtrace__CommandSub.obj;
1100
1101GcGlobal<trace__CommandSub> gtrace__CommandSub =
1102 { ObjHeader::Global(trace_e::CommandSub) };
1103
1104trace__ForkWait* trace::ForkWait = &gtrace__ForkWait.obj;
1105
1106GcGlobal<trace__ForkWait> gtrace__ForkWait =
1107 { ObjHeader::Global(trace_e::ForkWait) };
1108
1109trace__Fork* trace::Fork = &gtrace__Fork.obj;
1110
1111GcGlobal<trace__Fork> gtrace__Fork =
1112 { ObjHeader::Global(trace_e::Fork) };
1113
1114trace__PipelinePart* trace::PipelinePart = &gtrace__PipelinePart.obj;
1115
1116GcGlobal<trace__PipelinePart> gtrace__PipelinePart =
1117 { ObjHeader::Global(trace_e::PipelinePart) };
1118
1119trace__ProcessSub* trace::ProcessSub = &gtrace__ProcessSub.obj;
1120
1121GcGlobal<trace__ProcessSub> gtrace__ProcessSub =
1122 { ObjHeader::Global(trace_e::ProcessSub) };
1123
1124trace__HereDoc* trace::HereDoc = &gtrace__HereDoc.obj;
1125
1126GcGlobal<trace__HereDoc> gtrace__HereDoc =
1127 { ObjHeader::Global(trace_e::HereDoc) };
1128
1129hnode_t* trace__External::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1130 seen = seen ? seen : Alloc<Dict<int, bool>>();
1131 int heap_id = ObjectId(this);
1132 if (dict_contains(seen, heap_id)) {
1133 return Alloc<hnode::AlreadySeen>(heap_id);
1134 }
1135 seen->set(heap_id, true);
1136
1137 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1138 List<Field*>* L = out_node->fields;
1139
1140 if (this->argv != nullptr) { // List
1141 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
1142 for (ListIter<BigStr*> it(this->argv); !it.Done(); it.Next()) {
1143 BigStr* v_ = it.Value();
1144 hnode_t* h = ToPretty(v_);
1145 x0->children->append(h);
1146 }
1147 L->append(Alloc<Field>(StrFromC("argv"), x0));
1148 }
1149
1150 return out_node;
1151}
1152
1153
1154hnode_t* trace__CommandSub::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1155 seen = seen ? seen : Alloc<Dict<int, bool>>();
1156 int heap_id = ObjectId(this);
1157 if (dict_contains(seen, heap_id)) {
1158 return Alloc<hnode::AlreadySeen>(heap_id);
1159 }
1160 seen->set(heap_id, true);
1161
1162 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1163 return out_node;
1164}
1165
1166
1167hnode_t* trace__ForkWait::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1168 seen = seen ? seen : Alloc<Dict<int, bool>>();
1169 int heap_id = ObjectId(this);
1170 if (dict_contains(seen, heap_id)) {
1171 return Alloc<hnode::AlreadySeen>(heap_id);
1172 }
1173 seen->set(heap_id, true);
1174
1175 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1176 return out_node;
1177}
1178
1179
1180hnode_t* trace__Fork::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1181 seen = seen ? seen : Alloc<Dict<int, bool>>();
1182 int heap_id = ObjectId(this);
1183 if (dict_contains(seen, heap_id)) {
1184 return Alloc<hnode::AlreadySeen>(heap_id);
1185 }
1186 seen->set(heap_id, true);
1187
1188 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1189 return out_node;
1190}
1191
1192
1193hnode_t* trace__PipelinePart::PrettyTree(bool do_abbrev, Dict<int, bool>* seen)
1194 {
1195 seen = seen ? seen : Alloc<Dict<int, bool>>();
1196 int heap_id = ObjectId(this);
1197 if (dict_contains(seen, heap_id)) {
1198 return Alloc<hnode::AlreadySeen>(heap_id);
1199 }
1200 seen->set(heap_id, true);
1201
1202 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1203 return out_node;
1204}
1205
1206
1207hnode_t* trace__ProcessSub::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1208 seen = seen ? seen : Alloc<Dict<int, bool>>();
1209 int heap_id = ObjectId(this);
1210 if (dict_contains(seen, heap_id)) {
1211 return Alloc<hnode::AlreadySeen>(heap_id);
1212 }
1213 seen->set(heap_id, true);
1214
1215 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1216 return out_node;
1217}
1218
1219
1220hnode_t* trace__HereDoc::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1221 seen = seen ? seen : Alloc<Dict<int, bool>>();
1222 int heap_id = ObjectId(this);
1223 if (dict_contains(seen, heap_id)) {
1224 return Alloc<hnode::AlreadySeen>(heap_id);
1225 }
1226 seen->set(heap_id, true);
1227
1228 hnode::Record* out_node = runtime::NewRecord(trace_str(this->tag()));
1229 return out_node;
1230}
1231
1232
1233hnode_t* trace_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1234 switch (this->tag()) {
1235 case trace_e::External: {
1236 trace__External* obj = static_cast<trace__External*>(this);
1237 return obj->PrettyTree(do_abbrev, seen);
1238 }
1239 case trace_e::CommandSub: {
1240 trace__CommandSub* obj = static_cast<trace__CommandSub*>(this);
1241 return obj->PrettyTree(do_abbrev, seen);
1242 }
1243 case trace_e::ForkWait: {
1244 trace__ForkWait* obj = static_cast<trace__ForkWait*>(this);
1245 return obj->PrettyTree(do_abbrev, seen);
1246 }
1247 case trace_e::Fork: {
1248 trace__Fork* obj = static_cast<trace__Fork*>(this);
1249 return obj->PrettyTree(do_abbrev, seen);
1250 }
1251 case trace_e::PipelinePart: {
1252 trace__PipelinePart* obj = static_cast<trace__PipelinePart*>(this);
1253 return obj->PrettyTree(do_abbrev, seen);
1254 }
1255 case trace_e::ProcessSub: {
1256 trace__ProcessSub* obj = static_cast<trace__ProcessSub*>(this);
1257 return obj->PrettyTree(do_abbrev, seen);
1258 }
1259 case trace_e::HereDoc: {
1260 trace__HereDoc* obj = static_cast<trace__HereDoc*>(this);
1261 return obj->PrettyTree(do_abbrev, seen);
1262 }
1263 default:
1264 assert(0);
1265 }
1266}
1267BigStr* word_style_str(word_style_e tag, bool dot) {
1268 char buf[32];
1269 const char* v = nullptr;
1270 switch (tag) {
1271 case word_style_e::Expr:
1272 v = "Expr"; break;
1273 case word_style_e::Unquoted:
1274 v = "Unquoted"; break;
1275 case word_style_e::DQ:
1276 v = "DQ"; break;
1277 case word_style_e::SQ:
1278 v = "SQ"; break;
1279 default:
1280 assert(0);
1281 }
1282 if (dot) {
1283 snprintf(buf, 32, "word_style.%s", v);
1284 return StrFromC(buf);
1285 } else {
1286 return StrFromC(v);
1287 }
1288}
1289
1290hnode_t* HayNode::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
1291 seen = seen ? seen : Alloc<Dict<int, bool>>();
1292 int heap_id = ObjectId(this);
1293 if (dict_contains(seen, heap_id)) {
1294 return Alloc<hnode::AlreadySeen>(heap_id);
1295 }
1296 seen->set(heap_id, true);
1297
1298 hnode::Record* out_node = runtime::NewRecord(StrFromC("HayNode"));
1299 List<Field*>* L = out_node->fields;
1300
1301 if (this->children != nullptr) { // Dict
1302 auto* unnamed = NewList<hnode_t*>();
1303 auto* hdict = Alloc<hnode::Record>(kEmptyString, StrFromC("{"),
1304 StrFromC("}"),
1305 NewList<Field*>(), unnamed);
1306 for (DictIter<BigStr*, HayNode*> it(this->children); !it.Done(); it.Next())
1307 {
1308 auto k = it.Key();
1309 auto v = it.Value();
1310 unnamed->append(ToPretty(k));
1311 unnamed->append(v->PrettyTree(do_abbrev, seen));
1312 }
1313 L->append(Alloc<Field>(StrFromC("children"), hdict));
1314 }
1315
1316 return out_node;
1317}
1318
1319BigStr* comp_action_str(comp_action_e tag, bool dot) {
1320 char buf[32];
1321 const char* v = nullptr;
1322 switch (tag) {
1323 case comp_action_e::Other:
1324 v = "Other"; break;
1325 case comp_action_e::FileSystem:
1326 v = "FileSystem"; break;
1327 case comp_action_e::BashFunc:
1328 v = "BashFunc"; break;
1329 default:
1330 assert(0);
1331 }
1332 if (dot) {
1333 snprintf(buf, 32, "comp_action.%s", v);
1334 return StrFromC(buf);
1335 } else {
1336 return StrFromC(v);
1337 }
1338}
1339
1340} // namespace runtime_asdl