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