OILS / _gen / display / pretty.asdl.cc View on Github | oilshell.org

263 lines, 172 significant
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
8using hnode_asdl::hnode;
9using hnode_asdl::Field;
10using hnode_asdl::color_e;
11
12
13namespace pretty_asdl {
14
15
16hnode_t* MeasuredDoc::PrettyTree(bool do_abbrev, 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(do_abbrev, seen);
28 L->append(Alloc<Field>(StrFromC("doc"), x0));
29
30 hnode_t* x1 = this->measure->PrettyTree(do_abbrev, seen);
31 L->append(Alloc<Field>(StrFromC("measure"), x1));
32
33 return out_node;
34}
35
36
37hnode_t* Measure::PrettyTree(bool do_abbrev, 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 = ToPretty(this->flat);
49 L->append(Alloc<Field>(StrFromC("flat"), x0));
50
51 hnode_t* x1 = ToPretty(this->nonflat);
52 L->append(Alloc<Field>(StrFromC("nonflat"), x1));
53
54 return out_node;
55}
56
57
58hnode_t* List_Measured::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
59 seen = seen ? seen : Alloc<Dict<int, bool>>();
60 int heap_id = ObjectId(this);
61 if (dict_contains(seen, heap_id)) {
62 return Alloc<hnode::AlreadySeen>(heap_id);
63 }
64 seen->set(heap_id, true);
65
66 hnode::Array* out_node = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
67 for (ListIter<MeasuredDoc*> it(this); !it.Done(); it.Next()) {
68 MeasuredDoc* v_ = it.Value();
69 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
70 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
71 out_node->children->append(h);
72 }
73 return out_node;
74}
75
76BigStr* doc_str(int tag, bool dot) {
77 char buf[32];
78 const char* v = nullptr;
79 switch (tag) {
80 case doc_e::Break:
81 v = "Break"; break;
82 case doc_e::Text:
83 v = "Text"; break;
84 case doc_e::Indent:
85 v = "Indent"; break;
86 case doc_e::Group:
87 v = "Group"; break;
88 case doc_e::Flat:
89 v = "Flat"; break;
90 case doc_e::IfFlat:
91 v = "IfFlat"; break;
92 case doc_e::Concat:
93 v = "Concat"; break;
94 default:
95 assert(0);
96 }
97 if (dot) {
98 snprintf(buf, 32, "doc.%s", v);
99 return StrFromC(buf);
100 } else {
101 return StrFromC(v);
102 }
103}
104
105hnode_t* doc__Break::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(doc_str(this->tag()));
114 List<Field*>* L = out_node->fields;
115
116 hnode_t* x0 = ToPretty(this->string);
117 L->append(Alloc<Field>(StrFromC("string"), x0));
118
119 return out_node;
120}
121
122
123hnode_t* doc__Text::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
124 seen = seen ? seen : Alloc<Dict<int, bool>>();
125 int heap_id = ObjectId(this);
126 if (dict_contains(seen, heap_id)) {
127 return Alloc<hnode::AlreadySeen>(heap_id);
128 }
129 seen->set(heap_id, true);
130
131 hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
132 List<Field*>* L = out_node->fields;
133
134 hnode_t* x0 = ToPretty(this->string);
135 L->append(Alloc<Field>(StrFromC("string"), x0));
136
137 return out_node;
138}
139
140
141hnode_t* doc__Indent::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
142 seen = seen ? seen : Alloc<Dict<int, bool>>();
143 int heap_id = ObjectId(this);
144 if (dict_contains(seen, heap_id)) {
145 return Alloc<hnode::AlreadySeen>(heap_id);
146 }
147 seen->set(heap_id, true);
148
149 hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
150 List<Field*>* L = out_node->fields;
151
152 hnode_t* x0 = ToPretty(this->indent);
153 L->append(Alloc<Field>(StrFromC("indent"), x0));
154
155 hnode_t* x1 = this->mdoc->PrettyTree(do_abbrev, seen);
156 L->append(Alloc<Field>(StrFromC("mdoc"), x1));
157
158 return out_node;
159}
160
161
162hnode_t* doc__Flat::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
163 seen = seen ? seen : Alloc<Dict<int, bool>>();
164 int heap_id = ObjectId(this);
165 if (dict_contains(seen, heap_id)) {
166 return Alloc<hnode::AlreadySeen>(heap_id);
167 }
168 seen->set(heap_id, true);
169
170 hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
171 List<Field*>* L = out_node->fields;
172
173 hnode_t* x0 = this->mdoc->PrettyTree(do_abbrev, seen);
174 L->append(Alloc<Field>(StrFromC("mdoc"), x0));
175
176 return out_node;
177}
178
179
180hnode_t* doc__IfFlat::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
181 seen = seen ? seen : Alloc<Dict<int, bool>>();
182 int heap_id = ObjectId(this);
183 if (dict_contains(seen, heap_id)) {
184 return Alloc<hnode::AlreadySeen>(heap_id);
185 }
186 seen->set(heap_id, true);
187
188 hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
189 List<Field*>* L = out_node->fields;
190
191 hnode_t* x0 = this->flat_mdoc->PrettyTree(do_abbrev, seen);
192 L->append(Alloc<Field>(StrFromC("flat_mdoc"), x0));
193
194 hnode_t* x1 = this->nonflat_mdoc->PrettyTree(do_abbrev, seen);
195 L->append(Alloc<Field>(StrFromC("nonflat_mdoc"), x1));
196
197 return out_node;
198}
199
200
201hnode_t* doc_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
202 switch (this->tag()) {
203 case doc_e::Break: {
204 doc__Break* obj = static_cast<doc__Break*>(this);
205 return obj->PrettyTree(do_abbrev, seen);
206 }
207 case doc_e::Text: {
208 doc__Text* obj = static_cast<doc__Text*>(this);
209 return obj->PrettyTree(do_abbrev, seen);
210 }
211 case doc_e::Indent: {
212 doc__Indent* obj = static_cast<doc__Indent*>(this);
213 return obj->PrettyTree(do_abbrev, seen);
214 }
215 case doc_e::Group: {
216 MeasuredDoc* obj = static_cast<MeasuredDoc*>(this);
217 return obj->PrettyTree(do_abbrev, seen);
218 }
219 case doc_e::Flat: {
220 doc__Flat* obj = static_cast<doc__Flat*>(this);
221 return obj->PrettyTree(do_abbrev, seen);
222 }
223 case doc_e::IfFlat: {
224 doc__IfFlat* obj = static_cast<doc__IfFlat*>(this);
225 return obj->PrettyTree(do_abbrev, seen);
226 }
227 case doc_e::Concat: {
228 List_Measured* obj = static_cast<List_Measured*>(this);
229 return obj->PrettyTree(do_abbrev, seen);
230 }
231 default:
232 assert(0);
233 }
234}
235
236hnode_t* DocFragment::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
237 seen = seen ? seen : Alloc<Dict<int, bool>>();
238 int heap_id = ObjectId(this);
239 if (dict_contains(seen, heap_id)) {
240 return Alloc<hnode::AlreadySeen>(heap_id);
241 }
242 seen->set(heap_id, true);
243
244 hnode::Record* out_node = runtime::NewRecord(StrFromC("DocFragment"));
245 List<Field*>* L = out_node->fields;
246
247 hnode_t* x0 = this->mdoc->PrettyTree(do_abbrev, seen);
248 L->append(Alloc<Field>(StrFromC("mdoc"), x0));
249
250 hnode_t* x1 = ToPretty(this->indent);
251 L->append(Alloc<Field>(StrFromC("indent"), x1));
252
253 hnode_t* x2 = ToPretty(this->is_flat);
254 L->append(Alloc<Field>(StrFromC("is_flat"), x2));
255
256 hnode_t* x3 = this->measure->PrettyTree(do_abbrev, seen);
257 L->append(Alloc<Field>(StrFromC("measure"), x3));
258
259 return out_node;
260}
261
262
263} // namespace pretty_asdl