1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 13:39:40 +00:00

instead of using pre-compiled variable lists for remote member access get the variable list from the remote script on the fly

This commit is contained in:
Marc Zinnschlag 2014-02-14 11:15:16 +01:00
parent e76ef92669
commit 451e1f413b
6 changed files with 105 additions and 11 deletions

View file

@ -13,6 +13,7 @@
#include <components/compiler/scanner.hpp> #include <components/compiler/scanner.hpp>
#include <components/compiler/context.hpp> #include <components/compiler/context.hpp>
#include <components/compiler/exception.hpp> #include <components/compiler/exception.hpp>
#include <components/compiler/quickfileparser.hpp>
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
@ -159,20 +160,14 @@ namespace MWScript
return iter->second; return iter->second;
} }
Compiler::Locals locals;
if (const ESM::Script *script = mStore.get<ESM::Script>().find (name2)) if (const ESM::Script *script = mStore.get<ESM::Script>().find (name2))
{ {
int index = 0; Compiler::Locals locals;
for (int i=0; i<script->mData.mNumShorts; ++i) std::istringstream stream (script->mScriptText);
locals.declare ('s', script->mVarNames[index++]); Compiler::QuickFileParser parser (mErrorHandler, mCompilerContext, locals);
Compiler::Scanner scanner (mErrorHandler, stream, mCompilerContext.getExtensions());
for (int i=0; i<script->mData.mNumLongs; ++i) scanner.scan (parser);
locals.declare ('l', script->mVarNames[index++]);
for (int i=0; i<script->mData.mNumFloats; ++i)
locals.declare ('f', script->mVarNames[index++]);
std::map<std::string, Compiler::Locals>::iterator iter = std::map<std::string, Compiler::Locals>::iterator iter =
mOtherLocals.insert (std::make_pair (name2, locals)).first; mOtherLocals.insert (std::make_pair (name2, locals)).first;

View file

@ -60,6 +60,7 @@ add_component_dir (compiler
context controlparser errorhandler exception exprparser extensions fileparser generator context controlparser errorhandler exception exprparser extensions fileparser generator
lineparser literals locals output parser scanner scriptparser skipparser streamerrorhandler lineparser literals locals output parser scanner scriptparser skipparser streamerrorhandler
stringparser tokenloc nullerrorhandler opcodes extensions0 declarationparser stringparser tokenloc nullerrorhandler opcodes extensions0 declarationparser
quickfileparser
) )
add_component_dir (interpreter add_component_dir (interpreter

View file

@ -75,4 +75,9 @@ bool Compiler::DeclarationParser::parseSpecial (int code, const TokenLoc& loc, S
return false; return false;
return Parser::parseSpecial (code, loc, scanner); return Parser::parseSpecial (code, loc, scanner);
}
void Compiler::DeclarationParser::reset()
{
mState = State_Begin;
} }

View file

@ -35,6 +35,8 @@ namespace Compiler
///< Handle a special character token. ///< Handle a special character token.
/// \return fetch another token? /// \return fetch another token?
void reset();
}; };
} }

View file

@ -0,0 +1,52 @@
#include "quickfileparser.hpp"
#include "skipparser.hpp"
#include "scanner.hpp"
Compiler::QuickFileParser::QuickFileParser (ErrorHandler& errorHandler, Context& context,
Locals& locals)
: Parser (errorHandler, context), mDeclarationParser (errorHandler, context, locals)
{}
bool Compiler::QuickFileParser::parseName (const std::string& name, const TokenLoc& loc,
Scanner& scanner)
{
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return true;
}
bool Compiler::QuickFileParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{
if (keyword==Scanner::K_end)
return false;
if (keyword==Scanner::K_short || keyword==Scanner::K_long || keyword==Scanner::K_float)
{
mDeclarationParser.reset();
scanner.putbackKeyword (keyword, loc);
scanner.scan (mDeclarationParser);
return true;
}
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return true;
}
bool Compiler::QuickFileParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{
if (code!=Scanner::S_newline)
{
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
}
return true;
}
void Compiler::QuickFileParser::parseEOF (Scanner& scanner)
{
}

View file

@ -0,0 +1,39 @@
#ifndef COMPILER_QUICKFILEPARSER_H_INCLUDED
#define COMPILER_QUICKFILEPARSER_H_INCLUDED
#include "parser.hpp"
#include "declarationparser.hpp"
namespace Compiler
{
class Locals;
/// \brief File parser variant that ignores everything but variable declarations
class QuickFileParser : public Parser
{
DeclarationParser mDeclarationParser;
public:
QuickFileParser (ErrorHandler& errorHandler, Context& context, Locals& locals);
virtual bool parseName (const std::string& name, const TokenLoc& loc,
Scanner& scanner);
///< Handle a name token.
/// \return fetch another token?
virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
///< Handle a keyword token.
/// \return fetch another token?
virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
///< Handle a special character token.
/// \return fetch another token?
virtual void parseEOF (Scanner& scanner);
///< Handle EOF token.
};
}
#endif