allow (and discard) explicit reference on instructions that do not accept explicit references

This commit is contained in:
Marc Zinnschlag 2014-02-11 14:55:31 +01:00
parent 9de2922d22
commit 697bda6371
3 changed files with 21 additions and 4 deletions

View file

@ -38,7 +38,7 @@ namespace Compiler
} }
bool Extensions::isInstruction (int keyword, std::string& argumentType, bool Extensions::isInstruction (int keyword, std::string& argumentType,
bool explicitReference) const bool& explicitReference) const
{ {
std::map<int, Instruction>::const_iterator iter = mInstructions.find (keyword); std::map<int, Instruction>::const_iterator iter = mInstructions.find (keyword);
@ -46,7 +46,7 @@ namespace Compiler
return false; return false;
if (explicitReference && iter->second.mCodeExplicit==-1) if (explicitReference && iter->second.mCodeExplicit==-1)
return false; explicitReference = false;
argumentType = iter->second.mArguments; argumentType = iter->second.mArguments;
return true; return true;

View file

@ -52,8 +52,10 @@ namespace Compiler
/// types. /// types.
bool isInstruction (int keyword, std::string& argumentType, 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. ///< 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, void registerFunction (const std::string& keyword, char returnType,
const std::string& argumentType, int code, int codeExplicit = -1); const std::string& argumentType, int code, int codeExplicit = -1);

View file

@ -234,8 +234,15 @@ namespace Compiler
{ {
std::string argumentType; 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); int optionals = mExprParser.parseArguments (argumentType, scanner, mCode, true);
extensions->generateInstructionCode (keyword, mCode, mLiterals, mExplicit, optionals); 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) if (mState==BeginState)
{ {
switch (keyword) switch (keyword)