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

281 lines, 157 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;
102using value_asdl::Dict_;
103
104BigStr* _ValType(value_asdl::value_t* val) {
105 StackRoot _root0(&val);
106
107 return value_str(val->tag(), false);
108}
109
110_ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
111 this->msg = msg;
112 if (location == nullptr) {
113 this->location = loc::Missing;
114 }
115 else {
116 this->location = location;
117 }
118}
119
120bool _ErrorWithLocation::HasLocation() {
121 return this->location->tag() != loc_e::Missing;
122}
123
124BigStr* _ErrorWithLocation::UserErrorString() {
125 return this->msg;
126}
127
128Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
129}
130
131Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
132}
133
134FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
135}
136
137RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
138}
139
140FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
141 this->exit_status = exit_status;
142}
143
144int FatalRuntime::ExitStatus() {
145 return this->exit_status;
146}
147
148Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
149}
150
151ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : ::error::FatalRuntime(exit_status, msg, location) {
152 this->show_code = show_code;
153}
154
155Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(3, msg, location) {
156}
157
158Structured::Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties) : ::error::FatalRuntime(status, msg, location) {
159 this->properties = properties;
160}
161
162value_asdl::Dict_* Structured::ToDict() {
163 Dict<BigStr*, value_asdl::value_t*>* d = nullptr;
164 StackRoot _root0(&d);
165
166 d = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
167 if (this->properties != nullptr) {
168 d->update(this->properties);
169 }
170 d->set(str6, num::ToBig(this->ExitStatus()));
171 d->set(str7, Alloc<value::Str>(this->msg));
172 return Alloc<Dict_>(d, nullptr);
173}
174
175AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
176}
177
178TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
179}
180
181TypeErr::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) {
182}
183
184Runtime::Runtime(BigStr* msg) {
185 this->msg = msg;
186}
187
188BigStr* Runtime::UserErrorString() {
189 return this->msg;
190}
191
192Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos, int line_num) {
193 this->msg = msg;
194 this->s = s;
195 this->start_pos = start_pos;
196 this->end_pos = end_pos;
197 this->line_num = line_num;
198}
199
200BigStr* Decode::Message() {
201 int start;
202 int end;
203 BigStr* part = nullptr;
204 StackRoot _root0(&part);
205
206 start = max(0, (this->start_pos - 4));
207 end = min(len(this->s), (this->end_pos + 4));
208 part = this->s->slice(start, end);
209 return str_concat(this->msg, StrFormat(" (line %d, offset %d-%d: %r)", this->line_num, this->start_pos, this->end_pos, part));
210}
211
212BigStr* Decode::__str__() {
213 return this->Message();
214}
215
216Encode::Encode(BigStr* msg) {
217 this->msg = msg;
218}
219
220BigStr* Encode::Message() {
221 return this->msg;
222}
223
224[[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location) {
225 StackRoot _root0(&msg);
226 StackRoot _root1(&location);
227
228 throw Alloc<Usage>(msg, location);
229}
230
231[[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
232 StackRoot _root0(&msg);
233 StackRoot _root1(&location);
234
235 throw Alloc<Strict>(msg, location);
236}
237
238[[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
239 StackRoot _root0(&msg);
240 StackRoot _root1(&location);
241
242 throw Alloc<Parse>(msg, location);
243}
244
245[[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
246 StackRoot _root0(&msg);
247 StackRoot _root1(&location);
248
249 throw Alloc<FatalRuntime>(1, msg, location);
250}
251
252[[noreturn]] void e_die_status(int status, BigStr* msg, syntax_asdl::loc_t* location) {
253 StackRoot _root0(&msg);
254 StackRoot _root1(&location);
255
256 throw Alloc<FatalRuntime>(status, msg, location);
257}
258
259} // define namespace error
260
261namespace num { // define
262
263using value_asdl::value;
264
265value::Int* ToBig(int i) {
266 return Alloc<value::Int>(mops::IntWiden(i));
267}
268
269mops::BigInt Exponent(mops::BigInt x, mops::BigInt y) {
270 int y_int;
271 mops::BigInt result;
272 y_int = mops::BigTruncate(y);
273 result = mops::BigInt(1);
274 for (int i = 0; i < y_int; ++i) {
275 result = mops::Mul(result, x);
276 }
277 return result;
278}
279
280} // define namespace num
281