diff --git a/doc/repl/native.cpp b/doc/repl/native.cpp index 9b70e93..d298856 100644 --- a/doc/repl/native.cpp +++ b/doc/repl/native.cpp @@ -48,10 +48,13 @@ static void script_err_print_func(HSQUIRRELVM /*v*/, const SQChar* s,...) } -static void compile_error_handler(HSQUIRRELVM /*v*/, const SQChar *desc, const SQChar *source, +static void compile_error_handler(HSQUIRRELVM /*v*/, SQMessageSeverity sev, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column, const SQChar *extra_info) { - output += vaformat("Squirrel compile error %s (%d:%d): %s", source, int(line), int(column), desc); + const SQChar *sevName = "error"; + if (sev == SEV_HINT) sevName = "hint"; + else if (sev == SEV_WARNING) sevName = "warning"; + output += vaformat("Squirrel compile %s %s (%d:%d): %s", sevText, source, int(line), int(column), desc); if (extra_info) { output += "\n"; diff --git a/include/squirrel.h b/include/squirrel.h index 9f425b6..1a5811b 100644 --- a/include/squirrel.h +++ b/include/squirrel.h @@ -186,12 +186,18 @@ typedef struct tagSQStackInfos{ SQInteger line; }SQStackInfos; +typedef enum tagSQMessageSeverity{ + SEV_HINT, + SEV_WARNING, + SEV_ERROR, +}SQMessageSeverity; + typedef struct SQVM* HSQUIRRELVM; typedef SQObject HSQOBJECT; typedef SQMemberHandle HSQMEMBERHANDLE; typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM); typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size); -typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/, const SQChar * /*extra info*/); +typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,SQMessageSeverity /*severity*/,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/, const SQChar * /*extra info*/); typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...); typedef void (*SQDEBUGHOOK)(HSQUIRRELVM /*v*/, SQInteger /*type*/, const SQChar * /*sourcename*/, SQInteger /*line*/, const SQChar * /*funcname*/); typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger); diff --git a/sqstdlib/sqstdaux.cpp b/sqstdlib/sqstdaux.cpp index 826dbc1..502cc8a 100644 --- a/sqstdlib/sqstdaux.cpp +++ b/sqstdlib/sqstdaux.cpp @@ -186,7 +186,7 @@ static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v) return 0; } -void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column, const SQChar *extra) +void _sqstd_compiler_message(HSQUIRRELVM v,SQMessageSeverity severity,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column, const SQChar *extra) { SQPRINTFUNCTION pf = sq_geterrorfunc(v); if(pf) { @@ -199,7 +199,7 @@ void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSourc void sqstd_seterrorhandlers(HSQUIRRELVM v) { - sq_setcompilererrorhandler(v,_sqstd_compiler_error); + sq_setcompilererrorhandler(v,_sqstd_compiler_message); sq_newclosure(v,_sqstd_aux_printerror,0); sq_seterrorhandler(v); } diff --git a/squirrel/sqbinaryast.cpp b/squirrel/sqbinaryast.cpp index 74dc2ef..b2da75f 100644 --- a/squirrel/sqbinaryast.cpp +++ b/squirrel/sqbinaryast.cpp @@ -575,7 +575,7 @@ void SQASTReader::error(const char *fmt, ...) { vsnprintf(buffer, sizeof buffer, fmt, vl); va_end(vl); - _ss(vm)->_compilererrorhandler(vm, buffer, "BinaryAST", -1, -1, nullptr); + _ss(vm)->_compilererrorhandler(vm, SEV_ERROR, buffer, "BinaryAST", -1, -1, nullptr); } longjmp(_errorjmp, 1); } diff --git a/squirrel/sqcompilationcontext.cpp b/squirrel/sqcompilationcontext.cpp index 1e1c75d..95e999b 100644 --- a/squirrel/sqcompilationcontext.cpp +++ b/squirrel/sqcompilationcontext.cpp @@ -521,7 +521,7 @@ void SQCompilationContext::vreportDiagnostic(enum DiagnosticsId diagId, int32_t extra = extraInfo.c_str(); } - auto errorFunc = _ss(_vm)->_compilererrorhandler; + auto messageFunc = _ss(_vm)->_compilererrorhandler; const char *msg = message.c_str(); @@ -539,8 +539,11 @@ void SQCompilationContext::vreportDiagnostic(enum DiagnosticsId diagId, int32_t diagMsgFunc(_vm, &cm); } - if (_raiseError && errorFunc) { - errorFunc(_vm, msg, _sourceName, line, pos, extra); + if (_raiseError && messageFunc) { + SQMessageSeverity sev = SEV_ERROR; + if (desc.severity == DS_HINT) sev = SEV_HINT; + else if (desc.severity == DS_WARNING) sev = SEV_WARNING; + messageFunc(_vm, sev, msg, _sourceName, line, pos, extra); } if (isError) { _vm->_lasterror = SQString::Create(_ss(_vm), msg, message.length()); diff --git a/squirrel/static_analyzer/analyzer.cpp b/squirrel/static_analyzer/analyzer.cpp index 30f4b9c..2383f94 100644 --- a/squirrel/static_analyzer/analyzer.cpp +++ b/squirrel/static_analyzer/analyzer.cpp @@ -8067,7 +8067,7 @@ void StaticAnalyzer::reportGlobalNamesWarnings(HSQUIRRELVM vm) { message.clear(); SQCompilationContext::renderDiagnosticHeader(DiagnosticsId::DI_GLOBAL_NAME_REDEF, &message, name); - errorFunc(vm, message.c_str(), loc.filename, loc.line, loc.column, "\n"); + errorFunc(vm, SEV_WARNING, message.c_str(), loc.filename, loc.line, loc.column, "\n"); } } @@ -8092,7 +8092,7 @@ void StaticAnalyzer::reportGlobalNamesWarnings(HSQUIRRELVM vm) { message.clear(); SQCompilationContext::renderDiagnosticHeader(DiagnosticsId::DI_UNDEFINED_GLOBAL, &message, id.c_str()); - errorFunc(vm, message.c_str(), loc.filename, loc.line, loc.column, "\n"); + errorFunc(vm, SEV_WARNING, message.c_str(), loc.filename, loc.line, loc.column, "\n"); } } }