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

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