|
@@ -35,6 +35,13 @@
|
|
|
#include "console/simBase.h"
|
|
|
|
|
|
extern FuncVars gEvalFuncVars;
|
|
|
+extern FuncVars gGlobalScopeFuncVars;
|
|
|
+extern FuncVars *gFuncVars;
|
|
|
+
|
|
|
+namespace Con
|
|
|
+{
|
|
|
+extern bool scriptWarningsAsAsserts;
|
|
|
+};
|
|
|
|
|
|
namespace Compiler
|
|
|
{
|
|
@@ -124,12 +131,24 @@ namespace Compiler
|
|
|
getFunctionStringTable().reset();
|
|
|
getIdentTable().reset();
|
|
|
getFunctionVariableMappingTable().reset();
|
|
|
- gEvalFuncVars.clear();
|
|
|
+ gGlobalScopeFuncVars.clear();
|
|
|
+ gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars;
|
|
|
}
|
|
|
|
|
|
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
|
|
|
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
|
|
|
|
|
|
+ void scriptErrorHandler(const char* str)
|
|
|
+ {
|
|
|
+ if (Con::scriptWarningsAsAsserts)
|
|
|
+ {
|
|
|
+ AssertISV(false, str);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Con::warnf(ConsoleLogEntry::Type::Script, "%s", str);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
@@ -141,7 +160,11 @@ S32 FuncVars::assign(StringTableEntry var, TypeReq currentType, S32 lineNumber,
|
|
|
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
|
|
|
if (found != vars.end())
|
|
|
{
|
|
|
- AssertISV(!found->second.isConstant, avar("Reassigning variable %s when it is a constant. File: %s Line : %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
|
|
|
+ if (found->second.isConstant)
|
|
|
+ {
|
|
|
+ const char* str = avar("Script Warning: Reassigning variable %s when it is a constant. File: %s Line : %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
|
|
|
+ scriptErrorHandler(str);
|
|
|
+ }
|
|
|
return found->second.reg;
|
|
|
}
|
|
|
|
|
@@ -155,7 +178,15 @@ S32 FuncVars::assign(StringTableEntry var, TypeReq currentType, S32 lineNumber,
|
|
|
S32 FuncVars::lookup(StringTableEntry var, S32 lineNumber)
|
|
|
{
|
|
|
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
|
|
|
- AssertISV(found != vars.end(), avar("Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
|
|
|
+
|
|
|
+ if (found == vars.end())
|
|
|
+ {
|
|
|
+ const char* str = avar("Script Warning: Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
|
|
|
+ scriptErrorHandler(str);
|
|
|
+
|
|
|
+ return assign(var, TypeReqString, lineNumber, false);
|
|
|
+ }
|
|
|
+
|
|
|
return found->second.reg;
|
|
|
}
|
|
|
|
|
@@ -163,7 +194,15 @@ TypeReq FuncVars::lookupType(StringTableEntry var, S32 lineNumber)
|
|
|
{
|
|
|
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
|
|
|
|
|
|
- AssertISV(found != vars.end(), avar("Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
|
|
|
+ if (found == vars.end())
|
|
|
+ {
|
|
|
+ const char* str = avar("Script Warning: Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
|
|
|
+ scriptErrorHandler(str);
|
|
|
+
|
|
|
+ assign(var, TypeReqString, lineNumber, false);
|
|
|
+ return vars.find(var)->second.currentType;
|
|
|
+ }
|
|
|
+
|
|
|
return found->second.currentType;
|
|
|
}
|
|
|
|