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

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