1 | // _gen/asdl/examples/shared_variant.asdl.cc is generated by asdl_main.py
|
2 |
|
3 | #include "_gen/asdl/examples/shared_variant.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 shared_variant_asdl {
|
14 |
|
15 |
|
16 | hnode_t* prod::PrettyTree(Dict<int, bool>* seen) {
|
17 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
18 | int heap_id = ObjectId(this);
|
19 | if (dict_contains(seen, heap_id)) {
|
20 | return Alloc<hnode::AlreadySeen>(heap_id);
|
21 | }
|
22 | seen->set(heap_id, true);
|
23 |
|
24 | hnode::Record* out_node = runtime::NewRecord(StrFromC("prod"));
|
25 | List<Field*>* L = out_node->fields;
|
26 |
|
27 | hnode_t* x0 = runtime::NewLeaf(this->a, color_e::StringConst);
|
28 | L->append(Alloc<Field>(StrFromC("a"), x0));
|
29 |
|
30 | hnode_t* x1 = runtime::NewLeaf(this->b, color_e::StringConst);
|
31 | L->append(Alloc<Field>(StrFromC("b"), x1));
|
32 |
|
33 | return out_node;
|
34 | }
|
35 |
|
36 |
|
37 | hnode_t* DoubleQuoted::PrettyTree(Dict<int, bool>* seen) {
|
38 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
39 | int heap_id = ObjectId(this);
|
40 | if (dict_contains(seen, heap_id)) {
|
41 | return Alloc<hnode::AlreadySeen>(heap_id);
|
42 | }
|
43 | seen->set(heap_id, true);
|
44 |
|
45 | hnode::Record* out_node = runtime::NewRecord(StrFromC("DoubleQuoted"));
|
46 | List<Field*>* L = out_node->fields;
|
47 |
|
48 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->left), color_e::OtherConst);
|
49 | L->append(Alloc<Field>(StrFromC("left"), x0));
|
50 |
|
51 | if (this->tokens != nullptr) { // List
|
52 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
53 | for (ListIter<BigStr*> it(this->tokens); !it.Done(); it.Next()) {
|
54 | BigStr* v_ = it.Value();
|
55 | hnode_t* h = runtime::NewLeaf(v_, color_e::StringConst);
|
56 | x1->children->append(h);
|
57 | }
|
58 | L->append(Alloc<Field>(StrFromC("tokens"), x1));
|
59 | }
|
60 |
|
61 | return out_node;
|
62 | }
|
63 |
|
64 | BigStr* expr_str(int tag, bool dot) {
|
65 | char buf[32];
|
66 | const char* v = nullptr;
|
67 | switch (tag) {
|
68 | case expr_e::Binary:
|
69 | v = "Binary"; break;
|
70 | case expr_e::DoubleQuoted:
|
71 | v = "DoubleQuoted"; break;
|
72 | default:
|
73 | assert(0);
|
74 | }
|
75 | if (dot) {
|
76 | snprintf(buf, 32, "expr.%s", v);
|
77 | return StrFromC(buf);
|
78 | } else {
|
79 | return StrFromC(v);
|
80 | }
|
81 | }
|
82 |
|
83 | hnode_t* expr__Binary::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 |
|
91 | hnode::Record* out_node = runtime::NewRecord(expr_str(this->tag()));
|
92 | List<Field*>* L = out_node->fields;
|
93 |
|
94 | hnode_t* x0 = this->left->PrettyTree(seen);
|
95 | L->append(Alloc<Field>(StrFromC("left"), x0));
|
96 |
|
97 | hnode_t* x1 = this->right->PrettyTree(seen);
|
98 | L->append(Alloc<Field>(StrFromC("right"), x1));
|
99 |
|
100 | return out_node;
|
101 | }
|
102 |
|
103 |
|
104 | hnode_t* expr_t::PrettyTree(Dict<int, bool>* seen) {
|
105 | switch (this->tag()) {
|
106 | case expr_e::Binary: {
|
107 | expr__Binary* obj = static_cast<expr__Binary*>(this);
|
108 | return obj->PrettyTree(seen);
|
109 | }
|
110 | case expr_e::DoubleQuoted: {
|
111 | DoubleQuoted* obj = static_cast<DoubleQuoted*>(this);
|
112 | return obj->PrettyTree(seen);
|
113 | }
|
114 | default:
|
115 | assert(0);
|
116 | }
|
117 | }
|
118 |
|
119 | hnode_t* Token::PrettyTree(Dict<int, bool>* seen) {
|
120 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
121 | int heap_id = ObjectId(this);
|
122 | if (dict_contains(seen, heap_id)) {
|
123 | return Alloc<hnode::AlreadySeen>(heap_id);
|
124 | }
|
125 | seen->set(heap_id, true);
|
126 |
|
127 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Token"));
|
128 | List<Field*>* L = out_node->fields;
|
129 |
|
130 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->id), color_e::OtherConst);
|
131 | L->append(Alloc<Field>(StrFromC("id"), x0));
|
132 |
|
133 | hnode_t* x1 = runtime::NewLeaf(this->val, color_e::StringConst);
|
134 | L->append(Alloc<Field>(StrFromC("val"), x1));
|
135 |
|
136 | return out_node;
|
137 | }
|
138 |
|
139 | BigStr* tok_str(int tag, bool dot) {
|
140 | char buf[32];
|
141 | const char* v = nullptr;
|
142 | switch (tag) {
|
143 | case tok_e::Eof:
|
144 | v = "Eof"; break;
|
145 | case tok_e::Token:
|
146 | v = "Token"; break;
|
147 | default:
|
148 | assert(0);
|
149 | }
|
150 | if (dot) {
|
151 | snprintf(buf, 32, "tok.%s", v);
|
152 | return StrFromC(buf);
|
153 | } else {
|
154 | return StrFromC(v);
|
155 | }
|
156 | }
|
157 |
|
158 | tok__Eof* tok::Eof = >ok__Eof.obj;
|
159 |
|
160 | GcGlobal<tok__Eof> gtok__Eof =
|
161 | { ObjHeader::Global(tok_e::Eof) };
|
162 |
|
163 | hnode_t* tok__Eof::PrettyTree(Dict<int, bool>* seen) {
|
164 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
165 | int heap_id = ObjectId(this);
|
166 | if (dict_contains(seen, heap_id)) {
|
167 | return Alloc<hnode::AlreadySeen>(heap_id);
|
168 | }
|
169 | seen->set(heap_id, true);
|
170 |
|
171 | hnode::Record* out_node = runtime::NewRecord(tok_str(this->tag()));
|
172 | return out_node;
|
173 | }
|
174 |
|
175 |
|
176 | hnode_t* tok_t::PrettyTree(Dict<int, bool>* seen) {
|
177 | switch (this->tag()) {
|
178 | case tok_e::Eof: {
|
179 | tok__Eof* obj = static_cast<tok__Eof*>(this);
|
180 | return obj->PrettyTree(seen);
|
181 | }
|
182 | case tok_e::Token: {
|
183 | Token* obj = static_cast<Token*>(this);
|
184 | return obj->PrettyTree(seen);
|
185 | }
|
186 | default:
|
187 | assert(0);
|
188 | }
|
189 | }
|
190 |
|
191 | hnode_t* tok_struct::PrettyTree(Dict<int, bool>* seen) {
|
192 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
193 | int heap_id = ObjectId(this);
|
194 | if (dict_contains(seen, heap_id)) {
|
195 | return Alloc<hnode::AlreadySeen>(heap_id);
|
196 | }
|
197 | seen->set(heap_id, true);
|
198 |
|
199 | hnode::Record* out_node = runtime::NewRecord(StrFromC("tok_struct"));
|
200 | List<Field*>* L = out_node->fields;
|
201 |
|
202 | hnode_t* x0 = this->token->PrettyTree(seen);
|
203 | L->append(Alloc<Field>(StrFromC("token"), x0));
|
204 |
|
205 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->x), color_e::OtherConst);
|
206 | L->append(Alloc<Field>(StrFromC("x"), x1));
|
207 |
|
208 | return out_node;
|
209 | }
|
210 |
|
211 |
|
212 | hnode_t* tok_array::PrettyTree(Dict<int, bool>* seen) {
|
213 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
214 | int heap_id = ObjectId(this);
|
215 | if (dict_contains(seen, heap_id)) {
|
216 | return Alloc<hnode::AlreadySeen>(heap_id);
|
217 | }
|
218 | seen->set(heap_id, true);
|
219 |
|
220 | hnode::Record* out_node = runtime::NewRecord(StrFromC("tok_array"));
|
221 | List<Field*>* L = out_node->fields;
|
222 |
|
223 | if (this->tokens != nullptr) { // List
|
224 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
225 | for (ListIter<tok_t*> it(this->tokens); !it.Done(); it.Next()) {
|
226 | tok_t* v_ = it.Value();
|
227 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
228 | color_e::OtherConst) : v_->PrettyTree(seen);
|
229 | x0->children->append(h);
|
230 | }
|
231 | L->append(Alloc<Field>(StrFromC("tokens"), x0));
|
232 | }
|
233 |
|
234 | return out_node;
|
235 | }
|
236 |
|
237 | BigStr* word_part_str(int tag, bool dot) {
|
238 | char buf[32];
|
239 | const char* v = nullptr;
|
240 | switch (tag) {
|
241 | case word_part_e::Literal:
|
242 | v = "Literal"; break;
|
243 | case word_part_e::DoubleQuoted:
|
244 | v = "DoubleQuoted"; break;
|
245 | default:
|
246 | assert(0);
|
247 | }
|
248 | if (dot) {
|
249 | snprintf(buf, 32, "word_part.%s", v);
|
250 | return StrFromC(buf);
|
251 | } else {
|
252 | return StrFromC(v);
|
253 | }
|
254 | }
|
255 |
|
256 | hnode_t* word_part__Literal::PrettyTree(Dict<int, bool>* seen) {
|
257 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
258 | int heap_id = ObjectId(this);
|
259 | if (dict_contains(seen, heap_id)) {
|
260 | return Alloc<hnode::AlreadySeen>(heap_id);
|
261 | }
|
262 | seen->set(heap_id, true);
|
263 |
|
264 | hnode::Record* out_node = runtime::NewRecord(word_part_str(this->tag()));
|
265 | List<Field*>* L = out_node->fields;
|
266 |
|
267 | hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
|
268 | L->append(Alloc<Field>(StrFromC("s"), x0));
|
269 |
|
270 | return out_node;
|
271 | }
|
272 |
|
273 |
|
274 | hnode_t* word_part_t::PrettyTree(Dict<int, bool>* seen) {
|
275 | switch (this->tag()) {
|
276 | case word_part_e::Literal: {
|
277 | word_part__Literal* obj = static_cast<word_part__Literal*>(this);
|
278 | return obj->PrettyTree(seen);
|
279 | }
|
280 | case word_part_e::DoubleQuoted: {
|
281 | DoubleQuoted* obj = static_cast<DoubleQuoted*>(this);
|
282 | return obj->PrettyTree(seen);
|
283 | }
|
284 | default:
|
285 | assert(0);
|
286 | }
|
287 | }
|
288 | BigStr* cflow_str(int tag, bool dot) {
|
289 | char buf[32];
|
290 | const char* v = nullptr;
|
291 | switch (tag) {
|
292 | case cflow_e::Break:
|
293 | v = "Break"; break;
|
294 | case cflow_e::Continue:
|
295 | v = "Continue"; break;
|
296 | case cflow_e::Return:
|
297 | v = "Return"; break;
|
298 | default:
|
299 | assert(0);
|
300 | }
|
301 | if (dot) {
|
302 | snprintf(buf, 32, "cflow.%s", v);
|
303 | return StrFromC(buf);
|
304 | } else {
|
305 | return StrFromC(v);
|
306 | }
|
307 | }
|
308 |
|
309 | cflow__Break* cflow::Break = &gcflow__Break.obj;
|
310 |
|
311 | GcGlobal<cflow__Break> gcflow__Break =
|
312 | { ObjHeader::Global(cflow_e::Break) };
|
313 |
|
314 | cflow__Continue* cflow::Continue = &gcflow__Continue.obj;
|
315 |
|
316 | GcGlobal<cflow__Continue> gcflow__Continue =
|
317 | { ObjHeader::Global(cflow_e::Continue) };
|
318 |
|
319 | hnode_t* cflow__Break::PrettyTree(Dict<int, bool>* seen) {
|
320 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
321 | int heap_id = ObjectId(this);
|
322 | if (dict_contains(seen, heap_id)) {
|
323 | return Alloc<hnode::AlreadySeen>(heap_id);
|
324 | }
|
325 | seen->set(heap_id, true);
|
326 |
|
327 | hnode::Record* out_node = runtime::NewRecord(cflow_str(this->tag()));
|
328 | return out_node;
|
329 | }
|
330 |
|
331 |
|
332 | hnode_t* cflow__Continue::PrettyTree(Dict<int, bool>* seen) {
|
333 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
334 | int heap_id = ObjectId(this);
|
335 | if (dict_contains(seen, heap_id)) {
|
336 | return Alloc<hnode::AlreadySeen>(heap_id);
|
337 | }
|
338 | seen->set(heap_id, true);
|
339 |
|
340 | hnode::Record* out_node = runtime::NewRecord(cflow_str(this->tag()));
|
341 | return out_node;
|
342 | }
|
343 |
|
344 |
|
345 | hnode_t* cflow__Return::PrettyTree(Dict<int, bool>* seen) {
|
346 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
347 | int heap_id = ObjectId(this);
|
348 | if (dict_contains(seen, heap_id)) {
|
349 | return Alloc<hnode::AlreadySeen>(heap_id);
|
350 | }
|
351 | seen->set(heap_id, true);
|
352 |
|
353 | hnode::Record* out_node = runtime::NewRecord(cflow_str(this->tag()));
|
354 | List<Field*>* L = out_node->fields;
|
355 |
|
356 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->val), color_e::OtherConst);
|
357 | L->append(Alloc<Field>(StrFromC("val"), x0));
|
358 |
|
359 | return out_node;
|
360 | }
|
361 |
|
362 |
|
363 | hnode_t* cflow_t::PrettyTree(Dict<int, bool>* seen) {
|
364 | switch (this->tag()) {
|
365 | case cflow_e::Break: {
|
366 | cflow__Break* obj = static_cast<cflow__Break*>(this);
|
367 | return obj->PrettyTree(seen);
|
368 | }
|
369 | case cflow_e::Continue: {
|
370 | cflow__Continue* obj = static_cast<cflow__Continue*>(this);
|
371 | return obj->PrettyTree(seen);
|
372 | }
|
373 | case cflow_e::Return: {
|
374 | cflow__Return* obj = static_cast<cflow__Return*>(this);
|
375 | return obj->PrettyTree(seen);
|
376 | }
|
377 | default:
|
378 | assert(0);
|
379 | }
|
380 | }
|
381 |
|
382 | } // namespace shared_variant_asdl
|