mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Assembly: Removing some more strict-assembly syntax from parser.
This commit is contained in:
parent
e23998fc6e
commit
fdbbf75e78
@ -206,7 +206,6 @@ Statement Parser::parseStatement()
|
|||||||
return Statement{std::move(assignment)};
|
return Statement{std::move(assignment)};
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (m_dialect.flavour != AsmFlavour::Loose)
|
|
||||||
fatalParserError("Call or assignment expected.");
|
fatalParserError("Call or assignment expected.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -279,45 +278,8 @@ Expression Parser::parseExpression()
|
|||||||
ElementaryOperation operation = parseElementaryOperation();
|
ElementaryOperation operation = parseElementaryOperation();
|
||||||
if (operation.type() == typeid(FunctionCall))
|
if (operation.type() == typeid(FunctionCall))
|
||||||
return parseCall(std::move(operation));
|
return parseCall(std::move(operation));
|
||||||
else if (operation.type() == typeid(Instruction))
|
else if (currentToken() == Token::LParen)
|
||||||
{
|
|
||||||
solAssert(m_dialect.flavour == AsmFlavour::Loose, "");
|
|
||||||
Instruction const& instr = boost::get<Instruction>(operation);
|
|
||||||
// Disallow instructions returning multiple values (and DUP/SWAP) as expression.
|
|
||||||
if (
|
|
||||||
instructionInfo(instr.instruction).ret != 1 ||
|
|
||||||
isDupInstruction(instr.instruction) ||
|
|
||||||
isSwapInstruction(instr.instruction)
|
|
||||||
)
|
|
||||||
fatalParserError(
|
|
||||||
"Instruction \"" +
|
|
||||||
instructionNames().at(instr.instruction) +
|
|
||||||
"\" not allowed in this context."
|
|
||||||
);
|
|
||||||
if (m_dialect.flavour != AsmFlavour::Loose && currentToken() != Token::LParen)
|
|
||||||
fatalParserError(
|
|
||||||
"Non-functional instructions are not allowed in this context."
|
|
||||||
);
|
|
||||||
// Enforce functional notation for instructions requiring multiple arguments.
|
|
||||||
int args = instructionInfo(instr.instruction).args;
|
|
||||||
if (args > 0 && currentToken() != Token::LParen)
|
|
||||||
fatalParserError(string(
|
|
||||||
"Expected '(' (instruction \"" +
|
|
||||||
instructionNames().at(instr.instruction) +
|
|
||||||
"\" expects " +
|
|
||||||
to_string(args) +
|
|
||||||
" arguments)"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (currentToken() == Token::LParen)
|
|
||||||
return parseCall(std::move(operation));
|
return parseCall(std::move(operation));
|
||||||
else if (operation.type() == typeid(Instruction))
|
|
||||||
{
|
|
||||||
// Instructions not taking arguments are allowed as expressions.
|
|
||||||
solAssert(m_dialect.flavour == AsmFlavour::Loose, "");
|
|
||||||
Instruction& instr = boost::get<Instruction>(operation);
|
|
||||||
return FunctionalInstruction{std::move(instr.location), instr.instruction, {}};
|
|
||||||
}
|
|
||||||
else if (operation.type() == typeid(Identifier))
|
else if (operation.type() == typeid(Identifier))
|
||||||
return boost::get<Identifier>(operation);
|
return boost::get<Identifier>(operation);
|
||||||
else
|
else
|
||||||
@ -359,22 +321,8 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
|
|||||||
{
|
{
|
||||||
Identifier identifier{location(), literal};
|
Identifier identifier{location(), literal};
|
||||||
advance();
|
advance();
|
||||||
// If the builtin is not followed by `(` and we are in loose mode,
|
|
||||||
// fall back to instruction.
|
|
||||||
if (
|
|
||||||
m_dialect.flavour == AsmFlavour::Loose &&
|
|
||||||
instructions().count(identifier.name.str()) &&
|
|
||||||
m_scanner->currentToken() != Token::LParen
|
|
||||||
)
|
|
||||||
return Instruction{identifier.location, instructions().at(identifier.name.str())};
|
|
||||||
else
|
|
||||||
return FunctionCall{identifier.location, identifier, {}};
|
return FunctionCall{identifier.location, identifier, {}};
|
||||||
}
|
}
|
||||||
else if (m_dialect.flavour == AsmFlavour::Loose && instructions().count(literal.str()))
|
|
||||||
{
|
|
||||||
dev::eth::Instruction const& instr = instructions().at(literal.str());
|
|
||||||
ret = Instruction{location(), instr};
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ret = Identifier{location(), literal};
|
ret = Identifier{location(), literal};
|
||||||
advance();
|
advance();
|
||||||
@ -623,8 +571,6 @@ YulString Parser::expectAsmIdentifier()
|
|||||||
|
|
||||||
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 (m_dialect.flavour == AsmFlavour::Loose && instructions().count(name.str()))
|
|
||||||
fatalParserError("Cannot use instruction name \"" + name.str() + "\" as identifier name.");
|
|
||||||
advance();
|
advance();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user