1 | // _gen/asdl/examples/demo_lib.asdl.cc is generated by asdl_main.py
|
2 |
|
3 | #include "_gen/asdl/examples/demo_lib.asdl.h"
|
4 | #include <assert.h>
|
5 | #include "prebuilt/asdl/runtime.mycpp.h" // generated code uses wrappers here
|
6 |
|
7 | // Generated code uses these types
|
8 | using hnode_asdl::hnode;
|
9 | using hnode_asdl::Field;
|
10 | using hnode_asdl::color_e;
|
11 |
|
12 |
|
13 | namespace demo_lib_asdl {
|
14 |
|
15 | BigStr* value_str(int tag, bool dot) {
|
16 | char buf[32];
|
17 | const char* v = nullptr;
|
18 | switch (tag) {
|
19 | case value_e::Str:
|
20 | v = "Str"; break;
|
21 | case value_e::Array:
|
22 | v = "Array"; break;
|
23 | default:
|
24 | assert(0);
|
25 | }
|
26 | if (dot) {
|
27 | snprintf(buf, 32, "value.%s", v);
|
28 | return StrFromC(buf);
|
29 | } else {
|
30 | return StrFromC(v);
|
31 | }
|
32 | }
|
33 |
|
34 | value__Str* value::Str = &gvalue__Str.obj;
|
35 |
|
36 | GcGlobal<value__Str> gvalue__Str =
|
37 | { ObjHeader::Global(value_e::Str) };
|
38 |
|
39 | hnode_t* value__Str::PrettyTree(Dict<int, bool>* seen) {
|
40 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
41 | int heap_id = ObjectId(this);
|
42 | if (dict_contains(seen, heap_id)) {
|
43 | return Alloc<hnode::AlreadySeen>(heap_id);
|
44 | }
|
45 | seen->set(heap_id, true);
|
46 | hnode::Record* out_node = runtime::NewRecord(value_str(this->tag()));
|
47 | return out_node;
|
48 | }
|
49 |
|
50 |
|
51 | hnode_t* value__Array::PrettyTree(Dict<int, bool>* seen) {
|
52 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
53 | int heap_id = ObjectId(this);
|
54 | if (dict_contains(seen, heap_id)) {
|
55 | return Alloc<hnode::AlreadySeen>(heap_id);
|
56 | }
|
57 | seen->set(heap_id, true);
|
58 | hnode::Record* out_node = runtime::NewRecord(value_str(this->tag()));
|
59 | List<Field*>* L = out_node->fields;
|
60 |
|
61 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
62 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
63 |
|
64 | return out_node;
|
65 | }
|
66 |
|
67 |
|
68 | hnode_t* value_t::PrettyTree(Dict<int, bool>* seen) {
|
69 | switch (this->tag()) {
|
70 | case value_e::Str: {
|
71 | value__Str* obj = static_cast<value__Str*>(this);
|
72 | return obj->PrettyTree(seen);
|
73 | }
|
74 | case value_e::Array: {
|
75 | value__Array* obj = static_cast<value__Array*>(this);
|
76 | return obj->PrettyTree(seen);
|
77 | }
|
78 | default:
|
79 | assert(0);
|
80 | }
|
81 | }
|
82 |
|
83 | hnode_t* t2::PrettyTree(Dict<int, bool>* seen) {
|
84 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
85 | int heap_id = ObjectId(this);
|
86 | if (dict_contains(seen, heap_id)) {
|
87 | return Alloc<hnode::AlreadySeen>(heap_id);
|
88 | }
|
89 | seen->set(heap_id, true);
|
90 | hnode::Record* out_node = runtime::NewRecord(StrFromC("t2"));
|
91 | List<Field*>* L = out_node->fields;
|
92 |
|
93 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
94 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
95 |
|
96 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->b), color_e::OtherConst);
|
97 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
98 |
|
99 | return out_node;
|
100 | }
|
101 |
|
102 |
|
103 | hnode_t* t3::PrettyTree(Dict<int, bool>* seen) {
|
104 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
105 | int heap_id = ObjectId(this);
|
106 | if (dict_contains(seen, heap_id)) {
|
107 | return Alloc<hnode::AlreadySeen>(heap_id);
|
108 | }
|
109 | seen->set(heap_id, true);
|
110 | hnode::Record* out_node = runtime::NewRecord(StrFromC("t3"));
|
111 | List<Field*>* L = out_node->fields;
|
112 |
|
113 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
114 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
115 |
|
116 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->b), color_e::OtherConst);
|
117 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
118 |
|
119 | return out_node;
|
120 | }
|
121 |
|
122 |
|
123 | hnode_t* t4::PrettyTree(Dict<int, bool>* seen) {
|
124 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
125 | int heap_id = ObjectId(this);
|
126 | if (dict_contains(seen, heap_id)) {
|
127 | return Alloc<hnode::AlreadySeen>(heap_id);
|
128 | }
|
129 | seen->set(heap_id, true);
|
130 | hnode::Record* out_node = runtime::NewRecord(StrFromC("t4"));
|
131 | List<Field*>* L = out_node->fields;
|
132 |
|
133 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
134 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
135 |
|
136 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->b), color_e::OtherConst);
|
137 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
138 |
|
139 | return out_node;
|
140 | }
|
141 |
|
142 |
|
143 | } // namespace demo_lib_asdl
|