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