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