| 1 | // prebuilt/core/error.mycpp.cc: GENERATED by mycpp
|
| 2 |
|
| 3 | #include "prebuilt/core/error.mycpp.h"
|
| 4 | // This file is GENERATED by mycpp, from Python source code
|
| 5 |
|
| 6 | #include "mycpp/runtime.h"
|
| 7 |
|
| 8 | GLOBAL_STR(S_ijB, "(");
|
| 9 | GLOBAL_STR(S_hxb, ")");
|
| 10 | GLOBAL_STR(S_gFh, "F");
|
| 11 | GLOBAL_STR(S_cor, "T");
|
| 12 | GLOBAL_STR(S_tci, "_");
|
| 13 | GLOBAL_STR(S_gFE, "code");
|
| 14 | GLOBAL_STR(S_xho, "failglob: ");
|
| 15 | GLOBAL_STR(S_pBg, "message");
|
| 16 |
|
| 17 | namespace runtime { // forward declare
|
| 18 | class TraversalState;
|
| 19 | }
|
| 20 |
|
| 21 | namespace num { // forward declare
|
| 22 | }
|
| 23 |
|
| 24 | namespace runtime { // declare
|
| 25 |
|
| 26 | extern int NO_SPID;
|
| 27 | hnode::Record* NewRecord(BigStr* node_type);
|
| 28 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color);
|
| 29 | class TraversalState {
|
| 30 | public:
|
| 31 | TraversalState();
|
| 32 | Dict<int, bool>* seen{};
|
| 33 | Dict<int, int>* ref_count{};
|
| 34 |
|
| 35 | static constexpr ObjHeader obj_header() {
|
| 36 | return ObjHeader::ClassScanned(2, sizeof(TraversalState));
|
| 37 | }
|
| 38 |
|
| 39 | DISALLOW_COPY_AND_ASSIGN(TraversalState)
|
| 40 | };
|
| 41 |
|
| 42 | extern BigStr* TRUE_STR;
|
| 43 | extern BigStr* FALSE_STR;
|
| 44 |
|
| 45 | } // declare namespace runtime
|
| 46 |
|
| 47 | namespace num { // declare
|
| 48 |
|
| 49 | value::Int* ToBig(int i);
|
| 50 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y);
|
| 51 |
|
| 52 | } // declare namespace num
|
| 53 |
|
| 54 | namespace runtime { // define
|
| 55 |
|
| 56 | using hnode_asdl::hnode;
|
| 57 | using hnode_asdl::color_t;
|
| 58 | using hnode_asdl::color_e;
|
| 59 | int NO_SPID = -1;
|
| 60 |
|
| 61 | hnode::Record* NewRecord(BigStr* node_type) {
|
| 62 | return Alloc<hnode::Record>(node_type, S_ijB, S_hxb, Alloc<List<hnode_asdl::Field*>>(), nullptr);
|
| 63 | }
|
| 64 |
|
| 65 | hnode::Leaf* NewLeaf(BigStr* s, hnode_asdl::color_t e_color) {
|
| 66 | if (s == nullptr) {
|
| 67 | return Alloc<hnode::Leaf>(S_tci, color_e::OtherConst);
|
| 68 | }
|
| 69 | else {
|
| 70 | return Alloc<hnode::Leaf>(s, e_color);
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | TraversalState::TraversalState() {
|
| 75 | this->seen = Alloc<Dict<int, bool>>();
|
| 76 | this->ref_count = Alloc<Dict<int, int>>();
|
| 77 | }
|
| 78 | BigStr* TRUE_STR = S_cor;
|
| 79 | BigStr* FALSE_STR = S_gFh;
|
| 80 |
|
| 81 | } // define namespace runtime
|
| 82 |
|
| 83 | namespace error { // define
|
| 84 |
|
| 85 | using syntax_asdl::loc_e;
|
| 86 | using syntax_asdl::loc_t;
|
| 87 | using syntax_asdl::loc;
|
| 88 | using value_asdl::value;
|
| 89 | using value_asdl::value_t;
|
| 90 | using value_asdl::value_str;
|
| 91 | int EXPR_STATUS = 3;
|
| 92 | int CODEC_STATUS = 4;
|
| 93 | int GLOB_STATUS = 5;
|
| 94 | int BUILTIN_DEFAULT_STATUS = 10;
|
| 95 |
|
| 96 | BigStr* _ValType(value_asdl::value_t* val) {
|
| 97 | return value_str(val->tag(), false);
|
| 98 | }
|
| 99 |
|
| 100 | _ErrorWithLocation::_ErrorWithLocation(BigStr* msg, syntax_asdl::loc_t* location) {
|
| 101 | this->msg = msg;
|
| 102 | if (location == nullptr) {
|
| 103 | this->location = loc::Missing;
|
| 104 | }
|
| 105 | else {
|
| 106 | this->location = location;
|
| 107 | }
|
| 108 | }
|
| 109 |
|
| 110 | bool _ErrorWithLocation::HasLocation() {
|
| 111 | return this->location->tag() != loc_e::Missing;
|
| 112 | }
|
| 113 |
|
| 114 | BigStr* _ErrorWithLocation::UserErrorString() {
|
| 115 | return this->msg;
|
| 116 | }
|
| 117 |
|
| 118 | Usage::Usage(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 119 | }
|
| 120 |
|
| 121 | Parse::Parse(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 122 | }
|
| 123 |
|
| 124 | WordFailure::WordFailure(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 125 | }
|
| 126 |
|
| 127 | FailGlob::FailGlob(BigStr* msg, syntax_asdl::loc_t* location) : ::error::WordFailure(str_concat(S_xho, msg), location) {
|
| 128 | }
|
| 129 |
|
| 130 | VarSubFailure::VarSubFailure(BigStr* msg, syntax_asdl::loc_t* location) : ::error::WordFailure(msg, location) {
|
| 131 | }
|
| 132 |
|
| 133 | RedirectEval::RedirectEval(BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 134 | }
|
| 135 |
|
| 136 | FatalRuntime::FatalRuntime(int exit_status, BigStr* msg, syntax_asdl::loc_t* location) : ::error::_ErrorWithLocation(msg, location) {
|
| 137 | this->exit_status = exit_status;
|
| 138 | }
|
| 139 |
|
| 140 | int FatalRuntime::ExitStatus() {
|
| 141 | return this->exit_status;
|
| 142 | }
|
| 143 |
|
| 144 | Strict::Strict(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
|
| 145 | }
|
| 146 |
|
| 147 | ErrExit::ErrExit(int exit_status, BigStr* msg, syntax_asdl::loc_t* location, bool show_code) : ::error::FatalRuntime(exit_status, msg, location) {
|
| 148 | this->show_code = show_code;
|
| 149 | }
|
| 150 |
|
| 151 | NoUnset::NoUnset(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(1, msg, location) {
|
| 152 | }
|
| 153 |
|
| 154 | Expr::Expr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::FatalRuntime(EXPR_STATUS, msg, location) {
|
| 155 | }
|
| 156 |
|
| 157 | Structured::Structured(int status, BigStr* msg, syntax_asdl::loc_t* location, Dict<BigStr*, value_asdl::value_t*>* properties) : ::error::FatalRuntime(status, msg, location) {
|
| 158 | this->properties = properties;
|
| 159 | }
|
| 160 |
|
| 161 | value::Dict* Structured::ToDict() {
|
| 162 | Dict<BigStr*, value_asdl::value_t*>* d = nullptr;
|
| 163 | d = Alloc<Dict<BigStr*, value_asdl::value_t*>>();
|
| 164 | if (this->properties != nullptr) {
|
| 165 | d->update(this->properties);
|
| 166 | }
|
| 167 | d->set(S_gFE, num::ToBig(this->ExitStatus()));
|
| 168 | d->set(S_pBg, Alloc<value::Str>(this->msg));
|
| 169 | return Alloc<value::Dict>(d);
|
| 170 | }
|
| 171 |
|
| 172 | AssertionErr::AssertionErr(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
| 173 | }
|
| 174 |
|
| 175 | TypeErrVerbose::TypeErrVerbose(BigStr* msg, syntax_asdl::loc_t* location) : ::error::Expr(msg, location) {
|
| 176 | }
|
| 177 |
|
| 178 | 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) {
|
| 179 | }
|
| 180 |
|
| 181 | Runtime::Runtime(BigStr* msg) {
|
| 182 | this->msg = msg;
|
| 183 | }
|
| 184 |
|
| 185 | BigStr* Runtime::UserErrorString() {
|
| 186 | return this->msg;
|
| 187 | }
|
| 188 |
|
| 189 | Decode::Decode(BigStr* msg, BigStr* s, int start_pos, int end_pos, int line_num) {
|
| 190 | this->msg = msg;
|
| 191 | this->s = s;
|
| 192 | this->start_pos = start_pos;
|
| 193 | this->end_pos = end_pos;
|
| 194 | this->line_num = line_num;
|
| 195 | }
|
| 196 |
|
| 197 | BigStr* Decode::Message() {
|
| 198 | int start;
|
| 199 | int end;
|
| 200 | BigStr* part = nullptr;
|
| 201 | start = max(0, (this->start_pos - 4));
|
| 202 | end = min(len(this->s), (this->end_pos + 4));
|
| 203 | part = this->s->slice(start, end);
|
| 204 | return str_concat(this->msg, StrFormat(" (line %d, offset %d-%d: %r)", this->line_num, this->start_pos, this->end_pos, part));
|
| 205 | }
|
| 206 |
|
| 207 | BigStr* Decode::__str__() {
|
| 208 | return this->Message();
|
| 209 | }
|
| 210 |
|
| 211 | Encode::Encode(BigStr* msg) {
|
| 212 | this->msg = msg;
|
| 213 | }
|
| 214 |
|
| 215 | BigStr* Encode::Message() {
|
| 216 | return this->msg;
|
| 217 | }
|
| 218 |
|
| 219 | [[noreturn]] void e_usage(BigStr* msg, syntax_asdl::loc_t* location) {
|
| 220 | throw Alloc<Usage>(msg, location);
|
| 221 | }
|
| 222 |
|
| 223 | [[noreturn]] void e_strict(BigStr* msg, syntax_asdl::loc_t* location) {
|
| 224 | throw Alloc<Strict>(msg, location);
|
| 225 | }
|
| 226 |
|
| 227 | [[noreturn]] void p_die(BigStr* msg, syntax_asdl::loc_t* location) {
|
| 228 | throw Alloc<Parse>(msg, location);
|
| 229 | }
|
| 230 |
|
| 231 | [[noreturn]] void e_die(BigStr* msg, syntax_asdl::loc_t* location) {
|
| 232 | throw Alloc<FatalRuntime>(1, msg, location);
|
| 233 | }
|
| 234 |
|
| 235 | [[noreturn]] void e_die_status(int status, BigStr* msg, syntax_asdl::loc_t* location) {
|
| 236 | throw Alloc<FatalRuntime>(status, msg, location);
|
| 237 | }
|
| 238 |
|
| 239 | } // define namespace error
|
| 240 |
|
| 241 | namespace num { // define
|
| 242 |
|
| 243 | using value_asdl::value;
|
| 244 |
|
| 245 | value::Int* ToBig(int i) {
|
| 246 | return Alloc<value::Int>(mops::IntWiden(i));
|
| 247 | }
|
| 248 |
|
| 249 | mops::BigInt Exponent(mops::BigInt x, mops::BigInt y) {
|
| 250 | int y_int;
|
| 251 | mops::BigInt result;
|
| 252 | y_int = mops::BigTruncate(y);
|
| 253 | result = mops::BigInt(1);
|
| 254 | for (int i = 0; i < y_int; ++i) {
|
| 255 | result = mops::Mul(result, x);
|
| 256 | }
|
| 257 | return result;
|
| 258 | }
|
| 259 |
|
| 260 | } // define namespace num
|
| 261 |
|