From c37b007be076c4c2f86a60a1c4f7bf080374f7ed Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 9 Jul 2010 20:35:34 +0200 Subject: [PATCH] added verification for explicit references (check if the given ID exists) --- apps/mwcompiler/context.cpp | 5 +++++ apps/mwcompiler/context.hpp | 5 ++++- apps/openmw/mwscript/compilercontext.cpp | 25 ++++++++++++++++++++++++ apps/openmw/mwscript/compilercontext.hpp | 3 +++ components/compiler/context.hpp | 5 ++++- components/compiler/exprparser.cpp | 2 +- components/compiler/lineparser.cpp | 2 +- 7 files changed, 43 insertions(+), 4 deletions(-) diff --git a/apps/mwcompiler/context.cpp b/apps/mwcompiler/context.cpp index 895e2c62a..ff84494af 100644 --- a/apps/mwcompiler/context.cpp +++ b/apps/mwcompiler/context.cpp @@ -12,5 +12,10 @@ namespace SACompiler { return ' '; } + + bool Context::isId (const std::string& name) const + { + return false; + } } diff --git a/apps/mwcompiler/context.hpp b/apps/mwcompiler/context.hpp index be06bbca8..ebf84166c 100644 --- a/apps/mwcompiler/context.hpp +++ b/apps/mwcompiler/context.hpp @@ -13,7 +13,10 @@ namespace SACompiler ///< Is the compiler allowed to declare local variables? virtual char getGlobalType (const std::string& name) const; - ///< 'l: long, 's': short, 'f': float, ' ': does not exist. + ///< 'l: long, 's': short, 'f': float, ' ': does not exist. + + virtual bool isId (const std::string& name) const; + ///< Does \a name match an ID, that can be referenced? }; } diff --git a/apps/openmw/mwscript/compilercontext.cpp b/apps/openmw/mwscript/compilercontext.cpp index 1e5cdaf4a..5e4882f25 100644 --- a/apps/openmw/mwscript/compilercontext.cpp +++ b/apps/openmw/mwscript/compilercontext.cpp @@ -31,5 +31,30 @@ namespace MWScript return ' '; } + + bool CompilerContext::isId (const std::string& name) const + { + return + mEnvironment.mWorld->getStore().activators.find (name) || + mEnvironment.mWorld->getStore().potions.find (name) || + mEnvironment.mWorld->getStore().appas.find (name) || + mEnvironment.mWorld->getStore().armors.find (name) || + mEnvironment.mWorld->getStore().books.find (name) || + mEnvironment.mWorld->getStore().clothes.find (name) || + mEnvironment.mWorld->getStore().containers.find (name) || + mEnvironment.mWorld->getStore().creatures.find (name) || + mEnvironment.mWorld->getStore().doors.find (name) || + mEnvironment.mWorld->getStore().ingreds.find (name) || + mEnvironment.mWorld->getStore().creatureLists.find (name) || + mEnvironment.mWorld->getStore().itemLists.find (name) || + mEnvironment.mWorld->getStore().lights.find (name) || + mEnvironment.mWorld->getStore().lockpicks.find (name) || + mEnvironment.mWorld->getStore().miscItems.find (name) || + mEnvironment.mWorld->getStore().npcs.find (name) || + mEnvironment.mWorld->getStore().probes.find (name) || + mEnvironment.mWorld->getStore().repairs.find (name) || + mEnvironment.mWorld->getStore().statics.find (name) || + mEnvironment.mWorld->getStore().weapons.find (name); + } } diff --git a/apps/openmw/mwscript/compilercontext.hpp b/apps/openmw/mwscript/compilercontext.hpp index 41d5f314e..7a3411bba 100644 --- a/apps/openmw/mwscript/compilercontext.hpp +++ b/apps/openmw/mwscript/compilercontext.hpp @@ -35,6 +35,9 @@ namespace MWScript /// 'l: long, 's': short, 'f': float, ' ': does not exist. virtual char getGlobalType (const std::string& name) const; + + virtual bool isId (const std::string& name) const; + ///< Does \a name match an ID, that can be referenced? }; } diff --git a/components/compiler/context.hpp b/components/compiler/context.hpp index b34297cce..929119cf4 100644 --- a/components/compiler/context.hpp +++ b/components/compiler/context.hpp @@ -31,7 +31,10 @@ namespace Compiler } virtual char getGlobalType (const std::string& name) const = 0; - ///< 'l: long, 's': short, 'f': float, ' ': does not exist. + ///< 'l: long, 's': short, 'f': float, ' ': does not exist. + + virtual bool isId (const std::string& name) const = 0; + ///< Does \a name match an ID, that can be referenced? }; } diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 9ebd0c89a..e11dde521 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -275,7 +275,7 @@ namespace Compiler return true; } - if (mOperands.empty() && mOperators.empty() && mExplicit.empty()) + if (mExplicit.empty() && getContext().isId (name)) { mExplicit = name; return true; diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 0b5f563d0..d46d5f093 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -129,7 +129,7 @@ namespace Compiler return false; } - if (mState==BeginState) + if (mState==BeginState && getContext().isId (name)) { mState = PotentialExplicitState; mExplicit = toLower (name);