OILS / prebuilt / core / error.mycpp.cc View on Github | oils.pub

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