// _gen/mycpp/examples/expr.asdl.cc is generated by asdl_main.py #include "_gen/mycpp/examples/expr.asdl.h" #include #include "prebuilt/asdl/runtime.mycpp.h" // generated code uses wrappers here // Generated code uses these types using hnode_asdl::hnode; using hnode_asdl::Field; using hnode_asdl::color_e; namespace expr_asdl { BigStr* tok_str(tok_e tag, bool dot) { char buf[32]; const char* v = nullptr; switch (tag) { case tok_e::Const: v = "Const"; break; case tok_e::Var: v = "Var"; break; case tok_e::Op1: v = "Op1"; break; case tok_e::Op2: v = "Op2"; break; case tok_e::Paren: v = "Paren"; break; case tok_e::Eof: v = "Eof"; break; case tok_e::Invalid: v = "Invalid"; break; default: assert(0); } if (dot) { snprintf(buf, 32, "tok.%s", v); return StrFromC(buf); } else { return StrFromC(v); } } BigStr* expr_str(int tag, bool dot) { char buf[32]; const char* v = nullptr; switch (tag) { case expr_e::Const: v = "Const"; break; case expr_e::Var: v = "Var"; break; case expr_e::Binary: v = "Binary"; break; default: assert(0); } if (dot) { snprintf(buf, 32, "expr.%s", v); return StrFromC(buf); } else { return StrFromC(v); } } hnode_t* expr__Const::PrettyTree(Dict* seen) { seen = seen ? seen : Alloc>(); int heap_id = ObjectId(this); if (dict_contains(seen, heap_id)) { return Alloc(heap_id); } seen->set(heap_id, true); hnode::Record* out_node = runtime::NewRecord(expr_str(this->tag())); List* L = out_node->fields; hnode_t* x0 = Alloc(str(this->i), color_e::OtherConst); L->append(Alloc(StrFromC("i"), x0)); return out_node; } hnode_t* expr__Var::PrettyTree(Dict* seen) { seen = seen ? seen : Alloc>(); int heap_id = ObjectId(this); if (dict_contains(seen, heap_id)) { return Alloc(heap_id); } seen->set(heap_id, true); hnode::Record* out_node = runtime::NewRecord(expr_str(this->tag())); List* L = out_node->fields; hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst); L->append(Alloc(StrFromC("name"), x0)); return out_node; } hnode_t* expr__Binary::PrettyTree(Dict* seen) { seen = seen ? seen : Alloc>(); int heap_id = ObjectId(this); if (dict_contains(seen, heap_id)) { return Alloc(heap_id); } seen->set(heap_id, true); hnode::Record* out_node = runtime::NewRecord(expr_str(this->tag())); List* L = out_node->fields; hnode_t* x0 = runtime::NewLeaf(this->op, color_e::StringConst); L->append(Alloc(StrFromC("op"), x0)); hnode_t* x1 = this->left->PrettyTree(seen); L->append(Alloc(StrFromC("left"), x1)); hnode_t* x2 = this->right->PrettyTree(seen); L->append(Alloc(StrFromC("right"), x2)); return out_node; } hnode_t* expr_t::PrettyTree(Dict* seen) { switch (this->tag()) { case expr_e::Const: { expr__Const* obj = static_cast(this); return obj->PrettyTree(seen); } case expr_e::Var: { expr__Var* obj = static_cast(this); return obj->PrettyTree(seen); } case expr_e::Binary: { expr__Binary* obj = static_cast(this); return obj->PrettyTree(seen); } default: assert(0); } } hnode_t* CompoundWord::PrettyTree(Dict* seen) { seen = seen ? seen : Alloc>(); int heap_id = ObjectId(this); if (dict_contains(seen, heap_id)) { return Alloc(heap_id); } seen->set(heap_id, true); hnode::Array* out_node = Alloc(Alloc>()); for (ListIter it(this); !it.Done(); it.Next()) { BigStr* v_ = it.Value(); hnode_t* h = runtime::NewLeaf(v_, color_e::StringConst); out_node->children->append(h); } return out_node; } } // namespace expr_asdl