Merge pull request #2189 from ethereum/julia-instructions

Do not disallow EVM instructions as identifiers in Julia
This commit is contained in:
chriseth 2017-04-27 21:58:45 +02:00 committed by GitHub
commit 6776be33a8
2 changed files with 10 additions and 5 deletions

View File

@ -24,6 +24,7 @@
#include <ctype.h>
#include <algorithm>
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/interface/Exceptions.h>
using namespace std;
using namespace dev;
@ -73,7 +74,7 @@ assembly::Statement Parser::parseStatement()
expectToken(Token::Colon);
assignment.variableName.location = location();
assignment.variableName.name = m_scanner->currentLiteral();
if (instructions().count(assignment.variableName.name))
if (!m_julia && instructions().count(assignment.variableName.name))
fatalParserError("Identifier expected, got instruction name.");
assignment.location.end = endPosition();
expectToken(Token::Identifier);
@ -105,7 +106,7 @@ assembly::Statement Parser::parseStatement()
{
// functional assignment
FunctionalAssignment funAss = createWithLocation<FunctionalAssignment>(identifier.location);
if (instructions().count(identifier.name))
if (!m_julia && instructions().count(identifier.name))
fatalParserError("Cannot use instruction names for identifier names.");
m_scanner->next();
funAss.variableName = identifier;
@ -180,7 +181,7 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
else
literal = m_scanner->currentLiteral();
// first search the set of instructions.
if (instructions().count(literal))
if (!m_julia && instructions().count(literal))
{
dev::solidity::Instruction const& instr = instructions().at(literal);
if (_onlySinglePusher)
@ -259,6 +260,7 @@ assembly::Statement Parser::parseFunctionalInstruction(assembly::Statement&& _in
{
if (_instruction.type() == typeid(Instruction))
{
solAssert(!m_julia, "Instructions are invalid in JULIA");
FunctionalInstruction ret;
ret.instruction = std::move(boost::get<Instruction>(_instruction));
ret.location = ret.instruction.location;
@ -321,7 +323,7 @@ assembly::Statement Parser::parseFunctionalInstruction(assembly::Statement&& _in
string Parser::expectAsmIdentifier()
{
string name = m_scanner->currentLiteral();
if (instructions().count(name))
if (!m_julia && instructions().count(name))
fatalParserError("Cannot use instruction names for identifier names.");
expectToken(Token::Identifier);
return name;

View File

@ -37,7 +37,7 @@ namespace assembly
class Parser: public ParserBase
{
public:
Parser(ErrorList& _errors): ParserBase(_errors) {}
explicit Parser(ErrorList& _errors, bool _julia = false): ParserBase(_errors), m_julia(_julia) {}
/// Parses an inline assembly block starting with `{` and ending with `}`.
/// @returns an empty shared pointer on error.
@ -70,6 +70,9 @@ protected:
FunctionDefinition parseFunctionDefinition();
Statement parseFunctionalInstruction(Statement&& _instruction);
std::string expectAsmIdentifier();
private:
bool m_julia = false;
};
}