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 |
|
8 | namespace runtime { // forward declare
|
9 | class TraversalState;
|
10 | }
|
11 |
|
12 | namespace num { // forward declare
|
13 | }
|
14 |
|
15 | GLOBAL_STR(S_BEl, " (line %d, offset %d-%d: %r)");
|
16 | GLOBAL_STR(S_xFg, "%s, got %s");
|
17 | GLOBAL_STR(S_ijB, "(");
|
18 | GLOBAL_STR(S_hxb, ")");
|
19 | GLOBAL_STR(S_gFh, "F");
|
20 | GLOBAL_STR(S_cor, "T");
|
21 | GLOBAL_STR(S_tci, "_");
|
22 | GLOBAL_STR(S_gFE, "code");
|
23 | GLOBAL_STR(S_pBg, "message");
|
24 |
|
25 | namespace runtime { // declare
|
26 |
|
27 | extern int NO_SPID;
|
28 | hnode::Record* NewRecord(BigStr* node_type);
|
29 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
|
30 | class 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 |
|
43 | extern BigStr* TRUE_STR;
|
44 | extern BigStr* FALSE_STR;
|
45 |
|
46 | } // declare namespace runtime
|
47 |
|
48 | namespace num { // declare
|
49 |
|
50 | value::Int* ToBig(int i);
|
51 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
|
52 |
|
53 | } // declare namespace num
|
54 |
|
55 | namespace runtime { // define
|
56 |
|
57 | using hnode_asdl::hnode;
|
58 | using hnode_asdl::color_t;
|
59 | using hnode_asdl::color_e;
|
60 | int NO_SPID = -1;
|
61 |
|
62 | hnode::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 |
|
68 | hnode::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 |
|
79 | TraversalState::TraversalState() {
|
80 | this->seen = Alloc<Dict<int, bool>>();
|
81 | this->ref_count = Alloc<Dict<int, int>>();
|
82 | }
|
83 | BigStr* TRUE_STR = S_cor;
|
84 | BigStr* FALSE_STR = S_gFh;
|
85 |
|
86 | } // define namespace runtime
|
87 |
|
88 | namespace error { // define
|
89 |
|
90 | using syntax_asdl::loc_e;
|
91 | using syntax_asdl::loc_t;
|
92 | using syntax_asdl::loc;
|
93 | using value_asdl::value;
|
94 | using value_asdl::value_t;
|
95 | using value_asdl::value_str;
|
96 |
|
97 | BigStr* _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 |
|
113 | bool _ErrorWithLocation::HasLocation() {
|
114 | return this->location->tag() != loc_e::Missing;
|
115 | }
|
116 |
|
117 | BigStr* _ErrorWithLocation::UserErrorString() {
|
118 | return this->msg;
|
119 | }
|
120 |
|
121 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
122 | }
|
123 |
|
124 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
125 | }
|
126 |
|
127 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
128 | }
|
129 |
|
130 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
131 | }
|
132 |
|
133 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
134 | this->exit_status = exit_status;
|
135 | }
|
136 |
|
137 | int FatalRuntime::ExitStatus() {
|
138 | return this->exit_status;
|
139 | }
|
140 |
|
141 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
|
142 | }
|
143 |
|
144 | ErrExit::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 |
|
148 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(3, msg, location) {
|
149 | }
|
150 |
|
151 | Structured::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 |
|
155 | value::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 |
|
168 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
169 | }
|
170 |
|
171 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
172 | }
|
173 |
|
174 | TypeErr::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 |
|
177 | Runtime::Runtime(BigStr* msg) {
|
178 | this->msg = msg;
|
179 | }
|
180 |
|
181 | BigStr* Runtime::UserErrorString() {
|
182 | return this->msg;
|
183 | }
|
184 |
|
185 | Decode::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 |
|
193 | BigStr* 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 |
|
205 | BigStr* Decode::__str__() {
|
206 | return this->Message();
|
207 | }
|
208 |
|
209 | Encode::Encode(BigStr* msg) {
|
210 | this->msg = msg;
|
211 | }
|
212 |
|
213 | BigStr* 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 |
|
254 | namespace num { // define
|
255 |
|
256 | using value_asdl::value;
|
257 |
|
258 | value::Int* ToBig(int i) {
|
259 | return Alloc<value::Int>(mops::IntWiden(i));
|
260 | }
|
261 |
|
262 | mops::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 |
|