1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 07:39:40 +00:00

modified code to avoid a warning on MSVC

This commit is contained in:
Marc Zinnschlag 2010-08-29 23:40:59 +02:00
parent d4bf916f18
commit a899a290c0

View file

@ -23,7 +23,7 @@ namespace MWScript
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose), : mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext) mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext)
{} {}
bool ScriptManager::compile (const std::string& name) bool ScriptManager::compile (const std::string& name)
{ {
mParser.reset(); mParser.reset();
@ -32,22 +32,22 @@ namespace MWScript
bool Success = true; bool Success = true;
if (const ESM::Script *script = mStore.scripts.find (name)) if (const ESM::Script *script = mStore.scripts.find (name))
{ {
if (mVerbose) if (mVerbose)
std::cout << "compiling script: " << name << std::endl; std::cout << "compiling script: " << name << std::endl;
try try
{ {
std::istringstream input (script->scriptText); std::istringstream input (script->scriptText);
Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions()); Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions());
scanner.scan (mParser); scanner.scan (mParser);
if (!mErrorHandler.isGood()) if (!mErrorHandler.isGood())
Success = false; Success = false;
} }
catch (const std::exception& error) catch (...)
{ {
Success = false; Success = false;
} }
@ -59,20 +59,20 @@ namespace MWScript
<< script->scriptText << script->scriptText
<< std::endl << std::endl; << std::endl << std::endl;
} }
if (Success) if (Success)
{ {
std::vector<Interpreter::Type_Code> code; std::vector<Interpreter::Type_Code> code;
mParser.getCode (code); mParser.getCode (code);
mScripts.insert (std::make_pair (name, code)); mScripts.insert (std::make_pair (name, code));
// TODO sanity check on generated locals // TODO sanity check on generated locals
return true; return true;
} }
} }
return false; return false;
} }
void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext) void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext)
@ -80,7 +80,7 @@ namespace MWScript
// compile script // compile script
std::map<std::string, std::vector<Interpreter::Type_Code> >::iterator iter = std::map<std::string, std::vector<Interpreter::Type_Code> >::iterator iter =
mScripts.find (name); mScripts.find (name);
if (iter==mScripts.end()) if (iter==mScripts.end())
{ {
if (!compile (name)) if (!compile (name))
@ -90,28 +90,27 @@ namespace MWScript
mScripts.insert (std::make_pair (name, empty)); mScripts.insert (std::make_pair (name, empty));
return; return;
} }
iter = mScripts.find (name); iter = mScripts.find (name);
assert (iter!=mScripts.end()); assert (iter!=mScripts.end());
} }
// execute script // execute script
if (!iter->second.empty()) if (!iter->second.empty())
try try
{ {
Interpreter::Interpreter interpreter (interpreterContext); Interpreter::Interpreter interpreter (interpreterContext);
installOpcodes (interpreter); installOpcodes (interpreter);
interpreter.run (&iter->second[0], iter->second.size()); interpreter.run (&iter->second[0], iter->second.size());
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
std::cerr << "exeution of script " << name << " failed." << std::endl; std::cerr << "exeution of script " << name << " failed." << std::endl;
if (mVerbose) if (mVerbose)
std::cerr << "(" << e.what() << ")" << std::endl; std::cerr << "(" << e.what() << ")" << std::endl;
iter->second.clear(); // don't execute again. iter->second.clear(); // don't execute again.
} }
} }
} }