From 697bda63719add550ef35d3144592f278b1b86c6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 11 Feb 2014 14:55:31 +0100 Subject: [PATCH] allow (and discard) explicit reference on instructions that do not accept explicit references --- components/compiler/extensions.cpp | 4 ++-- components/compiler/extensions.hpp | 4 +++- components/compiler/lineparser.cpp | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/components/compiler/extensions.cpp b/components/compiler/extensions.cpp index c6a74b234b..6f5c2fc897 100644 --- a/components/compiler/extensions.cpp +++ b/components/compiler/extensions.cpp @@ -38,7 +38,7 @@ namespace Compiler } bool Extensions::isInstruction (int keyword, std::string& argumentType, - bool explicitReference) const + bool& explicitReference) const { std::map::const_iterator iter = mInstructions.find (keyword); @@ -46,7 +46,7 @@ namespace Compiler return false; if (explicitReference && iter->second.mCodeExplicit==-1) - return false; + explicitReference = false; argumentType = iter->second.mArguments; return true; diff --git a/components/compiler/extensions.hpp b/components/compiler/extensions.hpp index 53ebfa31b5..585c42681c 100644 --- a/components/compiler/extensions.hpp +++ b/components/compiler/extensions.hpp @@ -52,8 +52,10 @@ namespace Compiler /// types. bool isInstruction (int keyword, std::string& argumentType, - bool explicitReference) const; + bool& explicitReference) const; ///< Is this keyword registered with a function? If yes, return argument types. + /// \param explicitReference In: has explicit reference; Out: set to false, if + /// explicit reference is not available for this instruction. void registerFunction (const std::string& keyword, char returnType, const std::string& argumentType, int code, int codeExplicit = -1); diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 5987a48031..3b27905d46 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -234,8 +234,15 @@ namespace Compiler { std::string argumentType; - if (extensions->isInstruction (keyword, argumentType, mState==ExplicitState)) + bool hasExplicit = mState==ExplicitState; + if (extensions->isInstruction (keyword, argumentType, hasExplicit)) { + if (!hasExplicit && mState==ExplicitState) + { + getErrorHandler().warning ("stray explicit reference (ignoring it)", loc); + mExplicit.clear(); + } + int optionals = mExprParser.parseArguments (argumentType, scanner, mCode, true); extensions->generateInstructionCode (keyword, mCode, mLiterals, mExplicit, optionals); @@ -271,6 +278,14 @@ namespace Compiler } } + if (mState==ExplicitState) + { + // drop stray explicit reference + getErrorHandler().warning ("stray explicit reference (ignoring it)", loc); + mState = BeginState; + mExplicit.clear(); + } + if (mState==BeginState) { switch (keyword)