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