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

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