OILS / _gen / data_lang / nil8.asdl.cc View on Github | oils.pub

262 lines, 175 significant
1// _gen/data_lang/nil8.asdl.cc is generated by asdl_main.py
2
3#include "_gen/data_lang/nil8.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 nil8_asdl {
14
15BigStr* nvalue_str(int tag, bool dot) {
16 char buf[32];
17 const char* v = nullptr;
18 switch (tag) {
19 case nvalue_e::Null:
20 v = "Null"; break;
21 case nvalue_e::Bool:
22 v = "Bool"; break;
23 case nvalue_e::Int:
24 v = "Int"; break;
25 case nvalue_e::Float:
26 v = "Float"; break;
27 case nvalue_e::Str:
28 v = "Str"; break;
29 case nvalue_e::Symbol:
30 v = "Symbol"; break;
31 case nvalue_e::List:
32 v = "List"; break;
33 case nvalue_e::Record:
34 v = "Record"; break;
35 default:
36 assert(0);
37 }
38 if (dot) {
39 snprintf(buf, 32, "nvalue.%s", v);
40 return StrFromC(buf);
41 } else {
42 return StrFromC(v);
43 }
44}
45
46nvalue__Null* nvalue::Null = &gnvalue__Null.obj;
47
48GcGlobal<nvalue__Null> gnvalue__Null =
49 { ObjHeader::Global(nvalue_e::Null) };
50
51hnode_t* nvalue__Null::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
52 seen = seen ? seen : Alloc<Dict<int, bool>>();
53 int heap_id = ObjectId(this);
54 if (dict_contains(seen, heap_id)) {
55 return Alloc<hnode::AlreadySeen>(heap_id);
56 }
57 seen->set(heap_id, true);
58
59 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
60 return out_node;
61}
62
63
64hnode_t* nvalue__Bool::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
65 seen = seen ? seen : Alloc<Dict<int, bool>>();
66 int heap_id = ObjectId(this);
67 if (dict_contains(seen, heap_id)) {
68 return Alloc<hnode::AlreadySeen>(heap_id);
69 }
70 seen->set(heap_id, true);
71
72 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
73 List<Field*>* L = out_node->fields;
74
75 hnode_t* x0 = ToPretty(this->b);
76 L->append(Alloc<Field>(StrFromC("b"), x0));
77
78 return out_node;
79}
80
81
82hnode_t* nvalue__Int::PrettyTree(bool do_abbrev, 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
90 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
91 List<Field*>* L = out_node->fields;
92
93 hnode_t* x0 = ToPretty(this->i);
94 L->append(Alloc<Field>(StrFromC("i"), x0));
95
96 return out_node;
97}
98
99
100hnode_t* nvalue__Float::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
101 seen = seen ? seen : Alloc<Dict<int, bool>>();
102 int heap_id = ObjectId(this);
103 if (dict_contains(seen, heap_id)) {
104 return Alloc<hnode::AlreadySeen>(heap_id);
105 }
106 seen->set(heap_id, true);
107
108 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
109 List<Field*>* L = out_node->fields;
110
111 hnode_t* x0 = ToPretty(this->f);
112 L->append(Alloc<Field>(StrFromC("f"), x0));
113
114 return out_node;
115}
116
117
118hnode_t* nvalue__Str::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
119 seen = seen ? seen : Alloc<Dict<int, bool>>();
120 int heap_id = ObjectId(this);
121 if (dict_contains(seen, heap_id)) {
122 return Alloc<hnode::AlreadySeen>(heap_id);
123 }
124 seen->set(heap_id, true);
125
126 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
127 List<Field*>* L = out_node->fields;
128
129 hnode_t* x0 = ToPretty(this->s);
130 L->append(Alloc<Field>(StrFromC("s"), x0));
131
132 return out_node;
133}
134
135
136hnode_t* nvalue__Symbol::PrettyTree(bool do_abbrev, 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
144 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
145 List<Field*>* L = out_node->fields;
146
147 hnode_t* x0 = ToPretty(this->s);
148 L->append(Alloc<Field>(StrFromC("s"), x0));
149
150 return out_node;
151}
152
153
154hnode_t* nvalue__List::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
155 seen = seen ? seen : Alloc<Dict<int, bool>>();
156 int heap_id = ObjectId(this);
157 if (dict_contains(seen, heap_id)) {
158 return Alloc<hnode::AlreadySeen>(heap_id);
159 }
160 seen->set(heap_id, true);
161
162 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
163 List<Field*>* L = out_node->fields;
164
165 if (this->items != nullptr) { // List
166 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
167 for (ListIter<nvalue_t*> it(this->items); !it.Done(); it.Next()) {
168 nvalue_t* v_ = it.Value();
169 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
170 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
171 x0->children->append(h);
172 }
173 L->append(Alloc<Field>(StrFromC("items"), x0));
174 }
175
176 return out_node;
177}
178
179
180hnode_t* nvalue__Record::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(nvalue_str(this->tag()));
189 List<Field*>* L = out_node->fields;
190
191 hnode_t* x0 = ToPretty(this->name);
192 L->append(Alloc<Field>(StrFromC("name"), x0));
193
194 if (this->args != nullptr) { // List
195 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
196 for (ListIter<nvalue_t*> it(this->args); !it.Done(); it.Next()) {
197 nvalue_t* v_ = it.Value();
198 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
199 color_e::OtherConst) : v_->PrettyTree(do_abbrev, seen);
200 x1->children->append(h);
201 }
202 L->append(Alloc<Field>(StrFromC("args"), x1));
203 }
204
205 if (this->named != nullptr) { // Dict
206 auto* unnamed = NewList<hnode_t*>();
207 auto* hdict = Alloc<hnode::Record>(kEmptyString, StrFromC("{"),
208 StrFromC("}"),
209 NewList<Field*>(), unnamed);
210 for (DictIter<BigStr*, nvalue_t*> it(this->named); !it.Done(); it.Next()) {
211 auto k = it.Key();
212 auto v = it.Value();
213 unnamed->append(ToPretty(k));
214 unnamed->append(v->PrettyTree(do_abbrev, seen));
215 }
216 L->append(Alloc<Field>(StrFromC("named"), hdict));
217 }
218
219 return out_node;
220}
221
222
223hnode_t* nvalue_t::PrettyTree(bool do_abbrev, Dict<int, bool>* seen) {
224 switch (this->tag()) {
225 case nvalue_e::Null: {
226 nvalue__Null* obj = static_cast<nvalue__Null*>(this);
227 return obj->PrettyTree(do_abbrev, seen);
228 }
229 case nvalue_e::Bool: {
230 nvalue__Bool* obj = static_cast<nvalue__Bool*>(this);
231 return obj->PrettyTree(do_abbrev, seen);
232 }
233 case nvalue_e::Int: {
234 nvalue__Int* obj = static_cast<nvalue__Int*>(this);
235 return obj->PrettyTree(do_abbrev, seen);
236 }
237 case nvalue_e::Float: {
238 nvalue__Float* obj = static_cast<nvalue__Float*>(this);
239 return obj->PrettyTree(do_abbrev, seen);
240 }
241 case nvalue_e::Str: {
242 nvalue__Str* obj = static_cast<nvalue__Str*>(this);
243 return obj->PrettyTree(do_abbrev, seen);
244 }
245 case nvalue_e::Symbol: {
246 nvalue__Symbol* obj = static_cast<nvalue__Symbol*>(this);
247 return obj->PrettyTree(do_abbrev, seen);
248 }
249 case nvalue_e::List: {
250 nvalue__List* obj = static_cast<nvalue__List*>(this);
251 return obj->PrettyTree(do_abbrev, seen);
252 }
253 case nvalue_e::Record: {
254 nvalue__Record* obj = static_cast<nvalue__Record*>(this);
255 return obj->PrettyTree(do_abbrev, seen);
256 }
257 default:
258 assert(0);
259 }
260}
261
262} // namespace nil8_asdl