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 |
|
16 | hnode_t* MeasuredDoc::PrettyTree(Dict<int, bool>* seen) {
|
17 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
18 | int heap_id = ObjectId(this);
|
19 | if (dict_contains(seen, heap_id)) {
|
20 | return Alloc<hnode::AlreadySeen>(heap_id);
|
21 | }
|
22 | seen->set(heap_id, true);
|
23 | hnode::Record* out_node = runtime::NewRecord(StrFromC("MeasuredDoc"));
|
24 | List<Field*>* L = out_node->fields;
|
25 |
|
26 | hnode_t* x0 = this->doc->PrettyTree(seen);
|
27 | L->append(Alloc<Field>(StrFromC("doc"), x0));
|
28 |
|
29 | hnode_t* x1 = this->measure->PrettyTree(seen);
|
30 | L->append(Alloc<Field>(StrFromC("measure"), x1));
|
31 |
|
32 | return out_node;
|
33 | }
|
34 |
|
35 |
|
36 | hnode_t* Measure::PrettyTree(Dict<int, bool>* seen) {
|
37 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
38 | int heap_id = ObjectId(this);
|
39 | if (dict_contains(seen, heap_id)) {
|
40 | return Alloc<hnode::AlreadySeen>(heap_id);
|
41 | }
|
42 | seen->set(heap_id, true);
|
43 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Measure"));
|
44 | List<Field*>* L = out_node->fields;
|
45 |
|
46 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->flat), color_e::OtherConst);
|
47 | L->append(Alloc<Field>(StrFromC("flat"), x0));
|
48 |
|
49 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->nonflat), color_e::OtherConst);
|
50 | L->append(Alloc<Field>(StrFromC("nonflat"), x1));
|
51 |
|
52 | return out_node;
|
53 | }
|
54 |
|
55 | BigStr* doc_str(int tag, bool dot) {
|
56 | char buf[32];
|
57 | const char* v = nullptr;
|
58 | switch (tag) {
|
59 | case doc_e::Break:
|
60 | v = "Break"; break;
|
61 | case doc_e::Text:
|
62 | v = "Text"; break;
|
63 | case doc_e::Indent:
|
64 | v = "Indent"; break;
|
65 | case doc_e::Concat:
|
66 | v = "Concat"; break;
|
67 | case doc_e::Group:
|
68 | v = "Group"; break;
|
69 | default:
|
70 | assert(0);
|
71 | }
|
72 | if (dot) {
|
73 | snprintf(buf, 32, "doc.%s", v);
|
74 | return StrFromC(buf);
|
75 | } else {
|
76 | return StrFromC(v);
|
77 | }
|
78 | }
|
79 |
|
80 | hnode_t* doc__Break::PrettyTree(Dict<int, bool>* seen) {
|
81 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
82 | int heap_id = ObjectId(this);
|
83 | if (dict_contains(seen, heap_id)) {
|
84 | return Alloc<hnode::AlreadySeen>(heap_id);
|
85 | }
|
86 | seen->set(heap_id, true);
|
87 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
88 | List<Field*>* L = out_node->fields;
|
89 |
|
90 | hnode_t* x0 = runtime::NewLeaf(this->string, color_e::StringConst);
|
91 | L->append(Alloc<Field>(StrFromC("string"), x0));
|
92 |
|
93 | return out_node;
|
94 | }
|
95 |
|
96 |
|
97 | hnode_t* doc__Text::PrettyTree(Dict<int, bool>* seen) {
|
98 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
99 | int heap_id = ObjectId(this);
|
100 | if (dict_contains(seen, heap_id)) {
|
101 | return Alloc<hnode::AlreadySeen>(heap_id);
|
102 | }
|
103 | seen->set(heap_id, true);
|
104 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
105 | List<Field*>* L = out_node->fields;
|
106 |
|
107 | hnode_t* x0 = runtime::NewLeaf(this->string, color_e::StringConst);
|
108 | L->append(Alloc<Field>(StrFromC("string"), x0));
|
109 |
|
110 | return out_node;
|
111 | }
|
112 |
|
113 |
|
114 | hnode_t* doc__Indent::PrettyTree(Dict<int, bool>* seen) {
|
115 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
116 | int heap_id = ObjectId(this);
|
117 | if (dict_contains(seen, heap_id)) {
|
118 | return Alloc<hnode::AlreadySeen>(heap_id);
|
119 | }
|
120 | seen->set(heap_id, true);
|
121 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
122 | List<Field*>* L = out_node->fields;
|
123 |
|
124 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->indent), color_e::OtherConst);
|
125 | L->append(Alloc<Field>(StrFromC("indent"), x0));
|
126 |
|
127 | hnode_t* x1 = this->mdoc->PrettyTree(seen);
|
128 | L->append(Alloc<Field>(StrFromC("mdoc"), x1));
|
129 |
|
130 | return out_node;
|
131 | }
|
132 |
|
133 |
|
134 | hnode_t* doc__Concat::PrettyTree(Dict<int, bool>* seen) {
|
135 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
136 | int heap_id = ObjectId(this);
|
137 | if (dict_contains(seen, heap_id)) {
|
138 | return Alloc<hnode::AlreadySeen>(heap_id);
|
139 | }
|
140 | seen->set(heap_id, true);
|
141 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
142 | List<Field*>* L = out_node->fields;
|
143 |
|
144 | if (this->mdocs != nullptr) { // List
|
145 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
146 | for (ListIter<MeasuredDoc*> it(this->mdocs); !it.Done(); it.Next()) {
|
147 | MeasuredDoc* i0 = it.Value();
|
148 | hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
149 | color_e::OtherConst) : i0->PrettyTree(seen);
|
150 | x0->children->append(h);
|
151 | }
|
152 | L->append(Alloc<Field>(StrFromC("mdocs"), x0));
|
153 | }
|
154 |
|
155 | return out_node;
|
156 | }
|
157 |
|
158 |
|
159 | hnode_t* doc__Group::PrettyTree(Dict<int, bool>* seen) {
|
160 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
161 | int heap_id = ObjectId(this);
|
162 | if (dict_contains(seen, heap_id)) {
|
163 | return Alloc<hnode::AlreadySeen>(heap_id);
|
164 | }
|
165 | seen->set(heap_id, true);
|
166 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
167 | List<Field*>* L = out_node->fields;
|
168 |
|
169 | hnode_t* x0 = this->mdoc->PrettyTree(seen);
|
170 | L->append(Alloc<Field>(StrFromC("mdoc"), x0));
|
171 |
|
172 | return out_node;
|
173 | }
|
174 |
|
175 |
|
176 | hnode_t* doc_t::PrettyTree(Dict<int, bool>* seen) {
|
177 | switch (this->tag()) {
|
178 | case doc_e::Break: {
|
179 | doc__Break* obj = static_cast<doc__Break*>(this);
|
180 | return obj->PrettyTree(seen);
|
181 | }
|
182 | case doc_e::Text: {
|
183 | doc__Text* obj = static_cast<doc__Text*>(this);
|
184 | return obj->PrettyTree(seen);
|
185 | }
|
186 | case doc_e::Indent: {
|
187 | doc__Indent* obj = static_cast<doc__Indent*>(this);
|
188 | return obj->PrettyTree(seen);
|
189 | }
|
190 | case doc_e::Concat: {
|
191 | doc__Concat* obj = static_cast<doc__Concat*>(this);
|
192 | return obj->PrettyTree(seen);
|
193 | }
|
194 | case doc_e::Group: {
|
195 | doc__Group* obj = static_cast<doc__Group*>(this);
|
196 | return obj->PrettyTree(seen);
|
197 | }
|
198 | default:
|
199 | assert(0);
|
200 | }
|
201 | }
|
202 |
|
203 | hnode_t* DocFragment::PrettyTree(Dict<int, bool>* seen) {
|
204 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
205 | int heap_id = ObjectId(this);
|
206 | if (dict_contains(seen, heap_id)) {
|
207 | return Alloc<hnode::AlreadySeen>(heap_id);
|
208 | }
|
209 | seen->set(heap_id, true);
|
210 | hnode::Record* out_node = runtime::NewRecord(StrFromC("DocFragment"));
|
211 | List<Field*>* L = out_node->fields;
|
212 |
|
213 | hnode_t* x0 = this->mdoc->PrettyTree(seen);
|
214 | L->append(Alloc<Field>(StrFromC("mdoc"), x0));
|
215 |
|
216 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->indent), color_e::OtherConst);
|
217 | L->append(Alloc<Field>(StrFromC("indent"), x1));
|
218 |
|
219 | hnode_t* x2 = Alloc<hnode::Leaf>(this->is_flat ? runtime::TRUE_STR :
|
220 | runtime::FALSE_STR, color_e::OtherConst);
|
221 | L->append(Alloc<Field>(StrFromC("is_flat"), x2));
|
222 |
|
223 | hnode_t* x3 = this->measure->PrettyTree(seen);
|
224 | L->append(Alloc<Field>(StrFromC("measure"), x3));
|
225 |
|
226 | return out_node;
|
227 | }
|
228 |
|
229 |
|
230 | } // namespace pretty_asdl
|