From bf2b5c746ab92d1227c5a4d1f6c7458b2450faa1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 9 Jun 2017 14:44:38 +0200 Subject: Use lowercase when reporting instruction error. --- libsolidity/inlineasm/AsmParser.cpp | 38 +++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'libsolidity/inlineasm/AsmParser.cpp') 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 const& Parser::instructions() return s_instructions; } +std::map const& Parser::instructionNames() +{ + static map 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(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(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(args) + " arguments)") - ); + fatalParserError(string( + "Expected ')' (\"" + + instructionNames().at(instr) + + "\" expects " + + boost::lexical_cast(args) + + " arguments)" + )); expectToken(Token::RParen); return ret; } -- cgit v1.2.3