1 | // _gen/data_lang/pretty.asdl.cc is generated by asdl_main.py
|
2 |
|
3 | #include "_gen/data_lang/pretty.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 pretty_asdl {
|
14 |
|
15 | BigStr* doc_str(int tag, bool dot) {
|
16 | char buf[32];
|
17 | const char* v = nullptr;
|
18 | switch (tag) {
|
19 | case doc_e::Newline:
|
20 | v = "Newline"; break;
|
21 | case doc_e::Text:
|
22 | v = "Text"; break;
|
23 | case doc_e::Indent:
|
24 | v = "Indent"; break;
|
25 | case doc_e::Cat:
|
26 | v = "Cat"; break;
|
27 | default:
|
28 | assert(0);
|
29 | }
|
30 | if (dot) {
|
31 | snprintf(buf, 32, "doc.%s", v);
|
32 | return StrFromC(buf);
|
33 | } else {
|
34 | return StrFromC(v);
|
35 | }
|
36 | }
|
37 |
|
38 | doc__Newline* doc::Newline = &gdoc__Newline.obj;
|
39 |
|
40 | GcGlobal<doc__Newline> gdoc__Newline =
|
41 | { ObjHeader::Global(doc_e::Newline) };
|
42 |
|
43 | hnode_t* doc__Newline::PrettyTree(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 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
51 | return out_node;
|
52 | }
|
53 |
|
54 |
|
55 | hnode_t* doc__Text::PrettyTree(Dict<int, bool>* seen) {
|
56 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
57 | int heap_id = ObjectId(this);
|
58 | if (dict_contains(seen, heap_id)) {
|
59 | return Alloc<hnode::AlreadySeen>(heap_id);
|
60 | }
|
61 | seen->set(heap_id, true);
|
62 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
63 | List<Field*>* L = out_node->fields;
|
64 |
|
65 | hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
|
66 | L->append(Alloc<Field>(StrFromC("s"), x0));
|
67 |
|
68 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->width), color_e::OtherConst);
|
69 | L->append(Alloc<Field>(StrFromC("width"), x1));
|
70 |
|
71 | return out_node;
|
72 | }
|
73 |
|
74 |
|
75 | hnode_t* doc__Indent::PrettyTree(Dict<int, bool>* seen) {
|
76 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
77 | int heap_id = ObjectId(this);
|
78 | if (dict_contains(seen, heap_id)) {
|
79 | return Alloc<hnode::AlreadySeen>(heap_id);
|
80 | }
|
81 | seen->set(heap_id, true);
|
82 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
83 | List<Field*>* L = out_node->fields;
|
84 |
|
85 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->ind), color_e::OtherConst);
|
86 | L->append(Alloc<Field>(StrFromC("ind"), x0));
|
87 |
|
88 | if (this->children != nullptr) { // List
|
89 | hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
90 | for (ListIter<doc_t*> it(this->children); !it.Done(); it.Next()) {
|
91 | doc_t* i1 = it.Value();
|
92 | hnode_t* h = (i1 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
93 | color_e::OtherConst) : i1->PrettyTree(seen);
|
94 | x1->children->append(h);
|
95 | }
|
96 | L->append(Alloc<Field>(StrFromC("children"), x1));
|
97 | }
|
98 |
|
99 | return out_node;
|
100 | }
|
101 |
|
102 |
|
103 | hnode_t* doc__Cat::PrettyTree(Dict<int, bool>* seen) {
|
104 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
105 | int heap_id = ObjectId(this);
|
106 | if (dict_contains(seen, heap_id)) {
|
107 | return Alloc<hnode::AlreadySeen>(heap_id);
|
108 | }
|
109 | seen->set(heap_id, true);
|
110 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
111 | List<Field*>* L = out_node->fields;
|
112 |
|
113 | hnode_t* x0 = this->left->PrettyTree(seen);
|
114 | L->append(Alloc<Field>(StrFromC("left"), x0));
|
115 |
|
116 | hnode_t* x1 = this->right->PrettyTree(seen);
|
117 | L->append(Alloc<Field>(StrFromC("right"), x1));
|
118 |
|
119 | return out_node;
|
120 | }
|
121 |
|
122 |
|
123 | hnode_t* doc_t::PrettyTree(Dict<int, bool>* seen) {
|
124 | switch (this->tag()) {
|
125 | case doc_e::Newline: {
|
126 | doc__Newline* obj = static_cast<doc__Newline*>(this);
|
127 | return obj->PrettyTree(seen);
|
128 | }
|
129 | case doc_e::Text: {
|
130 | doc__Text* obj = static_cast<doc__Text*>(this);
|
131 | return obj->PrettyTree(seen);
|
132 | }
|
133 | case doc_e::Indent: {
|
134 | doc__Indent* obj = static_cast<doc__Indent*>(this);
|
135 | return obj->PrettyTree(seen);
|
136 | }
|
137 | case doc_e::Cat: {
|
138 | doc__Cat* obj = static_cast<doc__Cat*>(this);
|
139 | return obj->PrettyTree(seen);
|
140 | }
|
141 | default:
|
142 | assert(0);
|
143 | }
|
144 | }
|
145 |
|
146 | } // namespace pretty_asdl
|