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

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