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, "status");
|
15 | GLOBAL_STR(str7, "message");
|
16 | GLOBAL_STR(str8, "%s, got %s");
|
17 | GLOBAL_STR(str9, " (pos %d-%d: %r)");
|
18 |
|
19 | namespace runtime { // forward declare
|
20 |
|
21 | class TraversalState;
|
22 |
|
23 | } // forward declare namespace runtime
|
24 |
|
25 | namespace runtime { // declare
|
26 |
|
27 | using hnode_asdl::hnode;
|
28 | extern int NO_SPID;
|
29 | hnode::Record* NewRecord(BigStr* node_type);
|
30 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
|
31 | class TraversalState {
|
32 | public:
|
33 | TraversalState();
|
34 | Dict<int, bool>* seen;
|
35 | Dict<int, int>* ref_count;
|
36 |
|
37 | static constexpr ObjHeader obj_header() {
|
38 | return ObjHeader::ClassScanned(2, sizeof(TraversalState));
|
39 | }
|
40 |
|
41 | DISALLOW_COPY_AND_ASSIGN(TraversalState)
|
42 | };
|
43 |
|
44 | extern BigStr* TRUE_STR;
|
45 | extern BigStr* FALSE_STR;
|
46 |
|
47 |
|
48 | } // declare namespace runtime
|
49 |
|
50 | namespace runtime { // define
|
51 |
|
52 | using hnode_asdl::hnode;
|
53 | using hnode_asdl::color_t;
|
54 | using hnode_asdl::color_e;
|
55 | int NO_SPID = -1;
|
56 |
|
57 | hnode::Record* NewRecord(BigStr* node_type) {
|
58 | StackRoot _root0(&node_type);
|
59 |
|
60 | return Alloc<hnode::Record>(node_type, Alloc<List<hnode_asdl::Field*>>(), false, str0, str1, Alloc<List<hnode_asdl::hnode_t*>>());
|
61 | }
|
62 |
|
63 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color) {
|
64 | StackRoot _root0(&s);
|
65 |
|
66 | if (s == nullptr) {
|
67 | return Alloc<hnode::Leaf>(str2, color_e::OtherConst);
|
68 | }
|
69 | else {
|
70 | return Alloc<hnode::Leaf>(s, e_color);
|
71 | }
|
72 | }
|
73 |
|
74 | TraversalState::TraversalState() {
|
75 | this->seen = Alloc<Dict<int, bool>>();
|
76 | this->ref_count = Alloc<Dict<int, int>>();
|
77 | }
|
78 | BigStr* TRUE_STR = str3;
|
79 | BigStr* FALSE_STR = str4;
|
80 |
|
81 | } // define namespace runtime
|
82 |
|
83 | namespace error { // define
|
84 |
|
85 | using syntax_asdl::loc_e;
|
86 | using syntax_asdl::loc_t;
|
87 | using syntax_asdl::loc;
|
88 | using value_asdl::value;
|
89 | using value_asdl::value_t;
|
90 | using value_asdl::value_str;
|
91 |
|
92 | BigStr* _ValType(value_asdl::value_t* val) {
|
93 | StackRoot _root0(&val);
|
94 |
|
95 | return value_str(val->tag(), false);
|
96 | }
|
97 |
|
98 | _ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
|
99 | this->msg = msg;
|
100 | if (location == nullptr) {
|
101 | this->location = loc::Missing;
|
102 | }
|
103 | else {
|
104 | this->location = location;
|
105 | }
|
106 | }
|
107 |
|
108 | bool _ErrorWithLocation::HasLocation() {
|
109 | return this->location->tag() != loc_e::Missing;
|
110 | }
|
111 |
|
112 | BigStr* _ErrorWithLocation::UserErrorString() {
|
113 | return this->msg;
|
114 | }
|
115 |
|
116 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
117 | }
|
118 |
|
119 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
120 | }
|
121 |
|
122 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
123 | }
|
124 |
|
125 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
126 | }
|
127 |
|
128 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
129 | this->exit_status = exit_status;
|
130 | }
|
131 |
|
132 | int FatalRuntime::ExitStatus() {
|
133 | return this->exit_status;
|
134 | }
|
135 |
|
136 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(1, msg, location) {
|
137 | }
|
138 |
|
139 | ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : FatalRuntime(exit_status, msg, location) {
|
140 | this->show_code = show_code;
|
141 | }
|
142 |
|
143 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(3, msg, location) {
|
144 | }
|
145 |
|
146 | Structured::Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties) : FatalRuntime(status, msg, location) {
|
147 | this->properties = properties;
|
148 | }
|
149 |
|
150 | value::Dict* Structured::ToDict() {
|
151 | if (this->properties == nullptr) {
|
152 | this->properties = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
|
153 | }
|
154 | this->properties->set(str6, Alloc<value::Int>(this->ExitStatus()));
|
155 | this->properties->set(str7, Alloc<value::Str>(this->msg));
|
156 | return Alloc<value::Dict>(this->properties);
|
157 | }
|
158 |
|
159 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
|
160 | }
|
161 |
|
162 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
|
163 | }
|
164 |
|
165 | TypeErr::TypeErr(value_asdl::value_t* actual_val, BigStr* msg, syntax_asdl::loc_t* location) : TypeErrVerbose(StrFormat("%s, got %s", msg, _ValType(actual_val)), location) {
|
166 | }
|
167 |
|
168 | Runtime::Runtime(BigStr* msg) {
|
169 | this->msg = msg;
|
170 | }
|
171 |
|
172 | BigStr* Runtime::UserErrorString() {
|
173 | return this->msg;
|
174 | }
|
175 |
|
176 | Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos) {
|
177 | this->msg = msg;
|
178 | this->s = s;
|
179 | this->start_pos = start_pos;
|
180 | this->end_pos = end_pos;
|
181 | }
|
182 |
|
183 | BigStr* Decode::Message() {
|
184 | int start;
|
185 | int end;
|
186 | BigStr* part = nullptr;
|
187 | StackRoot _root0(&part);
|
188 |
|
189 | start = max(0, (this->start_pos - 4));
|
190 | end = min(len(this->s), (this->end_pos + 4));
|
191 | part = this->s->slice(start, end);
|
192 | return str_concat(this->msg, StrFormat(" (pos %d-%d: %r)", this->start_pos, this->end_pos, part));
|
193 | }
|
194 |
|
195 | BigStr* Decode::__str__() {
|
196 | return this->Message();
|
197 | }
|
198 |
|
199 | Encode::Encode(BigStr* msg) {
|
200 | this->msg = msg;
|
201 | }
|
202 |
|
203 | BigStr* Encode::Message() {
|
204 | return this->msg;
|
205 | }
|
206 |
|
207 | [[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location) {
|
208 | StackRoot _root0(&msg);
|
209 | StackRoot _root1(&location);
|
210 |
|
211 | throw Alloc<Usage>(msg, location);
|
212 | }
|
213 |
|
214 | [[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
|
215 | StackRoot _root0(&msg);
|
216 | StackRoot _root1(&location);
|
217 |
|
218 | throw Alloc<Strict>(msg, location);
|
219 | }
|
220 |
|
221 | [[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
|
222 | StackRoot _root0(&msg);
|
223 | StackRoot _root1(&location);
|
224 |
|
225 | throw Alloc<Parse>(msg, location);
|
226 | }
|
227 |
|
228 | [[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
|
229 | StackRoot _root0(&msg);
|
230 | StackRoot _root1(&location);
|
231 |
|
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 | StackRoot _root0(&msg);
|
237 | StackRoot _root1(&location);
|
238 |
|
239 | throw Alloc<FatalRuntime>(status, msg, location);
|
240 | }
|
241 |
|
242 | } // define namespace error
|
243 |
|