| 1 | // _gen/yaks/yaks.asdl.cc is generated by asdl_main.py
|
| 2 |
|
| 3 | #include "_gen/yaks/yaks.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 yaks_asdl {
|
| 14 |
|
| 15 |
|
| 16 | hnode_t* Token::PrettyTree(bool do_abbrev, 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("Token"));
|
| 25 | List<Field*>* L = out_node->fields;
|
| 26 |
|
| 27 | hnode_t* x0 = ToPretty(this->path);
|
| 28 | L->append(Alloc<Field>(StrFromC("path"), x0));
|
| 29 |
|
| 30 | hnode_t* x1 = ToPretty(this->chunk);
|
| 31 | L->append(Alloc<Field>(StrFromC("chunk"), x1));
|
| 32 |
|
| 33 | hnode_t* x2 = ToPretty(this->start);
|
| 34 | L->append(Alloc<Field>(StrFromC("start"), x2));
|
| 35 |
|
| 36 | hnode_t* x3 = ToPretty(this->length);
|
| 37 | L->append(Alloc<Field>(StrFromC("length"), x3));
|
| 38 |
|
| 39 | return out_node;
|
| 40 | }
|
| 41 |
|
| 42 |
|
| 43 | hnode_t* Bool::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 44 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 45 | int heap_id = ObjectId(this);
|
| 46 | if (dict_contains(seen, heap_id)) {
|
| 47 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 48 | }
|
| 49 | seen->set(heap_id, true);
|
| 50 |
|
| 51 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Bool"));
|
| 52 | List<Field*>* L = out_node->fields;
|
| 53 |
|
| 54 | hnode_t* x0 = ToPretty(this->b);
|
| 55 | L->append(Alloc<Field>(StrFromC("b"), x0));
|
| 56 |
|
| 57 | hnode_t* x1 = this->loc->PrettyTree(do_abbrev, seen);
|
| 58 | L->append(Alloc<Field>(StrFromC("loc"), x1));
|
| 59 |
|
| 60 | return out_node;
|
| 61 | }
|
| 62 |
|
| 63 |
|
| 64 | hnode_t* Int::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 65 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 66 | int heap_id = ObjectId(this);
|
| 67 | if (dict_contains(seen, heap_id)) {
|
| 68 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 69 | }
|
| 70 | seen->set(heap_id, true);
|
| 71 |
|
| 72 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Int"));
|
| 73 | List<Field*>* L = out_node->fields;
|
| 74 |
|
| 75 | hnode_t* x0 = ToPretty(this->i);
|
| 76 | L->append(Alloc<Field>(StrFromC("i"), x0));
|
| 77 |
|
| 78 | hnode_t* x1 = this->loc->PrettyTree(do_abbrev, seen);
|
| 79 | L->append(Alloc<Field>(StrFromC("loc"), x1));
|
| 80 |
|
| 81 | return out_node;
|
| 82 | }
|
| 83 |
|
| 84 |
|
| 85 | hnode_t* Str::PrettyTree(bool do_abbrev, 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("Str"));
|
| 94 | List<Field*>* L = out_node->fields;
|
| 95 |
|
| 96 | hnode_t* x0 = ToPretty(this->s);
|
| 97 | L->append(Alloc<Field>(StrFromC("s"), x0));
|
| 98 |
|
| 99 | hnode_t* x1 = this->loc->PrettyTree(do_abbrev, seen);
|
| 100 | L->append(Alloc<Field>(StrFromC("loc"), x1));
|
| 101 |
|
| 102 | return out_node;
|
| 103 | }
|
| 104 |
|
| 105 |
|
| 106 | hnode_t* MultiStr::PrettyTree(bool do_abbrev, 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("MultiStr"));
|
| 115 | List<Field*>* L = out_node->fields;
|
| 116 |
|
| 117 | if (this->lines != nullptr) { // List
|
| 118 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 119 | for (ListIter<Token*> it(this->lines); !it.Done(); it.Next()) {
|
| 120 | Token* v_ = it.Value();
|
| 121 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 122 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 123 | x0->children->append(h);
|
| 124 | }
|
| 125 | L->append(Alloc<Field>(StrFromC("lines"), x0));
|
| 126 | }
|
| 127 |
|
| 128 | return out_node;
|
| 129 | }
|
| 130 |
|
| 131 | BigStr* op_str(op_e tag, bool dot) {
|
| 132 | char buf[32];
|
| 133 | const char* v = nullptr;
|
| 134 | switch (tag) {
|
| 135 | case op_e::Plus:
|
| 136 | v = "Plus"; break;
|
| 137 | case op_e::Minus:
|
| 138 | v = "Minus"; break;
|
| 139 | default:
|
| 140 | assert(0);
|
| 141 | }
|
| 142 | if (dot) {
|
| 143 | snprintf(buf, 32, "op.%s", v);
|
| 144 | return StrFromC(buf);
|
| 145 | } else {
|
| 146 | return StrFromC(v);
|
| 147 | }
|
| 148 | }
|
| 149 | BigStr* kexpr_str(int tag, bool dot) {
|
| 150 | char buf[32];
|
| 151 | const char* v = nullptr;
|
| 152 | switch (tag) {
|
| 153 | case kexpr_e::Bool:
|
| 154 | v = "Bool"; break;
|
| 155 | case kexpr_e::Int:
|
| 156 | v = "Int"; break;
|
| 157 | case kexpr_e::Str:
|
| 158 | v = "Str"; break;
|
| 159 | case kexpr_e::MultiStr:
|
| 160 | v = "MultiStr"; break;
|
| 161 | case kexpr_e::Unary:
|
| 162 | v = "Unary"; break;
|
| 163 | case kexpr_e::Binary:
|
| 164 | v = "Binary"; break;
|
| 165 | case kexpr_e::Ternary:
|
| 166 | v = "Ternary"; break;
|
| 167 | case kexpr_e::Call:
|
| 168 | v = "Call"; break;
|
| 169 | default:
|
| 170 | assert(0);
|
| 171 | }
|
| 172 | if (dot) {
|
| 173 | snprintf(buf, 32, "kexpr.%s", v);
|
| 174 | return StrFromC(buf);
|
| 175 | } else {
|
| 176 | return StrFromC(v);
|
| 177 | }
|
| 178 | }
|
| 179 |
|
| 180 | hnode_t* kexpr__Unary::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 181 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 182 | int heap_id = ObjectId(this);
|
| 183 | if (dict_contains(seen, heap_id)) {
|
| 184 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 185 | }
|
| 186 | seen->set(heap_id, true);
|
| 187 |
|
| 188 | hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
|
| 189 | List<Field*>* L = out_node->fields;
|
| 190 |
|
| 191 | hnode_t* x0 = this->op->PrettyTree(do_abbrev, seen);
|
| 192 | L->append(Alloc<Field>(StrFromC("op"), x0));
|
| 193 |
|
| 194 | hnode_t* x1 = this->child->PrettyTree(do_abbrev, seen);
|
| 195 | L->append(Alloc<Field>(StrFromC("child"), x1));
|
| 196 |
|
| 197 | return out_node;
|
| 198 | }
|
| 199 |
|
| 200 |
|
| 201 | hnode_t* kexpr__Binary::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 202 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 203 | int heap_id = ObjectId(this);
|
| 204 | if (dict_contains(seen, heap_id)) {
|
| 205 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 206 | }
|
| 207 | seen->set(heap_id, true);
|
| 208 |
|
| 209 | hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
|
| 210 | List<Field*>* L = out_node->fields;
|
| 211 |
|
| 212 | hnode_t* x0 = this->op->PrettyTree(do_abbrev, seen);
|
| 213 | L->append(Alloc<Field>(StrFromC("op"), x0));
|
| 214 |
|
| 215 | hnode_t* x1 = this->left->PrettyTree(do_abbrev, seen);
|
| 216 | L->append(Alloc<Field>(StrFromC("left"), x1));
|
| 217 |
|
| 218 | hnode_t* x2 = this->right->PrettyTree(do_abbrev, seen);
|
| 219 | L->append(Alloc<Field>(StrFromC("right"), x2));
|
| 220 |
|
| 221 | return out_node;
|
| 222 | }
|
| 223 |
|
| 224 |
|
| 225 | hnode_t* kexpr__Ternary::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 226 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 227 | int heap_id = ObjectId(this);
|
| 228 | if (dict_contains(seen, heap_id)) {
|
| 229 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 230 | }
|
| 231 | seen->set(heap_id, true);
|
| 232 |
|
| 233 | hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
|
| 234 | List<Field*>* L = out_node->fields;
|
| 235 |
|
| 236 | hnode_t* x0 = this->op->PrettyTree(do_abbrev, seen);
|
| 237 | L->append(Alloc<Field>(StrFromC("op"), x0));
|
| 238 |
|
| 239 | hnode_t* x1 = this->left->PrettyTree(do_abbrev, seen);
|
| 240 | L->append(Alloc<Field>(StrFromC("left"), x1));
|
| 241 |
|
| 242 | hnode_t* x2 = this->cond->PrettyTree(do_abbrev, seen);
|
| 243 | L->append(Alloc<Field>(StrFromC("cond"), x2));
|
| 244 |
|
| 245 | hnode_t* x3 = this->right->PrettyTree(do_abbrev, seen);
|
| 246 | L->append(Alloc<Field>(StrFromC("right"), x3));
|
| 247 |
|
| 248 | return out_node;
|
| 249 | }
|
| 250 |
|
| 251 |
|
| 252 | hnode_t* kexpr__Call::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 253 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 254 | int heap_id = ObjectId(this);
|
| 255 | if (dict_contains(seen, heap_id)) {
|
| 256 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 257 | }
|
| 258 | seen->set(heap_id, true);
|
| 259 |
|
| 260 | hnode::Record* out_node = runtime::NewRecord(kexpr_str(this->tag()));
|
| 261 | List<Field*>* L = out_node->fields;
|
| 262 |
|
| 263 | hnode_t* x0 = this->f->PrettyTree(do_abbrev, seen);
|
| 264 | L->append(Alloc<Field>(StrFromC("f"), x0));
|
| 265 |
|
| 266 | if (this->args != nullptr) { // List
|
| 267 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 268 | for (ListIter<kexpr_t*> it(this->args); !it.Done(); it.Next()) {
|
| 269 | kexpr_t* v_ = it.Value();
|
| 270 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 271 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 272 | x1->children->append(h);
|
| 273 | }
|
| 274 | L->append(Alloc<Field>(StrFromC("args"), x1));
|
| 275 | }
|
| 276 |
|
| 277 | return out_node;
|
| 278 | }
|
| 279 |
|
| 280 |
|
| 281 | hnode_t* kexpr_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 282 | switch (this->tag()) {
|
| 283 | case kexpr_e::Bool: {
|
| 284 | Bool* obj = static_cast<Bool*>(this);
|
| 285 | return obj->PrettyTree(do_abbrev, seen);
|
| 286 | }
|
| 287 | case kexpr_e::Int: {
|
| 288 | Int* obj = static_cast<Int*>(this);
|
| 289 | return obj->PrettyTree(do_abbrev, seen);
|
| 290 | }
|
| 291 | case kexpr_e::Str: {
|
| 292 | Str* obj = static_cast<Str*>(this);
|
| 293 | return obj->PrettyTree(do_abbrev, seen);
|
| 294 | }
|
| 295 | case kexpr_e::MultiStr: {
|
| 296 | MultiStr* obj = static_cast<MultiStr*>(this);
|
| 297 | return obj->PrettyTree(do_abbrev, seen);
|
| 298 | }
|
| 299 | case kexpr_e::Unary: {
|
| 300 | kexpr__Unary* obj = static_cast<kexpr__Unary*>(this);
|
| 301 | return obj->PrettyTree(do_abbrev, seen);
|
| 302 | }
|
| 303 | case kexpr_e::Binary: {
|
| 304 | kexpr__Binary* obj = static_cast<kexpr__Binary*>(this);
|
| 305 | return obj->PrettyTree(do_abbrev, seen);
|
| 306 | }
|
| 307 | case kexpr_e::Ternary: {
|
| 308 | kexpr__Ternary* obj = static_cast<kexpr__Ternary*>(this);
|
| 309 | return obj->PrettyTree(do_abbrev, seen);
|
| 310 | }
|
| 311 | case kexpr_e::Call: {
|
| 312 | kexpr__Call* obj = static_cast<kexpr__Call*>(this);
|
| 313 | return obj->PrettyTree(do_abbrev, seen);
|
| 314 | }
|
| 315 | default:
|
| 316 | assert(0);
|
| 317 | }
|
| 318 | }
|
| 319 |
|
| 320 | hnode_t* Field_::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 321 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 322 | int heap_id = ObjectId(this);
|
| 323 | if (dict_contains(seen, heap_id)) {
|
| 324 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 325 | }
|
| 326 | seen->set(heap_id, true);
|
| 327 |
|
| 328 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Field_"));
|
| 329 | List<Field*>* L = out_node->fields;
|
| 330 |
|
| 331 | hnode_t* x0 = ToPretty(this->name);
|
| 332 | L->append(Alloc<Field>(StrFromC("name"), x0));
|
| 333 |
|
| 334 | hnode_t* x1 = this->typ->PrettyTree(do_abbrev, seen);
|
| 335 | L->append(Alloc<Field>(StrFromC("typ"), x1));
|
| 336 |
|
| 337 | return out_node;
|
| 338 | }
|
| 339 |
|
| 340 |
|
| 341 | hnode_t* variant::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 342 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 343 | int heap_id = ObjectId(this);
|
| 344 | if (dict_contains(seen, heap_id)) {
|
| 345 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 346 | }
|
| 347 | seen->set(heap_id, true);
|
| 348 |
|
| 349 | hnode::Record* out_node = runtime::NewRecord(StrFromC("variant"));
|
| 350 | List<Field*>* L = out_node->fields;
|
| 351 |
|
| 352 | if (this->fields != nullptr) { // List
|
| 353 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 354 | for (ListIter<Field_*> it(this->fields); !it.Done(); it.Next()) {
|
| 355 | Field_* v_ = it.Value();
|
| 356 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 357 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 358 | x0->children->append(h);
|
| 359 | }
|
| 360 | L->append(Alloc<Field>(StrFromC("fields"), x0));
|
| 361 | }
|
| 362 |
|
| 363 | return out_node;
|
| 364 | }
|
| 365 |
|
| 366 | BigStr* ktype_str(int tag, bool dot) {
|
| 367 | char buf[32];
|
| 368 | const char* v = nullptr;
|
| 369 | switch (tag) {
|
| 370 | case ktype_e::Bool:
|
| 371 | v = "Bool"; break;
|
| 372 | case ktype_e::Int:
|
| 373 | v = "Int"; break;
|
| 374 | case ktype_e::Str:
|
| 375 | v = "Str"; break;
|
| 376 | case ktype_e::List:
|
| 377 | v = "List"; break;
|
| 378 | case ktype_e::Dict:
|
| 379 | v = "Dict"; break;
|
| 380 | case ktype_e::Class:
|
| 381 | v = "Class"; break;
|
| 382 | case ktype_e::Data:
|
| 383 | v = "Data"; break;
|
| 384 | case ktype_e::Enum:
|
| 385 | v = "Enum"; break;
|
| 386 | default:
|
| 387 | assert(0);
|
| 388 | }
|
| 389 | if (dot) {
|
| 390 | snprintf(buf, 32, "ktype.%s", v);
|
| 391 | return StrFromC(buf);
|
| 392 | } else {
|
| 393 | return StrFromC(v);
|
| 394 | }
|
| 395 | }
|
| 396 |
|
| 397 | ktype__Bool* ktype::Bool = &gktype__Bool.obj;
|
| 398 |
|
| 399 | GcGlobal<ktype__Bool> gktype__Bool =
|
| 400 | { ObjHeader::Global(ktype_e::Bool) };
|
| 401 |
|
| 402 | ktype__Int* ktype::Int = &gktype__Int.obj;
|
| 403 |
|
| 404 | GcGlobal<ktype__Int> gktype__Int =
|
| 405 | { ObjHeader::Global(ktype_e::Int) };
|
| 406 |
|
| 407 | ktype__Str* ktype::Str = &gktype__Str.obj;
|
| 408 |
|
| 409 | GcGlobal<ktype__Str> gktype__Str =
|
| 410 | { ObjHeader::Global(ktype_e::Str) };
|
| 411 |
|
| 412 | hnode_t* ktype__Bool::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 413 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 414 | int heap_id = ObjectId(this);
|
| 415 | if (dict_contains(seen, heap_id)) {
|
| 416 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 417 | }
|
| 418 | seen->set(heap_id, true);
|
| 419 |
|
| 420 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 421 | return out_node;
|
| 422 | }
|
| 423 |
|
| 424 |
|
| 425 | hnode_t* ktype__Int::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 426 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 427 | int heap_id = ObjectId(this);
|
| 428 | if (dict_contains(seen, heap_id)) {
|
| 429 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 430 | }
|
| 431 | seen->set(heap_id, true);
|
| 432 |
|
| 433 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 434 | return out_node;
|
| 435 | }
|
| 436 |
|
| 437 |
|
| 438 | hnode_t* ktype__Str::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 439 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 440 | int heap_id = ObjectId(this);
|
| 441 | if (dict_contains(seen, heap_id)) {
|
| 442 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 443 | }
|
| 444 | seen->set(heap_id, true);
|
| 445 |
|
| 446 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 447 | return out_node;
|
| 448 | }
|
| 449 |
|
| 450 |
|
| 451 | hnode_t* ktype__List::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 452 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 453 | int heap_id = ObjectId(this);
|
| 454 | if (dict_contains(seen, heap_id)) {
|
| 455 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 456 | }
|
| 457 | seen->set(heap_id, true);
|
| 458 |
|
| 459 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 460 | List<Field*>* L = out_node->fields;
|
| 461 |
|
| 462 | hnode_t* x0 = this->T->PrettyTree(do_abbrev, seen);
|
| 463 | L->append(Alloc<Field>(StrFromC("T"), x0));
|
| 464 |
|
| 465 | return out_node;
|
| 466 | }
|
| 467 |
|
| 468 |
|
| 469 | hnode_t* ktype__Dict::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 470 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 471 | int heap_id = ObjectId(this);
|
| 472 | if (dict_contains(seen, heap_id)) {
|
| 473 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 474 | }
|
| 475 | seen->set(heap_id, true);
|
| 476 |
|
| 477 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 478 | List<Field*>* L = out_node->fields;
|
| 479 |
|
| 480 | hnode_t* x0 = this->K->PrettyTree(do_abbrev, seen);
|
| 481 | L->append(Alloc<Field>(StrFromC("K"), x0));
|
| 482 |
|
| 483 | hnode_t* x1 = this->V->PrettyTree(do_abbrev, seen);
|
| 484 | L->append(Alloc<Field>(StrFromC("V"), x1));
|
| 485 |
|
| 486 | return out_node;
|
| 487 | }
|
| 488 |
|
| 489 |
|
| 490 | hnode_t* ktype__Class::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 491 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 492 | int heap_id = ObjectId(this);
|
| 493 | if (dict_contains(seen, heap_id)) {
|
| 494 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 495 | }
|
| 496 | seen->set(heap_id, true);
|
| 497 |
|
| 498 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 499 | List<Field*>* L = out_node->fields;
|
| 500 |
|
| 501 | hnode_t* x0 = ToPretty(this->name);
|
| 502 | L->append(Alloc<Field>(StrFromC("name"), x0));
|
| 503 |
|
| 504 | return out_node;
|
| 505 | }
|
| 506 |
|
| 507 |
|
| 508 | hnode_t* ktype__Data::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 509 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 510 | int heap_id = ObjectId(this);
|
| 511 | if (dict_contains(seen, heap_id)) {
|
| 512 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 513 | }
|
| 514 | seen->set(heap_id, true);
|
| 515 |
|
| 516 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 517 | List<Field*>* L = out_node->fields;
|
| 518 |
|
| 519 | if (this->fields != nullptr) { // List
|
| 520 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 521 | for (ListIter<Field_*> it(this->fields); !it.Done(); it.Next()) {
|
| 522 | Field_* v_ = it.Value();
|
| 523 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 524 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 525 | x0->children->append(h);
|
| 526 | }
|
| 527 | L->append(Alloc<Field>(StrFromC("fields"), x0));
|
| 528 | }
|
| 529 |
|
| 530 | return out_node;
|
| 531 | }
|
| 532 |
|
| 533 |
|
| 534 | hnode_t* ktype__Enum::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 535 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 536 | int heap_id = ObjectId(this);
|
| 537 | if (dict_contains(seen, heap_id)) {
|
| 538 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 539 | }
|
| 540 | seen->set(heap_id, true);
|
| 541 |
|
| 542 | hnode::Record* out_node = runtime::NewRecord(ktype_str(this->tag()));
|
| 543 | List<Field*>* L = out_node->fields;
|
| 544 |
|
| 545 | if (this->variants != nullptr) { // List
|
| 546 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 547 | for (ListIter<variant*> it(this->variants); !it.Done(); it.Next()) {
|
| 548 | variant* v_ = it.Value();
|
| 549 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 550 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 551 | x0->children->append(h);
|
| 552 | }
|
| 553 | L->append(Alloc<Field>(StrFromC("variants"), x0));
|
| 554 | }
|
| 555 |
|
| 556 | return out_node;
|
| 557 | }
|
| 558 |
|
| 559 |
|
| 560 | hnode_t* ktype_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 561 | switch (this->tag()) {
|
| 562 | case ktype_e::Bool: {
|
| 563 | ktype__Bool* obj = static_cast<ktype__Bool*>(this);
|
| 564 | return obj->PrettyTree(do_abbrev, seen);
|
| 565 | }
|
| 566 | case ktype_e::Int: {
|
| 567 | ktype__Int* obj = static_cast<ktype__Int*>(this);
|
| 568 | return obj->PrettyTree(do_abbrev, seen);
|
| 569 | }
|
| 570 | case ktype_e::Str: {
|
| 571 | ktype__Str* obj = static_cast<ktype__Str*>(this);
|
| 572 | return obj->PrettyTree(do_abbrev, seen);
|
| 573 | }
|
| 574 | case ktype_e::List: {
|
| 575 | ktype__List* obj = static_cast<ktype__List*>(this);
|
| 576 | return obj->PrettyTree(do_abbrev, seen);
|
| 577 | }
|
| 578 | case ktype_e::Dict: {
|
| 579 | ktype__Dict* obj = static_cast<ktype__Dict*>(this);
|
| 580 | return obj->PrettyTree(do_abbrev, seen);
|
| 581 | }
|
| 582 | case ktype_e::Class: {
|
| 583 | ktype__Class* obj = static_cast<ktype__Class*>(this);
|
| 584 | return obj->PrettyTree(do_abbrev, seen);
|
| 585 | }
|
| 586 | case ktype_e::Data: {
|
| 587 | ktype__Data* obj = static_cast<ktype__Data*>(this);
|
| 588 | return obj->PrettyTree(do_abbrev, seen);
|
| 589 | }
|
| 590 | case ktype_e::Enum: {
|
| 591 | ktype__Enum* obj = static_cast<ktype__Enum*>(this);
|
| 592 | return obj->PrettyTree(do_abbrev, seen);
|
| 593 | }
|
| 594 | default:
|
| 595 | assert(0);
|
| 596 | }
|
| 597 | }
|
| 598 |
|
| 599 | hnode_t* NameType::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 600 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 601 | int heap_id = ObjectId(this);
|
| 602 | if (dict_contains(seen, heap_id)) {
|
| 603 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 604 | }
|
| 605 | seen->set(heap_id, true);
|
| 606 |
|
| 607 | hnode::Record* out_node = runtime::NewRecord(StrFromC("NameType"));
|
| 608 | List<Field*>* L = out_node->fields;
|
| 609 |
|
| 610 | hnode_t* x0 = ToPretty(this->name);
|
| 611 | L->append(Alloc<Field>(StrFromC("name"), x0));
|
| 612 |
|
| 613 | hnode_t* x1 = this->typ->PrettyTree(do_abbrev, seen);
|
| 614 | L->append(Alloc<Field>(StrFromC("typ"), x1));
|
| 615 |
|
| 616 | return out_node;
|
| 617 | }
|
| 618 |
|
| 619 | BigStr* stmt_str(int tag, bool dot) {
|
| 620 | char buf[32];
|
| 621 | const char* v = nullptr;
|
| 622 | switch (tag) {
|
| 623 | case stmt_e::VarDecl:
|
| 624 | v = "VarDecl"; break;
|
| 625 | case stmt_e::PlaceMutation:
|
| 626 | v = "PlaceMutation"; break;
|
| 627 | case stmt_e::If:
|
| 628 | v = "If"; break;
|
| 629 | case stmt_e::Switch:
|
| 630 | v = "Switch"; break;
|
| 631 | case stmt_e::For:
|
| 632 | v = "For"; break;
|
| 633 | case stmt_e::While:
|
| 634 | v = "While"; break;
|
| 635 | case stmt_e::Break:
|
| 636 | v = "Break"; break;
|
| 637 | case stmt_e::Continue:
|
| 638 | v = "Continue"; break;
|
| 639 | case stmt_e::Return:
|
| 640 | v = "Return"; break;
|
| 641 | case stmt_e::Try:
|
| 642 | v = "Try"; break;
|
| 643 | case stmt_e::With:
|
| 644 | v = "With"; break;
|
| 645 | default:
|
| 646 | assert(0);
|
| 647 | }
|
| 648 | if (dot) {
|
| 649 | snprintf(buf, 32, "stmt.%s", v);
|
| 650 | return StrFromC(buf);
|
| 651 | } else {
|
| 652 | return StrFromC(v);
|
| 653 | }
|
| 654 | }
|
| 655 |
|
| 656 | stmt__If* stmt::If = &gstmt__If.obj;
|
| 657 |
|
| 658 | GcGlobal<stmt__If> gstmt__If =
|
| 659 | { ObjHeader::Global(stmt_e::If) };
|
| 660 |
|
| 661 | stmt__Switch* stmt::Switch = &gstmt__Switch.obj;
|
| 662 |
|
| 663 | GcGlobal<stmt__Switch> gstmt__Switch =
|
| 664 | { ObjHeader::Global(stmt_e::Switch) };
|
| 665 |
|
| 666 | stmt__For* stmt::For = &gstmt__For.obj;
|
| 667 |
|
| 668 | GcGlobal<stmt__For> gstmt__For =
|
| 669 | { ObjHeader::Global(stmt_e::For) };
|
| 670 |
|
| 671 | stmt__While* stmt::While = &gstmt__While.obj;
|
| 672 |
|
| 673 | GcGlobal<stmt__While> gstmt__While =
|
| 674 | { ObjHeader::Global(stmt_e::While) };
|
| 675 |
|
| 676 | stmt__Break* stmt::Break = &gstmt__Break.obj;
|
| 677 |
|
| 678 | GcGlobal<stmt__Break> gstmt__Break =
|
| 679 | { ObjHeader::Global(stmt_e::Break) };
|
| 680 |
|
| 681 | stmt__Continue* stmt::Continue = &gstmt__Continue.obj;
|
| 682 |
|
| 683 | GcGlobal<stmt__Continue> gstmt__Continue =
|
| 684 | { ObjHeader::Global(stmt_e::Continue) };
|
| 685 |
|
| 686 | stmt__Try* stmt::Try = &gstmt__Try.obj;
|
| 687 |
|
| 688 | GcGlobal<stmt__Try> gstmt__Try =
|
| 689 | { ObjHeader::Global(stmt_e::Try) };
|
| 690 |
|
| 691 | stmt__With* stmt::With = &gstmt__With.obj;
|
| 692 |
|
| 693 | GcGlobal<stmt__With> gstmt__With =
|
| 694 | { ObjHeader::Global(stmt_e::With) };
|
| 695 |
|
| 696 | hnode_t* stmt__VarDecl::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 697 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 698 | int heap_id = ObjectId(this);
|
| 699 | if (dict_contains(seen, heap_id)) {
|
| 700 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 701 | }
|
| 702 | seen->set(heap_id, true);
|
| 703 |
|
| 704 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 705 | List<Field*>* L = out_node->fields;
|
| 706 |
|
| 707 | hnode_t* x0 = this->keyword->PrettyTree(do_abbrev, seen);
|
| 708 | L->append(Alloc<Field>(StrFromC("keyword"), x0));
|
| 709 |
|
| 710 | return out_node;
|
| 711 | }
|
| 712 |
|
| 713 |
|
| 714 | hnode_t* stmt__PlaceMutation::PrettyTree(bool do_abbrev, Dict<int, bool>* seen)
|
| 715 | {
|
| 716 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 717 | int heap_id = ObjectId(this);
|
| 718 | if (dict_contains(seen, heap_id)) {
|
| 719 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 720 | }
|
| 721 | seen->set(heap_id, true);
|
| 722 |
|
| 723 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 724 | List<Field*>* L = out_node->fields;
|
| 725 |
|
| 726 | hnode_t* x0 = this->keyword->PrettyTree(do_abbrev, seen);
|
| 727 | L->append(Alloc<Field>(StrFromC("keyword"), x0));
|
| 728 |
|
| 729 | return out_node;
|
| 730 | }
|
| 731 |
|
| 732 |
|
| 733 | hnode_t* stmt__If::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 734 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 735 | int heap_id = ObjectId(this);
|
| 736 | if (dict_contains(seen, heap_id)) {
|
| 737 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 738 | }
|
| 739 | seen->set(heap_id, true);
|
| 740 |
|
| 741 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 742 | return out_node;
|
| 743 | }
|
| 744 |
|
| 745 |
|
| 746 | hnode_t* stmt__Switch::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 747 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 748 | int heap_id = ObjectId(this);
|
| 749 | if (dict_contains(seen, heap_id)) {
|
| 750 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 751 | }
|
| 752 | seen->set(heap_id, true);
|
| 753 |
|
| 754 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 755 | return out_node;
|
| 756 | }
|
| 757 |
|
| 758 |
|
| 759 | hnode_t* stmt__For::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 760 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 761 | int heap_id = ObjectId(this);
|
| 762 | if (dict_contains(seen, heap_id)) {
|
| 763 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 764 | }
|
| 765 | seen->set(heap_id, true);
|
| 766 |
|
| 767 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 768 | return out_node;
|
| 769 | }
|
| 770 |
|
| 771 |
|
| 772 | hnode_t* stmt__While::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 773 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 774 | int heap_id = ObjectId(this);
|
| 775 | if (dict_contains(seen, heap_id)) {
|
| 776 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 777 | }
|
| 778 | seen->set(heap_id, true);
|
| 779 |
|
| 780 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 781 | return out_node;
|
| 782 | }
|
| 783 |
|
| 784 |
|
| 785 | hnode_t* stmt__Break::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 786 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 787 | int heap_id = ObjectId(this);
|
| 788 | if (dict_contains(seen, heap_id)) {
|
| 789 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 790 | }
|
| 791 | seen->set(heap_id, true);
|
| 792 |
|
| 793 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 794 | return out_node;
|
| 795 | }
|
| 796 |
|
| 797 |
|
| 798 | hnode_t* stmt__Continue::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 799 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 800 | int heap_id = ObjectId(this);
|
| 801 | if (dict_contains(seen, heap_id)) {
|
| 802 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 803 | }
|
| 804 | seen->set(heap_id, true);
|
| 805 |
|
| 806 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 807 | return out_node;
|
| 808 | }
|
| 809 |
|
| 810 |
|
| 811 | hnode_t* stmt__Return::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(stmt_str(this->tag()));
|
| 820 | List<Field*>* L = out_node->fields;
|
| 821 |
|
| 822 | hnode_t* x0 = this->e->PrettyTree(do_abbrev, seen);
|
| 823 | L->append(Alloc<Field>(StrFromC("e"), x0));
|
| 824 |
|
| 825 | return out_node;
|
| 826 | }
|
| 827 |
|
| 828 |
|
| 829 | hnode_t* stmt__Try::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 830 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 831 | int heap_id = ObjectId(this);
|
| 832 | if (dict_contains(seen, heap_id)) {
|
| 833 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 834 | }
|
| 835 | seen->set(heap_id, true);
|
| 836 |
|
| 837 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 838 | return out_node;
|
| 839 | }
|
| 840 |
|
| 841 |
|
| 842 | hnode_t* stmt__With::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 843 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 844 | int heap_id = ObjectId(this);
|
| 845 | if (dict_contains(seen, heap_id)) {
|
| 846 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 847 | }
|
| 848 | seen->set(heap_id, true);
|
| 849 |
|
| 850 | hnode::Record* out_node = runtime::NewRecord(stmt_str(this->tag()));
|
| 851 | return out_node;
|
| 852 | }
|
| 853 |
|
| 854 |
|
| 855 | hnode_t* stmt_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 856 | switch (this->tag()) {
|
| 857 | case stmt_e::VarDecl: {
|
| 858 | stmt__VarDecl* obj = static_cast<stmt__VarDecl*>(this);
|
| 859 | return obj->PrettyTree(do_abbrev, seen);
|
| 860 | }
|
| 861 | case stmt_e::PlaceMutation: {
|
| 862 | stmt__PlaceMutation* obj = static_cast<stmt__PlaceMutation*>(this);
|
| 863 | return obj->PrettyTree(do_abbrev, seen);
|
| 864 | }
|
| 865 | case stmt_e::If: {
|
| 866 | stmt__If* obj = static_cast<stmt__If*>(this);
|
| 867 | return obj->PrettyTree(do_abbrev, seen);
|
| 868 | }
|
| 869 | case stmt_e::Switch: {
|
| 870 | stmt__Switch* obj = static_cast<stmt__Switch*>(this);
|
| 871 | return obj->PrettyTree(do_abbrev, seen);
|
| 872 | }
|
| 873 | case stmt_e::For: {
|
| 874 | stmt__For* obj = static_cast<stmt__For*>(this);
|
| 875 | return obj->PrettyTree(do_abbrev, seen);
|
| 876 | }
|
| 877 | case stmt_e::While: {
|
| 878 | stmt__While* obj = static_cast<stmt__While*>(this);
|
| 879 | return obj->PrettyTree(do_abbrev, seen);
|
| 880 | }
|
| 881 | case stmt_e::Break: {
|
| 882 | stmt__Break* obj = static_cast<stmt__Break*>(this);
|
| 883 | return obj->PrettyTree(do_abbrev, seen);
|
| 884 | }
|
| 885 | case stmt_e::Continue: {
|
| 886 | stmt__Continue* obj = static_cast<stmt__Continue*>(this);
|
| 887 | return obj->PrettyTree(do_abbrev, seen);
|
| 888 | }
|
| 889 | case stmt_e::Return: {
|
| 890 | stmt__Return* obj = static_cast<stmt__Return*>(this);
|
| 891 | return obj->PrettyTree(do_abbrev, seen);
|
| 892 | }
|
| 893 | case stmt_e::Try: {
|
| 894 | stmt__Try* obj = static_cast<stmt__Try*>(this);
|
| 895 | return obj->PrettyTree(do_abbrev, seen);
|
| 896 | }
|
| 897 | case stmt_e::With: {
|
| 898 | stmt__With* obj = static_cast<stmt__With*>(this);
|
| 899 | return obj->PrettyTree(do_abbrev, seen);
|
| 900 | }
|
| 901 | default:
|
| 902 | assert(0);
|
| 903 | }
|
| 904 | }
|
| 905 | BigStr* class_def_str(class_def_e tag, bool dot) {
|
| 906 | char buf[32];
|
| 907 | const char* v = nullptr;
|
| 908 | switch (tag) {
|
| 909 | case class_def_e::Constructor:
|
| 910 | v = "Constructor"; break;
|
| 911 | case class_def_e::Destructor:
|
| 912 | v = "Destructor"; break;
|
| 913 | case class_def_e::Method:
|
| 914 | v = "Method"; break;
|
| 915 | case class_def_e::Field:
|
| 916 | v = "Field"; break;
|
| 917 | default:
|
| 918 | assert(0);
|
| 919 | }
|
| 920 | if (dot) {
|
| 921 | snprintf(buf, 32, "class_def.%s", v);
|
| 922 | return StrFromC(buf);
|
| 923 | } else {
|
| 924 | return StrFromC(v);
|
| 925 | }
|
| 926 | }
|
| 927 |
|
| 928 | hnode_t* Signature::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 929 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 930 | int heap_id = ObjectId(this);
|
| 931 | if (dict_contains(seen, heap_id)) {
|
| 932 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 933 | }
|
| 934 | seen->set(heap_id, true);
|
| 935 |
|
| 936 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Signature"));
|
| 937 | List<Field*>* L = out_node->fields;
|
| 938 |
|
| 939 | if (this->params != nullptr) { // List
|
| 940 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 941 | for (ListIter<NameType*> it(this->params); !it.Done(); it.Next()) {
|
| 942 | NameType* v_ = it.Value();
|
| 943 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 944 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 945 | x0->children->append(h);
|
| 946 | }
|
| 947 | L->append(Alloc<Field>(StrFromC("params"), x0));
|
| 948 | }
|
| 949 |
|
| 950 | hnode_t* x1 = this->return_type->PrettyTree(do_abbrev, seen);
|
| 951 | L->append(Alloc<Field>(StrFromC("return_type"), x1));
|
| 952 |
|
| 953 | return out_node;
|
| 954 | }
|
| 955 |
|
| 956 | BigStr* mod_def_str(int tag, bool dot) {
|
| 957 | char buf[32];
|
| 958 | const char* v = nullptr;
|
| 959 | switch (tag) {
|
| 960 | case mod_def_e::Global:
|
| 961 | v = "Global"; break;
|
| 962 | case mod_def_e::Func:
|
| 963 | v = "Func"; break;
|
| 964 | case mod_def_e::Class:
|
| 965 | v = "Class"; break;
|
| 966 | case mod_def_e::Import:
|
| 967 | v = "Import"; break;
|
| 968 | case mod_def_e::Include:
|
| 969 | v = "Include"; break;
|
| 970 | case mod_def_e::Data:
|
| 971 | v = "Data"; break;
|
| 972 | case mod_def_e::Enum:
|
| 973 | v = "Enum"; break;
|
| 974 | default:
|
| 975 | assert(0);
|
| 976 | }
|
| 977 | if (dot) {
|
| 978 | snprintf(buf, 32, "mod_def.%s", v);
|
| 979 | return StrFromC(buf);
|
| 980 | } else {
|
| 981 | return StrFromC(v);
|
| 982 | }
|
| 983 | }
|
| 984 |
|
| 985 | mod_def__Import* mod_def::Import = &gmod_def__Import.obj;
|
| 986 |
|
| 987 | GcGlobal<mod_def__Import> gmod_def__Import =
|
| 988 | { ObjHeader::Global(mod_def_e::Import) };
|
| 989 |
|
| 990 | mod_def__Data* mod_def::Data = &gmod_def__Data.obj;
|
| 991 |
|
| 992 | GcGlobal<mod_def__Data> gmod_def__Data =
|
| 993 | { ObjHeader::Global(mod_def_e::Data) };
|
| 994 |
|
| 995 | mod_def__Enum* mod_def::Enum = &gmod_def__Enum.obj;
|
| 996 |
|
| 997 | GcGlobal<mod_def__Enum> gmod_def__Enum =
|
| 998 | { ObjHeader::Global(mod_def_e::Enum) };
|
| 999 |
|
| 1000 | hnode_t* mod_def__Global::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1001 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1002 | int heap_id = ObjectId(this);
|
| 1003 | if (dict_contains(seen, heap_id)) {
|
| 1004 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1005 | }
|
| 1006 | seen->set(heap_id, true);
|
| 1007 |
|
| 1008 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1009 | List<Field*>* L = out_node->fields;
|
| 1010 |
|
| 1011 | hnode_t* x0 = this->name_type->PrettyTree(do_abbrev, seen);
|
| 1012 | L->append(Alloc<Field>(StrFromC("name_type"), x0));
|
| 1013 |
|
| 1014 | return out_node;
|
| 1015 | }
|
| 1016 |
|
| 1017 |
|
| 1018 | hnode_t* mod_def__Func::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1019 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1020 | int heap_id = ObjectId(this);
|
| 1021 | if (dict_contains(seen, heap_id)) {
|
| 1022 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1023 | }
|
| 1024 | seen->set(heap_id, true);
|
| 1025 |
|
| 1026 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1027 | List<Field*>* L = out_node->fields;
|
| 1028 |
|
| 1029 | hnode_t* x0 = ToPretty(this->name);
|
| 1030 | L->append(Alloc<Field>(StrFromC("name"), x0));
|
| 1031 |
|
| 1032 | hnode_t* x1 = this->sig->PrettyTree(do_abbrev, seen);
|
| 1033 | L->append(Alloc<Field>(StrFromC("sig"), x1));
|
| 1034 |
|
| 1035 | if (this->statements != nullptr) { // List
|
| 1036 | hnode::Array* x2 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 1037 | for (ListIter<stmt_t*> it(this->statements); !it.Done(); it.Next()) {
|
| 1038 | stmt_t* v_ = it.Value();
|
| 1039 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 1040 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 1041 | x2->children->append(h);
|
| 1042 | }
|
| 1043 | L->append(Alloc<Field>(StrFromC("statements"), x2));
|
| 1044 | }
|
| 1045 |
|
| 1046 | return out_node;
|
| 1047 | }
|
| 1048 |
|
| 1049 |
|
| 1050 | hnode_t* mod_def__Class::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1051 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1052 | int heap_id = ObjectId(this);
|
| 1053 | if (dict_contains(seen, heap_id)) {
|
| 1054 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1055 | }
|
| 1056 | seen->set(heap_id, true);
|
| 1057 |
|
| 1058 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1059 | List<Field*>* L = out_node->fields;
|
| 1060 |
|
| 1061 | hnode_t* x0 = ToPretty(this->name);
|
| 1062 | L->append(Alloc<Field>(StrFromC("name"), x0));
|
| 1063 |
|
| 1064 | if (this->defs != nullptr) { // List
|
| 1065 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 1066 | for (ListIter<class_def_t> it(this->defs); !it.Done(); it.Next()) {
|
| 1067 | class_def_t v_ = it.Value();
|
| 1068 | hnode_t* h = Alloc<hnode::Leaf>(class_def_str(v_), color_e::TypeName);
|
| 1069 | x1->children->append(h);
|
| 1070 | }
|
| 1071 | L->append(Alloc<Field>(StrFromC("defs"), x1));
|
| 1072 | }
|
| 1073 |
|
| 1074 | return out_node;
|
| 1075 | }
|
| 1076 |
|
| 1077 |
|
| 1078 | hnode_t* mod_def__Import::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1079 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1080 | int heap_id = ObjectId(this);
|
| 1081 | if (dict_contains(seen, heap_id)) {
|
| 1082 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1083 | }
|
| 1084 | seen->set(heap_id, true);
|
| 1085 |
|
| 1086 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1087 | return out_node;
|
| 1088 | }
|
| 1089 |
|
| 1090 |
|
| 1091 | hnode_t* mod_def__Include::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1092 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1093 | int heap_id = ObjectId(this);
|
| 1094 | if (dict_contains(seen, heap_id)) {
|
| 1095 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1096 | }
|
| 1097 | seen->set(heap_id, true);
|
| 1098 |
|
| 1099 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1100 | List<Field*>* L = out_node->fields;
|
| 1101 |
|
| 1102 | hnode_t* x0 = ToPretty(this->path);
|
| 1103 | L->append(Alloc<Field>(StrFromC("path"), x0));
|
| 1104 |
|
| 1105 | return out_node;
|
| 1106 | }
|
| 1107 |
|
| 1108 |
|
| 1109 | hnode_t* mod_def__Data::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1110 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1111 | int heap_id = ObjectId(this);
|
| 1112 | if (dict_contains(seen, heap_id)) {
|
| 1113 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1114 | }
|
| 1115 | seen->set(heap_id, true);
|
| 1116 |
|
| 1117 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1118 | return out_node;
|
| 1119 | }
|
| 1120 |
|
| 1121 |
|
| 1122 | hnode_t* mod_def__Enum::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1123 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1124 | int heap_id = ObjectId(this);
|
| 1125 | if (dict_contains(seen, heap_id)) {
|
| 1126 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1127 | }
|
| 1128 | seen->set(heap_id, true);
|
| 1129 |
|
| 1130 | hnode::Record* out_node = runtime::NewRecord(mod_def_str(this->tag()));
|
| 1131 | return out_node;
|
| 1132 | }
|
| 1133 |
|
| 1134 |
|
| 1135 | hnode_t* mod_def_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1136 | switch (this->tag()) {
|
| 1137 | case mod_def_e::Global: {
|
| 1138 | mod_def__Global* obj = static_cast<mod_def__Global*>(this);
|
| 1139 | return obj->PrettyTree(do_abbrev, seen);
|
| 1140 | }
|
| 1141 | case mod_def_e::Func: {
|
| 1142 | mod_def__Func* obj = static_cast<mod_def__Func*>(this);
|
| 1143 | return obj->PrettyTree(do_abbrev, seen);
|
| 1144 | }
|
| 1145 | case mod_def_e::Class: {
|
| 1146 | mod_def__Class* obj = static_cast<mod_def__Class*>(this);
|
| 1147 | return obj->PrettyTree(do_abbrev, seen);
|
| 1148 | }
|
| 1149 | case mod_def_e::Import: {
|
| 1150 | mod_def__Import* obj = static_cast<mod_def__Import*>(this);
|
| 1151 | return obj->PrettyTree(do_abbrev, seen);
|
| 1152 | }
|
| 1153 | case mod_def_e::Include: {
|
| 1154 | mod_def__Include* obj = static_cast<mod_def__Include*>(this);
|
| 1155 | return obj->PrettyTree(do_abbrev, seen);
|
| 1156 | }
|
| 1157 | case mod_def_e::Data: {
|
| 1158 | mod_def__Data* obj = static_cast<mod_def__Data*>(this);
|
| 1159 | return obj->PrettyTree(do_abbrev, seen);
|
| 1160 | }
|
| 1161 | case mod_def_e::Enum: {
|
| 1162 | mod_def__Enum* obj = static_cast<mod_def__Enum*>(this);
|
| 1163 | return obj->PrettyTree(do_abbrev, seen);
|
| 1164 | }
|
| 1165 | default:
|
| 1166 | assert(0);
|
| 1167 | }
|
| 1168 | }
|
| 1169 |
|
| 1170 | hnode_t* Module::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1171 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1172 | int heap_id = ObjectId(this);
|
| 1173 | if (dict_contains(seen, heap_id)) {
|
| 1174 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1175 | }
|
| 1176 | seen->set(heap_id, true);
|
| 1177 |
|
| 1178 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Module"));
|
| 1179 | List<Field*>* L = out_node->fields;
|
| 1180 |
|
| 1181 | hnode_t* x0 = ToPretty(this->name);
|
| 1182 | L->append(Alloc<Field>(StrFromC("name"), x0));
|
| 1183 |
|
| 1184 | if (this->defs != nullptr) { // List
|
| 1185 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 1186 | for (ListIter<mod_def_t*> it(this->defs); !it.Done(); it.Next()) {
|
| 1187 | mod_def_t* v_ = it.Value();
|
| 1188 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 1189 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 1190 | x1->children->append(h);
|
| 1191 | }
|
| 1192 | L->append(Alloc<Field>(StrFromC("defs"), x1));
|
| 1193 | }
|
| 1194 |
|
| 1195 | return out_node;
|
| 1196 | }
|
| 1197 |
|
| 1198 |
|
| 1199 | hnode_t* Program::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
|
| 1200 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
| 1201 | int heap_id = ObjectId(this);
|
| 1202 | if (dict_contains(seen, heap_id)) {
|
| 1203 | return Alloc<hnode::AlreadySeen>(heap_id);
|
| 1204 | }
|
| 1205 | seen->set(heap_id, true);
|
| 1206 |
|
| 1207 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Program"));
|
| 1208 | List<Field*>* L = out_node->fields;
|
| 1209 |
|
| 1210 | hnode_t* x0 = ToPretty(this->main_module);
|
| 1211 | L->append(Alloc<Field>(StrFromC("main_module"), x0));
|
| 1212 |
|
| 1213 | if (this->modules != nullptr) { // List
|
| 1214 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
| 1215 | for (ListIter<Module*> it(this->modules); !it.Done(); it.Next()) {
|
| 1216 | Module* v_ = it.Value();
|
| 1217 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
| 1218 | color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
|
| 1219 | x1->children->append(h);
|
| 1220 | }
|
| 1221 | L->append(Alloc<Field>(StrFromC("modules"), x1));
|
| 1222 | }
|
| 1223 |
|
| 1224 | return out_node;
|
| 1225 | }
|
| 1226 |
|
| 1227 |
|
| 1228 | } // namespace yaks_asdl
|