mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[langutil] ParserBase: make advance() overridable and make sure it's used.
This commit is contained in:
parent
26598a2603
commit
f561c1e90b
@ -89,7 +89,7 @@ void ParserBase::expectToken(Token _value, bool _advance)
|
|||||||
_advance = false;
|
_advance = false;
|
||||||
}
|
}
|
||||||
if (_advance)
|
if (_advance)
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentNodeName, bool _advance)
|
void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentNodeName, bool _advance)
|
||||||
@ -102,7 +102,7 @@ void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentN
|
|||||||
SourceLocation errorLoc = currentLocation();
|
SourceLocation errorLoc = currentLocation();
|
||||||
int startPosition = errorLoc.start;
|
int startPosition = errorLoc.start;
|
||||||
while (m_scanner->currentToken() != _value && m_scanner->currentToken() != Token::EOS)
|
while (m_scanner->currentToken() != _value && m_scanner->currentToken() != Token::EOS)
|
||||||
m_scanner->next();
|
advance();
|
||||||
|
|
||||||
string const expectedToken = ParserBase::tokenName(_value);
|
string const expectedToken = ParserBase::tokenName(_value);
|
||||||
if (m_scanner->currentToken() == Token::EOS)
|
if (m_scanner->currentToken() == Token::EOS)
|
||||||
@ -126,7 +126,7 @@ void ParserBase::expectTokenOrConsumeUntil(Token _value, string const& _currentN
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_advance)
|
if (_advance)
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserBase::increaseRecursionDepth()
|
void ParserBase::increaseRecursionDepth()
|
||||||
|
@ -81,7 +81,7 @@ protected:
|
|||||||
Token peekNextToken() const;
|
Token peekNextToken() const;
|
||||||
std::string tokenName(Token _token);
|
std::string tokenName(Token _token);
|
||||||
std::string currentLiteral() const;
|
std::string currentLiteral() const;
|
||||||
Token advance();
|
virtual Token advance();
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/// Increases the recursion depth and throws an exception if it is too deep.
|
/// Increases the recursion depth and throws an exception if it is too deep.
|
||||||
|
@ -206,7 +206,7 @@ ASTPointer<PragmaDirective> Parser::parsePragmaDirective()
|
|||||||
literals.push_back(literal);
|
literals.push_back(literal);
|
||||||
tokens.push_back(token);
|
tokens.push_back(token);
|
||||||
}
|
}
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
while (m_scanner->currentToken() != Token::Semicolon && m_scanner->currentToken() != Token::EOS);
|
while (m_scanner->currentToken() != Token::Semicolon && m_scanner->currentToken() != Token::EOS);
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
@ -242,7 +242,7 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
|
|||||||
path = getLiteralAndAdvance();
|
path = getLiteralAndAdvance();
|
||||||
if (m_scanner->currentToken() == Token::As)
|
if (m_scanner->currentToken() == Token::As)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
tie(unitAlias, unitAliasLocation) = expectIdentifierWithLocation();
|
tie(unitAlias, unitAliasLocation) = expectIdentifierWithLocation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
|
|||||||
{
|
{
|
||||||
if (m_scanner->currentToken() == Token::LBrace)
|
if (m_scanner->currentToken() == Token::LBrace)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
ASTPointer<ASTString> alias;
|
ASTPointer<ASTString> alias;
|
||||||
@ -264,13 +264,13 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
|
|||||||
symbolAliases.emplace_back(ImportDirective::SymbolAlias{move(id), move(alias), aliasLocation});
|
symbolAliases.emplace_back(ImportDirective::SymbolAlias{move(id), move(alias), aliasLocation});
|
||||||
if (m_scanner->currentToken() != Token::Comma)
|
if (m_scanner->currentToken() != Token::Comma)
|
||||||
break;
|
break;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
expectToken(Token::RBrace);
|
expectToken(Token::RBrace);
|
||||||
}
|
}
|
||||||
else if (m_scanner->currentToken() == Token::Mul)
|
else if (m_scanner->currentToken() == Token::Mul)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
expectToken(Token::As);
|
expectToken(Token::As);
|
||||||
tie(unitAlias, unitAliasLocation) = expectIdentifierWithLocation();
|
tie(unitAlias, unitAliasLocation) = expectIdentifierWithLocation();
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
|
|||||||
// compatibility and because it is a really common word.
|
// compatibility and because it is a really common word.
|
||||||
if (m_scanner->currentToken() != Token::Identifier || m_scanner->currentLiteral() != "from")
|
if (m_scanner->currentToken() != Token::Identifier || m_scanner->currentLiteral() != "from")
|
||||||
fatalParserError(8208_error, "Expected \"from\".");
|
fatalParserError(8208_error, "Expected \"from\".");
|
||||||
m_scanner->next();
|
advance();
|
||||||
if (m_scanner->currentToken() != Token::StringLiteral)
|
if (m_scanner->currentToken() != Token::StringLiteral)
|
||||||
fatalParserError(6845_error, "Expected import path.");
|
fatalParserError(6845_error, "Expected import path.");
|
||||||
path = getLiteralAndAdvance();
|
path = getLiteralAndAdvance();
|
||||||
@ -299,7 +299,7 @@ std::pair<ContractKind, bool> Parser::parseContractKind()
|
|||||||
if (m_scanner->currentToken() == Token::Abstract)
|
if (m_scanner->currentToken() == Token::Abstract)
|
||||||
{
|
{
|
||||||
abstract = true;
|
abstract = true;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
switch (m_scanner->currentToken())
|
switch (m_scanner->currentToken())
|
||||||
{
|
{
|
||||||
@ -316,7 +316,7 @@ std::pair<ContractKind, bool> Parser::parseContractKind()
|
|||||||
parserError(3515_error, "Expected keyword \"contract\", \"interface\" or \"library\".");
|
parserError(3515_error, "Expected keyword \"contract\", \"interface\" or \"library\".");
|
||||||
return std::make_pair(ContractKind::Contract, abstract);
|
return std::make_pair(ContractKind::Contract, abstract);
|
||||||
}
|
}
|
||||||
m_scanner->next();
|
advance();
|
||||||
return std::make_pair(kind, abstract);
|
return std::make_pair(kind, abstract);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
|
|||||||
if (m_scanner->currentToken() == Token::Is)
|
if (m_scanner->currentToken() == Token::Is)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
baseContracts.push_back(parseInheritanceSpecifier());
|
baseContracts.push_back(parseInheritanceSpecifier());
|
||||||
}
|
}
|
||||||
while (m_scanner->currentToken() == Token::Comma);
|
while (m_scanner->currentToken() == Token::Comma);
|
||||||
@ -419,7 +419,7 @@ ASTPointer<InheritanceSpecifier> Parser::parseInheritanceSpecifier()
|
|||||||
unique_ptr<vector<ASTPointer<Expression>>> arguments;
|
unique_ptr<vector<ASTPointer<Expression>>> arguments;
|
||||||
if (m_scanner->currentToken() == Token::LParen)
|
if (m_scanner->currentToken() == Token::LParen)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
arguments = make_unique<vector<ASTPointer<Expression>>>(parseFunctionCallListArguments());
|
arguments = make_unique<vector<ASTPointer<Expression>>>(parseFunctionCallListArguments());
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
expectToken(Token::RParen);
|
expectToken(Token::RParen);
|
||||||
@ -450,7 +450,7 @@ Visibility Parser::parseVisibilitySpecifier()
|
|||||||
default:
|
default:
|
||||||
solAssert(false, "Invalid visibility specifier.");
|
solAssert(false, "Invalid visibility specifier.");
|
||||||
}
|
}
|
||||||
m_scanner->next();
|
advance();
|
||||||
return visibility;
|
return visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,11 +462,11 @@ ASTPointer<OverrideSpecifier> Parser::parseOverrideSpecifier()
|
|||||||
std::vector<ASTPointer<IdentifierPath>> overrides;
|
std::vector<ASTPointer<IdentifierPath>> overrides;
|
||||||
|
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
|
|
||||||
if (m_scanner->currentToken() == Token::LParen)
|
if (m_scanner->currentToken() == Token::LParen)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
overrides.push_back(parseIdentifierPath());
|
overrides.push_back(parseIdentifierPath());
|
||||||
@ -502,7 +502,7 @@ StateMutability Parser::parseStateMutability()
|
|||||||
default:
|
default:
|
||||||
solAssert(false, "Invalid state mutability specifier.");
|
solAssert(false, "Invalid state mutability specifier.");
|
||||||
}
|
}
|
||||||
m_scanner->next();
|
advance();
|
||||||
return stateMutability;
|
return stateMutability;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +533,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _isStateVari
|
|||||||
Declaration::visibilityToString(result.visibility) +
|
Declaration::visibilityToString(result.visibility) +
|
||||||
"\"."
|
"\"."
|
||||||
);
|
);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result.visibility = parseVisibilitySpecifier();
|
result.visibility = parseVisibilitySpecifier();
|
||||||
@ -548,7 +548,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _isStateVari
|
|||||||
stateMutabilityToString(result.stateMutability) +
|
stateMutabilityToString(result.stateMutability) +
|
||||||
"\"."
|
"\"."
|
||||||
);
|
);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result.stateMutability = parseStateMutability();
|
result.stateMutability = parseStateMutability();
|
||||||
@ -566,7 +566,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _isStateVari
|
|||||||
parserError(6879_error, "Virtual already specified.");
|
parserError(6879_error, "Virtual already specified.");
|
||||||
|
|
||||||
result.isVirtual = true;
|
result.isVirtual = true;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@ -574,7 +574,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _isStateVari
|
|||||||
if (m_scanner->currentToken() == Token::Returns)
|
if (m_scanner->currentToken() == Token::Returns)
|
||||||
{
|
{
|
||||||
bool const permitEmptyParameterList = false;
|
bool const permitEmptyParameterList = false;
|
||||||
m_scanner->next();
|
advance();
|
||||||
result.returnParameters = parseParameterList(options, permitEmptyParameterList);
|
result.returnParameters = parseParameterList(options, permitEmptyParameterList);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -593,7 +593,7 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinition(bool _freeFunction)
|
|||||||
SourceLocation nameLocation;
|
SourceLocation nameLocation;
|
||||||
if (kind == Token::Function)
|
if (kind == Token::Function)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
if (
|
if (
|
||||||
m_scanner->currentToken() == Token::Constructor ||
|
m_scanner->currentToken() == Token::Constructor ||
|
||||||
m_scanner->currentToken() == Token::Fallback ||
|
m_scanner->currentToken() == Token::Fallback ||
|
||||||
@ -616,7 +616,7 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinition(bool _freeFunction)
|
|||||||
parserError(3323_error, message);
|
parserError(3323_error, message);
|
||||||
else
|
else
|
||||||
parserWarning(3445_error, message);
|
parserWarning(3445_error, message);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tie(name, nameLocation) = expectIdentifierWithLocation();
|
tie(name, nameLocation) = expectIdentifierWithLocation();
|
||||||
@ -624,7 +624,7 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinition(bool _freeFunction)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
solAssert(kind == Token::Constructor || kind == Token::Fallback || kind == Token::Receive, "");
|
solAssert(kind == Token::Constructor || kind == Token::Fallback || kind == Token::Receive, "");
|
||||||
m_scanner->next();
|
advance();
|
||||||
name = make_shared<ASTString>();
|
name = make_shared<ASTString>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,7 +633,7 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinition(bool _freeFunction)
|
|||||||
ASTPointer<Block> block;
|
ASTPointer<Block> block;
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
if (m_scanner->currentToken() == Token::Semicolon)
|
if (m_scanner->currentToken() == Token::Semicolon)
|
||||||
m_scanner->next();
|
advance();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
block = parseBlock();
|
block = parseBlock();
|
||||||
@ -751,7 +751,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
|||||||
Declaration::visibilityToString(visibility) +
|
Declaration::visibilityToString(visibility) +
|
||||||
"\"."
|
"\"."
|
||||||
);
|
);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
visibility = parseVisibilitySpecifier();
|
visibility = parseVisibilitySpecifier();
|
||||||
@ -805,7 +805,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,7 +821,7 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration(
|
|||||||
{
|
{
|
||||||
if (m_scanner->currentToken() == Token::Assign)
|
if (m_scanner->currentToken() == Token::Assign)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
value = parseExpression();
|
value = parseExpression();
|
||||||
nodeFactory.setEndPositionFromNode(value);
|
nodeFactory.setEndPositionFromNode(value);
|
||||||
}
|
}
|
||||||
@ -879,7 +879,7 @@ ASTPointer<ModifierDefinition> Parser::parseModifierDefinition()
|
|||||||
parserError(2662_error, "Virtual already specified.");
|
parserError(2662_error, "Virtual already specified.");
|
||||||
|
|
||||||
isVirtual = true;
|
isVirtual = true;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@ -893,7 +893,7 @@ ASTPointer<ModifierDefinition> Parser::parseModifierDefinition()
|
|||||||
nodeFactory.setEndPositionFromNode(block);
|
nodeFactory.setEndPositionFromNode(block);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_scanner->next(); // just consume the ';'
|
advance(); // just consume the ';'
|
||||||
|
|
||||||
return nodeFactory.createNode<ModifierDefinition>(name, nameLocation, documentation, parameters, isVirtual, overrides, block);
|
return nodeFactory.createNode<ModifierDefinition>(name, nameLocation, documentation, parameters, isVirtual, overrides, block);
|
||||||
}
|
}
|
||||||
@ -923,7 +923,7 @@ ASTPointer<EventDefinition> Parser::parseEventDefinition()
|
|||||||
if (m_scanner->currentToken() == Token::Anonymous)
|
if (m_scanner->currentToken() == Token::Anonymous)
|
||||||
{
|
{
|
||||||
anonymous = true;
|
anonymous = true;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
expectToken(Token::Semicolon);
|
expectToken(Token::Semicolon);
|
||||||
@ -955,7 +955,7 @@ ASTPointer<UsingForDirective> Parser::parseUsingDirective()
|
|||||||
ASTPointer<TypeName> typeName;
|
ASTPointer<TypeName> typeName;
|
||||||
expectToken(Token::For);
|
expectToken(Token::For);
|
||||||
if (m_scanner->currentToken() == Token::Mul)
|
if (m_scanner->currentToken() == Token::Mul)
|
||||||
m_scanner->next();
|
advance();
|
||||||
else
|
else
|
||||||
typeName = parseTypeName();
|
typeName = parseTypeName();
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
@ -971,7 +971,7 @@ ASTPointer<ModifierInvocation> Parser::parseModifierInvocation()
|
|||||||
unique_ptr<vector<ASTPointer<Expression>>> arguments;
|
unique_ptr<vector<ASTPointer<Expression>>> arguments;
|
||||||
if (m_scanner->currentToken() == Token::LParen)
|
if (m_scanner->currentToken() == Token::LParen)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
arguments = make_unique<vector<ASTPointer<Expression>>>(parseFunctionCallListArguments());
|
arguments = make_unique<vector<ASTPointer<Expression>>>(parseFunctionCallListArguments());
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
expectToken(Token::RParen);
|
expectToken(Token::RParen);
|
||||||
@ -1013,7 +1013,7 @@ ASTPointer<IdentifierPath> Parser::parseIdentifierPath()
|
|||||||
vector<ASTString> identifierPath{*expectIdentifierToken()};
|
vector<ASTString> identifierPath{*expectIdentifierToken()};
|
||||||
while (m_scanner->currentToken() == Token::Period)
|
while (m_scanner->currentToken() == Token::Period)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
identifierPath.push_back(*expectIdentifierTokenOrAddress());
|
identifierPath.push_back(*expectIdentifierTokenOrAddress());
|
||||||
}
|
}
|
||||||
@ -1025,7 +1025,7 @@ ASTPointer<TypeName> Parser::parseTypeNameSuffix(ASTPointer<TypeName> type, ASTN
|
|||||||
RecursionGuard recursionGuard(*this);
|
RecursionGuard recursionGuard(*this);
|
||||||
while (m_scanner->currentToken() == Token::LBrack)
|
while (m_scanner->currentToken() == Token::LBrack)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
ASTPointer<Expression> length;
|
ASTPointer<Expression> length;
|
||||||
if (m_scanner->currentToken() != Token::RBrack)
|
if (m_scanner->currentToken() != Token::RBrack)
|
||||||
length = parseExpression();
|
length = parseExpression();
|
||||||
@ -1050,7 +1050,7 @@ ASTPointer<TypeName> Parser::parseTypeName()
|
|||||||
ElementaryTypeNameToken elemTypeName(token, firstSize, secondSize);
|
ElementaryTypeNameToken elemTypeName(token, firstSize, secondSize);
|
||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
auto stateMutability = elemTypeName.token() == Token::Address
|
auto stateMutability = elemTypeName.token() == Token::Address
|
||||||
? optional<StateMutability>{StateMutability::NonPayable}
|
? optional<StateMutability>{StateMutability::NonPayable}
|
||||||
: nullopt;
|
: nullopt;
|
||||||
@ -1064,7 +1064,7 @@ ASTPointer<TypeName> Parser::parseTypeName()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
parserError(9106_error, "State mutability can only be specified for address types.");
|
parserError(9106_error, "State mutability can only be specified for address types.");
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type = nodeFactory.createNode<ElementaryTypeName>(elemTypeName, stateMutability);
|
type = nodeFactory.createNode<ElementaryTypeName>(elemTypeName, stateMutability);
|
||||||
@ -1117,7 +1117,7 @@ ASTPointer<Mapping> Parser::parseMapping()
|
|||||||
keyType = ASTNodeFactory(*this).createNode<ElementaryTypeName>(
|
keyType = ASTNodeFactory(*this).createNode<ElementaryTypeName>(
|
||||||
ElementaryTypeNameToken{token, firstSize, secondSize}
|
ElementaryTypeNameToken{token, firstSize, secondSize}
|
||||||
);
|
);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatalParserError(1005_error, "Expected elementary type name or identifier for mapping key type");
|
fatalParserError(1005_error, "Expected elementary type name or identifier for mapping key type");
|
||||||
@ -1151,7 +1151,7 @@ ASTPointer<ParameterList> Parser::parseParameterList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
return nodeFactory.createNode<ParameterList>(parameters);
|
return nodeFactory.createNode<ParameterList>(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1164,7 +1164,7 @@ ASTPointer<Block> Parser::parseBlock(bool _allowUnchecked, ASTPointer<ASTString>
|
|||||||
{
|
{
|
||||||
if (!_allowUnchecked)
|
if (!_allowUnchecked)
|
||||||
parserError(5296_error, "\"unchecked\" blocks can only be used inside regular blocks.");
|
parserError(5296_error, "\"unchecked\" blocks can only be used inside regular blocks.");
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
expectToken(Token::LBrace);
|
expectToken(Token::LBrace);
|
||||||
vector<ASTPointer<Statement>> statements;
|
vector<ASTPointer<Statement>> statements;
|
||||||
@ -1215,17 +1215,17 @@ ASTPointer<Statement> Parser::parseStatement(bool _allowUnchecked)
|
|||||||
return parseBlock(_allowUnchecked, docString);
|
return parseBlock(_allowUnchecked, docString);
|
||||||
case Token::Continue:
|
case Token::Continue:
|
||||||
statement = ASTNodeFactory(*this).createNode<Continue>(docString);
|
statement = ASTNodeFactory(*this).createNode<Continue>(docString);
|
||||||
m_scanner->next();
|
advance();
|
||||||
break;
|
break;
|
||||||
case Token::Break:
|
case Token::Break:
|
||||||
statement = ASTNodeFactory(*this).createNode<Break>(docString);
|
statement = ASTNodeFactory(*this).createNode<Break>(docString);
|
||||||
m_scanner->next();
|
advance();
|
||||||
break;
|
break;
|
||||||
case Token::Return:
|
case Token::Return:
|
||||||
{
|
{
|
||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
ASTPointer<Expression> expression;
|
ASTPointer<Expression> expression;
|
||||||
if (m_scanner->next() != Token::Semicolon)
|
if (advance() != Token::Semicolon)
|
||||||
{
|
{
|
||||||
expression = parseExpression();
|
expression = parseExpression();
|
||||||
nodeFactory.setEndPositionFromNode(expression);
|
nodeFactory.setEndPositionFromNode(expression);
|
||||||
@ -1236,7 +1236,7 @@ ASTPointer<Statement> Parser::parseStatement(bool _allowUnchecked)
|
|||||||
case Token::Throw:
|
case Token::Throw:
|
||||||
{
|
{
|
||||||
statement = ASTNodeFactory(*this).createNode<Throw>(docString);
|
statement = ASTNodeFactory(*this).createNode<Throw>(docString);
|
||||||
m_scanner->next();
|
advance();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Token::Try:
|
case Token::Try:
|
||||||
@ -1252,7 +1252,7 @@ ASTPointer<Statement> Parser::parseStatement(bool _allowUnchecked)
|
|||||||
else if (m_insideModifier && m_scanner->currentLiteral() == "_")
|
else if (m_insideModifier && m_scanner->currentLiteral() == "_")
|
||||||
{
|
{
|
||||||
statement = ASTNodeFactory(*this).createNode<PlaceholderStatement>(docString);
|
statement = ASTNodeFactory(*this).createNode<PlaceholderStatement>(docString);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
statement = parseSimpleStatement(docString);
|
statement = parseSimpleStatement(docString);
|
||||||
@ -1291,7 +1291,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
|
|||||||
if (m_scanner->currentLiteral() != "evmasm")
|
if (m_scanner->currentLiteral() != "evmasm")
|
||||||
fatalParserError(4531_error, "Only \"evmasm\" supported.");
|
fatalParserError(4531_error, "Only \"evmasm\" supported.");
|
||||||
// This can be used in the future to set the dialect.
|
// This can be used in the future to set the dialect.
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
yul::Parser asmParser(m_errorReporter, dialect);
|
yul::Parser asmParser(m_errorReporter, dialect);
|
||||||
@ -1315,7 +1315,7 @@ ASTPointer<IfStatement> Parser::parseIfStatement(ASTPointer<ASTString> const& _d
|
|||||||
ASTPointer<Statement> falseBody;
|
ASTPointer<Statement> falseBody;
|
||||||
if (m_scanner->currentToken() == Token::Else)
|
if (m_scanner->currentToken() == Token::Else)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
falseBody = parseStatement();
|
falseBody = parseStatement();
|
||||||
nodeFactory.setEndPositionFromNode(falseBody);
|
nodeFactory.setEndPositionFromNode(falseBody);
|
||||||
}
|
}
|
||||||
@ -1336,7 +1336,7 @@ ASTPointer<TryStatement> Parser::parseTryStatement(ASTPointer<ASTString> const&
|
|||||||
ASTPointer<ParameterList> returnsParameters;
|
ASTPointer<ParameterList> returnsParameters;
|
||||||
if (m_scanner->currentToken() == Token::Returns)
|
if (m_scanner->currentToken() == Token::Returns)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
VarDeclParserOptions options;
|
VarDeclParserOptions options;
|
||||||
options.allowEmptyName = true;
|
options.allowEmptyName = true;
|
||||||
options.allowLocationSpecifier = true;
|
options.allowLocationSpecifier = true;
|
||||||
@ -1448,7 +1448,7 @@ ASTPointer<EmitStatement> Parser::parseEmitStatement(ASTPointer<ASTString> const
|
|||||||
expectToken(Token::Emit, false);
|
expectToken(Token::Emit, false);
|
||||||
|
|
||||||
ASTNodeFactory nodeFactory(*this);
|
ASTNodeFactory nodeFactory(*this);
|
||||||
m_scanner->next();
|
advance();
|
||||||
ASTNodeFactory eventCallNodeFactory(*this);
|
ASTNodeFactory eventCallNodeFactory(*this);
|
||||||
|
|
||||||
if (m_scanner->currentToken() != Token::Identifier)
|
if (m_scanner->currentToken() != Token::Identifier)
|
||||||
@ -1460,7 +1460,7 @@ ASTPointer<EmitStatement> Parser::parseEmitStatement(ASTPointer<ASTString> const
|
|||||||
iap.path.push_back(parseIdentifier());
|
iap.path.push_back(parseIdentifier());
|
||||||
if (m_scanner->currentToken() != Token::Period)
|
if (m_scanner->currentToken() != Token::Period)
|
||||||
break;
|
break;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto eventName = expressionFromIndexAccessStructure(iap);
|
auto eventName = expressionFromIndexAccessStructure(iap);
|
||||||
@ -1491,7 +1491,7 @@ ASTPointer<RevertStatement> Parser::parseRevertStatement(ASTPointer<ASTString> c
|
|||||||
iap.path.push_back(parseIdentifier());
|
iap.path.push_back(parseIdentifier());
|
||||||
if (m_scanner->currentToken() != Token::Period)
|
if (m_scanner->currentToken() != Token::Period)
|
||||||
break;
|
break;
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto errorName = expressionFromIndexAccessStructure(iap);
|
auto errorName = expressionFromIndexAccessStructure(iap);
|
||||||
@ -1521,7 +1521,7 @@ ASTPointer<Statement> Parser::parseSimpleStatement(ASTPointer<ASTString> const&
|
|||||||
expectToken(Token::LParen);
|
expectToken(Token::LParen);
|
||||||
while (m_scanner->currentToken() == Token::Comma)
|
while (m_scanner->currentToken() == Token::Comma)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
emptyComponents++;
|
emptyComponents++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1652,7 +1652,7 @@ ASTPointer<VariableDeclarationStatement> Parser::parseVariableDeclarationStateme
|
|||||||
ASTPointer<Expression> value;
|
ASTPointer<Expression> value;
|
||||||
if (m_scanner->currentToken() == Token::Assign)
|
if (m_scanner->currentToken() == Token::Assign)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
value = parseExpression();
|
value = parseExpression();
|
||||||
nodeFactory.setEndPositionFromNode(value);
|
nodeFactory.setEndPositionFromNode(value);
|
||||||
}
|
}
|
||||||
@ -1678,7 +1678,7 @@ ASTPointer<Expression> Parser::parseExpression(
|
|||||||
if (TokenTraits::isAssignmentOp(m_scanner->currentToken()))
|
if (TokenTraits::isAssignmentOp(m_scanner->currentToken()))
|
||||||
{
|
{
|
||||||
Token assignmentOperator = m_scanner->currentToken();
|
Token assignmentOperator = m_scanner->currentToken();
|
||||||
m_scanner->next();
|
advance();
|
||||||
ASTPointer<Expression> rightHandSide = parseExpression();
|
ASTPointer<Expression> rightHandSide = parseExpression();
|
||||||
ASTNodeFactory nodeFactory(*this, expression);
|
ASTNodeFactory nodeFactory(*this, expression);
|
||||||
nodeFactory.setEndPositionFromNode(rightHandSide);
|
nodeFactory.setEndPositionFromNode(rightHandSide);
|
||||||
@ -1686,7 +1686,7 @@ ASTPointer<Expression> Parser::parseExpression(
|
|||||||
}
|
}
|
||||||
else if (m_scanner->currentToken() == Token::Conditional)
|
else if (m_scanner->currentToken() == Token::Conditional)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
ASTPointer<Expression> trueExpression = parseExpression();
|
ASTPointer<Expression> trueExpression = parseExpression();
|
||||||
expectToken(Token::Colon);
|
expectToken(Token::Colon);
|
||||||
ASTPointer<Expression> falseExpression = parseExpression();
|
ASTPointer<Expression> falseExpression = parseExpression();
|
||||||
@ -1711,7 +1711,7 @@ ASTPointer<Expression> Parser::parseBinaryExpression(
|
|||||||
while (TokenTraits::precedence(m_scanner->currentToken()) == precedence)
|
while (TokenTraits::precedence(m_scanner->currentToken()) == precedence)
|
||||||
{
|
{
|
||||||
Token op = m_scanner->currentToken();
|
Token op = m_scanner->currentToken();
|
||||||
m_scanner->next();
|
advance();
|
||||||
|
|
||||||
static_assert(TokenTraits::hasExpHighestPrecedence(), "Exp does not have the highest precedence");
|
static_assert(TokenTraits::hasExpHighestPrecedence(), "Exp does not have the highest precedence");
|
||||||
|
|
||||||
@ -1736,7 +1736,7 @@ ASTPointer<Expression> Parser::parseUnaryExpression(
|
|||||||
if (!_partiallyParsedExpression && (TokenTraits::isUnaryOp(token) || TokenTraits::isCountOp(token)))
|
if (!_partiallyParsedExpression && (TokenTraits::isUnaryOp(token) || TokenTraits::isCountOp(token)))
|
||||||
{
|
{
|
||||||
// prefix expression
|
// prefix expression
|
||||||
m_scanner->next();
|
advance();
|
||||||
ASTPointer<Expression> subExpression = parseUnaryExpression();
|
ASTPointer<Expression> subExpression = parseUnaryExpression();
|
||||||
nodeFactory.setEndPositionFromNode(subExpression);
|
nodeFactory.setEndPositionFromNode(subExpression);
|
||||||
return nodeFactory.createNode<UnaryOperation>(token, subExpression, true);
|
return nodeFactory.createNode<UnaryOperation>(token, subExpression, true);
|
||||||
@ -1750,7 +1750,7 @@ ASTPointer<Expression> Parser::parseUnaryExpression(
|
|||||||
if (!TokenTraits::isCountOp(token))
|
if (!TokenTraits::isCountOp(token))
|
||||||
return subExpression;
|
return subExpression;
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
return nodeFactory.createNode<UnaryOperation>(token, subExpression, false);
|
return nodeFactory.createNode<UnaryOperation>(token, subExpression, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1793,7 +1793,7 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
|||||||
{
|
{
|
||||||
case Token::LBrack:
|
case Token::LBrack:
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
ASTPointer<Expression> index;
|
ASTPointer<Expression> index;
|
||||||
ASTPointer<Expression> endIndex;
|
ASTPointer<Expression> endIndex;
|
||||||
if (m_scanner->currentToken() != Token::RBrack && m_scanner->currentToken() != Token::Colon)
|
if (m_scanner->currentToken() != Token::RBrack && m_scanner->currentToken() != Token::Colon)
|
||||||
@ -1817,14 +1817,14 @@ ASTPointer<Expression> Parser::parseLeftHandSideExpression(
|
|||||||
}
|
}
|
||||||
case Token::Period:
|
case Token::Period:
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
expression = nodeFactory.createNode<MemberAccess>(expression, expectIdentifierTokenOrAddress());
|
expression = nodeFactory.createNode<MemberAccess>(expression, expectIdentifierTokenOrAddress());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Token::LParen:
|
case Token::LParen:
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
vector<ASTPointer<Expression>> arguments;
|
vector<ASTPointer<Expression>> arguments;
|
||||||
vector<ASTPointer<ASTString>> names;
|
vector<ASTPointer<ASTString>> names;
|
||||||
std::tie(arguments, names) = parseFunctionCallArguments();
|
std::tie(arguments, names) = parseFunctionCallArguments();
|
||||||
@ -1878,7 +1878,7 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
ASTPointer<ASTString> literal = getLiteralAndAdvance();
|
ASTPointer<ASTString> literal = getLiteralAndAdvance();
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(m_scanner->currentToken());
|
Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(m_scanner->currentToken());
|
||||||
m_scanner->next();
|
advance();
|
||||||
expression = nodeFactory.createNode<Literal>(token, literal, subdenomination);
|
expression = nodeFactory.createNode<Literal>(token, literal, subdenomination);
|
||||||
}
|
}
|
||||||
else if (TokenTraits::isTimeSubdenomination(m_scanner->peekNextToken()))
|
else if (TokenTraits::isTimeSubdenomination(m_scanner->peekNextToken()))
|
||||||
@ -1886,7 +1886,7 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
ASTPointer<ASTString> literal = getLiteralAndAdvance();
|
ASTPointer<ASTString> literal = getLiteralAndAdvance();
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(m_scanner->currentToken());
|
Literal::SubDenomination subdenomination = static_cast<Literal::SubDenomination>(m_scanner->currentToken());
|
||||||
m_scanner->next();
|
advance();
|
||||||
expression = nodeFactory.createNode<Literal>(token, literal, subdenomination);
|
expression = nodeFactory.createNode<Literal>(token, literal, subdenomination);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1903,11 +1903,11 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
Token firstToken = m_scanner->currentToken();
|
Token firstToken = m_scanner->currentToken();
|
||||||
while (m_scanner->peekNextToken() == firstToken)
|
while (m_scanner->peekNextToken() == firstToken)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
literal += m_scanner->currentLiteral();
|
literal += m_scanner->currentLiteral();
|
||||||
}
|
}
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
if (m_scanner->currentToken() == Token::Illegal)
|
if (m_scanner->currentToken() == Token::Illegal)
|
||||||
fatalParserError(5428_error, to_string(m_scanner->currentError()));
|
fatalParserError(5428_error, to_string(m_scanner->currentError()));
|
||||||
expression = nodeFactory.createNode<Literal>(token, make_shared<ASTString>(literal));
|
expression = nodeFactory.createNode<Literal>(token, make_shared<ASTString>(literal));
|
||||||
@ -1920,7 +1920,7 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
case Token::Type:
|
case Token::Type:
|
||||||
// Inside expressions "type" is the name of a special, globally-available function.
|
// Inside expressions "type" is the name of a special, globally-available function.
|
||||||
nodeFactory.markEndPosition();
|
nodeFactory.markEndPosition();
|
||||||
m_scanner->next();
|
advance();
|
||||||
expression = nodeFactory.createNode<Identifier>(make_shared<ASTString>("type"));
|
expression = nodeFactory.createNode<Identifier>(make_shared<ASTString>("type"));
|
||||||
break;
|
break;
|
||||||
case Token::LParen:
|
case Token::LParen:
|
||||||
@ -1929,7 +1929,7 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
// Tuple/parenthesized expression or inline array/bracketed expression.
|
// Tuple/parenthesized expression or inline array/bracketed expression.
|
||||||
// Special cases: ()/[] is empty tuple/array type, (x) is not a real tuple,
|
// Special cases: ()/[] is empty tuple/array type, (x) is not a real tuple,
|
||||||
// (x,) is one-dimensional tuple, elements in arrays cannot be left out, only in tuples.
|
// (x,) is one-dimensional tuple, elements in arrays cannot be left out, only in tuples.
|
||||||
m_scanner->next();
|
advance();
|
||||||
vector<ASTPointer<Expression>> components;
|
vector<ASTPointer<Expression>> components;
|
||||||
Token oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack);
|
Token oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack);
|
||||||
bool isArray = (token == Token::LBrack);
|
bool isArray = (token == Token::LBrack);
|
||||||
@ -1968,7 +1968,7 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
|
|||||||
ElementaryTypeNameToken(m_scanner->currentToken(), firstSize, secondSize)
|
ElementaryTypeNameToken(m_scanner->currentToken(), firstSize, secondSize)
|
||||||
);
|
);
|
||||||
expression = nodeFactory.createNode<ElementaryTypeNameExpression>(expressionType);
|
expression = nodeFactory.createNode<ElementaryTypeNameExpression>(expressionType);
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fatalParserError(6933_error, "Expected primary expression.");
|
fatalParserError(6933_error, "Expected primary expression.");
|
||||||
@ -2030,7 +2030,7 @@ pair<vector<ASTPointer<Expression>>, vector<ASTPointer<ASTString>>> Parser::pars
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
parserError(2074_error, "Unexpected trailing comma.");
|
parserError(2074_error, "Unexpected trailing comma.");
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
@ -2142,7 +2142,7 @@ Parser::IndexAccessedPath Parser::parseIndexAccessedPath()
|
|||||||
iap.path.push_back(parseIdentifier());
|
iap.path.push_back(parseIdentifier());
|
||||||
while (m_scanner->currentToken() == Token::Period)
|
while (m_scanner->currentToken() == Token::Period)
|
||||||
{
|
{
|
||||||
m_scanner->next();
|
advance();
|
||||||
iap.path.push_back(parseIdentifierOrAddress());
|
iap.path.push_back(parseIdentifierOrAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2155,7 +2155,7 @@ Parser::IndexAccessedPath Parser::parseIndexAccessedPath()
|
|||||||
ElementaryTypeNameToken(m_scanner->currentToken(), firstNum, secondNum)
|
ElementaryTypeNameToken(m_scanner->currentToken(), firstNum, secondNum)
|
||||||
);
|
);
|
||||||
iap.path.push_back(ASTNodeFactory(*this).createNode<ElementaryTypeNameExpression>(expressionType));
|
iap.path.push_back(ASTNodeFactory(*this).createNode<ElementaryTypeNameExpression>(expressionType));
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
while (m_scanner->currentToken() == Token::LBrack)
|
while (m_scanner->currentToken() == Token::LBrack)
|
||||||
{
|
{
|
||||||
@ -2271,7 +2271,7 @@ ASTPointer<ASTString> Parser::expectIdentifierTokenOrAddress()
|
|||||||
if (m_scanner->currentToken() == Token::Address)
|
if (m_scanner->currentToken() == Token::Address)
|
||||||
{
|
{
|
||||||
result = make_shared<ASTString>("address");
|
result = make_shared<ASTString>("address");
|
||||||
m_scanner->next();
|
advance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2284,7 +2284,7 @@ ASTPointer<ASTString> Parser::expectIdentifierTokenOrAddress()
|
|||||||
ASTPointer<ASTString> Parser::getLiteralAndAdvance()
|
ASTPointer<ASTString> Parser::getLiteralAndAdvance()
|
||||||
{
|
{
|
||||||
ASTPointer<ASTString> identifier = make_shared<ASTString>(m_scanner->currentLiteral());
|
ASTPointer<ASTString> identifier = make_shared<ASTString>(m_scanner->currentLiteral());
|
||||||
m_scanner->next();
|
advance();
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user