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