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

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