mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove FunctionCall from ElementaryOperation.
This commit is contained in:
parent
a9be2e4bb8
commit
5071709b25
@ -27,6 +27,7 @@
|
|||||||
#include <liblangutil/Scanner.h>
|
#include <liblangutil/Scanner.h>
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
#include <libsolutil/Common.h>
|
#include <libsolutil/Common.h>
|
||||||
|
#include <libsolutil/Visitor.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ Statement Parser::parseStatement()
|
|||||||
// Options left:
|
// Options left:
|
||||||
// Expression/FunctionCall
|
// Expression/FunctionCall
|
||||||
// Assignment
|
// Assignment
|
||||||
ElementaryOperation elementary(parseLiteralOrIdentifier());
|
variant<Literal, Identifier> elementary(parseLiteralOrIdentifier());
|
||||||
|
|
||||||
switch (currentToken())
|
switch (currentToken())
|
||||||
{
|
{
|
||||||
@ -212,7 +213,7 @@ Case Parser::parseCase()
|
|||||||
else if (currentToken() == Token::Case)
|
else if (currentToken() == Token::Case)
|
||||||
{
|
{
|
||||||
advance();
|
advance();
|
||||||
ElementaryOperation literal = parseLiteralOrIdentifier();
|
variant<Literal, Identifier> literal = parseLiteralOrIdentifier();
|
||||||
if (!holds_alternative<Literal>(literal))
|
if (!holds_alternative<Literal>(literal))
|
||||||
fatalParserError(4805_error, "Literal expected.");
|
fatalParserError(4805_error, "Literal expected.");
|
||||||
_case.value = make_unique<Literal>(std::get<Literal>(std::move(literal)));
|
_case.value = make_unique<Literal>(std::get<Literal>(std::move(literal)));
|
||||||
@ -251,38 +252,37 @@ Expression Parser::parseExpression()
|
|||||||
{
|
{
|
||||||
RecursionGuard recursionGuard(*this);
|
RecursionGuard recursionGuard(*this);
|
||||||
|
|
||||||
ElementaryOperation operation = parseLiteralOrIdentifier();
|
variant<Literal, Identifier> operation = parseLiteralOrIdentifier();
|
||||||
if (holds_alternative<Identifier>(operation))
|
return visit(GenericVisitor{
|
||||||
{
|
[&](Identifier& _identifier) -> Expression
|
||||||
if (currentToken() == Token::LParen)
|
{
|
||||||
return parseCall(std::move(operation));
|
if (currentToken() == Token::LParen)
|
||||||
auto identifier = std::get<Identifier>(operation);
|
return parseCall(std::move(operation));
|
||||||
if (m_dialect.builtin(identifier.name))
|
if (m_dialect.builtin(_identifier.name))
|
||||||
fatalParserError(
|
fatalParserError(
|
||||||
7104_error,
|
7104_error,
|
||||||
identifier.location,
|
_identifier.location,
|
||||||
"Builtin function \"" + identifier.name.str() + "\" must be called."
|
"Builtin function \"" + _identifier.name.str() + "\" must be called."
|
||||||
);
|
);
|
||||||
return identifier;
|
return move(_identifier);
|
||||||
}
|
},
|
||||||
else
|
[&](Literal& _literal) -> Expression
|
||||||
{
|
{
|
||||||
yulAssert(holds_alternative<Literal>(operation), "");
|
return move(_literal);
|
||||||
return std::get<Literal>(operation);
|
}
|
||||||
}
|
}, operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser::ElementaryOperation Parser::parseLiteralOrIdentifier()
|
variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
|
||||||
{
|
{
|
||||||
RecursionGuard recursionGuard(*this);
|
RecursionGuard recursionGuard(*this);
|
||||||
ElementaryOperation ret;
|
|
||||||
switch (currentToken())
|
switch (currentToken())
|
||||||
{
|
{
|
||||||
case Token::Identifier:
|
case Token::Identifier:
|
||||||
{
|
{
|
||||||
ret = Identifier{currentLocation(), YulString{currentLiteral()}};
|
Identifier identifier{currentLocation(), YulString{currentLiteral()}};
|
||||||
advance();
|
advance();
|
||||||
break;
|
return identifier;
|
||||||
}
|
}
|
||||||
case Token::StringLiteral:
|
case Token::StringLiteral:
|
||||||
case Token::Number:
|
case Token::Number:
|
||||||
@ -322,8 +322,7 @@ Parser::ElementaryOperation Parser::parseLiteralOrIdentifier()
|
|||||||
literal.type = expectAsmIdentifier();
|
literal.type = expectAsmIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = std::move(literal);
|
return literal;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case Token::HexStringLiteral:
|
case Token::HexStringLiteral:
|
||||||
fatalParserError(3772_error, "Hex literals are not valid in this context.");
|
fatalParserError(3772_error, "Hex literals are not valid in this context.");
|
||||||
@ -331,7 +330,7 @@ Parser::ElementaryOperation Parser::parseLiteralOrIdentifier()
|
|||||||
default:
|
default:
|
||||||
fatalParserError(1856_error, "Literal or identifier expected.");
|
fatalParserError(1856_error, "Literal or identifier expected.");
|
||||||
}
|
}
|
||||||
return ret;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableDeclaration Parser::parseVariableDeclaration()
|
VariableDeclaration Parser::parseVariableDeclaration()
|
||||||
@ -405,7 +404,7 @@ FunctionDefinition Parser::parseFunctionDefinition()
|
|||||||
return funDef;
|
return funDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionCall Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
|
FunctionCall Parser::parseCall(variant<Literal, Identifier>&& _initialOp)
|
||||||
{
|
{
|
||||||
RecursionGuard recursionGuard(*this);
|
RecursionGuard recursionGuard(*this);
|
||||||
|
|
||||||
|
@ -61,8 +61,6 @@ public:
|
|||||||
std::unique_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
std::unique_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using ElementaryOperation = std::variant<Literal, Identifier, FunctionCall>;
|
|
||||||
|
|
||||||
langutil::SourceLocation currentLocation() const override
|
langutil::SourceLocation currentLocation() const override
|
||||||
{
|
{
|
||||||
return m_locationOverride ? *m_locationOverride : ParserBase::currentLocation();
|
return m_locationOverride ? *m_locationOverride : ParserBase::currentLocation();
|
||||||
@ -84,10 +82,10 @@ protected:
|
|||||||
Expression parseExpression();
|
Expression parseExpression();
|
||||||
/// Parses an elementary operation, i.e. a literal, identifier, instruction or
|
/// Parses an elementary operation, i.e. a literal, identifier, instruction or
|
||||||
/// builtin functian call (only the name).
|
/// builtin functian call (only the name).
|
||||||
ElementaryOperation parseLiteralOrIdentifier();
|
std::variant<Literal, Identifier> parseLiteralOrIdentifier();
|
||||||
VariableDeclaration parseVariableDeclaration();
|
VariableDeclaration parseVariableDeclaration();
|
||||||
FunctionDefinition parseFunctionDefinition();
|
FunctionDefinition parseFunctionDefinition();
|
||||||
FunctionCall parseCall(ElementaryOperation&& _initialOp);
|
FunctionCall parseCall(std::variant<Literal, Identifier>&& _initialOp);
|
||||||
TypedName parseTypedName();
|
TypedName parseTypedName();
|
||||||
YulString expectAsmIdentifier();
|
YulString expectAsmIdentifier();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user