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