Merge pull request #6960 from ethereum/fixAsmParser

Asm Parser: Properly consider tokens when checking for clashes with builtins.
This commit is contained in:
chriseth 2019-06-19 10:57:46 +02:00 committed by GitHub
commit 5675b742ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -384,17 +384,10 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
case Token::Identifier: case Token::Identifier:
case Token::Return: case Token::Return:
case Token::Byte: case Token::Byte:
case Token::Bool:
case Token::Address: case Token::Address:
{ {
YulString literal; YulString literal{currentLiteral()};
if (currentToken() == Token::Return)
literal = "return"_yulstring;
else if (currentToken() == Token::Byte)
literal = "byte"_yulstring;
else if (currentToken() == Token::Address)
literal = "address"_yulstring;
else
literal = YulString{currentLiteral()};
// first search the set of builtins, then the instructions. // first search the set of builtins, then the instructions.
if (m_dialect.builtin(literal)) if (m_dialect.builtin(literal))
{ {
@ -648,26 +641,25 @@ TypedName Parser::parseTypedName()
YulString Parser::expectAsmIdentifier() YulString Parser::expectAsmIdentifier()
{ {
YulString name = YulString{currentLiteral()}; YulString name{currentLiteral()};
if (m_dialect.flavour == AsmFlavour::Yul)
{
switch (currentToken()) switch (currentToken())
{ {
case Token::Return: case Token::Return:
case Token::Byte: case Token::Byte:
case Token::Address: case Token::Address:
case Token::Bool: case Token::Bool:
advance(); case Token::Identifier:
return name; break;
default: default:
expectToken(Token::Identifier);
break; break;
} }
}
else if (m_dialect.builtin(name)) if (m_dialect.builtin(name))
fatalParserError("Cannot use builtin function name \"" + name.str() + "\" as identifier name."); fatalParserError("Cannot use builtin function name \"" + name.str() + "\" as identifier name.");
else if (instructions().count(name.str())) else if (m_dialect.flavour == AsmFlavour::Loose && instructions().count(name.str()))
fatalParserError("Cannot use instruction names for identifier names."); fatalParserError("Cannot use instruction name \"" + name.str() + "\" as identifier name.");
expectToken(Token::Identifier); advance();
return name; return name;
} }