From f4fc8f6b383f0c065e9f9016aad82588b6199999 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 3 May 2025 21:25:14 +0200 Subject: [PATCH] Codechange: replace Error with simple throw --- src/3rdparty/squirrel/squirrel/sqcompiler.cpp | 54 +++++++++---------- .../squirrel/squirrel/sqfuncstate.cpp | 9 +--- src/3rdparty/squirrel/squirrel/sqfuncstate.h | 1 - src/3rdparty/squirrel/squirrel/sqlexer.cpp | 41 +++++++------- src/3rdparty/squirrel/squirrel/sqlexer.h | 1 - 5 files changed, 45 insertions(+), 61 deletions(-) diff --git a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp index 94dd3b24c0..496e7b6192 100644 --- a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp +++ b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp @@ -63,10 +63,6 @@ public: _sourcename = SQString::Create(_ss(v), sourcename); _lineinfo = lineinfo;_raiseerror = raiseerror; } - [[noreturn]] void Error(const std::string &msg) - { - throw CompileException(msg); - } void Lex(){ _token = _lex.Lex();} void PushExpState(){ _expstates.push_back(ExpState()); } bool IsDerefToken(SQInteger tok) @@ -111,9 +107,9 @@ public: default: etypename = _lex.Tok2Str(tok); } - Error(fmt::format("expected '{}'", etypename)); + throw CompileException(fmt::format("expected '{}'", etypename)); } - Error(fmt::format("expected '{:c}'", tok)); + throw CompileException(fmt::format("expected '{:c}'", tok)); } } SQObjectPtr ret; @@ -140,7 +136,7 @@ public: { if(_token == ';') { Lex(); return; } if(!IsEndOfStatement()) { - Error("end of statement expected (; or lf)"); + throw CompileException("end of statement expected (; or lf)"); } } void MoveIfCurrentTargetIsLocal() { @@ -233,7 +229,7 @@ public: } break;} case TK_BREAK: - if(_fs->_breaktargets.size() <= 0)Error("'break' has to be in a loop block"); + if(_fs->_breaktargets.size() <= 0)throw CompileException("'break' has to be in a loop block"); if(_fs->_breaktargets.top() > 0){ _fs->AddInstruction(_OP_POPTRAP, _fs->_breaktargets.top(), 0); } @@ -243,7 +239,7 @@ public: Lex(); break; case TK_CONTINUE: - if(_fs->_continuetargets.size() <= 0)Error("'continue' has to be in a loop block"); + if(_fs->_continuetargets.size() <= 0)throw CompileException("'continue' has to be in a loop block"); if(_fs->_continuetargets.top() > 0) { _fs->AddInstruction(_OP_POPTRAP, _fs->_continuetargets.top(), 0); } @@ -356,19 +352,19 @@ public: SQInteger op = _token; SQInteger ds = _exst._deref; bool freevar = _exst._freevar; - if(ds == DEREF_NO_DEREF) Error("can't assign expression"); + if(ds == DEREF_NO_DEREF) throw CompileException("can't assign expression"); Lex(); Expression(); switch(op){ case TK_NEWSLOT: - if(freevar) Error("free variables cannot be modified"); + if(freevar) throw CompileException("free variables cannot be modified"); if(ds == DEREF_FIELD) EmitDerefOp(_OP_NEWSLOT); else //if _derefstate != DEREF_NO_DEREF && DEREF_FIELD so is the index of a local - Error("can't 'create' a local slot"); + throw CompileException("can't 'create' a local slot"); break; case '=': //ASSIGN - if(freevar) Error("free variables cannot be modified"); + if(freevar) throw CompileException("free variables cannot be modified"); if(ds == DEREF_FIELD) EmitDerefOp(_OP_SET); else {//if _derefstate != DEREF_NO_DEREF && DEREF_FIELD so is the index of a local @@ -533,7 +529,7 @@ public: if(_token == TK_PARENT) { Lex(); if(!NeedGet()) - Error("parent cannot be set"); + throw CompileException("parent cannot be set"); SQInteger src = _fs->PopTarget(); _fs->AddInstruction(_OP_GETPARENT, _fs->PushTarget(), src); } @@ -546,7 +542,7 @@ public: } break; case '[': - if(_lex._prevtoken == '\n') Error("cannot brake deref/or comma needed after [exp]=exp slot declaration"); + if(_lex._prevtoken == '\n') throw CompileException("cannot brake deref/or comma needed after [exp]=exp slot declaration"); Lex(); Expression(); Expect(']'); pos = -1; if(NeedGet()) Emit2ArgsOP(_OP_GET); @@ -638,7 +634,7 @@ public: Expect('.'); constid = Expect(TK_IDENTIFIER); if(!_table(constant)->Get(constid,constval)) { constval.Null(); - Error(fmt::format("invalid constant [{}.{}]", _stringval(id),_stringval(constid))); + throw CompileException(fmt::format("invalid constant [{}.{}]", _stringval(id),_stringval(constid))); } } else { @@ -742,7 +738,7 @@ public: case TK_DELEGATE : DelegateExpr(); break; case '(': Lex(); CommaExpr(); Expect(')'); break; - default: Error("expression expected"); + default: throw CompileException("expression expected"); } return -1; } @@ -771,7 +767,7 @@ public: nargs++; if(_token == ','){ Lex(); - if(_token == ')') Error("expression expected, found ')'"); + if(_token == ')') throw CompileException("expression expected, found ')'"); } } Lex(); @@ -1082,13 +1078,13 @@ public: _exst._funcarg = false; PrefixedExpr(); es = PopExpState(); - if(es._deref == DEREF_NO_DEREF) Error("invalid class name"); + if(es._deref == DEREF_NO_DEREF) throw CompileException("invalid class name"); if(es._deref == DEREF_FIELD) { ClassExp(); EmitDerefOp(_OP_NEWSLOT); _fs->PopTarget(); } - else Error("cannot create a class in a local with the syntax(class )"); + else throw CompileException("cannot create a class in a local with the syntax(class )"); } SQObject ExpectScalar() { @@ -1118,12 +1114,12 @@ public: val._unVal.fFloat = -_lex._fvalue; break; default: - Error("scalar expected : integer,float"); + throw CompileException("scalar expected : integer,float"); val._type = OT_NULL; // Silent compile-warning } break; default: - Error("scalar expected : integer,float or string"); + throw CompileException("scalar expected : integer,float or string"); val._type = OT_NULL; // Silent compile-warning } Lex(); @@ -1226,9 +1222,9 @@ public: _exst._funcarg = false; PrefixedExpr(); es = PopExpState(); - if(es._deref == DEREF_NO_DEREF) Error("can't delete an expression"); + if(es._deref == DEREF_NO_DEREF) throw CompileException("can't delete an expression"); if(es._deref == DEREF_FIELD) Emit2ArgsOP(_OP_DELETE); - else Error("cannot delete a local"); + else throw CompileException("cannot delete a local"); } void PrefixIncDec(SQInteger token) { @@ -1255,10 +1251,10 @@ public: SQInteger defparams = 0; while(_token!=')') { if(_token == TK_VARPARAMS) { - if(defparams > 0) Error("function with default parameters cannot have variable number of parameters"); + if(defparams > 0) throw CompileException("function with default parameters cannot have variable number of parameters"); funcstate->_varparams = true; Lex(); - if(_token != ')') Error("expected ')'"); + if(_token != ')') throw CompileException("expected ')'"); break; } else { @@ -1271,10 +1267,10 @@ public: defparams++; } else { - if(defparams > 0) Error("expected '='"); + if(defparams > 0) throw CompileException("expected '='"); } if(_token == ',') Lex(); - else if(_token != ')') Error("expected ')' or ','"); + else if(_token != ')') throw CompileException("expected ')' or ','"); } } Expect(')'); @@ -1289,7 +1285,7 @@ public: //outers are treated as implicit local variables funcstate->AddOuterValue(paramname); if(_token == ',') Lex(); - else if(_token != ')') Error("expected ')' or ','"); + else if(_token != ')') throw CompileException("expected ')' or ','"); } Lex(); } diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp index 41cef7c63e..03fcf5f134 100644 --- a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp +++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp @@ -110,11 +110,6 @@ SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent) } -void SQFuncState::Error(const SQChar *err) -{ - throw CompileException(err); -} - #ifdef _DEBUG_DUMP void SQFuncState::Dump(SQFunctionProto *func) { @@ -234,7 +229,7 @@ SQInteger SQFuncState::GetConstant(const SQObject &cons) _nliterals++; if(_nliterals > MAX_LITERALS) { val.Null(); - Error("internal compiler error: too many literals"); + throw CompileException("internal compiler error: too many literals"); } } return _integer(val); @@ -264,7 +259,7 @@ SQInteger SQFuncState::AllocStackPos() SQInteger npos=_vlocals.size(); _vlocals.push_back(SQLocalVarInfo()); if(_vlocals.size()>((SQUnsignedInteger)_stacksize)) { - if(_stacksize>MAX_FUNC_STACKSIZE) Error("internal compiler error: too many locals"); + if(_stacksize>MAX_FUNC_STACKSIZE) throw CompileException("internal compiler error: too many locals"); _stacksize=_vlocals.size(); } return npos; diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.h b/src/3rdparty/squirrel/squirrel/sqfuncstate.h index f64b974971..d67f6dcc91 100644 --- a/src/3rdparty/squirrel/squirrel/sqfuncstate.h +++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.h @@ -11,7 +11,6 @@ struct SQFuncState #ifdef _DEBUG_DUMP void Dump(SQFunctionProto *func); #endif - [[noreturn]] void Error(const SQChar *err); SQFuncState *PushChildState(SQSharedState *ss); void PopChildState(); void AddInstruction(SQOpcode _op,SQInteger arg0=0,SQInteger arg1=0,SQInteger arg2=0,SQInteger arg3=0){SQInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);} diff --git a/src/3rdparty/squirrel/squirrel/sqlexer.cpp b/src/3rdparty/squirrel/squirrel/sqlexer.cpp index 6d6bba4960..6523540880 100644 --- a/src/3rdparty/squirrel/squirrel/sqlexer.cpp +++ b/src/3rdparty/squirrel/squirrel/sqlexer.cpp @@ -92,15 +92,10 @@ SQLexer::SQLexer(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up) Next(); } -[[noreturn]] void SQLexer::Error(const SQChar *err) -{ - throw CompileException(err); -} - void SQLexer::Next() { char32_t t = _readf(_up); - if(t > MAX_CHAR) Error("Invalid character"); + if(t > MAX_CHAR) throw CompileException("Invalid character"); if(t != 0) { _currdata = t; return; @@ -127,7 +122,7 @@ void SQLexer::LexBlockComment() switch(CUR_CHAR) { case '*': { NEXT(); if(CUR_CHAR == '/') { done = true; NEXT(); }}; continue; case '\n': _currentline++; NEXT(); continue; - case SQUIRREL_EOB: Error("missing \"*/\" in comment"); + case SQUIRREL_EOB: throw CompileException("missing \"*/\" in comment"); default: NEXT(); } } @@ -196,11 +191,11 @@ SQInteger SQLexer::Lex() SQInteger stype; NEXT(); if(CUR_CHAR != '"') - Error("string expected"); + throw CompileException("string expected"); if((stype=ReadString('"',true))!=-1) { RETURN_TOKEN(stype); } - Error("error parsing the string"); + throw CompileException("error parsing the string"); } case '"': case '\'': { @@ -208,7 +203,7 @@ SQInteger SQLexer::Lex() if((stype=ReadString(CUR_CHAR,false))!=-1){ RETURN_TOKEN(stype); } - Error("error parsing the string"); + throw CompileException("error parsing the string"); } case '{': case '}': case '(': case ')': case '[': case ']': case ';': case ',': case '?': case '^': case '~': @@ -218,7 +213,7 @@ SQInteger SQLexer::Lex() NEXT(); if (CUR_CHAR != '.'){ RETURN_TOKEN('.') } NEXT(); - if (CUR_CHAR != '.'){ Error("invalid token '..'"); } + if (CUR_CHAR != '.'){ throw CompileException("invalid token '..'"); } NEXT(); RETURN_TOKEN(TK_VARPARAMS); case '&': @@ -264,7 +259,7 @@ SQInteger SQLexer::Lex() } else { SQInteger c = CUR_CHAR; - if (iscntrl((int)c)) Error("unexpected character(control)"); + if (iscntrl((int)c)) throw CompileException("unexpected character(control)"); NEXT(); RETURN_TOKEN(c); } @@ -294,10 +289,10 @@ SQInteger SQLexer::ReadString(char32_t ndelim,bool verbatim) while(CUR_CHAR != ndelim) { switch(CUR_CHAR) { case SQUIRREL_EOB: - Error("unfinished string"); + throw CompileException("unfinished string"); return -1; case '\n': - if(!verbatim) Error("newline in a constant"); + if(!verbatim) throw CompileException("newline in a constant"); APPEND_CHAR(CUR_CHAR); NEXT(); _currentline++; break; @@ -309,7 +304,7 @@ SQInteger SQLexer::ReadString(char32_t ndelim,bool verbatim) NEXT(); switch(CUR_CHAR) { case 'x': NEXT(); { - if(!isxdigit(CUR_CHAR)) Error("hexadecimal number expected"); + if(!isxdigit(CUR_CHAR)) throw CompileException("hexadecimal number expected"); const SQInteger maxdigits = 4; SQChar temp[maxdigits]; size_t n = 0; @@ -319,7 +314,7 @@ SQInteger SQLexer::ReadString(char32_t ndelim,bool verbatim) NEXT(); } auto val = ParseInteger(std::string_view{temp, n}, 16); - if (!val.has_value()) Error("hexadecimal number expected"); + if (!val.has_value()) throw CompileException("hexadecimal number expected"); APPEND_CHAR(static_cast(*val)); } break; @@ -335,7 +330,7 @@ SQInteger SQLexer::ReadString(char32_t ndelim,bool verbatim) case '"': APPEND_CHAR('"'); NEXT(); break; case '\'': APPEND_CHAR('\''); NEXT(); break; default: - Error("unrecognised escaper char"); + throw CompileException("unrecognised escaper char"); break; } } @@ -357,8 +352,8 @@ SQInteger SQLexer::ReadString(char32_t ndelim,bool verbatim) TERMINATE_BUFFER(); SQInteger len = _longstr.size()-1; if(ndelim == '\'') { - if(len == 0) Error("empty constant"); - if(len > 1) Error("constant too long"); + if(len == 0) throw CompileException("empty constant"); + if(len > 1) throw CompileException("constant too long"); _nvalue = _longstr[0]; return TK_INTEGER; } @@ -420,7 +415,7 @@ SQInteger SQLexer::ReadNumber() APPEND_CHAR(CUR_CHAR); NEXT(); } - if(isdigit(CUR_CHAR)) Error("invalid octal number"); + if(isdigit(CUR_CHAR)) throw CompileException("invalid octal number"); } else { NEXT(); @@ -429,7 +424,7 @@ SQInteger SQLexer::ReadNumber() APPEND_CHAR(CUR_CHAR); NEXT(); } - if(_longstr.size() > MAX_HEX_DIGITS) Error("too many digits for an Hex number"); + if(_longstr.size() > MAX_HEX_DIGITS) throw CompileException("too many digits for an Hex number"); } } else { @@ -437,7 +432,7 @@ SQInteger SQLexer::ReadNumber() while (CUR_CHAR == '.' || isdigit(CUR_CHAR) || isexponent(CUR_CHAR)) { if(CUR_CHAR == '.' || isexponent(CUR_CHAR)) type = TFLOAT; if(isexponent(CUR_CHAR)) { - if(type != TFLOAT) Error("invalid numeric format"); + if(type != TFLOAT) throw CompileException("invalid numeric format"); type = TSCIENTIFIC; APPEND_CHAR(CUR_CHAR); NEXT(); @@ -445,7 +440,7 @@ SQInteger SQLexer::ReadNumber() APPEND_CHAR(CUR_CHAR); NEXT(); } - if(!isdigit(CUR_CHAR)) Error("exponent expected"); + if(!isdigit(CUR_CHAR)) throw CompileException("exponent expected"); } APPEND_CHAR(CUR_CHAR); diff --git a/src/3rdparty/squirrel/squirrel/sqlexer.h b/src/3rdparty/squirrel/squirrel/sqlexer.h index 9ce9469b24..818c7a8d81 100644 --- a/src/3rdparty/squirrel/squirrel/sqlexer.h +++ b/src/3rdparty/squirrel/squirrel/sqlexer.h @@ -6,7 +6,6 @@ struct SQLexer { ~SQLexer(); SQLexer(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up); - [[noreturn]] void Error(const SQChar *err); SQInteger Lex(); const SQChar *Tok2Str(SQInteger tok); private: