OILS / prebuilt / core / error.mycpp.cc View on Github | oilshell.org

243 lines, 136 significant
1// prebuilt/core/error.mycpp.cc: GENERATED by mycpp
2
3#include "prebuilt/core/error.mycpp.h"
4// BEGIN mycpp output
5
6#include "mycpp/runtime.h"
7
8GLOBAL_STR(str0, "(");
9GLOBAL_STR(str1, ")");
10GLOBAL_STR(str2, "_");
11GLOBAL_STR(str3, "T");
12GLOBAL_STR(str4, "F");
13GLOBAL_STR(str5, "<%s %r>");
14GLOBAL_STR(str6, "status");
15GLOBAL_STR(str7, "message");
16GLOBAL_STR(str8, "%s, got %s");
17GLOBAL_STR(str9, " (pos %d-%d: %r)");
18
19namespace runtime { // forward declare
20
21 class TraversalState;
22
23} // forward declare namespace runtime
24
25namespace runtime { // declare
26
27using hnode_asdl::hnode;
28extern int NO_SPID;
29hnode::Record* NewRecord(BigStr* node_type);
30hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
31class TraversalState {
32 public:
33 TraversalState();
34 Dict<int, bool>* seen;
35 Dict<int, int>* ref_count;
36
37 static constexpr ObjHeader obj_header() {
38 return ObjHeader::ClassScanned(2, sizeof(TraversalState));
39 }
40
41 DISALLOW_COPY_AND_ASSIGN(TraversalState)
42};
43
44extern BigStr* TRUE_STR;
45extern BigStr* FALSE_STR;
46
47
48} // declare namespace runtime
49
50namespace runtime { // define
51
52using hnode_asdl::hnode;
53using hnode_asdl::color_t;
54using hnode_asdl::color_e;
55int NO_SPID = -1;
56
57hnode::Record* NewRecord(BigStr* node_type) {
58 StackRoot _root0(&node_type);
59
60 return Alloc<hnode::Record>(node_type, Alloc<List<hnode_asdl::Field*>>(), false, str0, str1, Alloc<List<hnode_asdl::hnode_t*>>());
61}
62
63hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color) {
64 StackRoot _root0(&s);
65
66 if (s == nullptr) {
67 return Alloc<hnode::Leaf>(str2, color_e::OtherConst);
68 }
69 else {
70 return Alloc<hnode::Leaf>(s, e_color);
71 }
72}
73
74TraversalState::TraversalState() {
75 this->seen = Alloc<Dict<int, bool>>();
76 this->ref_count = Alloc<Dict<int, int>>();
77}
78BigStr* TRUE_STR = str3;
79BigStr* FALSE_STR = str4;
80
81} // define namespace runtime
82
83namespace error { // define
84
85using syntax_asdl::loc_e;
86using syntax_asdl::loc_t;
87using syntax_asdl::loc;
88using value_asdl::value;
89using value_asdl::value_t;
90using value_asdl::value_str;
91
92BigStr* _ValType(value_asdl::value_t* val) {
93 StackRoot _root0(&val);
94
95 return value_str(val->tag(), false);
96}
97
98_ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
99 this->msg = msg;
100 if (location == nullptr) {
101 this->location = loc::Missing;
102 }
103 else {
104 this->location = location;
105 }
106}
107
108bool _ErrorWithLocation::HasLocation() {
109 return this->location->tag() != loc_e::Missing;
110}
111
112BigStr* _ErrorWithLocation::UserErrorString() {
113 return this->msg;
114}
115
116Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
117}
118
119Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
120}
121
122FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
123}
124
125RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
126}
127
128FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
129 this->exit_status = exit_status;
130}
131
132int FatalRuntime::ExitStatus() {
133 return this->exit_status;
134}
135
136Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(1, msg, location) {
137}
138
139ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : FatalRuntime(exit_status, msg, location) {
140 this->show_code = show_code;
141}
142
143Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(3, msg, location) {
144}
145
146Structured::Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties) : FatalRuntime(status, msg, location) {
147 this->properties = properties;
148}
149
150value::Dict* Structured::ToDict() {
151 if (this->properties == nullptr) {
152 this->properties = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
153 }
154 this->properties->set(str6, Alloc<value::Int>(this->ExitStatus()));
155 this->properties->set(str7, Alloc<value::Str>(this->msg));
156 return Alloc<value::Dict>(this->properties);
157}
158
159AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
160}
161
162TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
163}
164
165TypeErr::TypeErr(value_asdl::value_t* actual_val, BigStr* msg, syntax_asdl::loc_t* location) : TypeErrVerbose(StrFormat("%s, got %s", msg, _ValType(actual_val)), location) {
166}
167
168Runtime::Runtime(BigStr* msg) {
169 this->msg = msg;
170}
171
172BigStr* Runtime::UserErrorString() {
173 return this->msg;
174}
175
176Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos) {
177 this->msg = msg;
178 this->s = s;
179 this->start_pos = start_pos;
180 this->end_pos = end_pos;
181}
182
183BigStr* Decode::Message() {
184 int start;
185 int end;
186 BigStr* part = nullptr;
187 StackRoot _root0(&part);
188
189 start = max(0, (this->start_pos - 4));
190 end = min(len(this->s), (this->end_pos + 4));
191 part = this->s->slice(start, end);
192 return str_concat(this->msg, StrFormat(" (pos %d-%d: %r)", this->start_pos, this->end_pos, part));
193}
194
195BigStr* Decode::__str__() {
196 return this->Message();
197}
198
199Encode::Encode(BigStr* msg) {
200 this->msg = msg;
201}
202
203BigStr* Encode::Message() {
204 return this->msg;
205}
206
207[[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location) {
208 StackRoot _root0(&msg);
209 StackRoot _root1(&location);
210
211 throw Alloc<Usage>(msg, location);
212}
213
214[[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
215 StackRoot _root0(&msg);
216 StackRoot _root1(&location);
217
218 throw Alloc<Strict>(msg, location);
219}
220
221[[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
222 StackRoot _root0(&msg);
223 StackRoot _root1(&location);
224
225 throw Alloc<Parse>(msg, location);
226}
227
228[[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
229 StackRoot _root0(&msg);
230 StackRoot _root1(&location);
231
232 throw Alloc<FatalRuntime>(1, msg, location);
233}
234
235[[noreturn]] void e_die_status(int status, BigStr* msg, syntax_asdl::loc_t* location) {
236 StackRoot _root0(&msg);
237 StackRoot _root1(&location);
238
239 throw Alloc<FatalRuntime>(status, msg, location);
240}
241
242} // define namespace error
243