OILS / _gen / asdl / hnode.asdl.h View on Github | oils.pub

188 lines, 125 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 Leaf = 2,
30 Array = 3,
31 Record = 4,
32 };
33};
34
35class hnode_t {
36 protected:
37 hnode_t() {
38 }
39 public:
40 int tag() const {
41 return ObjHeader::FromObject(this)->type_tag;
42 }
43 constexpr int sum_type_id() {
44 return 0;
45 }
46
47 DISALLOW_COPY_AND_ASSIGN(hnode_t)
48};
49
50class hnode__AlreadySeen : public hnode_t {
51 public:
52 hnode__AlreadySeen(int heap_id)
53 : heap_id(heap_id) {
54 }
55
56 static hnode__AlreadySeen* CreateNull(bool alloc_lists = false) {
57 return Alloc<hnode__AlreadySeen>(-1);
58 }
59
60 int type_id() {
61 return this->sum_type_id() + this->tag();
62 }
63
64 static constexpr ObjHeader obj_header() {
65 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::AlreadySeen), 0);
66 }
67 int heap_id;
68
69 DISALLOW_COPY_AND_ASSIGN(hnode__AlreadySeen)
70};
71
72class hnode__Leaf : public hnode_t {
73 public:
74 hnode__Leaf(BigStr* s, color_t color)
75 : s(s),
76 color(color) {
77 }
78
79 static hnode__Leaf* CreateNull(bool alloc_lists = false) {
80 return Alloc<hnode__Leaf>(kEmptyString, color_e::TypeName);
81 }
82
83 int type_id() {
84 return this->sum_type_id() + this->tag();
85 }
86
87 static constexpr ObjHeader obj_header() {
88 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::Leaf), 1);
89 }
90 BigStr* s;
91 color_t color;
92
93 DISALLOW_COPY_AND_ASSIGN(hnode__Leaf)
94};
95
96class hnode__Array : public hnode_t {
97 public:
98 hnode__Array(List<hnode_t*>* children)
99 : children(children) {
100 }
101
102 static hnode__Array* CreateNull(bool alloc_lists = false) {
103 return Alloc<hnode__Array>(alloc_lists ? Alloc<List<hnode_t*>>() : nullptr);
104 }
105
106 int type_id() {
107 return this->sum_type_id() + this->tag();
108 }
109
110 static constexpr ObjHeader obj_header() {
111 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::Array), 1);
112 }
113 List<hnode_t*>* children;
114
115 DISALLOW_COPY_AND_ASSIGN(hnode__Array)
116};
117
118class hnode__Record : public hnode_t {
119 public:
120 hnode__Record(BigStr* node_type, BigStr* left, BigStr* right, List<Field*>*
121 fields, List<hnode_t*>* unnamed_fields)
122 : node_type(node_type),
123 left(left),
124 right(right),
125 fields(fields),
126 unnamed_fields(unnamed_fields) {
127 }
128
129 static hnode__Record* CreateNull(bool alloc_lists = false) {
130 return Alloc<hnode__Record>(kEmptyString, kEmptyString, kEmptyString,
131 alloc_lists ? Alloc<List<Field*>>() : nullptr,
132 nullptr);
133 }
134
135 int type_id() {
136 return this->sum_type_id() + this->tag();
137 }
138
139 static constexpr ObjHeader obj_header() {
140 return ObjHeader::AsdlClass(static_cast<uint16_t>(hnode_e::Record), 5);
141 }
142 BigStr* node_type;
143 BigStr* left;
144 BigStr* right;
145 List<Field*>* fields;
146 List<hnode_t*>* unnamed_fields;
147
148 DISALLOW_COPY_AND_ASSIGN(hnode__Record)
149};
150
151ASDL_NAMES hnode {
152 typedef hnode__AlreadySeen AlreadySeen;
153 typedef hnode__Leaf Leaf;
154 typedef hnode__Array Array;
155 typedef hnode__Record Record;
156};
157
158enum class alloc_members_e {
159 List = 1,
160 Dict = 2,
161 Struct = 3,
162};
163typedef alloc_members_e alloc_members_t;
164
165class Field {
166 public:
167 Field(BigStr* name, hnode_t* val)
168 : name(name),
169 val(val) {
170 }
171
172 static Field* CreateNull(bool alloc_lists = false) {
173 return Alloc<Field>(kEmptyString, nullptr);
174 }
175
176 static constexpr ObjHeader obj_header() {
177 return ObjHeader::AsdlClass(64, 2);
178 }
179 BigStr* name;
180 hnode_t* val;
181
182 DISALLOW_COPY_AND_ASSIGN(Field)
183};
184
185
186} // namespace hnode_asdl
187
188#endif // HNODE_ASDL