OILS / _gen / asdl / hnode.asdl.h View on Github | oilshell.org

197 lines, 131 significant
1// _gen/asdl/hnode.asdl.h is generated by asdl_main.py
2
3#ifndef HNODE_ASDL
4#define HNODE_ASDL
5
6#include <cstdint>
7
8#include "mycpp/runtime.h"
9namespace hnode_asdl {
10
11// use struct instead of namespace so 'using' works consistently
12#define ASDL_NAMES struct
13
14class Field;
15class hnode_t;
16
17enum class color_e {
18 TypeName = 1,
19 StringConst = 2,
20 OtherConst = 3,
21 UserType = 4,
22 External = 5,
23};
24typedef color_e color_t;
25
26ASDL_NAMES hnode_e {
27 enum no_name {
28 AlreadySeen = 1,
29 Record = 2,
30 Array = 3,
31 Leaf = 4,
32 External = 5,
33 };
34};
35
36class hnode_t {
37 protected:
38 hnode_t() {
39 }
40 public:
41 int tag() const {
42 return ObjHeader::FromObject(this)->type_tag;
43 }
44 DISALLOW_COPY_AND_ASSIGN(hnode_t)
45};
46
47class hnode__AlreadySeen : public hnode_t {
48 public:
49 hnode__AlreadySeen(int heap_id)
50 : heap_id(heap_id) {
51 }
52
53 static hnode__AlreadySeen* CreateNull(bool alloc_lists = false) {
54 return Alloc<hnode__AlreadySeen>(-1);
55 }
56
57 static constexpr ObjHeader obj_header() {
58 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::AlreadySeen), 0);
59 }
60
61 int heap_id;
62
63 DISALLOW_COPY_AND_ASSIGN(hnode__AlreadySeen)
64};
65
66class hnode__Record : public hnode_t {
67 public:
68 hnode__Record(BigStr* node_type, List<Field*>* fields, bool abbrev, BigStr*
69 left, BigStr* right, List<hnode_t*>* unnamed_fields)
70 : node_type(node_type),
71 fields(fields),
72 left(left),
73 right(right),
74 unnamed_fields(unnamed_fields),
75 abbrev(abbrev) {
76 }
77
78 static hnode__Record* CreateNull(bool alloc_lists = false) {
79 return Alloc<hnode__Record>(kEmptyString, alloc_lists ?
80 Alloc<List<Field*>>() : nullptr, false,
81 kEmptyString, kEmptyString, alloc_lists ?
82 Alloc<List<hnode_t*>>() : nullptr);
83 }
84
85 static constexpr ObjHeader obj_header() {
86 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::Record), 5);
87 }
88
89 BigStr* node_type;
90 List<Field*>* fields;
91 BigStr* left;
92 BigStr* right;
93 List<hnode_t*>* unnamed_fields;
94 bool abbrev;
95
96 DISALLOW_COPY_AND_ASSIGN(hnode__Record)
97};
98
99class hnode__Array : public hnode_t {
100 public:
101 hnode__Array(List<hnode_t*>* children)
102 : children(children) {
103 }
104
105 static hnode__Array* CreateNull(bool alloc_lists = false) {
106 return Alloc<hnode__Array>(alloc_lists ? Alloc<List<hnode_t*>>() : nullptr);
107 }
108
109 static constexpr ObjHeader obj_header() {
110 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::Array), 1);
111 }
112
113 List<hnode_t*>* children;
114
115 DISALLOW_COPY_AND_ASSIGN(hnode__Array)
116};
117
118class hnode__Leaf : public hnode_t {
119 public:
120 hnode__Leaf(BigStr* s, color_t color)
121 : s(s),
122 color(color) {
123 }
124
125 static hnode__Leaf* CreateNull(bool alloc_lists = false) {
126 return Alloc<hnode__Leaf>(kEmptyString, color_e::TypeName);
127 }
128
129 static constexpr ObjHeader obj_header() {
130 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::Leaf), 1);
131 }
132
133 BigStr* s;
134 color_t color;
135
136 DISALLOW_COPY_AND_ASSIGN(hnode__Leaf)
137};
138
139class hnode__External : public hnode_t {
140 public:
141 hnode__External(void* obj)
142 : obj(obj) {
143 }
144
145 static hnode__External* CreateNull(bool alloc_lists = false) {
146 return Alloc<hnode__External>(nullptr);
147 }
148
149 static constexpr ObjHeader obj_header() {
150 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::External), 1);
151 }
152
153 void* obj;
154
155 DISALLOW_COPY_AND_ASSIGN(hnode__External)
156};
157
158ASDL_NAMES hnode {
159 typedef hnode__AlreadySeen AlreadySeen;
160 typedef hnode__Record Record;
161 typedef hnode__Array Array;
162 typedef hnode__Leaf Leaf;
163 typedef hnode__External External;
164};
165
166enum class alloc_members_e {
167 List = 1,
168 Dict = 2,
169 Struct = 3,
170};
171typedef alloc_members_e alloc_members_t;
172
173class Field {
174 public:
175 Field(BigStr* name, hnode_t* val)
176 : name(name),
177 val(val) {
178 }
179
180 static Field* CreateNull(bool alloc_lists = false) {
181 return Alloc<Field>(kEmptyString, nullptr);
182 }
183
184 static constexpr ObjHeader obj_header() {
185 return ObjHeader::AsdlClass(64, 2);
186 }
187
188 BigStr* name;
189 hnode_t* val;
190
191 DISALLOW_COPY_AND_ASSIGN(Field)
192};
193
194
195} // namespace hnode_asdl
196
197#endif // HNODE_ASDL