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

261 lines, 174 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(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(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 = Alloc<hnode::Leaf>(this->b ? runtime::TRUE_STR :
76 runtime::FALSE_STR, color_e::OtherConst);
77 L->append(Alloc<Field>(StrFromC("b"), x0));
78
79 return out_node;
80}
81
82
83hnode_t* nvalue__Int::PrettyTree(Dict<int, bool>* seen) {
84 seen = seen ? seen : Alloc<Dict<int, bool>>();
85 int heap_id = ObjectId(this);
86 if (dict_contains(seen, heap_id)) {
87 return Alloc<hnode::AlreadySeen>(heap_id);
88 }
89 seen->set(heap_id, true);
90
91 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
92 List<Field*>* L = out_node->fields;
93
94 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->i), color_e::OtherConst);
95 L->append(Alloc<Field>(StrFromC("i"), x0));
96
97 return out_node;
98}
99
100
101hnode_t* nvalue__Float::PrettyTree(Dict<int, bool>* seen) {
102 seen = seen ? seen : Alloc<Dict<int, bool>>();
103 int heap_id = ObjectId(this);
104 if (dict_contains(seen, heap_id)) {
105 return Alloc<hnode::AlreadySeen>(heap_id);
106 }
107 seen->set(heap_id, true);
108
109 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
110 List<Field*>* L = out_node->fields;
111
112 hnode_t* x0 = Alloc<hnode::Leaf>(str(this->f), color_e::OtherConst);
113 L->append(Alloc<Field>(StrFromC("f"), x0));
114
115 return out_node;
116}
117
118
119hnode_t* nvalue__Str::PrettyTree(Dict<int, bool>* seen) {
120 seen = seen ? seen : Alloc<Dict<int, bool>>();
121 int heap_id = ObjectId(this);
122 if (dict_contains(seen, heap_id)) {
123 return Alloc<hnode::AlreadySeen>(heap_id);
124 }
125 seen->set(heap_id, true);
126
127 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
128 List<Field*>* L = out_node->fields;
129
130 hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
131 L->append(Alloc<Field>(StrFromC("s"), x0));
132
133 return out_node;
134}
135
136
137hnode_t* nvalue__Symbol::PrettyTree(Dict<int, bool>* seen) {
138 seen = seen ? seen : Alloc<Dict<int, bool>>();
139 int heap_id = ObjectId(this);
140 if (dict_contains(seen, heap_id)) {
141 return Alloc<hnode::AlreadySeen>(heap_id);
142 }
143 seen->set(heap_id, true);
144
145 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
146 List<Field*>* L = out_node->fields;
147
148 hnode_t* x0 = runtime::NewLeaf(this->s, color_e::StringConst);
149 L->append(Alloc<Field>(StrFromC("s"), x0));
150
151 return out_node;
152}
153
154
155hnode_t* nvalue__List::PrettyTree(Dict<int, bool>* seen) {
156 seen = seen ? seen : Alloc<Dict<int, bool>>();
157 int heap_id = ObjectId(this);
158 if (dict_contains(seen, heap_id)) {
159 return Alloc<hnode::AlreadySeen>(heap_id);
160 }
161 seen->set(heap_id, true);
162
163 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
164 List<Field*>* L = out_node->fields;
165
166 if (this->items != nullptr) { // List
167 hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
168 for (ListIter<nvalue_t*> it(this->items); !it.Done(); it.Next()) {
169 nvalue_t* v_ = it.Value();
170 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
171 color_e::OtherConst) : v_->PrettyTree(seen);
172 x0->children->append(h);
173 }
174 L->append(Alloc<Field>(StrFromC("items"), x0));
175 }
176
177 return out_node;
178}
179
180
181hnode_t* nvalue__Record::PrettyTree(Dict<int, bool>* seen) {
182 seen = seen ? seen : Alloc<Dict<int, bool>>();
183 int heap_id = ObjectId(this);
184 if (dict_contains(seen, heap_id)) {
185 return Alloc<hnode::AlreadySeen>(heap_id);
186 }
187 seen->set(heap_id, true);
188
189 hnode::Record* out_node = runtime::NewRecord(nvalue_str(this->tag()));
190 List<Field*>* L = out_node->fields;
191
192 hnode_t* x0 = runtime::NewLeaf(this->name, color_e::StringConst);
193 L->append(Alloc<Field>(StrFromC("name"), x0));
194
195 if (this->args != nullptr) { // List
196 hnode::Array* x1 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
197 for (ListIter<nvalue_t*> it(this->args); !it.Done(); it.Next()) {
198 nvalue_t* v_ = it.Value();
199 hnode_t* h = (v_ == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
200 color_e::OtherConst) : v_->PrettyTree(seen);
201 x1->children->append(h);
202 }
203 L->append(Alloc<Field>(StrFromC("args"), x1));
204 }
205
206 if (this->named) { // Dict
207 auto m = Alloc<hnode::Leaf>(StrFromC("Dict"), color_e::OtherConst);
208 hnode::Array* x2 = Alloc<hnode::Array>(NewList<hnode_t*>({m}));
209 for (DictIter<BigStr*, nvalue_t*> it(this->named); !it.Done(); it.Next()) {
210 auto k2 = it.Key();
211 auto v2 = it.Value();
212 x2->children->append(runtime::NewLeaf(k2, color_e::StringConst));
213 x2->children->append(v2->PrettyTree(seen));
214 }
215 L->append(Alloc<Field>(StrFromC ("named"), x2));
216 }
217
218 return out_node;
219}
220
221
222hnode_t* nvalue_t::PrettyTree(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(seen);
227 }
228 case nvalue_e::Bool: {
229 nvalue__Bool* obj = static_cast<nvalue__Bool*>(this);
230 return obj->PrettyTree(seen);
231 }
232 case nvalue_e::Int: {
233 nvalue__Int* obj = static_cast<nvalue__Int*>(this);
234 return obj->PrettyTree(seen);
235 }
236 case nvalue_e::Float: {
237 nvalue__Float* obj = static_cast<nvalue__Float*>(this);
238 return obj->PrettyTree(seen);
239 }
240 case nvalue_e::Str: {
241 nvalue__Str* obj = static_cast<nvalue__Str*>(this);
242 return obj->PrettyTree(seen);
243 }
244 case nvalue_e::Symbol: {
245 nvalue__Symbol* obj = static_cast<nvalue__Symbol*>(this);
246 return obj->PrettyTree(seen);
247 }
248 case nvalue_e::List: {
249 nvalue__List* obj = static_cast<nvalue__List*>(this);
250 return obj->PrettyTree(seen);
251 }
252 case nvalue_e::Record: {
253 nvalue__Record* obj = static_cast<nvalue__Record*>(this);
254 return obj->PrettyTree(seen);
255 }
256 default:
257 assert(0);
258 }
259}
260
261} // namespace nil8_asdl