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

261 lines, 145 significant
1// prebuilt/core/error.mycpp.cc: GENERATED by mycpp
2
3#include "prebuilt/core/error.mycpp.h"
4// This file is GENERATED by mycpp, from Python source code
5
6#include "mycpp/runtime.h"
7
8GLOBAL_STR(S_ijB, "(");
9GLOBAL_STR(S_hxb, ")");
10GLOBAL_STR(S_gFh, "F");
11GLOBAL_STR(S_cor, "T");
12GLOBAL_STR(S_tci, "_");
13GLOBAL_STR(S_gFE, "code");
14GLOBAL_STR(S_xho, "failglob: ");
15GLOBAL_STR(S_pBg, "message");
16
17namespace runtime { // forward declare
18 class TraversalState;
19}
20
21namespace num { // forward declare
22}
23
24namespace runtime { // declare
25
26extern int NO_SPID;
27hnode::Record* NewRecord(BigStr* node_type);
28hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
29class TraversalState {
30 public:
31 TraversalState();
32 Dict<int, bool>* seen{};
33 Dict<int, int>* ref_count{};
34
35 static constexpr ObjHeader obj_header() {
36 return ObjHeader::ClassScanned(2, sizeof(TraversalState));
37 }
38
39 DISALLOW_COPY_AND_ASSIGN(TraversalState)
40};
41
42extern BigStr* TRUE_STR;
43extern BigStr* FALSE_STR;
44
45} // declare namespace runtime
46
47namespace num { // declare
48
49value::Int* ToBig(int i);
50mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
51
52} // declare namespace num
53
54namespace runtime { // define
55
56using hnode_asdl::hnode;
57using hnode_asdl::color_t;
58using hnode_asdl::color_e;
59int NO_SPID = -1;
60
61hnode::Record* NewRecord(BigStr* node_type) {
62 return Alloc<hnode::Record>(node_type, S_ijB, S_hxb, Alloc<List<hnode_asdl::Field*>>(), nullptr);
63}
64
65hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color) {
66 if (s == nullptr) {
67 return Alloc<hnode::Leaf>(S_tci, 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 = S_cor;
79BigStr* FALSE_STR = S_gFh;
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;
91int EXPR_STATUS = 3;
92int CODEC_STATUS = 4;
93int GLOB_STATUS = 5;
94int BUILTIN_DEFAULT_STATUS = 10;
95
96BigStr* _ValType(value_asdl::value_t* val) {
97 return value_str(val->tag(), false);
98}
99
100_ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
101 this->msg = msg;
102 if (location == nullptr) {
103 this->location = loc::Missing;
104 }
105 else {
106 this->location = location;
107 }
108}
109
110bool _ErrorWithLocation::HasLocation() {
111 return this->location->tag() != loc_e::Missing;
112}
113
114BigStr* _ErrorWithLocation::UserErrorString() {
115 return this->msg;
116}
117
118Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
119}
120
121Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
122}
123
124WordFailure::WordFailure(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
125}
126
127FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::WordFailure(str_concat(S_xho, msg), location) {
128}
129
130VarSubFailure::VarSubFailure(BigStr* msg, syntax_asdl::loc_t* location) : ::error::WordFailure(msg, location) {
131}
132
133RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
134}
135
136FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
137 this->exit_status = exit_status;
138}
139
140int FatalRuntime::ExitStatus() {
141 return this->exit_status;
142}
143
144Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
145}
146
147ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : ::error::FatalRuntime(exit_status, msg, location) {
148 this->show_code = show_code;
149}
150
151NoUnset::NoUnset(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
152}
153
154Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(EXPR_STATUS, 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 d = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
164 if (this->properties != nullptr) {
165 d->update(this->properties);
166 }
167 d->set(S_gFE, num::ToBig(this->ExitStatus()));
168 d->set(S_pBg, Alloc<value::Str>(this->msg));
169 return Alloc<value::Dict>(d);
170}
171
172AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
173}
174
175TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
176}
177
178TypeErr::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) {
179}
180
181Runtime::Runtime(BigStr* msg) {
182 this->msg = msg;
183}
184
185BigStr* Runtime::UserErrorString() {
186 return this->msg;
187}
188
189Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos, int line_num) {
190 this->msg = msg;
191 this->s = s;
192 this->start_pos = start_pos;
193 this->end_pos = end_pos;
194 this->line_num = line_num;
195}
196
197BigStr* Decode::Message() {
198 int start;
199 int end;
200 BigStr* part = nullptr;
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 throw Alloc<Usage>(msg, location);
221}
222
223[[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
224 throw Alloc<Strict>(msg, location);
225}
226
227[[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
228 throw Alloc<Parse>(msg, location);
229}
230
231[[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
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 throw Alloc<FatalRuntime>(status, msg, location);
237}
238
239} // define namespace error
240
241namespace num { // define
242
243using value_asdl::value;
244
245value::Int* ToBig(int i) {
246 return Alloc<value::Int>(mops::IntWiden(i));
247}
248
249mops::BigInt Exponent(mops::BigInt x, mops::BigInt y) {
250 int y_int;
251 mops::BigInt result;
252 y_int = mops::BigTruncate(y);
253 result = mops::BigInt(1);
254 for (int i = 0; i < y_int; ++i) {
255 result = mops::Mul(result, x);
256 }
257 return result;
258}
259
260} // define namespace num
261