1 | // _gen/display/pretty.asdl.cc is generated by asdl_main.py
|
2 |
|
3 | #include "_gen/display/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 |
|
24 | hnode::Record* out_node = runtime::NewRecord(StrFromC("MeasuredDoc"));
|
25 | List<Field*>* L = out_node->fields;
|
26 |
|
27 | hnode_t* x0 = this->doc->PrettyTree(seen);
|
28 | L->append(Alloc<Field>(StrFromC("doc"), x0));
|
29 |
|
30 | hnode_t* x1 = this->measure->PrettyTree(seen);
|
31 | L->append(Alloc<Field>(StrFromC("measure"), x1));
|
32 |
|
33 | return out_node;
|
34 | }
|
35 |
|
36 |
|
37 | hnode_t* Measure::PrettyTree(Dict<int, bool>* seen) {
|
38 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
39 | int heap_id = ObjectId(this);
|
40 | if (dict_contains(seen, heap_id)) {
|
41 | return Alloc<hnode::AlreadySeen>(heap_id);
|
42 | }
|
43 | seen->set(heap_id, true);
|
44 |
|
45 | hnode::Record* out_node = runtime::NewRecord(StrFromC("Measure"));
|
46 | List<Field*>* L = out_node->fields;
|
47 |
|
48 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->flat), color_e::OtherConst);
|
49 | L->append(Alloc<Field>(StrFromC("flat"), x0));
|
50 |
|
51 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->nonflat), color_e::OtherConst);
|
52 | L->append(Alloc<Field>(StrFromC("nonflat"), x1));
|
53 |
|
54 | return out_node;
|
55 | }
|
56 |
|
57 | BigStr* doc_str(int tag, bool dot) {
|
58 | char buf[32];
|
59 | const char* v = nullptr;
|
60 | switch (tag) {
|
61 | case doc_e::Break:
|
62 | v = "Break"; break;
|
63 | case doc_e::Text:
|
64 | v = "Text"; break;
|
65 | case doc_e::Indent:
|
66 | v = "Indent"; break;
|
67 | case doc_e::Concat:
|
68 | v = "Concat"; break;
|
69 | case doc_e::Group:
|
70 | v = "Group"; break;
|
71 | case doc_e::IfFlat:
|
72 | v = "IfFlat"; break;
|
73 | case doc_e::Flat:
|
74 | v = "Flat"; break;
|
75 | default:
|
76 | assert(0);
|
77 | }
|
78 | if (dot) {
|
79 | snprintf(buf, 32, "doc.%s", v);
|
80 | return StrFromC(buf);
|
81 | } else {
|
82 | return StrFromC(v);
|
83 | }
|
84 | }
|
85 |
|
86 | hnode_t* doc__Break::PrettyTree(Dict<int, bool>* seen) {
|
87 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
88 | int heap_id = ObjectId(this);
|
89 | if (dict_contains(seen, heap_id)) {
|
90 | return Alloc<hnode::AlreadySeen>(heap_id);
|
91 | }
|
92 | seen->set(heap_id, true);
|
93 |
|
94 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
95 | List<Field*>* L = out_node->fields;
|
96 |
|
97 | hnode_t* x0 = runtime::NewLeaf(this->string, color_e::StringConst);
|
98 | L->append(Alloc<Field>(StrFromC("string"), x0));
|
99 |
|
100 | return out_node;
|
101 | }
|
102 |
|
103 |
|
104 | hnode_t* doc__Text::PrettyTree(Dict<int, bool>* seen) {
|
105 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
106 | int heap_id = ObjectId(this);
|
107 | if (dict_contains(seen, heap_id)) {
|
108 | return Alloc<hnode::AlreadySeen>(heap_id);
|
109 | }
|
110 | seen->set(heap_id, true);
|
111 |
|
112 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
113 | List<Field*>* L = out_node->fields;
|
114 |
|
115 | hnode_t* x0 = runtime::NewLeaf(this->string, color_e::StringConst);
|
116 | L->append(Alloc<Field>(StrFromC("string"), x0));
|
117 |
|
118 | return out_node;
|
119 | }
|
120 |
|
121 |
|
122 | hnode_t* doc__Indent::PrettyTree(Dict<int, bool>* seen) {
|
123 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
124 | int heap_id = ObjectId(this);
|
125 | if (dict_contains(seen, heap_id)) {
|
126 | return Alloc<hnode::AlreadySeen>(heap_id);
|
127 | }
|
128 | seen->set(heap_id, true);
|
129 |
|
130 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
131 | List<Field*>* L = out_node->fields;
|
132 |
|
133 | hnode_t* x0 = Alloc<hnode::Leaf>(str(this->indent), color_e::OtherConst);
|
134 | L->append(Alloc<Field>(StrFromC("indent"), x0));
|
135 |
|
136 | hnode_t* x1 = this->mdoc->PrettyTree(seen);
|
137 | L->append(Alloc<Field>(StrFromC("mdoc"), x1));
|
138 |
|
139 | return out_node;
|
140 | }
|
141 |
|
142 |
|
143 | hnode_t* doc__Concat::PrettyTree(Dict<int, bool>* seen) {
|
144 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
145 | int heap_id = ObjectId(this);
|
146 | if (dict_contains(seen, heap_id)) {
|
147 | return Alloc<hnode::AlreadySeen>(heap_id);
|
148 | }
|
149 | seen->set(heap_id, true);
|
150 |
|
151 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
152 | List<Field*>* L = out_node->fields;
|
153 |
|
154 | if (this->mdocs != nullptr) { // List
|
155 | hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
|
156 | for (ListIter<MeasuredDoc*> it(this->mdocs); !it.Done(); it.Next()) {
|
157 | MeasuredDoc* v_ = it.Value();
|
158 | hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
|
159 | color_e::OtherConst) : v_->PrettyTree(seen);
|
160 | x0->children->append(h);
|
161 | }
|
162 | L->append(Alloc<Field>(StrFromC("mdocs"), x0));
|
163 | }
|
164 |
|
165 | return out_node;
|
166 | }
|
167 |
|
168 |
|
169 | hnode_t* doc__Group::PrettyTree(Dict<int, bool>* seen) {
|
170 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
171 | int heap_id = ObjectId(this);
|
172 | if (dict_contains(seen, heap_id)) {
|
173 | return Alloc<hnode::AlreadySeen>(heap_id);
|
174 | }
|
175 | seen->set(heap_id, true);
|
176 |
|
177 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
178 | List<Field*>* L = out_node->fields;
|
179 |
|
180 | hnode_t* x0 = this->mdoc->PrettyTree(seen);
|
181 | L->append(Alloc<Field>(StrFromC("mdoc"), x0));
|
182 |
|
183 | return out_node;
|
184 | }
|
185 |
|
186 |
|
187 | hnode_t* doc__IfFlat::PrettyTree(Dict<int, bool>* seen) {
|
188 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
189 | int heap_id = ObjectId(this);
|
190 | if (dict_contains(seen, heap_id)) {
|
191 | return Alloc<hnode::AlreadySeen>(heap_id);
|
192 | }
|
193 | seen->set(heap_id, true);
|
194 |
|
195 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
196 | List<Field*>* L = out_node->fields;
|
197 |
|
198 | hnode_t* x0 = this->flat_mdoc->PrettyTree(seen);
|
199 | L->append(Alloc<Field>(StrFromC("flat_mdoc"), x0));
|
200 |
|
201 | hnode_t* x1 = this->nonflat_mdoc->PrettyTree(seen);
|
202 | L->append(Alloc<Field>(StrFromC("nonflat_mdoc"), x1));
|
203 |
|
204 | return out_node;
|
205 | }
|
206 |
|
207 |
|
208 | hnode_t* doc__Flat::PrettyTree(Dict<int, bool>* seen) {
|
209 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
210 | int heap_id = ObjectId(this);
|
211 | if (dict_contains(seen, heap_id)) {
|
212 | return Alloc<hnode::AlreadySeen>(heap_id);
|
213 | }
|
214 | seen->set(heap_id, true);
|
215 |
|
216 | hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
|
217 | List<Field*>* L = out_node->fields;
|
218 |
|
219 | hnode_t* x0 = this->mdoc->PrettyTree(seen);
|
220 | L->append(Alloc<Field>(StrFromC("mdoc"), x0));
|
221 |
|
222 | return out_node;
|
223 | }
|
224 |
|
225 |
|
226 | hnode_t* doc_t::PrettyTree(Dict<int, bool>* seen) {
|
227 | switch (this->tag()) {
|
228 | case doc_e::Break: {
|
229 | doc__Break* obj = static_cast<doc__Break*>(this);
|
230 | return obj->PrettyTree(seen);
|
231 | }
|
232 | case doc_e::Text: {
|
233 | doc__Text* obj = static_cast<doc__Text*>(this);
|
234 | return obj->PrettyTree(seen);
|
235 | }
|
236 | case doc_e::Indent: {
|
237 | doc__Indent* obj = static_cast<doc__Indent*>(this);
|
238 | return obj->PrettyTree(seen);
|
239 | }
|
240 | case doc_e::Concat: {
|
241 | doc__Concat* obj = static_cast<doc__Concat*>(this);
|
242 | return obj->PrettyTree(seen);
|
243 | }
|
244 | case doc_e::Group: {
|
245 | doc__Group* obj = static_cast<doc__Group*>(this);
|
246 | return obj->PrettyTree(seen);
|
247 | }
|
248 | case doc_e::IfFlat: {
|
249 | doc__IfFlat* obj = static_cast<doc__IfFlat*>(this);
|
250 | return obj->PrettyTree(seen);
|
251 | }
|
252 | case doc_e::Flat: {
|
253 | doc__Flat* obj = static_cast<doc__Flat*>(this);
|
254 | return obj->PrettyTree(seen);
|
255 | }
|
256 | default:
|
257 | assert(0);
|
258 | }
|
259 | }
|
260 |
|
261 | hnode_t* DocFragment::PrettyTree(Dict<int, bool>* seen) {
|
262 | seen = seen ? seen : Alloc<Dict<int, bool>>();
|
263 | int heap_id = ObjectId(this);
|
264 | if (dict_contains(seen, heap_id)) {
|
265 | return Alloc<hnode::AlreadySeen>(heap_id);
|
266 | }
|
267 | seen->set(heap_id, true);
|
268 |
|
269 | hnode::Record* out_node = runtime::NewRecord(StrFromC("DocFragment"));
|
270 | List<Field*>* L = out_node->fields;
|
271 |
|
272 | hnode_t* x0 = this->mdoc->PrettyTree(seen);
|
273 | L->append(Alloc<Field>(StrFromC("mdoc"), x0));
|
274 |
|
275 | hnode_t* x1 = Alloc<hnode::Leaf>(str(this->indent), color_e::OtherConst);
|
276 | L->append(Alloc<Field>(StrFromC("indent"), x1));
|
277 |
|
278 | hnode_t* x2 = Alloc<hnode::Leaf>(this->is_flat ? runtime::TRUE_STR :
|
279 | runtime::FALSE_STR, color_e::OtherConst);
|
280 | L->append(Alloc<Field>(StrFromC("is_flat"), x2));
|
281 |
|
282 | hnode_t* x3 = this->measure->PrettyTree(seen);
|
283 | L->append(Alloc<Field>(StrFromC("measure"), x3));
|
284 |
|
285 | return out_node;
|
286 | }
|
287 |
|
288 |
|
289 | } // namespace pretty_asdl
|