Optionally allow to treat script assert as warning

This commit allows us to treat variable use before assign errors and local variables inside of the global scope as warnings instead of asserts. This will allow for easier porting of legacy scripts. It is highly recommended use this as an aid to port scripts, but can be used in production if needbe.
This commit is contained in:
Jeff Hutchinson 2021-11-16 23:56:52 -05:00
parent b5bd242e23
commit 2e03108856
6 changed files with 60 additions and 12 deletions

View file

@ -57,11 +57,16 @@ namespace Compiler
using namespace Compiler;
FuncVars gEvalFuncVars;
FuncVars gGlobalScopeFuncVars;
FuncVars* gFuncVars = NULL;
inline FuncVars* getFuncVars(S32 lineNumber)
{
AssertISV(gFuncVars, avar("Attemping to use local variable in global scope. File: %s Line: %d", CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
if (gFuncVars == &gGlobalScopeFuncVars)
{
const char* str = avar("Attemping to use local variable in global scope. File: %s Line: %d", CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
scriptErrorHandler(str);
}
return gFuncVars;
}
@ -1552,8 +1557,7 @@ U32 FunctionDeclStmtNode::compileStmt(CodeStream& codeStream, U32 ip)
tbl->add(fnName, nameSpace, varName);
}
// In eval mode, global func vars are allowed.
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : NULL;
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars;
return ip;
}