diff options
author | chriseth <chris@ethereum.org> | 2017-06-09 20:44:38 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-06-09 21:17:29 +0800 |
commit | bf2b5c746ab92d1227c5a4d1f6c7458b2450faa1 (patch) | |
tree | a04b171563aff8bfb53e00403b2bcd6681fc6027 /libsolidity/inlineasm | |
parent | 76667fed4f9865c4a3a5a267c469446f8bce1bef (diff) | |
download | dexon-solidity-bf2b5c746ab92d1227c5a4d1f6c7458b2450faa1.tar.gz dexon-solidity-bf2b5c746ab92d1227c5a4d1f6c7458b2450faa1.tar.zst dexon-solidity-bf2b5c746ab92d1227c5a4d1f6c7458b2450faa1.zip |
Use lowercase when reporting instruction error.
Diffstat (limited to 'libsolidity/inlineasm')
-rw-r--r-- | libsolidity/inlineasm/AsmParser.cpp | 38 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmParser.h | 3 |
2 files changed, 30 insertions, 11 deletions
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 3200b360..68a9cb03 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -206,6 +206,20 @@ std::map<string, dev::solidity::Instruction> const& Parser::instructions() return s_instructions; } +std::map<dev::solidity::Instruction, string> const& Parser::instructionNames() +{ + static map<dev::solidity::Instruction, string> s_instructionNames; + if (s_instructionNames.empty()) + { + for (auto const& instr: instructions()) + s_instructionNames[instr.second] = instr.first; + // set the ambiguous instructions to a clear default + s_instructionNames[solidity::Instruction::SELFDESTRUCT] = "selfdestruct"; + s_instructionNames[solidity::Instruction::KECCAK256] = "keccak256"; + } + return s_instructionNames; +} + assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher) { Statement ret; @@ -233,7 +247,7 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher) { InstructionInfo info = dev::solidity::instructionInfo(instr); if (info.ret != 1) - fatalParserError("Instruction " + info.name + " not allowed in this context."); + fatalParserError("Instruction \"" + literal + "\" not allowed in this context."); } ret = Instruction{location(), instr}; } @@ -363,9 +377,9 @@ assembly::Statement Parser::parseCall(assembly::Statement&& _instruction) /// check for premature closing parentheses if (currentToken() == Token::RParen) fatalParserError(string( - "Expected expression (" + - instrInfo.name + - " expects " + + "Expected expression (\"" + + instructionNames().at(instr) + + "\" expects " + boost::lexical_cast<string>(args) + " arguments)" )); @@ -375,9 +389,9 @@ assembly::Statement Parser::parseCall(assembly::Statement&& _instruction) { if (currentToken() != Token::Comma) fatalParserError(string( - "Expected comma (" + - instrInfo.name + - " expects " + + "Expected comma (\"" + + instructionNames().at(instr) + + "\" expects " + boost::lexical_cast<string>(args) + " arguments)" )); @@ -387,9 +401,13 @@ assembly::Statement Parser::parseCall(assembly::Statement&& _instruction) } ret.location.end = endPosition(); if (currentToken() == Token::Comma) - fatalParserError( - string("Expected ')' (" + instrInfo.name + " expects " + boost::lexical_cast<string>(args) + " arguments)") - ); + fatalParserError(string( + "Expected ')' (\"" + + instructionNames().at(instr) + + "\" expects " + + boost::lexical_cast<string>(args) + + " arguments)" + )); expectToken(Token::RParen); return ret; } diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index e32b1d25..5fafad23 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -65,7 +65,8 @@ protected: Case parseCase(); /// Parses a functional expression that has to push exactly one stack element Statement parseExpression(); - std::map<std::string, dev::solidity::Instruction> const& instructions(); + static std::map<std::string, dev::solidity::Instruction> const& instructions(); + static std::map<dev::solidity::Instruction, std::string> const& instructionNames(); Statement parseElementaryOperation(bool _onlySinglePusher = false); VariableDeclaration parseVariableDeclaration(); FunctionDefinition parseFunctionDefinition(); |