diff --git a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp index 668e5a4d27..6f67796839 100644 --- a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp +++ b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp @@ -57,19 +57,15 @@ typedef sqvector ExpStateVec; class SQCompiler { public: - SQCompiler(SQVM *v, SQLEXREADFUNC rg, SQUserPointer up, const SQChar* sourcename, bool raiseerror, bool lineinfo) : _token(0), _fs(nullptr), _lex(_ss(v), rg, up, ThrowError, this), _debugline(0), _debugop(0) + SQCompiler(SQVM *v, SQLEXREADFUNC rg, SQUserPointer up, const SQChar* sourcename, bool raiseerror, bool lineinfo) : _token(0), _fs(nullptr), _lex(_ss(v), rg, up), _debugline(0), _debugop(0) { _vm=v; _sourcename = SQString::Create(_ss(v), sourcename); _lineinfo = lineinfo;_raiseerror = raiseerror; } - NORETURN static void ThrowError(void *ud, const SQChar *s) { - SQCompiler *c = (SQCompiler *)ud; - c->Error(s); - } - NORETURN void Error(const std::string &msg) + [[noreturn]] void Error(const std::string &msg) { - throw msg; + throw CompileException(msg); } void Lex(){ _token = _lex.Lex();} void PushExpState(){ _expstates.push_back(ExpState()); } @@ -159,7 +155,7 @@ public: _debugline = 1; _debugop = 0; - SQFuncState funcstate(_ss(_vm), nullptr,ThrowError,this); + SQFuncState funcstate(_ss(_vm), nullptr); funcstate._name = SQString::Create(_ss(_vm), "main"); _fs = &funcstate; _fs->AddParameter(_fs->CreateString("this")); @@ -181,12 +177,12 @@ public: #endif return true; } - catch (const std::string &compilererror) { + catch (const CompileException &compilererror) { if(_raiseerror && _ss(_vm)->_compilererrorhandler) { - _ss(_vm)->_compilererrorhandler(_vm, compilererror.c_str(), type(_sourcename) == OT_STRING ? _stringval(_sourcename) : "unknown", + _ss(_vm)->_compilererrorhandler(_vm, compilererror.what(), type(_sourcename) == OT_STRING ? _stringval(_sourcename) : "unknown", _lex._currentline, _lex._currentcolumn); } - _vm->_lasterror = SQString::Create(_ss(_vm), compilererror); + _vm->_lasterror = SQString::Create(_ss(_vm), compilererror.what()); return false; } } diff --git a/src/3rdparty/squirrel/squirrel/sqcompiler.h b/src/3rdparty/squirrel/squirrel/sqcompiler.h index 08946fb60c..cdb6b1d65c 100644 --- a/src/3rdparty/squirrel/squirrel/sqcompiler.h +++ b/src/3rdparty/squirrel/squirrel/sqcompiler.h @@ -71,12 +71,7 @@ struct SQVM; #define TK_ENUM 323 #define TK_CONST 324 -/* MSVC doesn't like NORETURN for function prototypes, but we kinda need it for GCC. */ -#if defined(_MSC_VER) && !defined(__clang__) -typedef void(*CompilerErrorFunc)(void *ud, const SQChar *s); -#else -typedef NORETURN void(*CompilerErrorFunc)(void *ud, const SQChar *s); -#endif +using CompileException = std::runtime_error; bool Compile(SQVM *vm, SQLEXREADFUNC rg, SQUserPointer up, const SQChar *sourcename, SQObjectPtr &out, bool raiseerror, bool lineinfo); #endif //_SQCOMPILER_H_ diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp index 1f9decc6e0..e6e64ba81a 100644 --- a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp +++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp @@ -93,7 +93,7 @@ void DumpLiteral(SQObjectPtr &o) } #endif -SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed) +SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent) { _nliterals = 0; _literals = SQTable::Create(ss,0); @@ -106,15 +106,13 @@ SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc _traps = 0; _returnexp = 0; _varparams = false; - _errfunc = efunc; - _errtarget = ed; _bgenerator = false; } void SQFuncState::Error(const SQChar *err) { - _errfunc(_errtarget,err); + throw CompileException(err); } #ifdef _DEBUG_DUMP @@ -550,7 +548,7 @@ SQFunctionProto *SQFuncState::BuildProto() SQFuncState *SQFuncState::PushChildState(SQSharedState *ss) { SQFuncState *child = (SQFuncState *)sq_malloc(sizeof(SQFuncState)); - new (child) SQFuncState(ss,this,_errfunc,_errtarget); + new (child) SQFuncState(ss,this); _childstates.push_back(child); return child; } diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.h b/src/3rdparty/squirrel/squirrel/sqfuncstate.h index c0bf1e5e9e..739eb16261 100644 --- a/src/3rdparty/squirrel/squirrel/sqfuncstate.h +++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.h @@ -6,12 +6,12 @@ struct SQFuncState { - SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed); + SQFuncState(SQSharedState *ss,SQFuncState *parent); ~SQFuncState(); #ifdef _DEBUG_DUMP void Dump(SQFunctionProto *func); #endif - void Error(const SQChar *err); + [[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);} @@ -75,9 +75,6 @@ struct SQFuncState SQSharedState *_sharedstate; sqvector _childstates; SQInteger GetConstant(const SQObject &cons); -private: - CompilerErrorFunc _errfunc; - void *_errtarget; }; diff --git a/src/3rdparty/squirrel/squirrel/sqlexer.cpp b/src/3rdparty/squirrel/squirrel/sqlexer.cpp index e91e9ecc52..f8e9d1754c 100644 --- a/src/3rdparty/squirrel/squirrel/sqlexer.cpp +++ b/src/3rdparty/squirrel/squirrel/sqlexer.cpp @@ -35,10 +35,8 @@ void SQLexer::APPEND_CHAR(char32_t c) } } -SQLexer::SQLexer(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,CompilerErrorFunc efunc,void *ed) +SQLexer::SQLexer(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up) { - _errfunc = efunc; - _errtarget = ed; _sharedstate = ss; _keywords = SQTable::Create(ss, 26); ADD_KEYWORD(while, TK_WHILE); @@ -96,7 +94,7 @@ SQLexer::SQLexer(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up,CompilerE NORETURN void SQLexer::Error(const SQChar *err) { - _errfunc(_errtarget,err); + throw CompileException(err); } void SQLexer::Next() diff --git a/src/3rdparty/squirrel/squirrel/sqlexer.h b/src/3rdparty/squirrel/squirrel/sqlexer.h index 3a4e76b339..9ce9469b24 100644 --- a/src/3rdparty/squirrel/squirrel/sqlexer.h +++ b/src/3rdparty/squirrel/squirrel/sqlexer.h @@ -5,8 +5,8 @@ struct SQLexer { ~SQLexer(); - SQLexer(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up,CompilerErrorFunc efunc,void *ed); - NORETURN void Error(const SQChar *err); + SQLexer(SQSharedState *ss,SQLEXREADFUNC rg,SQUserPointer up); + [[noreturn]] void Error(const SQChar *err); SQInteger Lex(); const SQChar *Tok2Str(SQInteger tok); private: @@ -35,8 +35,6 @@ public: char32_t _currdata; SQSharedState *_sharedstate; sqvector _longstr; - CompilerErrorFunc _errfunc; - void *_errtarget; }; #endif