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