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 | GLOBAL_STR(str0, "(");
|
9 | GLOBAL_STR(str1, ")");
|
10 | GLOBAL_STR(str2, "_");
|
11 | GLOBAL_STR(str3, "T");
|
12 | GLOBAL_STR(str4, "F");
|
13 | GLOBAL_STR(str5, "<%s %r>");
|
14 | GLOBAL_STR(str6, "code");
|
15 | GLOBAL_STR(str7, "message");
|
16 | GLOBAL_STR(str8, "%s, got %s");
|
17 | GLOBAL_STR(str9, " (line %d, offset %d-%d: %r)");
|
18 |
|
19 | namespace runtime { // forward declare
|
20 |
|
21 | class TraversalState;
|
22 |
|
23 | } // forward declare namespace runtime
|
24 |
|
25 | namespace num { // forward declare
|
26 |
|
27 |
|
28 | } // forward declare namespace num
|
29 |
|
30 | namespace runtime { // declare
|
31 |
|
32 | using hnode_asdl::hnode;
|
33 | extern int NO_SPID;
|
34 | hnode::Record* NewRecord(BigStr* node_type);
|
35 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
|
36 | class 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 |
|
49 | extern BigStr* TRUE_STR;
|
50 | extern BigStr* FALSE_STR;
|
51 |
|
52 | } // declare namespace runtime
|
53 |
|
54 | namespace num { // declare
|
55 |
|
56 | value::Int* ToBig(int i);
|
57 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
|
58 |
|
59 | } // declare namespace num
|
60 |
|
61 | namespace runtime { // define
|
62 |
|
63 | using hnode_asdl::hnode;
|
64 | using hnode_asdl::color_t;
|
65 | using hnode_asdl::color_e;
|
66 | int NO_SPID = -1;
|
67 |
|
68 | hnode::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 |
|
74 | hnode::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 |
|
85 | TraversalState::TraversalState() {
|
86 | this->seen = Alloc<Dict<int, bool>>();
|
87 | this->ref_count = Alloc<Dict<int, int>>();
|
88 | }
|
89 | BigStr* TRUE_STR = str3;
|
90 | BigStr* FALSE_STR = str4;
|
91 |
|
92 | } // define namespace runtime
|
93 |
|
94 | namespace error { // define
|
95 |
|
96 | using syntax_asdl::loc_e;
|
97 | using syntax_asdl::loc_t;
|
98 | using syntax_asdl::loc;
|
99 | using value_asdl::value;
|
100 | using value_asdl::value_t;
|
101 | using value_asdl::value_str;
|
102 |
|
103 | BigStr* _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 |
|
119 | bool _ErrorWithLocation::HasLocation() {
|
120 | return this->location->tag() != loc_e::Missing;
|
121 | }
|
122 |
|
123 | BigStr* _ErrorWithLocation::UserErrorString() {
|
124 | return this->msg;
|
125 | }
|
126 |
|
127 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
128 | }
|
129 |
|
130 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
131 | }
|
132 |
|
133 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
134 | }
|
135 |
|
136 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
137 | }
|
138 |
|
139 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
140 | this->exit_status = exit_status;
|
141 | }
|
142 |
|
143 | int FatalRuntime::ExitStatus() {
|
144 | return this->exit_status;
|
145 | }
|
146 |
|
147 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
|
148 | }
|
149 |
|
150 | ErrExit::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 |
|
154 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(3, msg, location) {
|
155 | }
|
156 |
|
157 | Structured::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 |
|
161 | value::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 |
|
174 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
175 | }
|
176 |
|
177 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
178 | }
|
179 |
|
180 | 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) {
|
181 | }
|
182 |
|
183 | Runtime::Runtime(BigStr* msg) {
|
184 | this->msg = msg;
|
185 | }
|
186 |
|
187 | BigStr* Runtime::UserErrorString() {
|
188 | return this->msg;
|
189 | }
|
190 |
|
191 | Decode::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 |
|
199 | BigStr* 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 |
|
211 | BigStr* Decode::__str__() {
|
212 | return this->Message();
|
213 | }
|
214 |
|
215 | Encode::Encode(BigStr* msg) {
|
216 | this->msg = msg;
|
217 | }
|
218 |
|
219 | BigStr* 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 |
|
260 | namespace num { // define
|
261 |
|
262 | using value_asdl::value;
|
263 |
|
264 | value::Int* ToBig(int i) {
|
265 | return Alloc<value::Int>(mops::IntWiden(i));
|
266 | }
|
267 |
|
268 | mops::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 |
|