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 |
|
47 | hnode::Record* out_node = runtime::NewRecord(value_str(this->tag()));
|
48 | return out_node;
|
49 | }
|
50 |
|
51 |
|
52 | hnode_t* value__Array::PrettyTree(Dict<int, bool>* seen) {
|
53 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
54 | int heap_id = ObjectId(this);
|
55 | if (dict_contains(seen, heap_id)) {
|
56 | return Alloc<hnode::AlreadySeen>(heap_id);
|
57 | }
|
58 | seen->set(heap_id, true);
|
59 |
|
60 | hnode::Record* out_node = runtime::NewRecord(value_str(this->tag()));
|
61 | List<Field*>* L = out_node->fields;
|
62 |
|
63 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
64 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
65 |
|
66 | return out_node;
|
67 | }
|
68 |
|
69 |
|
70 | hnode_t* value_t::PrettyTree(Dict<int, bool>* seen) {
|
71 | switch (this->tag()) {
|
72 | case value_e::Str: {
|
73 | value__Str* obj = static_cast<value__Str*>(this);
|
74 | return obj->PrettyTree(seen);
|
75 | }
|
76 | case value_e::Array: {
|
77 | value__Array* obj = static_cast<value__Array*>(this);
|
78 | return obj->PrettyTree(seen);
|
79 | }
|
80 | default:
|
81 | assert(0);
|
82 | }
|
83 | }
|
84 |
|
85 | hnode_t* t2::PrettyTree(Dict<int, bool>* seen) {
|
86 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
87 | int heap_id = ObjectId(this);
|
88 | if (dict_contains(seen, heap_id)) {
|
89 | return Alloc<hnode::AlreadySeen>(heap_id);
|
90 | }
|
91 | seen->set(heap_id, true);
|
92 |
|
93 | hnode::Record* out_node = runtime::NewRecord(StrFromC("t2"));
|
94 | List<Field*>* L = out_node->fields;
|
95 |
|
96 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
97 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
98 |
|
99 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->b), color_e::OtherConst);
|
100 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
101 |
|
102 | return out_node;
|
103 | }
|
104 |
|
105 |
|
106 | hnode_t* t3::PrettyTree(Dict<int, bool>* seen) {
|
107 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
108 | int heap_id = ObjectId(this);
|
109 | if (dict_contains(seen, heap_id)) {
|
110 | return Alloc<hnode::AlreadySeen>(heap_id);
|
111 | }
|
112 | seen->set(heap_id, true);
|
113 |
|
114 | hnode::Record* out_node = runtime::NewRecord(StrFromC("t3"));
|
115 | List<Field*>* L = out_node->fields;
|
116 |
|
117 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
118 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
119 |
|
120 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->b), color_e::OtherConst);
|
121 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
122 |
|
123 | return out_node;
|
124 | }
|
125 |
|
126 |
|
127 | hnode_t* t4::PrettyTree(Dict<int, bool>* seen) {
|
128 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
129 | int heap_id = ObjectId(this);
|
130 | if (dict_contains(seen, heap_id)) {
|
131 | return Alloc<hnode::AlreadySeen>(heap_id);
|
132 | }
|
133 | seen->set(heap_id, true);
|
134 |
|
135 | hnode::Record* out_node = runtime::NewRecord(StrFromC("t4"));
|
136 | List<Field*>* L = out_node->fields;
|
137 |
|
138 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->a), color_e::OtherConst);
|
139 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
140 |
|
141 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->b), color_e::OtherConst);
|
142 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
143 |
|
144 | return out_node;
|
145 | }
|
146 |
|
147 |
|
148 | } // namespace demo_lib_asdl
|