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