1 | // prebuilt/frontend/args.mycpp.cc: GENERATED by mycpp
|
2 |
|
3 | #include "prebuilt/frontend/args.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, "\n<html>\n <head>\n <title>oil AST</title>\n <style>\n .n { color: brown }\n .s { font-weight: bold }\n .o { color: darkgreen }\n </style>\n </head>\n <body>\n <pre>\n");
|
14 | GLOBAL_STR(str6, "\n </pre>\n </body>\n</html>\n ");
|
15 | GLOBAL_STR(str7, "n");
|
16 | GLOBAL_STR(str8, "s");
|
17 | GLOBAL_STR(str9, "o");
|
18 | GLOBAL_STR(str10, "o");
|
19 | GLOBAL_STR(str11, "o");
|
20 | GLOBAL_STR(str12, "<span class=\"%s\">");
|
21 | GLOBAL_STR(str13, "</span>");
|
22 | GLOBAL_STR(str14, " ");
|
23 | GLOBAL_STR(str15, "\n");
|
24 | GLOBAL_STR(str16, " ");
|
25 | GLOBAL_STR(str17, "]");
|
26 | GLOBAL_STR(str18, " ");
|
27 | GLOBAL_STR(str19, " ");
|
28 | GLOBAL_STR(str20, "\n");
|
29 | GLOBAL_STR(str21, "\n");
|
30 | GLOBAL_STR(str22, " ");
|
31 | GLOBAL_STR(str23, "%s%s: [");
|
32 | GLOBAL_STR(str24, "\n");
|
33 | GLOBAL_STR(str25, "\n");
|
34 | GLOBAL_STR(str26, "%s]");
|
35 | GLOBAL_STR(str27, "%s%s: ");
|
36 | GLOBAL_STR(str28, "\n");
|
37 | GLOBAL_STR(str29, "\n");
|
38 | GLOBAL_STR(str30, " ");
|
39 | GLOBAL_STR(str31, "UNTYPED any");
|
40 | GLOBAL_STR(str32, "...0x%s");
|
41 | GLOBAL_STR(str33, " ");
|
42 | GLOBAL_STR(str34, " ");
|
43 | GLOBAL_STR(str35, " %s:");
|
44 | GLOBAL_STR(str36, "UNTYPED any");
|
45 | GLOBAL_STR(str37, "[");
|
46 | GLOBAL_STR(str38, " ");
|
47 | GLOBAL_STR(str39, "]");
|
48 | GLOBAL_STR(str40, "...0x%s");
|
49 | GLOBAL_STR(str41, "\u001b[0;0m");
|
50 | GLOBAL_STR(str42, "\u001b[1m");
|
51 | GLOBAL_STR(str43, "\u001b[4m");
|
52 | GLOBAL_STR(str44, "\u001b[7m");
|
53 | GLOBAL_STR(str45, "\u001b[31m");
|
54 | GLOBAL_STR(str46, "\u001b[32m");
|
55 | GLOBAL_STR(str47, "\u001b[33m");
|
56 | GLOBAL_STR(str48, "\u001b[34m");
|
57 | GLOBAL_STR(str49, "\u001b[35m");
|
58 | GLOBAL_STR(str50, "\u001b[36m");
|
59 | GLOBAL_STR(str51, "&");
|
60 | GLOBAL_STR(str52, "&");
|
61 | GLOBAL_STR(str53, "<");
|
62 | GLOBAL_STR(str54, "<");
|
63 | GLOBAL_STR(str55, ">");
|
64 | GLOBAL_STR(str56, ">");
|
65 | GLOBAL_STR(str57, "<%s %r>");
|
66 | GLOBAL_STR(str58, "status");
|
67 | GLOBAL_STR(str59, "message");
|
68 | GLOBAL_STR(str60, "%s, got %s");
|
69 | GLOBAL_STR(str61, " (line %d, offset %d-%d: %r)");
|
70 | GLOBAL_STR(str62, "-");
|
71 | GLOBAL_STR(str63, "_");
|
72 | GLOBAL_STR(str64, "<_Attributes %s>");
|
73 | GLOBAL_STR(str65, "<args.Reader %r %d>");
|
74 | GLOBAL_STR(str66, "expected argument to %r");
|
75 | GLOBAL_STR(str67, "-");
|
76 | GLOBAL_STR(str68, "expected integer after %s, got %r");
|
77 | GLOBAL_STR(str69, "-");
|
78 | GLOBAL_STR(str70, "got invalid integer for %s: %s");
|
79 | GLOBAL_STR(str71, "-");
|
80 | GLOBAL_STR(str72, "expected number after %r, got %r");
|
81 | GLOBAL_STR(str73, "-");
|
82 | GLOBAL_STR(str74, "got invalid float for %s: %s");
|
83 | GLOBAL_STR(str75, "-");
|
84 | GLOBAL_STR(str76, "got invalid argument %r to %r, expected one of: %s");
|
85 | GLOBAL_STR(str77, "-");
|
86 | GLOBAL_STR(str78, "|");
|
87 | GLOBAL_STR(str79, "0");
|
88 | GLOBAL_STR(str80, "F");
|
89 | GLOBAL_STR(str81, "false");
|
90 | GLOBAL_STR(str82, "False");
|
91 | GLOBAL_STR(str83, "1");
|
92 | GLOBAL_STR(str84, "T");
|
93 | GLOBAL_STR(str85, "true");
|
94 | GLOBAL_STR(str86, "Talse");
|
95 | GLOBAL_STR(str87, "got invalid argument to boolean flag: %r");
|
96 | GLOBAL_STR(str88, "-");
|
97 | GLOBAL_STR(str89, "-");
|
98 | GLOBAL_STR(str90, "Invalid option %r");
|
99 | GLOBAL_STR(str91, "Expected argument for action");
|
100 | GLOBAL_STR(str92, "Invalid action name %r");
|
101 | GLOBAL_STR(str93, "--");
|
102 | GLOBAL_STR(str94, "--");
|
103 | GLOBAL_STR(str95, "=");
|
104 | GLOBAL_STR(str96, "got invalid flag %r");
|
105 | GLOBAL_STR(str97, "-");
|
106 | GLOBAL_STR(str98, "0");
|
107 | GLOBAL_STR(str99, "Z");
|
108 | GLOBAL_STR(str100, "-");
|
109 | GLOBAL_STR(str101, "doesn't accept flag %s");
|
110 | GLOBAL_STR(str102, "-");
|
111 | GLOBAL_STR(str103, "+");
|
112 | GLOBAL_STR(str104, "+");
|
113 | GLOBAL_STR(str105, "doesn't accept option %s");
|
114 | GLOBAL_STR(str106, "+");
|
115 | GLOBAL_STR(str107, "-");
|
116 | GLOBAL_STR(str108, "--");
|
117 | GLOBAL_STR(str109, "--");
|
118 | GLOBAL_STR(str110, "got invalid flag %r");
|
119 | GLOBAL_STR(str111, "-");
|
120 | GLOBAL_STR(str112, "+");
|
121 | GLOBAL_STR(str113, "got invalid flag %r");
|
122 | GLOBAL_STR(str114, "-");
|
123 |
|
124 | namespace ansi { // forward declare
|
125 |
|
126 |
|
127 | } // forward declare namespace ansi
|
128 |
|
129 | namespace cgi { // forward declare
|
130 |
|
131 |
|
132 | } // forward declare namespace cgi
|
133 |
|
134 | namespace j8_lite { // forward declare
|
135 |
|
136 |
|
137 | } // forward declare namespace j8_lite
|
138 |
|
139 | namespace error { // forward declare
|
140 |
|
141 | class _ErrorWithLocation;
|
142 | class Usage;
|
143 | class Parse;
|
144 | class FailGlob;
|
145 | class RedirectEval;
|
146 | class FatalRuntime;
|
147 | class Strict;
|
148 | class ErrExit;
|
149 | class Expr;
|
150 | class Structured;
|
151 | class AssertionErr;
|
152 | class TypeErrVerbose;
|
153 | class TypeErr;
|
154 | class Runtime;
|
155 | class Decode;
|
156 | class Encode;
|
157 |
|
158 | } // forward declare namespace error
|
159 |
|
160 | namespace num { // forward declare
|
161 |
|
162 |
|
163 | } // forward declare namespace num
|
164 |
|
165 | namespace ansi { // declare
|
166 |
|
167 | extern BigStr* RESET;
|
168 | extern BigStr* BOLD;
|
169 | extern BigStr* UNDERLINE;
|
170 | extern BigStr* REVERSE;
|
171 | extern BigStr* RED;
|
172 | extern BigStr* GREEN;
|
173 | extern BigStr* YELLOW;
|
174 | extern BigStr* BLUE;
|
175 | extern BigStr* MAGENTA;
|
176 | extern BigStr* CYAN;
|
177 |
|
178 |
|
179 | } // declare namespace ansi
|
180 |
|
181 | namespace cgi { // declare
|
182 |
|
183 | BigStr* escape(BigStr* s);
|
184 |
|
185 |
|
186 | } // declare namespace cgi
|
187 |
|
188 | namespace j8_lite { // declare
|
189 |
|
190 | BigStr* EncodeString(BigStr* s, bool unquoted_ok = false);
|
191 | BigStr* MaybeShellEncode(BigStr* s);
|
192 | BigStr* ShellEncode(BigStr* s);
|
193 | BigStr* YshEncode(BigStr* s, bool unquoted_ok = false);
|
194 |
|
195 |
|
196 | } // declare namespace j8_lite
|
197 |
|
198 | namespace error { // declare
|
199 |
|
200 | using syntax_asdl::loc;
|
201 | BigStr* _ValType(value_asdl::value_t* val);
|
202 | class _ErrorWithLocation {
|
203 | public:
|
204 | _ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location);
|
205 | bool HasLocation();
|
206 | BigStr* UserErrorString();
|
207 | syntax_asdl::loc_t* location;
|
208 | BigStr* msg;
|
209 |
|
210 | static constexpr uint32_t field_mask() {
|
211 | return maskbit(offsetof(_ErrorWithLocation, location))
|
212 | | maskbit(offsetof(_ErrorWithLocation, msg));
|
213 | }
|
214 |
|
215 | static constexpr ObjHeader obj_header() {
|
216 | return ObjHeader::ClassFixed(field_mask(), sizeof(_ErrorWithLocation));
|
217 | }
|
218 |
|
219 | DISALLOW_COPY_AND_ASSIGN(_ErrorWithLocation)
|
220 | };
|
221 |
|
222 | class Usage : public _ErrorWithLocation {
|
223 | public:
|
224 | Usage(BigStr* msg, syntax_asdl::loc_t* location);
|
225 |
|
226 | static constexpr uint32_t field_mask() {
|
227 | return _ErrorWithLocation::field_mask();
|
228 | }
|
229 |
|
230 | static constexpr ObjHeader obj_header() {
|
231 | return ObjHeader::ClassFixed(field_mask(), sizeof(Usage));
|
232 | }
|
233 |
|
234 | DISALLOW_COPY_AND_ASSIGN(Usage)
|
235 | };
|
236 |
|
237 | class Parse : public _ErrorWithLocation {
|
238 | public:
|
239 | Parse(BigStr* msg, syntax_asdl::loc_t* location);
|
240 |
|
241 | static constexpr uint32_t field_mask() {
|
242 | return _ErrorWithLocation::field_mask();
|
243 | }
|
244 |
|
245 | static constexpr ObjHeader obj_header() {
|
246 | return ObjHeader::ClassFixed(field_mask(), sizeof(Parse));
|
247 | }
|
248 |
|
249 | DISALLOW_COPY_AND_ASSIGN(Parse)
|
250 | };
|
251 |
|
252 | class FailGlob : public _ErrorWithLocation {
|
253 | public:
|
254 | FailGlob(BigStr* msg, syntax_asdl::loc_t* location);
|
255 |
|
256 | static constexpr uint32_t field_mask() {
|
257 | return _ErrorWithLocation::field_mask();
|
258 | }
|
259 |
|
260 | static constexpr ObjHeader obj_header() {
|
261 | return ObjHeader::ClassFixed(field_mask(), sizeof(FailGlob));
|
262 | }
|
263 |
|
264 | DISALLOW_COPY_AND_ASSIGN(FailGlob)
|
265 | };
|
266 |
|
267 | class RedirectEval : public _ErrorWithLocation {
|
268 | public:
|
269 | RedirectEval(BigStr* msg, syntax_asdl::loc_t* location);
|
270 |
|
271 | static constexpr uint32_t field_mask() {
|
272 | return _ErrorWithLocation::field_mask();
|
273 | }
|
274 |
|
275 | static constexpr ObjHeader obj_header() {
|
276 | return ObjHeader::ClassFixed(field_mask(), sizeof(RedirectEval));
|
277 | }
|
278 |
|
279 | DISALLOW_COPY_AND_ASSIGN(RedirectEval)
|
280 | };
|
281 |
|
282 | class FatalRuntime : public _ErrorWithLocation {
|
283 | public:
|
284 | FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location);
|
285 | int ExitStatus();
|
286 |
|
287 | int exit_status;
|
288 |
|
289 | static constexpr uint32_t field_mask() {
|
290 | return _ErrorWithLocation::field_mask();
|
291 | }
|
292 |
|
293 | static constexpr ObjHeader obj_header() {
|
294 | return ObjHeader::ClassFixed(field_mask(), sizeof(FatalRuntime));
|
295 | }
|
296 |
|
297 | DISALLOW_COPY_AND_ASSIGN(FatalRuntime)
|
298 | };
|
299 |
|
300 | class Strict : public FatalRuntime {
|
301 | public:
|
302 | Strict(BigStr* msg, syntax_asdl::loc_t* location);
|
303 |
|
304 | static constexpr uint32_t field_mask() {
|
305 | return FatalRuntime::field_mask();
|
306 | }
|
307 |
|
308 | static constexpr ObjHeader obj_header() {
|
309 | return ObjHeader::ClassFixed(field_mask(), sizeof(Strict));
|
310 | }
|
311 |
|
312 | DISALLOW_COPY_AND_ASSIGN(Strict)
|
313 | };
|
314 |
|
315 | class ErrExit : public FatalRuntime {
|
316 | public:
|
317 | ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code = false);
|
318 |
|
319 | bool show_code;
|
320 |
|
321 | static constexpr uint32_t field_mask() {
|
322 | return FatalRuntime::field_mask();
|
323 | }
|
324 |
|
325 | static constexpr ObjHeader obj_header() {
|
326 | return ObjHeader::ClassFixed(field_mask(), sizeof(ErrExit));
|
327 | }
|
328 |
|
329 | DISALLOW_COPY_AND_ASSIGN(ErrExit)
|
330 | };
|
331 |
|
332 | class Expr : public FatalRuntime {
|
333 | public:
|
334 | Expr(BigStr* msg, syntax_asdl::loc_t* location);
|
335 |
|
336 | static constexpr uint32_t field_mask() {
|
337 | return FatalRuntime::field_mask();
|
338 | }
|
339 |
|
340 | static constexpr ObjHeader obj_header() {
|
341 | return ObjHeader::ClassFixed(field_mask(), sizeof(Expr));
|
342 | }
|
343 |
|
344 | DISALLOW_COPY_AND_ASSIGN(Expr)
|
345 | };
|
346 |
|
347 | class Structured : public FatalRuntime {
|
348 | public:
|
349 | Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties = nullptr);
|
350 | value::Dict* ToDict();
|
351 |
|
352 | Dict<BigStr*, value_asdl::value_t*>* properties;
|
353 |
|
354 | static constexpr uint32_t field_mask() {
|
355 | return FatalRuntime::field_mask()
|
356 | | maskbit(offsetof(Structured, properties));
|
357 | }
|
358 |
|
359 | static constexpr ObjHeader obj_header() {
|
360 | return ObjHeader::ClassFixed(field_mask(), sizeof(Structured));
|
361 | }
|
362 |
|
363 | DISALLOW_COPY_AND_ASSIGN(Structured)
|
364 | };
|
365 |
|
366 | class AssertionErr : public Expr {
|
367 | public:
|
368 | AssertionErr(BigStr* msg, syntax_asdl::loc_t* location);
|
369 |
|
370 | static constexpr uint32_t field_mask() {
|
371 | return Expr::field_mask();
|
372 | }
|
373 |
|
374 | static constexpr ObjHeader obj_header() {
|
375 | return ObjHeader::ClassFixed(field_mask(), sizeof(AssertionErr));
|
376 | }
|
377 |
|
378 | DISALLOW_COPY_AND_ASSIGN(AssertionErr)
|
379 | };
|
380 |
|
381 | class TypeErrVerbose : public Expr {
|
382 | public:
|
383 | TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location);
|
384 |
|
385 | static constexpr uint32_t field_mask() {
|
386 | return Expr::field_mask();
|
387 | }
|
388 |
|
389 | static constexpr ObjHeader obj_header() {
|
390 | return ObjHeader::ClassFixed(field_mask(), sizeof(TypeErrVerbose));
|
391 | }
|
392 |
|
393 | DISALLOW_COPY_AND_ASSIGN(TypeErrVerbose)
|
394 | };
|
395 |
|
396 | class TypeErr : public TypeErrVerbose {
|
397 | public:
|
398 | TypeErr(value_asdl::value_t* actual_val, BigStr* msg, syntax_asdl::loc_t* location);
|
399 |
|
400 | static constexpr uint32_t field_mask() {
|
401 | return TypeErrVerbose::field_mask();
|
402 | }
|
403 |
|
404 | static constexpr ObjHeader obj_header() {
|
405 | return ObjHeader::ClassFixed(field_mask(), sizeof(TypeErr));
|
406 | }
|
407 |
|
408 | DISALLOW_COPY_AND_ASSIGN(TypeErr)
|
409 | };
|
410 |
|
411 | class Runtime {
|
412 | public:
|
413 | Runtime(BigStr* msg);
|
414 | BigStr* UserErrorString();
|
415 | BigStr* msg;
|
416 |
|
417 | static constexpr ObjHeader obj_header() {
|
418 | return ObjHeader::ClassScanned(1, sizeof(Runtime));
|
419 | }
|
420 |
|
421 | DISALLOW_COPY_AND_ASSIGN(Runtime)
|
422 | };
|
423 |
|
424 | class Decode {
|
425 | public:
|
426 | Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos, int line_num);
|
427 | BigStr* Message();
|
428 | BigStr* __str__();
|
429 | BigStr* msg;
|
430 | BigStr* s;
|
431 | int start_pos;
|
432 | int end_pos;
|
433 | int line_num;
|
434 |
|
435 | static constexpr ObjHeader obj_header() {
|
436 | return ObjHeader::ClassScanned(2, sizeof(Decode));
|
437 | }
|
438 |
|
439 | DISALLOW_COPY_AND_ASSIGN(Decode)
|
440 | };
|
441 |
|
442 | class Encode {
|
443 | public:
|
444 | Encode(BigStr* msg);
|
445 | BigStr* Message();
|
446 | BigStr* msg;
|
447 |
|
448 | static constexpr ObjHeader obj_header() {
|
449 | return ObjHeader::ClassScanned(1, sizeof(Encode));
|
450 | }
|
451 |
|
452 | DISALLOW_COPY_AND_ASSIGN(Encode)
|
453 | };
|
454 |
|
455 | [[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location);
|
456 | [[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location);
|
457 | [[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location);
|
458 | [[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location = nullptr);
|
459 | [[noreturn]] void e_die_status(int status, BigStr* msg, syntax_asdl::loc_t* location = nullptr);
|
460 |
|
461 |
|
462 | } // declare namespace error
|
463 |
|
464 | namespace num { // declare
|
465 |
|
466 | value::Int* ToBig(int i);
|
467 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
|
468 | int Exponent2(int x, int y);
|
469 | mops::BigInt IntDivide(mops::BigInt x, mops::BigInt y);
|
470 | int IntDivide2(int x, int y);
|
471 | mops::BigInt IntRemainder(mops::BigInt x, mops::BigInt y);
|
472 | int IntRemainder2(int x, int y);
|
473 |
|
474 |
|
475 | } // declare namespace num
|
476 |
|
477 | namespace runtime { // define
|
478 |
|
479 | using hnode_asdl::hnode;
|
480 | using hnode_asdl::color_t;
|
481 | using hnode_asdl::color_e;
|
482 | int NO_SPID = -1;
|
483 |
|
484 | hnode::Record* NewRecord(BigStr* node_type) {
|
485 | StackRoot _root0(&node_type);
|
486 |
|
487 | return Alloc<hnode::Record>(node_type, Alloc<List<hnode_asdl::Field*>>(), false, str0, str1, Alloc<List<hnode_asdl::hnode_t*>>());
|
488 | }
|
489 |
|
490 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color) {
|
491 | StackRoot _root0(&s);
|
492 |
|
493 | if (s == nullptr) {
|
494 | return Alloc<hnode::Leaf>(str2, color_e::OtherConst);
|
495 | }
|
496 | else {
|
497 | return Alloc<hnode::Leaf>(s, e_color);
|
498 | }
|
499 | }
|
500 |
|
501 | TraversalState::TraversalState() {
|
502 | this->seen = Alloc<Dict<int, bool>>();
|
503 | this->ref_count = Alloc<Dict<int, int>>();
|
504 | }
|
505 | BigStr* TRUE_STR = str3;
|
506 | BigStr* FALSE_STR = str4;
|
507 |
|
508 | } // define namespace runtime
|
509 |
|
510 | namespace format { // define
|
511 |
|
512 | using hnode_asdl::hnode;
|
513 | using hnode_asdl::hnode_e;
|
514 | using hnode_asdl::hnode_t;
|
515 | using hnode_asdl::color_e;
|
516 | using hnode_asdl::color_t;
|
517 |
|
518 | format::ColorOutput* DetectConsoleOutput(mylib::Writer* f) {
|
519 | StackRoot _root0(&f);
|
520 |
|
521 | if (f->isatty()) {
|
522 | return Alloc<AnsiOutput>(f);
|
523 | }
|
524 | else {
|
525 | return Alloc<TextOutput>(f);
|
526 | }
|
527 | }
|
528 |
|
529 | ColorOutput::ColorOutput(mylib::Writer* f) {
|
530 | this->f = f;
|
531 | this->num_chars = 0;
|
532 | }
|
533 |
|
534 | format::ColorOutput* ColorOutput::NewTempBuffer() {
|
535 | FAIL(kNotImplemented); // Python NotImplementedError
|
536 | }
|
537 |
|
538 | void ColorOutput::FileHeader() {
|
539 | ; // pass
|
540 | }
|
541 |
|
542 | void ColorOutput::FileFooter() {
|
543 | ; // pass
|
544 | }
|
545 |
|
546 | void ColorOutput::PushColor(hnode_asdl::color_t e_color) {
|
547 | FAIL(kNotImplemented); // Python NotImplementedError
|
548 | }
|
549 |
|
550 | void ColorOutput::PopColor() {
|
551 | FAIL(kNotImplemented); // Python NotImplementedError
|
552 | }
|
553 |
|
554 | void ColorOutput::write(BigStr* s) {
|
555 | StackRoot _root0(&s);
|
556 |
|
557 | this->f->write(s);
|
558 | this->num_chars += len(s);
|
559 | }
|
560 |
|
561 | void ColorOutput::WriteRaw(Tuple2<BigStr*, int>* raw) {
|
562 | BigStr* s = nullptr;
|
563 | int num_chars;
|
564 | StackRoot _root0(&raw);
|
565 | StackRoot _root1(&s);
|
566 |
|
567 | Tuple2<BigStr*, int>* tup0 = raw;
|
568 | s = tup0->at0();
|
569 | num_chars = tup0->at1();
|
570 | this->f->write(s);
|
571 | this->num_chars += num_chars;
|
572 | }
|
573 |
|
574 | int ColorOutput::NumChars() {
|
575 | return this->num_chars;
|
576 | }
|
577 |
|
578 | Tuple2<BigStr*, int> ColorOutput::GetRaw() {
|
579 | mylib::BufWriter* f = nullptr;
|
580 | StackRoot _root0(&f);
|
581 |
|
582 | f = static_cast<mylib::BufWriter*>(this->f);
|
583 | return Tuple2<BigStr*, int>(f->getvalue(), this->num_chars);
|
584 | }
|
585 |
|
586 | TextOutput::TextOutput(mylib::Writer* f) : ColorOutput(f) {
|
587 | }
|
588 |
|
589 | format::TextOutput* TextOutput::NewTempBuffer() {
|
590 | return Alloc<TextOutput>(Alloc<mylib::BufWriter>());
|
591 | }
|
592 |
|
593 | void TextOutput::PushColor(hnode_asdl::color_t e_color) {
|
594 | ; // pass
|
595 | }
|
596 |
|
597 | void TextOutput::PopColor() {
|
598 | ; // pass
|
599 | }
|
600 |
|
601 | HtmlOutput::HtmlOutput(mylib::Writer* f) : ColorOutput(f) {
|
602 | }
|
603 |
|
604 | format::HtmlOutput* HtmlOutput::NewTempBuffer() {
|
605 | return Alloc<HtmlOutput>(Alloc<mylib::BufWriter>());
|
606 | }
|
607 |
|
608 | void HtmlOutput::FileHeader() {
|
609 | this->f->write(str5);
|
610 | }
|
611 |
|
612 | void HtmlOutput::FileFooter() {
|
613 | this->f->write(str6);
|
614 | }
|
615 |
|
616 | void HtmlOutput::PushColor(hnode_asdl::color_t e_color) {
|
617 | BigStr* css_class = nullptr;
|
618 | StackRoot _root0(&css_class);
|
619 |
|
620 | if (e_color == color_e::TypeName) {
|
621 | css_class = str7;
|
622 | }
|
623 | else {
|
624 | if (e_color == color_e::StringConst) {
|
625 | css_class = str8;
|
626 | }
|
627 | else {
|
628 | if (e_color == color_e::OtherConst) {
|
629 | css_class = str9;
|
630 | }
|
631 | else {
|
632 | if (e_color == color_e::External) {
|
633 | css_class = str10;
|
634 | }
|
635 | else {
|
636 | if (e_color == color_e::UserType) {
|
637 | css_class = str11;
|
638 | }
|
639 | else {
|
640 | assert(0); // AssertionError
|
641 | }
|
642 | }
|
643 | }
|
644 | }
|
645 | }
|
646 | this->f->write(StrFormat("<span class=\"%s\">", css_class));
|
647 | }
|
648 |
|
649 | void HtmlOutput::PopColor() {
|
650 | this->f->write(str13);
|
651 | }
|
652 |
|
653 | void HtmlOutput::write(BigStr* s) {
|
654 | StackRoot _root0(&s);
|
655 |
|
656 | this->f->write(cgi::escape(s));
|
657 | this->num_chars += len(s);
|
658 | }
|
659 |
|
660 | AnsiOutput::AnsiOutput(mylib::Writer* f) : ColorOutput(f) {
|
661 | }
|
662 |
|
663 | format::AnsiOutput* AnsiOutput::NewTempBuffer() {
|
664 | return Alloc<AnsiOutput>(Alloc<mylib::BufWriter>());
|
665 | }
|
666 |
|
667 | void AnsiOutput::PushColor(hnode_asdl::color_t e_color) {
|
668 | if (e_color == color_e::TypeName) {
|
669 | this->f->write(ansi::YELLOW);
|
670 | }
|
671 | else {
|
672 | if (e_color == color_e::StringConst) {
|
673 | this->f->write(ansi::BOLD);
|
674 | }
|
675 | else {
|
676 | if (e_color == color_e::OtherConst) {
|
677 | this->f->write(ansi::GREEN);
|
678 | }
|
679 | else {
|
680 | if (e_color == color_e::External) {
|
681 | this->f->write(str_concat(ansi::BOLD, ansi::BLUE));
|
682 | }
|
683 | else {
|
684 | if (e_color == color_e::UserType) {
|
685 | this->f->write(ansi::GREEN);
|
686 | }
|
687 | else {
|
688 | assert(0); // AssertionError
|
689 | }
|
690 | }
|
691 | }
|
692 | }
|
693 | }
|
694 | }
|
695 |
|
696 | void AnsiOutput::PopColor() {
|
697 | this->f->write(ansi::RESET);
|
698 | }
|
699 | int INDENT = 2;
|
700 |
|
701 | _PrettyPrinter::_PrettyPrinter(int max_col) {
|
702 | this->max_col = max_col;
|
703 | }
|
704 |
|
705 | bool _PrettyPrinter::_PrintWrappedArray(List<hnode_asdl::hnode_t*>* array, int prefix_len, format::ColorOutput* f, int indent) {
|
706 | bool all_fit;
|
707 | int chars_so_far;
|
708 | int i;
|
709 | format::ColorOutput* single_f = nullptr;
|
710 | BigStr* s = nullptr;
|
711 | int num_chars;
|
712 | StackRoot _root0(&array);
|
713 | StackRoot _root1(&f);
|
714 | StackRoot _root2(&single_f);
|
715 | StackRoot _root3(&s);
|
716 |
|
717 | all_fit = true;
|
718 | chars_so_far = prefix_len;
|
719 | i = 0;
|
720 | for (ListIter<hnode_asdl::hnode_t*> it(array); !it.Done(); it.Next(), ++i) {
|
721 | hnode_asdl::hnode_t* val = it.Value();
|
722 | StackRoot _for(&val );
|
723 | if (i != 0) {
|
724 | f->write(str14);
|
725 | }
|
726 | single_f = f->NewTempBuffer();
|
727 | if (_TrySingleLine(val, single_f, (this->max_col - chars_so_far))) {
|
728 | Tuple2<BigStr*, int> tup1 = single_f->GetRaw();
|
729 | s = tup1.at0();
|
730 | num_chars = tup1.at1();
|
731 | f->WriteRaw((Alloc<Tuple2<BigStr*, int>>(s, num_chars)));
|
732 | chars_so_far += single_f->NumChars();
|
733 | }
|
734 | else {
|
735 | f->write(str15);
|
736 | this->PrintNode(val, f, (indent + INDENT));
|
737 | chars_so_far = 0;
|
738 | all_fit = false;
|
739 | }
|
740 | }
|
741 | return all_fit;
|
742 | }
|
743 |
|
744 | bool _PrettyPrinter::_PrintWholeArray(List<hnode_asdl::hnode_t*>* array, int prefix_len, format::ColorOutput* f, int indent) {
|
745 | bool all_fit;
|
746 | List<Tuple2<BigStr*, int>*>* pieces = nullptr;
|
747 | int chars_so_far;
|
748 | format::ColorOutput* single_f = nullptr;
|
749 | BigStr* s = nullptr;
|
750 | int num_chars;
|
751 | int i;
|
752 | StackRoot _root0(&array);
|
753 | StackRoot _root1(&f);
|
754 | StackRoot _root2(&pieces);
|
755 | StackRoot _root3(&single_f);
|
756 | StackRoot _root4(&s);
|
757 |
|
758 | all_fit = true;
|
759 | pieces = Alloc<List<Tuple2<BigStr*, int>*>>();
|
760 | chars_so_far = prefix_len;
|
761 | for (ListIter<hnode_asdl::hnode_t*> it(array); !it.Done(); it.Next()) {
|
762 | hnode_asdl::hnode_t* item = it.Value();
|
763 | StackRoot _for(&item );
|
764 | single_f = f->NewTempBuffer();
|
765 | if (_TrySingleLine(item, single_f, (this->max_col - chars_so_far))) {
|
766 | Tuple2<BigStr*, int> tup2 = single_f->GetRaw();
|
767 | s = tup2.at0();
|
768 | num_chars = tup2.at1();
|
769 | pieces->append((Alloc<Tuple2<BigStr*, int>>(s, num_chars)));
|
770 | chars_so_far += single_f->NumChars();
|
771 | }
|
772 | else {
|
773 | all_fit = false;
|
774 | break;
|
775 | }
|
776 | }
|
777 | if (all_fit) {
|
778 | i = 0;
|
779 | for (ListIter<Tuple2<BigStr*, int>*> it(pieces); !it.Done(); it.Next(), ++i) {
|
780 | Tuple2<BigStr*, int>* p = it.Value();
|
781 | StackRoot _for(&p );
|
782 | if (i != 0) {
|
783 | f->write(str16);
|
784 | }
|
785 | f->WriteRaw(p);
|
786 | }
|
787 | f->write(str17);
|
788 | }
|
789 | return all_fit;
|
790 | }
|
791 |
|
792 | void _PrettyPrinter::_PrintRecord(hnode::Record* node, format::ColorOutput* f, int indent) {
|
793 | BigStr* ind = nullptr;
|
794 | BigStr* prefix = nullptr;
|
795 | int prefix_len;
|
796 | bool all_fit;
|
797 | BigStr* name = nullptr;
|
798 | hnode_asdl::hnode_t* val = nullptr;
|
799 | BigStr* ind1 = nullptr;
|
800 | hnode_asdl::hnode_t* UP_val = nullptr;
|
801 | int tag;
|
802 | BigStr* name_str = nullptr;
|
803 | format::ColorOutput* single_f = nullptr;
|
804 | BigStr* s = nullptr;
|
805 | int num_chars;
|
806 | StackRoot _root0(&node);
|
807 | StackRoot _root1(&f);
|
808 | StackRoot _root2(&ind);
|
809 | StackRoot _root3(&prefix);
|
810 | StackRoot _root4(&name);
|
811 | StackRoot _root5(&val);
|
812 | StackRoot _root6(&ind1);
|
813 | StackRoot _root7(&UP_val);
|
814 | StackRoot _root8(&name_str);
|
815 | StackRoot _root9(&single_f);
|
816 | StackRoot _root10(&s);
|
817 |
|
818 | ind = str_repeat(str18, indent);
|
819 | if (node->abbrev) {
|
820 | prefix = str_concat(ind, node->left);
|
821 | f->write(prefix);
|
822 | if (len(node->node_type)) {
|
823 | f->PushColor(color_e::TypeName);
|
824 | f->write(node->node_type);
|
825 | f->PopColor();
|
826 | f->write(str19);
|
827 | }
|
828 | prefix_len = ((len(prefix) + len(node->node_type)) + 1);
|
829 | all_fit = this->_PrintWrappedArray(node->unnamed_fields, prefix_len, f, indent);
|
830 | if (!all_fit) {
|
831 | f->write(str20);
|
832 | f->write(ind);
|
833 | }
|
834 | f->write(node->right);
|
835 | }
|
836 | else {
|
837 | f->write(str_concat(ind, node->left));
|
838 | f->PushColor(color_e::TypeName);
|
839 | f->write(node->node_type);
|
840 | f->PopColor();
|
841 | f->write(str21);
|
842 | for (ListIter<hnode_asdl::Field*> it(node->fields); !it.Done(); it.Next()) {
|
843 | hnode_asdl::Field* field = it.Value();
|
844 | StackRoot _for(&field );
|
845 | name = field->name;
|
846 | val = field->val;
|
847 | ind1 = str_repeat(str22, (indent + INDENT));
|
848 | UP_val = val;
|
849 | tag = val->tag();
|
850 | if (tag == hnode_e::Array) {
|
851 | hnode::Array* val = static_cast<hnode::Array*>(UP_val);
|
852 | name_str = StrFormat("%s%s: [", ind1, name);
|
853 | f->write(name_str);
|
854 | prefix_len = len(name_str);
|
855 | if (!this->_PrintWholeArray(val->children, prefix_len, f, indent)) {
|
856 | f->write(str24);
|
857 | for (ListIter<hnode_asdl::hnode_t*> it(val->children); !it.Done(); it.Next()) {
|
858 | hnode_asdl::hnode_t* child = it.Value();
|
859 | StackRoot _for(&child );
|
860 | this->PrintNode(child, f, ((indent + INDENT) + INDENT));
|
861 | f->write(str25);
|
862 | }
|
863 | f->write(StrFormat("%s]", ind1));
|
864 | }
|
865 | }
|
866 | else {
|
867 | name_str = StrFormat("%s%s: ", ind1, name);
|
868 | f->write(name_str);
|
869 | prefix_len = len(name_str);
|
870 | single_f = f->NewTempBuffer();
|
871 | if (_TrySingleLine(val, single_f, (this->max_col - prefix_len))) {
|
872 | Tuple2<BigStr*, int> tup3 = single_f->GetRaw();
|
873 | s = tup3.at0();
|
874 | num_chars = tup3.at1();
|
875 | f->WriteRaw((Alloc<Tuple2<BigStr*, int>>(s, num_chars)));
|
876 | }
|
877 | else {
|
878 | f->write(str28);
|
879 | this->PrintNode(val, f, ((indent + INDENT) + INDENT));
|
880 | }
|
881 | }
|
882 | f->write(str29);
|
883 | }
|
884 | f->write(str_concat(ind, node->right));
|
885 | }
|
886 | }
|
887 |
|
888 | void _PrettyPrinter::PrintNode(hnode_asdl::hnode_t* node, format::ColorOutput* f, int indent) {
|
889 | BigStr* ind = nullptr;
|
890 | format::ColorOutput* single_f = nullptr;
|
891 | BigStr* s = nullptr;
|
892 | int num_chars;
|
893 | hnode_asdl::hnode_t* UP_node = nullptr;
|
894 | int tag;
|
895 | StackRoot _root0(&node);
|
896 | StackRoot _root1(&f);
|
897 | StackRoot _root2(&ind);
|
898 | StackRoot _root3(&single_f);
|
899 | StackRoot _root4(&s);
|
900 | StackRoot _root5(&UP_node);
|
901 |
|
902 | ind = str_repeat(str30, indent);
|
903 | single_f = f->NewTempBuffer();
|
904 | single_f->write(ind);
|
905 | if (_TrySingleLine(node, single_f, (this->max_col - indent))) {
|
906 | Tuple2<BigStr*, int> tup4 = single_f->GetRaw();
|
907 | s = tup4.at0();
|
908 | num_chars = tup4.at1();
|
909 | f->WriteRaw((Alloc<Tuple2<BigStr*, int>>(s, num_chars)));
|
910 | return ;
|
911 | }
|
912 | UP_node = node;
|
913 | tag = node->tag();
|
914 | if (tag == hnode_e::Leaf) {
|
915 | hnode::Leaf* node = static_cast<hnode::Leaf*>(UP_node);
|
916 | f->PushColor(node->color);
|
917 | f->write(j8_lite::EncodeString(node->s, true));
|
918 | f->PopColor();
|
919 | }
|
920 | else {
|
921 | if (tag == hnode_e::External) {
|
922 | hnode::External* node = static_cast<hnode::External*>(UP_node);
|
923 | f->PushColor(color_e::External);
|
924 | // if not PYTHON
|
925 | {
|
926 | f->write(str31);
|
927 | }
|
928 | // endif MYCPP
|
929 | f->PopColor();
|
930 | }
|
931 | else {
|
932 | if (tag == hnode_e::Record) {
|
933 | hnode::Record* node = static_cast<hnode::Record*>(UP_node);
|
934 | this->_PrintRecord(node, f, indent);
|
935 | }
|
936 | else {
|
937 | if (tag == hnode_e::AlreadySeen) {
|
938 | hnode::AlreadySeen* node = static_cast<hnode::AlreadySeen*>(UP_node);
|
939 | f->write(StrFormat("...0x%s", mylib::hex_lower(node->heap_id)));
|
940 | }
|
941 | else {
|
942 | assert(0); // AssertionError
|
943 | }
|
944 | }
|
945 | }
|
946 | }
|
947 | }
|
948 |
|
949 | bool _TrySingleLineObj(hnode::Record* node, format::ColorOutput* f, int max_chars) {
|
950 | int i;
|
951 | StackRoot _root0(&node);
|
952 | StackRoot _root1(&f);
|
953 |
|
954 | f->write(node->left);
|
955 | if (node->abbrev) {
|
956 | if (len(node->node_type)) {
|
957 | f->PushColor(color_e::TypeName);
|
958 | f->write(node->node_type);
|
959 | f->PopColor();
|
960 | f->write(str33);
|
961 | }
|
962 | i = 0;
|
963 | for (ListIter<hnode_asdl::hnode_t*> it(node->unnamed_fields); !it.Done(); it.Next(), ++i) {
|
964 | hnode_asdl::hnode_t* val = it.Value();
|
965 | StackRoot _for(&val );
|
966 | if (i != 0) {
|
967 | f->write(str34);
|
968 | }
|
969 | if (!_TrySingleLine(val, f, max_chars)) {
|
970 | return false;
|
971 | }
|
972 | }
|
973 | }
|
974 | else {
|
975 | f->PushColor(color_e::TypeName);
|
976 | f->write(node->node_type);
|
977 | f->PopColor();
|
978 | for (ListIter<hnode_asdl::Field*> it(node->fields); !it.Done(); it.Next()) {
|
979 | hnode_asdl::Field* field = it.Value();
|
980 | StackRoot _for(&field );
|
981 | f->write(StrFormat(" %s:", field->name));
|
982 | if (!_TrySingleLine(field->val, f, max_chars)) {
|
983 | return false;
|
984 | }
|
985 | }
|
986 | }
|
987 | f->write(node->right);
|
988 | return true;
|
989 | }
|
990 |
|
991 | bool _TrySingleLine(hnode_asdl::hnode_t* node, format::ColorOutput* f, int max_chars) {
|
992 | hnode_asdl::hnode_t* UP_node = nullptr;
|
993 | int tag;
|
994 | int i;
|
995 | int num_chars_so_far;
|
996 | StackRoot _root0(&node);
|
997 | StackRoot _root1(&f);
|
998 | StackRoot _root2(&UP_node);
|
999 |
|
1000 | UP_node = node;
|
1001 | tag = node->tag();
|
1002 | if (tag == hnode_e::Leaf) {
|
1003 | hnode::Leaf* node = static_cast<hnode::Leaf*>(UP_node);
|
1004 | f->PushColor(node->color);
|
1005 | f->write(j8_lite::EncodeString(node->s, true));
|
1006 | f->PopColor();
|
1007 | }
|
1008 | else {
|
1009 | if (tag == hnode_e::External) {
|
1010 | hnode::External* node = static_cast<hnode::External*>(UP_node);
|
1011 | f->PushColor(color_e::External);
|
1012 | // if not PYTHON
|
1013 | {
|
1014 | f->write(str36);
|
1015 | }
|
1016 | // endif MYCPP
|
1017 | f->PopColor();
|
1018 | }
|
1019 | else {
|
1020 | if (tag == hnode_e::Array) {
|
1021 | hnode::Array* node = static_cast<hnode::Array*>(UP_node);
|
1022 | f->write(str37);
|
1023 | i = 0;
|
1024 | for (ListIter<hnode_asdl::hnode_t*> it(node->children); !it.Done(); it.Next(), ++i) {
|
1025 | hnode_asdl::hnode_t* item = it.Value();
|
1026 | StackRoot _for(&item );
|
1027 | if (i != 0) {
|
1028 | f->write(str38);
|
1029 | }
|
1030 | if (!_TrySingleLine(item, f, max_chars)) {
|
1031 | return false;
|
1032 | }
|
1033 | }
|
1034 | f->write(str39);
|
1035 | }
|
1036 | else {
|
1037 | if (tag == hnode_e::Record) {
|
1038 | hnode::Record* node = static_cast<hnode::Record*>(UP_node);
|
1039 | return _TrySingleLineObj(node, f, max_chars);
|
1040 | }
|
1041 | else {
|
1042 | if (tag == hnode_e::AlreadySeen) {
|
1043 | hnode::AlreadySeen* node = static_cast<hnode::AlreadySeen*>(UP_node);
|
1044 | f->write(StrFormat("...0x%s", mylib::hex_lower(node->heap_id)));
|
1045 | }
|
1046 | else {
|
1047 | assert(0); // AssertionError
|
1048 | }
|
1049 | }
|
1050 | }
|
1051 | }
|
1052 | }
|
1053 | num_chars_so_far = f->NumChars();
|
1054 | if (num_chars_so_far > max_chars) {
|
1055 | return false;
|
1056 | }
|
1057 | return true;
|
1058 | }
|
1059 |
|
1060 | void PrintTree(hnode_asdl::hnode_t* node, format::ColorOutput* f) {
|
1061 | format::_PrettyPrinter* pp = nullptr;
|
1062 | StackRoot _root0(&node);
|
1063 | StackRoot _root1(&f);
|
1064 | StackRoot _root2(&pp);
|
1065 |
|
1066 | pp = Alloc<_PrettyPrinter>(100);
|
1067 | pp->PrintNode(node, f, 0);
|
1068 | }
|
1069 |
|
1070 | } // define namespace format
|
1071 |
|
1072 | namespace ansi { // define
|
1073 |
|
1074 | BigStr* RESET = str41;
|
1075 | BigStr* BOLD = str42;
|
1076 | BigStr* UNDERLINE = str43;
|
1077 | BigStr* REVERSE = str44;
|
1078 | BigStr* RED = str45;
|
1079 | BigStr* GREEN = str46;
|
1080 | BigStr* YELLOW = str47;
|
1081 | BigStr* BLUE = str48;
|
1082 | BigStr* MAGENTA = str49;
|
1083 | BigStr* CYAN = str50;
|
1084 |
|
1085 | } // define namespace ansi
|
1086 |
|
1087 | namespace cgi { // define
|
1088 |
|
1089 |
|
1090 | BigStr* escape(BigStr* s) {
|
1091 | StackRoot _root0(&s);
|
1092 |
|
1093 | s = s->replace(str51, str52);
|
1094 | s = s->replace(str53, str54);
|
1095 | s = s->replace(str55, str56);
|
1096 | return s;
|
1097 | }
|
1098 |
|
1099 | } // define namespace cgi
|
1100 |
|
1101 | namespace j8_lite { // define
|
1102 |
|
1103 |
|
1104 | BigStr* EncodeString(BigStr* s, bool unquoted_ok) {
|
1105 | StackRoot _root0(&s);
|
1106 |
|
1107 | if ((unquoted_ok and fastfunc::CanOmitQuotes(s))) {
|
1108 | return s;
|
1109 | }
|
1110 | return fastfunc::J8EncodeString(s, 1);
|
1111 | }
|
1112 |
|
1113 | BigStr* MaybeShellEncode(BigStr* s) {
|
1114 | StackRoot _root0(&s);
|
1115 |
|
1116 | if (fastfunc::CanOmitQuotes(s)) {
|
1117 | return s;
|
1118 | }
|
1119 | return fastfunc::ShellEncodeString(s, 0);
|
1120 | }
|
1121 |
|
1122 | BigStr* ShellEncode(BigStr* s) {
|
1123 | StackRoot _root0(&s);
|
1124 |
|
1125 | return fastfunc::ShellEncodeString(s, 0);
|
1126 | }
|
1127 |
|
1128 | BigStr* YshEncode(BigStr* s, bool unquoted_ok) {
|
1129 | StackRoot _root0(&s);
|
1130 |
|
1131 | if ((unquoted_ok and fastfunc::CanOmitQuotes(s))) {
|
1132 | return s;
|
1133 | }
|
1134 | return fastfunc::ShellEncodeString(s, 1);
|
1135 | }
|
1136 |
|
1137 | } // define namespace j8_lite
|
1138 |
|
1139 | namespace error { // define
|
1140 |
|
1141 | using syntax_asdl::loc_e;
|
1142 | using syntax_asdl::loc_t;
|
1143 | using syntax_asdl::loc;
|
1144 | using value_asdl::value;
|
1145 | using value_asdl::value_t;
|
1146 | using value_asdl::value_str;
|
1147 |
|
1148 | BigStr* _ValType(value_asdl::value_t* val) {
|
1149 | StackRoot _root0(&val);
|
1150 |
|
1151 | return value_str(val->tag(), false);
|
1152 | }
|
1153 |
|
1154 | _ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
|
1155 | this->msg = msg;
|
1156 | if (location == nullptr) {
|
1157 | this->location = loc::Missing;
|
1158 | }
|
1159 | else {
|
1160 | this->location = location;
|
1161 | }
|
1162 | }
|
1163 |
|
1164 | bool _ErrorWithLocation::HasLocation() {
|
1165 | return this->location->tag() != loc_e::Missing;
|
1166 | }
|
1167 |
|
1168 | BigStr* _ErrorWithLocation::UserErrorString() {
|
1169 | return this->msg;
|
1170 | }
|
1171 |
|
1172 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
1173 | }
|
1174 |
|
1175 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
1176 | }
|
1177 |
|
1178 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
1179 | }
|
1180 |
|
1181 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
1182 | }
|
1183 |
|
1184 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : _ErrorWithLocation(msg, location) {
|
1185 | this->exit_status = exit_status;
|
1186 | }
|
1187 |
|
1188 | int FatalRuntime::ExitStatus() {
|
1189 | return this->exit_status;
|
1190 | }
|
1191 |
|
1192 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(1, msg, location) {
|
1193 | }
|
1194 |
|
1195 | ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : FatalRuntime(exit_status, msg, location) {
|
1196 | this->show_code = show_code;
|
1197 | }
|
1198 |
|
1199 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : FatalRuntime(3, msg, location) {
|
1200 | }
|
1201 |
|
1202 | Structured::Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties) : FatalRuntime(status, msg, location) {
|
1203 | this->properties = properties;
|
1204 | }
|
1205 |
|
1206 | value::Dict* Structured::ToDict() {
|
1207 | if (this->properties == nullptr) {
|
1208 | this->properties = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
|
1209 | }
|
1210 | this->properties->set(str58, num::ToBig(this->ExitStatus()));
|
1211 | this->properties->set(str59, Alloc<value::Str>(this->msg));
|
1212 | return Alloc<value::Dict>(this->properties);
|
1213 | }
|
1214 |
|
1215 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
|
1216 | }
|
1217 |
|
1218 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : Expr(msg, location) {
|
1219 | }
|
1220 |
|
1221 | 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) {
|
1222 | }
|
1223 |
|
1224 | Runtime::Runtime(BigStr* msg) {
|
1225 | this->msg = msg;
|
1226 | }
|
1227 |
|
1228 | BigStr* Runtime::UserErrorString() {
|
1229 | return this->msg;
|
1230 | }
|
1231 |
|
1232 | Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos, int line_num) {
|
1233 | this->msg = msg;
|
1234 | this->s = s;
|
1235 | this->start_pos = start_pos;
|
1236 | this->end_pos = end_pos;
|
1237 | this->line_num = line_num;
|
1238 | }
|
1239 |
|
1240 | BigStr* Decode::Message() {
|
1241 | int start;
|
1242 | int end;
|
1243 | BigStr* part = nullptr;
|
1244 | StackRoot _root0(&part);
|
1245 |
|
1246 | start = max(0, (this->start_pos - 4));
|
1247 | end = min(len(this->s), (this->end_pos + 4));
|
1248 | part = this->s->slice(start, end);
|
1249 | return str_concat(this->msg, StrFormat(" (line %d, offset %d-%d: %r)", this->line_num, this->start_pos, this->end_pos, part));
|
1250 | }
|
1251 |
|
1252 | BigStr* Decode::__str__() {
|
1253 | return this->Message();
|
1254 | }
|
1255 |
|
1256 | Encode::Encode(BigStr* msg) {
|
1257 | this->msg = msg;
|
1258 | }
|
1259 |
|
1260 | BigStr* Encode::Message() {
|
1261 | return this->msg;
|
1262 | }
|
1263 |
|
1264 | [[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location) {
|
1265 | StackRoot _root0(&msg);
|
1266 | StackRoot _root1(&location);
|
1267 |
|
1268 | throw Alloc<Usage>(msg, location);
|
1269 | }
|
1270 |
|
1271 | [[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
|
1272 | StackRoot _root0(&msg);
|
1273 | StackRoot _root1(&location);
|
1274 |
|
1275 | throw Alloc<Strict>(msg, location);
|
1276 | }
|
1277 |
|
1278 | [[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
|
1279 | StackRoot _root0(&msg);
|
1280 | StackRoot _root1(&location);
|
1281 |
|
1282 | throw Alloc<Parse>(msg, location);
|
1283 | }
|
1284 |
|
1285 | [[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
|
1286 | StackRoot _root0(&msg);
|
1287 | StackRoot _root1(&location);
|
1288 |
|
1289 | throw Alloc<FatalRuntime>(1, msg, location);
|
1290 | }
|
1291 |
|
1292 | [[noreturn]] void e_die_status(int status, BigStr* msg, syntax_asdl::loc_t* location) {
|
1293 | StackRoot _root0(&msg);
|
1294 | StackRoot _root1(&location);
|
1295 |
|
1296 | throw Alloc<FatalRuntime>(status, msg, location);
|
1297 | }
|
1298 |
|
1299 | } // define namespace error
|
1300 |
|
1301 | namespace num { // define
|
1302 |
|
1303 | using value_asdl::value;
|
1304 |
|
1305 | value::Int* ToBig(int i) {
|
1306 | return Alloc<value::Int>(mops::IntWiden(i));
|
1307 | }
|
1308 |
|
1309 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y) {
|
1310 | int y_int;
|
1311 | mops::BigInt result;
|
1312 | y_int = mops::BigTruncate(y);
|
1313 | result = mops::BigInt(1);
|
1314 | for (int i = 0; i < y_int; ++i) {
|
1315 | result = mops::Mul(result, x);
|
1316 | }
|
1317 | return result;
|
1318 | }
|
1319 |
|
1320 | int Exponent2(int x, int y) {
|
1321 | return mops::BigTruncate(Exponent(mops::IntWiden(x), mops::IntWiden(y)));
|
1322 | }
|
1323 |
|
1324 | mops::BigInt IntDivide(mops::BigInt x, mops::BigInt y) {
|
1325 | mops::BigInt ZERO;
|
1326 | int sign;
|
1327 | mops::BigInt ax;
|
1328 | mops::BigInt ay;
|
1329 | ZERO = mops::BigInt(0);
|
1330 | sign = 1;
|
1331 | if (mops::Greater(ZERO, x)) {
|
1332 | ax = mops::Negate(x);
|
1333 | sign = -1;
|
1334 | }
|
1335 | else {
|
1336 | ax = x;
|
1337 | }
|
1338 | if (mops::Greater(ZERO, y)) {
|
1339 | ay = mops::Negate(y);
|
1340 | sign = -sign;
|
1341 | }
|
1342 | else {
|
1343 | ay = y;
|
1344 | }
|
1345 | return mops::Mul(mops::IntWiden(sign), mops::Div(ax, ay));
|
1346 | }
|
1347 |
|
1348 | int IntDivide2(int x, int y) {
|
1349 | return mops::BigTruncate(IntDivide(mops::IntWiden(x), mops::IntWiden(y)));
|
1350 | }
|
1351 |
|
1352 | mops::BigInt IntRemainder(mops::BigInt x, mops::BigInt y) {
|
1353 | mops::BigInt ZERO;
|
1354 | mops::BigInt ax;
|
1355 | int sign;
|
1356 | mops::BigInt ay;
|
1357 | ZERO = mops::BigInt(0);
|
1358 | if (mops::Greater(ZERO, x)) {
|
1359 | ax = mops::Negate(x);
|
1360 | sign = -1;
|
1361 | }
|
1362 | else {
|
1363 | ax = x;
|
1364 | sign = 1;
|
1365 | }
|
1366 | if (mops::Greater(ZERO, y)) {
|
1367 | ay = mops::Negate(y);
|
1368 | }
|
1369 | else {
|
1370 | ay = y;
|
1371 | }
|
1372 | return mops::Mul(mops::IntWiden(sign), mops::Rem(ax, ay));
|
1373 | }
|
1374 |
|
1375 | int IntRemainder2(int x, int y) {
|
1376 | return mops::BigTruncate(IntRemainder(mops::IntWiden(x), mops::IntWiden(y)));
|
1377 | }
|
1378 |
|
1379 | } // define namespace num
|
1380 |
|
1381 | namespace args { // define
|
1382 |
|
1383 | using syntax_asdl::loc;
|
1384 | using syntax_asdl::loc_t;
|
1385 | using syntax_asdl::CompoundWord;
|
1386 | using value_asdl::value;
|
1387 | using value_asdl::value_e;
|
1388 | using value_asdl::value_t;
|
1389 | using error::e_usage;
|
1390 | int String = 1;
|
1391 | int Int = 2;
|
1392 | int Float = 3;
|
1393 | int Bool = 4;
|
1394 |
|
1395 | _Attributes::_Attributes(Dict<BigStr*, value_asdl::value_t*>* defaults) {
|
1396 | this->attrs = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
|
1397 | this->opt_changes = Alloc<List<Tuple2<BigStr*, bool>*>>();
|
1398 | this->shopt_changes = Alloc<List<Tuple2<BigStr*, bool>*>>();
|
1399 | this->show_options = false;
|
1400 | this->actions = Alloc<List<BigStr*>>();
|
1401 | this->saw_double_dash = false;
|
1402 | for (DictIter<BigStr*, value_asdl::value_t*> it(defaults); !it.Done(); it.Next()) {
|
1403 | BigStr* name = it.Key();
|
1404 | value_asdl::value_t* v = it.Value();
|
1405 | this->Set(name, v);
|
1406 | }
|
1407 | }
|
1408 |
|
1409 | void _Attributes::SetTrue(BigStr* name) {
|
1410 | StackRoot _root0(&name);
|
1411 |
|
1412 | this->Set(name, Alloc<value::Bool>(true));
|
1413 | }
|
1414 |
|
1415 | void _Attributes::Set(BigStr* name, value_asdl::value_t* val) {
|
1416 | StackRoot _root0(&name);
|
1417 | StackRoot _root1(&val);
|
1418 |
|
1419 | name = name->replace(str62, str63);
|
1420 | this->attrs->set(name, val);
|
1421 | }
|
1422 |
|
1423 | Reader::Reader(List<BigStr*>* argv, List<syntax_asdl::CompoundWord*>* locs) {
|
1424 | this->argv = argv;
|
1425 | this->locs = locs;
|
1426 | this->n = len(argv);
|
1427 | this->i = 0;
|
1428 | }
|
1429 |
|
1430 | void Reader::Next() {
|
1431 | this->i += 1;
|
1432 | }
|
1433 |
|
1434 | BigStr* Reader::Peek() {
|
1435 | if (this->i >= this->n) {
|
1436 | return nullptr;
|
1437 | }
|
1438 | else {
|
1439 | return this->argv->at(this->i);
|
1440 | }
|
1441 | }
|
1442 |
|
1443 | Tuple2<BigStr*, syntax_asdl::loc_t*> Reader::Peek2() {
|
1444 | if (this->i >= this->n) {
|
1445 | return Tuple2<BigStr*, syntax_asdl::loc_t*>(nullptr, loc::Missing);
|
1446 | }
|
1447 | else {
|
1448 | return Tuple2<BigStr*, syntax_asdl::loc_t*>(this->argv->at(this->i), this->locs->at(this->i));
|
1449 | }
|
1450 | }
|
1451 |
|
1452 | BigStr* Reader::ReadRequired(BigStr* error_msg) {
|
1453 | BigStr* arg = nullptr;
|
1454 | StackRoot _root0(&error_msg);
|
1455 | StackRoot _root1(&arg);
|
1456 |
|
1457 | arg = this->Peek();
|
1458 | if (arg == nullptr) {
|
1459 | e_usage(error_msg, this->_FirstLocation());
|
1460 | }
|
1461 | this->Next();
|
1462 | return arg;
|
1463 | }
|
1464 |
|
1465 | Tuple2<BigStr*, syntax_asdl::loc_t*> Reader::ReadRequired2(BigStr* error_msg) {
|
1466 | BigStr* arg = nullptr;
|
1467 | syntax_asdl::CompoundWord* location = nullptr;
|
1468 | StackRoot _root0(&error_msg);
|
1469 | StackRoot _root1(&arg);
|
1470 | StackRoot _root2(&location);
|
1471 |
|
1472 | arg = this->Peek();
|
1473 | if (arg == nullptr) {
|
1474 | e_usage(error_msg, this->_FirstLocation());
|
1475 | }
|
1476 | location = this->locs->at(this->i);
|
1477 | this->Next();
|
1478 | return Tuple2<BigStr*, syntax_asdl::loc_t*>(arg, location);
|
1479 | }
|
1480 |
|
1481 | List<BigStr*>* Reader::Rest() {
|
1482 | return this->argv->slice(this->i);
|
1483 | }
|
1484 |
|
1485 | Tuple2<List<BigStr*>*, List<syntax_asdl::CompoundWord*>*> Reader::Rest2() {
|
1486 | return Tuple2<List<BigStr*>*, List<syntax_asdl::CompoundWord*>*>(this->argv->slice(this->i), this->locs->slice(this->i));
|
1487 | }
|
1488 |
|
1489 | bool Reader::AtEnd() {
|
1490 | return this->i >= this->n;
|
1491 | }
|
1492 |
|
1493 | syntax_asdl::loc_t* Reader::_FirstLocation() {
|
1494 | if ((this->locs != nullptr and this->locs->at(0) != nullptr)) {
|
1495 | return this->locs->at(0);
|
1496 | }
|
1497 | else {
|
1498 | return loc::Missing;
|
1499 | }
|
1500 | }
|
1501 |
|
1502 | syntax_asdl::loc_t* Reader::Location() {
|
1503 | int i;
|
1504 | if (this->locs != nullptr) {
|
1505 | if (this->i == this->n) {
|
1506 | i = (this->n - 1);
|
1507 | }
|
1508 | else {
|
1509 | i = this->i;
|
1510 | }
|
1511 | if (this->locs->at(i) != nullptr) {
|
1512 | return this->locs->at(i);
|
1513 | }
|
1514 | else {
|
1515 | return loc::Missing;
|
1516 | }
|
1517 | }
|
1518 | else {
|
1519 | return loc::Missing;
|
1520 | }
|
1521 | }
|
1522 |
|
1523 | _Action::_Action() {
|
1524 | ; // pass
|
1525 | }
|
1526 |
|
1527 | bool _Action::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1528 | StackRoot _root0(&attached_arg);
|
1529 | StackRoot _root1(&arg_r);
|
1530 | StackRoot _root2(&out);
|
1531 |
|
1532 | FAIL(kNotImplemented); // Python NotImplementedError
|
1533 | }
|
1534 |
|
1535 | _ArgAction::_ArgAction(BigStr* name, bool quit_parsing_flags, List<BigStr*>* valid) {
|
1536 | this->name = name;
|
1537 | this->quit_parsing_flags = quit_parsing_flags;
|
1538 | this->valid = valid;
|
1539 | }
|
1540 |
|
1541 | value_asdl::value_t* _ArgAction::_Value(BigStr* arg, syntax_asdl::loc_t* location) {
|
1542 | StackRoot _root0(&arg);
|
1543 | StackRoot _root1(&location);
|
1544 |
|
1545 | FAIL(kNotImplemented); // Python NotImplementedError
|
1546 | }
|
1547 |
|
1548 | bool _ArgAction::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1549 | BigStr* arg = nullptr;
|
1550 | value_asdl::value_t* val = nullptr;
|
1551 | StackRoot _root0(&attached_arg);
|
1552 | StackRoot _root1(&arg_r);
|
1553 | StackRoot _root2(&out);
|
1554 | StackRoot _root3(&arg);
|
1555 | StackRoot _root4(&val);
|
1556 |
|
1557 | if (attached_arg != nullptr) {
|
1558 | arg = attached_arg;
|
1559 | }
|
1560 | else {
|
1561 | arg_r->Next();
|
1562 | arg = arg_r->Peek();
|
1563 | if (arg == nullptr) {
|
1564 | e_usage(StrFormat("expected argument to %r", str_concat(str67, this->name)), arg_r->Location());
|
1565 | }
|
1566 | }
|
1567 | val = this->_Value(arg, arg_r->Location());
|
1568 | out->Set(this->name, val);
|
1569 | return this->quit_parsing_flags;
|
1570 | }
|
1571 |
|
1572 | SetToInt::SetToInt(BigStr* name) : _ArgAction(name, false, nullptr) {
|
1573 | }
|
1574 |
|
1575 | value_asdl::value_t* SetToInt::_Value(BigStr* arg, syntax_asdl::loc_t* location) {
|
1576 | mops::BigInt i;
|
1577 | StackRoot _root0(&arg);
|
1578 | StackRoot _root1(&location);
|
1579 |
|
1580 | try {
|
1581 | i = mops::FromStr(arg);
|
1582 | }
|
1583 | catch (ValueError*) {
|
1584 | e_usage(StrFormat("expected integer after %s, got %r", str_concat(str69, this->name), arg), location);
|
1585 | }
|
1586 | if (mops::Greater(mops::BigInt(0), i)) {
|
1587 | e_usage(StrFormat("got invalid integer for %s: %s", str_concat(str71, this->name), arg), location);
|
1588 | }
|
1589 | return Alloc<value::Int>(i);
|
1590 | }
|
1591 |
|
1592 | SetToFloat::SetToFloat(BigStr* name) : _ArgAction(name, false, nullptr) {
|
1593 | }
|
1594 |
|
1595 | value_asdl::value_t* SetToFloat::_Value(BigStr* arg, syntax_asdl::loc_t* location) {
|
1596 | double f;
|
1597 | StackRoot _root0(&arg);
|
1598 | StackRoot _root1(&location);
|
1599 |
|
1600 | try {
|
1601 | f = to_float(arg);
|
1602 | }
|
1603 | catch (ValueError*) {
|
1604 | e_usage(StrFormat("expected number after %r, got %r", str_concat(str73, this->name), arg), location);
|
1605 | }
|
1606 | if (f < 0) {
|
1607 | e_usage(StrFormat("got invalid float for %s: %s", str_concat(str75, this->name), arg), location);
|
1608 | }
|
1609 | return Alloc<value::Float>(f);
|
1610 | }
|
1611 |
|
1612 | SetToString::SetToString(BigStr* name, bool quit_parsing_flags, List<BigStr*>* valid) : _ArgAction(name, quit_parsing_flags, valid) {
|
1613 | }
|
1614 |
|
1615 | value_asdl::value_t* SetToString::_Value(BigStr* arg, syntax_asdl::loc_t* location) {
|
1616 | StackRoot _root0(&arg);
|
1617 | StackRoot _root1(&location);
|
1618 |
|
1619 | if ((this->valid != nullptr and !list_contains(this->valid, arg))) {
|
1620 | e_usage(StrFormat("got invalid argument %r to %r, expected one of: %s", arg, str_concat(str77, this->name), str78->join(this->valid)), location);
|
1621 | }
|
1622 | return Alloc<value::Str>(arg);
|
1623 | }
|
1624 |
|
1625 | SetAttachedBool::SetAttachedBool(BigStr* name) {
|
1626 | this->name = name;
|
1627 | }
|
1628 |
|
1629 | bool SetAttachedBool::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1630 | bool b;
|
1631 | StackRoot _root0(&attached_arg);
|
1632 | StackRoot _root1(&arg_r);
|
1633 | StackRoot _root2(&out);
|
1634 |
|
1635 | if (attached_arg != nullptr) {
|
1636 | if ((str_equals(attached_arg, str79) || str_equals(attached_arg, str80) || str_equals(attached_arg, str81) || str_equals(attached_arg, str82))) {
|
1637 | b = false;
|
1638 | }
|
1639 | else {
|
1640 | if ((str_equals(attached_arg, str83) || str_equals(attached_arg, str84) || str_equals(attached_arg, str85) || str_equals(attached_arg, str86))) {
|
1641 | b = true;
|
1642 | }
|
1643 | else {
|
1644 | e_usage(StrFormat("got invalid argument to boolean flag: %r", attached_arg), loc::Missing);
|
1645 | }
|
1646 | }
|
1647 | }
|
1648 | else {
|
1649 | b = true;
|
1650 | }
|
1651 | out->Set(this->name, Alloc<value::Bool>(b));
|
1652 | return false;
|
1653 | }
|
1654 |
|
1655 | SetToTrue::SetToTrue(BigStr* name) {
|
1656 | this->name = name;
|
1657 | }
|
1658 |
|
1659 | bool SetToTrue::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1660 | StackRoot _root0(&attached_arg);
|
1661 | StackRoot _root1(&arg_r);
|
1662 | StackRoot _root2(&out);
|
1663 |
|
1664 | out->SetTrue(this->name);
|
1665 | return false;
|
1666 | }
|
1667 |
|
1668 | SetOption::SetOption(BigStr* name) {
|
1669 | this->name = name;
|
1670 | }
|
1671 |
|
1672 | bool SetOption::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1673 | bool b;
|
1674 | StackRoot _root0(&attached_arg);
|
1675 | StackRoot _root1(&arg_r);
|
1676 | StackRoot _root2(&out);
|
1677 |
|
1678 | b = maybe_str_equals(attached_arg, str88);
|
1679 | out->opt_changes->append((Alloc<Tuple2<BigStr*, bool>>(this->name, b)));
|
1680 | return false;
|
1681 | }
|
1682 |
|
1683 | SetNamedOption::SetNamedOption(bool shopt) {
|
1684 | this->names = Alloc<List<BigStr*>>();
|
1685 | this->shopt = shopt;
|
1686 | }
|
1687 |
|
1688 | void SetNamedOption::ArgName(BigStr* name) {
|
1689 | StackRoot _root0(&name);
|
1690 |
|
1691 | this->names->append(name);
|
1692 | }
|
1693 |
|
1694 | bool SetNamedOption::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1695 | bool b;
|
1696 | BigStr* arg = nullptr;
|
1697 | BigStr* attr_name = nullptr;
|
1698 | List<Tuple2<BigStr*, bool>*>* changes = nullptr;
|
1699 | StackRoot _root0(&attached_arg);
|
1700 | StackRoot _root1(&arg_r);
|
1701 | StackRoot _root2(&out);
|
1702 | StackRoot _root3(&arg);
|
1703 | StackRoot _root4(&attr_name);
|
1704 | StackRoot _root5(&changes);
|
1705 |
|
1706 | b = maybe_str_equals(attached_arg, str89);
|
1707 | arg_r->Next();
|
1708 | arg = arg_r->Peek();
|
1709 | if (arg == nullptr) {
|
1710 | out->show_options = true;
|
1711 | return true;
|
1712 | }
|
1713 | attr_name = arg;
|
1714 | if ((len(this->names) and !list_contains(this->names, attr_name))) {
|
1715 | e_usage(StrFormat("Invalid option %r", arg), loc::Missing);
|
1716 | }
|
1717 | changes = this->shopt ? out->shopt_changes : out->opt_changes;
|
1718 | changes->append((Alloc<Tuple2<BigStr*, bool>>(attr_name, b)));
|
1719 | return false;
|
1720 | }
|
1721 |
|
1722 | SetAction::SetAction(BigStr* name) {
|
1723 | this->name = name;
|
1724 | }
|
1725 |
|
1726 | bool SetAction::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1727 | StackRoot _root0(&attached_arg);
|
1728 | StackRoot _root1(&arg_r);
|
1729 | StackRoot _root2(&out);
|
1730 |
|
1731 | out->actions->append(this->name);
|
1732 | return false;
|
1733 | }
|
1734 |
|
1735 | SetNamedAction::SetNamedAction() {
|
1736 | this->names = Alloc<List<BigStr*>>();
|
1737 | }
|
1738 |
|
1739 | void SetNamedAction::ArgName(BigStr* name) {
|
1740 | StackRoot _root0(&name);
|
1741 |
|
1742 | this->names->append(name);
|
1743 | }
|
1744 |
|
1745 | bool SetNamedAction::OnMatch(BigStr* attached_arg, args::Reader* arg_r, args::_Attributes* out) {
|
1746 | BigStr* arg = nullptr;
|
1747 | BigStr* attr_name = nullptr;
|
1748 | StackRoot _root0(&attached_arg);
|
1749 | StackRoot _root1(&arg_r);
|
1750 | StackRoot _root2(&out);
|
1751 | StackRoot _root3(&arg);
|
1752 | StackRoot _root4(&attr_name);
|
1753 |
|
1754 | arg_r->Next();
|
1755 | arg = arg_r->Peek();
|
1756 | if (arg == nullptr) {
|
1757 | e_usage(str91, loc::Missing);
|
1758 | }
|
1759 | attr_name = arg;
|
1760 | if ((len(this->names) and !list_contains(this->names, attr_name))) {
|
1761 | e_usage(StrFormat("Invalid action name %r", arg), loc::Missing);
|
1762 | }
|
1763 | out->actions->append(attr_name);
|
1764 | return false;
|
1765 | }
|
1766 |
|
1767 | args::_Attributes* Parse(flag_spec::_FlagSpec* spec, args::Reader* arg_r) {
|
1768 | args::_Attributes* out = nullptr;
|
1769 | BigStr* arg = nullptr;
|
1770 | int pos;
|
1771 | BigStr* suffix = nullptr;
|
1772 | BigStr* flag_name = nullptr;
|
1773 | args::_Action* action = nullptr;
|
1774 | int n;
|
1775 | BigStr* ch = nullptr;
|
1776 | BigStr* attached_arg = nullptr;
|
1777 | StackRoot _root0(&spec);
|
1778 | StackRoot _root1(&arg_r);
|
1779 | StackRoot _root2(&out);
|
1780 | StackRoot _root3(&arg);
|
1781 | StackRoot _root4(&suffix);
|
1782 | StackRoot _root5(&flag_name);
|
1783 | StackRoot _root6(&action);
|
1784 | StackRoot _root7(&ch);
|
1785 | StackRoot _root8(&attached_arg);
|
1786 |
|
1787 | out = Alloc<_Attributes>(spec->defaults);
|
1788 | while (!arg_r->AtEnd()) {
|
1789 | arg = arg_r->Peek();
|
1790 | if (maybe_str_equals(arg, str93)) {
|
1791 | out->saw_double_dash = true;
|
1792 | arg_r->Next();
|
1793 | break;
|
1794 | }
|
1795 | if ((len(spec->actions_long) and arg->startswith(str94))) {
|
1796 | pos = arg->find(str95, 2);
|
1797 | if (pos == -1) {
|
1798 | suffix = nullptr;
|
1799 | flag_name = arg->slice(2);
|
1800 | }
|
1801 | else {
|
1802 | suffix = arg->slice((pos + 1));
|
1803 | flag_name = arg->slice(2, pos);
|
1804 | }
|
1805 | action = spec->actions_long->get(flag_name);
|
1806 | if (action == nullptr) {
|
1807 | e_usage(StrFormat("got invalid flag %r", arg), arg_r->Location());
|
1808 | }
|
1809 | action->OnMatch(suffix, arg_r, out);
|
1810 | arg_r->Next();
|
1811 | continue;
|
1812 | }
|
1813 | else {
|
1814 | if ((arg->startswith(str97) and len(arg) > 1)) {
|
1815 | n = len(arg);
|
1816 | for (int i = 1; i < n; ++i) {
|
1817 | ch = arg->at(i);
|
1818 | if (str_equals(ch, str98)) {
|
1819 | ch = str99;
|
1820 | }
|
1821 | if (list_contains(spec->plus_flags, ch)) {
|
1822 | out->Set(ch, Alloc<value::Str>(str100));
|
1823 | continue;
|
1824 | }
|
1825 | if (list_contains(spec->arity0, ch)) {
|
1826 | out->SetTrue(ch);
|
1827 | continue;
|
1828 | }
|
1829 | if (dict_contains(spec->arity1, ch)) {
|
1830 | action = spec->arity1->at(ch);
|
1831 | attached_arg = i < (n - 1) ? arg->slice((i + 1)) : nullptr;
|
1832 | action->OnMatch(attached_arg, arg_r, out);
|
1833 | break;
|
1834 | }
|
1835 | e_usage(StrFormat("doesn't accept flag %s", str_concat(str102, ch)), arg_r->Location());
|
1836 | }
|
1837 | arg_r->Next();
|
1838 | }
|
1839 | else {
|
1840 | if ((len(spec->plus_flags) and (arg->startswith(str103) and len(arg) > 1))) {
|
1841 | n = len(arg);
|
1842 | for (int i = 1; i < n; ++i) {
|
1843 | ch = arg->at(i);
|
1844 | if (list_contains(spec->plus_flags, ch)) {
|
1845 | out->Set(ch, Alloc<value::Str>(str104));
|
1846 | continue;
|
1847 | }
|
1848 | e_usage(StrFormat("doesn't accept option %s", str_concat(str106, ch)), arg_r->Location());
|
1849 | }
|
1850 | arg_r->Next();
|
1851 | }
|
1852 | else {
|
1853 | break;
|
1854 | }
|
1855 | }
|
1856 | }
|
1857 | }
|
1858 | return out;
|
1859 | }
|
1860 |
|
1861 | args::_Attributes* ParseLikeEcho(flag_spec::_FlagSpec* spec, args::Reader* arg_r) {
|
1862 | args::_Attributes* out = nullptr;
|
1863 | BigStr* arg = nullptr;
|
1864 | BigStr* chars = nullptr;
|
1865 | bool done;
|
1866 | StackRoot _root0(&spec);
|
1867 | StackRoot _root1(&arg_r);
|
1868 | StackRoot _root2(&out);
|
1869 | StackRoot _root3(&arg);
|
1870 | StackRoot _root4(&chars);
|
1871 |
|
1872 | out = Alloc<_Attributes>(spec->defaults);
|
1873 | while (!arg_r->AtEnd()) {
|
1874 | arg = arg_r->Peek();
|
1875 | chars = arg->slice(1);
|
1876 | if ((arg->startswith(str107) and len(chars))) {
|
1877 | done = false;
|
1878 | for (StrIter it(chars); !it.Done(); it.Next()) {
|
1879 | BigStr* c = it.Value();
|
1880 | StackRoot _for(&c );
|
1881 | if (!list_contains(spec->arity0, c)) {
|
1882 | done = true;
|
1883 | break;
|
1884 | }
|
1885 | }
|
1886 | if (done) {
|
1887 | break;
|
1888 | }
|
1889 | for (StrIter it(chars); !it.Done(); it.Next()) {
|
1890 | BigStr* ch = it.Value();
|
1891 | StackRoot _for(&ch );
|
1892 | out->SetTrue(ch);
|
1893 | }
|
1894 | }
|
1895 | else {
|
1896 | break;
|
1897 | }
|
1898 | arg_r->Next();
|
1899 | }
|
1900 | return out;
|
1901 | }
|
1902 |
|
1903 | args::_Attributes* ParseMore(flag_spec::_FlagSpecAndMore* spec, args::Reader* arg_r) {
|
1904 | args::_Attributes* out = nullptr;
|
1905 | bool quit;
|
1906 | BigStr* arg = nullptr;
|
1907 | args::_Action* action = nullptr;
|
1908 | BigStr* char0 = nullptr;
|
1909 | BigStr* attached_arg = nullptr;
|
1910 | StackRoot _root0(&spec);
|
1911 | StackRoot _root1(&arg_r);
|
1912 | StackRoot _root2(&out);
|
1913 | StackRoot _root3(&arg);
|
1914 | StackRoot _root4(&action);
|
1915 | StackRoot _root5(&char0);
|
1916 | StackRoot _root6(&attached_arg);
|
1917 |
|
1918 | out = Alloc<_Attributes>(spec->defaults);
|
1919 | quit = false;
|
1920 | while (!arg_r->AtEnd()) {
|
1921 | arg = arg_r->Peek();
|
1922 | if (maybe_str_equals(arg, str108)) {
|
1923 | out->saw_double_dash = true;
|
1924 | arg_r->Next();
|
1925 | break;
|
1926 | }
|
1927 | if (arg->startswith(str109)) {
|
1928 | action = spec->actions_long->get(arg->slice(2));
|
1929 | if (action == nullptr) {
|
1930 | e_usage(StrFormat("got invalid flag %r", arg), arg_r->Location());
|
1931 | }
|
1932 | action->OnMatch(nullptr, arg_r, out);
|
1933 | arg_r->Next();
|
1934 | continue;
|
1935 | }
|
1936 | if (((arg->startswith(str111) or arg->startswith(str112)) and len(arg) > 1)) {
|
1937 | char0 = arg->at(0);
|
1938 | for (StrIter it(arg->slice(1)); !it.Done(); it.Next()) {
|
1939 | BigStr* ch = it.Value();
|
1940 | StackRoot _for(&ch );
|
1941 | action = spec->actions_short->get(ch);
|
1942 | if (action == nullptr) {
|
1943 | e_usage(StrFormat("got invalid flag %r", str_concat(str114, ch)), arg_r->Location());
|
1944 | }
|
1945 | attached_arg = list_contains(spec->plus_flags, ch) ? char0 : nullptr;
|
1946 | quit = action->OnMatch(attached_arg, arg_r, out);
|
1947 | }
|
1948 | arg_r->Next();
|
1949 | if (quit) {
|
1950 | break;
|
1951 | }
|
1952 | else {
|
1953 | continue;
|
1954 | }
|
1955 | }
|
1956 | break;
|
1957 | }
|
1958 | return out;
|
1959 | }
|
1960 |
|
1961 | } // define namespace args
|
1962 |
|