From b7cafcbdf95c807f46fc07f4788d82981b7112b4 Mon Sep 17 00:00:00 2001 From: mingchuan Date: Wed, 23 May 2018 12:31:20 +0800 Subject: Allow using `calldata` keyword to specify data location --- libsolidity/parsing/Parser.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index e2e1eebc..aec9ebbb 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -592,11 +592,22 @@ ASTPointer Parser::parseVariableDeclaration( else if (!type) parserError(string("Location specifier needs explicit type name.")); else - location = ( - token == Token::Memory ? - VariableDeclaration::Location::Memory : - VariableDeclaration::Location::Storage - ); + { + switch (token) + { + case Token::Storage: + location = VariableDeclaration::Location::Storage; + break; + case Token::Memory: + location = VariableDeclaration::Location::Memory; + break; + case Token::CallData: + location = VariableDeclaration::Location::CallData; + break; + default: + solAssert(false, "Unknown data location."); + } + } } else break; -- cgit v1.2.3 From 2e9f5d1c98af76dbab4960f095a5fef1ddfc7db5 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 23 May 2018 11:57:52 +0200 Subject: Introduces emit token and removes identifier workaround. --- libsolidity/parsing/Parser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index aec9ebbb..e9810fe3 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -939,10 +939,11 @@ ASTPointer Parser::parseStatement() } case Token::Assembly: return parseInlineAssembly(docString); + case Token::Emit: + statement = parseEmitStatement(docString); + break; case Token::Identifier: - if (m_scanner->currentLiteral() == "emit") - statement = parseEmitStatement(docString); - else if (m_insideModifier && m_scanner->currentLiteral() == "_") + if (m_insideModifier && m_scanner->currentLiteral() == "_") { statement = ASTNodeFactory(*this).createNode(docString); m_scanner->next(); @@ -1062,6 +1063,8 @@ ASTPointer Parser::parseForStatement(ASTPointer const& ASTPointer Parser::parseEmitStatement(ASTPointer const& _docString) { + expectToken(Token::Emit, false); + ASTNodeFactory nodeFactory(*this); m_scanner->next(); ASTNodeFactory eventCallNodeFactory(*this); -- cgit v1.2.3 From 3984beef7d389776c23053e3136ae99296c12e8e Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 8 May 2018 13:08:06 +0200 Subject: Remove constant keyword from parser. --- libsolidity/parsing/Parser.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index e9810fe3..e2bd6fb4 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -322,11 +322,18 @@ StateMutability Parser::parseStateMutability(Token::Value _token) StateMutability stateMutability(StateMutability::NonPayable); if (_token == Token::Payable) stateMutability = StateMutability::Payable; - // FIXME: constant should be removed at the next breaking release - else if (_token == Token::View || _token == Token::Constant) + else if (_token == Token::View) stateMutability = StateMutability::View; else if (_token == Token::Pure) stateMutability = StateMutability::Pure; + else if (_token == Token::Constant) + { + stateMutability = StateMutability::View; + parserError( + "The state mutability modifier \"constant\" was removed in version 0.5.0. " + "Use \"view\" or \"pure\" instead." + ); + } else solAssert(false, "Invalid state mutability specifier."); m_scanner->next(); -- cgit v1.2.3 From 182a0a95516e4f218524b929035e6a1bd5d2742c Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 27 Jun 2018 12:29:03 +0200 Subject: Disallows old constructor syntax. --- libsolidity/parsing/Parser.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index e2bd6fb4..0bee2a91 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -239,13 +239,10 @@ ASTPointer Parser::parseContractDefinition(Token::Value _exp Token::Value currentTokenValue = m_scanner->currentToken(); if (currentTokenValue == Token::RBrace) break; - else if ( - currentTokenValue == Token::Function || - (currentTokenValue == Token::Identifier && m_scanner->currentLiteral() == "constructor") - ) + else if (currentTokenValue == Token::Function || currentTokenValue == Token::Constructor) // This can be a function or a state variable of function type (especially // complicated to distinguish fallback function from function type state variable) - subNodes.push_back(parseFunctionDefinitionOrFunctionTypeStateVariable(name.get())); + subNodes.push_back(parseFunctionDefinitionOrFunctionTypeStateVariable()); else if (currentTokenValue == Token::Struct) subNodes.push_back(parseStructDefinition()); else if (currentTokenValue == Token::Enum) @@ -340,30 +337,31 @@ StateMutability Parser::parseStateMutability(Token::Value _token) return stateMutability; } -Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( - bool _forceEmptyName, - bool _allowModifiers, - ASTString const* _contractName -) +Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers) { RecursionGuard recursionGuard(*this); FunctionHeaderParserResult result; result.isConstructor = false; - if (m_scanner->currentToken() == Token::Identifier && m_scanner->currentLiteral() == "constructor") + if (m_scanner->currentToken() == Token::Constructor) result.isConstructor = true; else if (m_scanner->currentToken() != Token::Function) solAssert(false, "Function or constructor expected."); m_scanner->next(); - if (result.isConstructor || _forceEmptyName || m_scanner->currentToken() == Token::LParen) + if (result.isConstructor) result.name = make_shared(); + else if (_forceEmptyName || m_scanner->currentToken() == Token::LParen) + result.name = make_shared(); + else if (m_scanner->currentToken() == Token::Constructor) + fatalParserError(string( + "This function is named \"constructor\" but is not the constructor of the contract. " + "If you intend this to be a constructor, use \"constructor(...) { ... }\" without the \"function\" keyword to define it." + )); else result.name = expectIdentifierToken(); - if (!result.name->empty() && _contractName && *result.name == *_contractName) - result.isConstructor = true; VarDeclParserOptions options; options.allowLocationSpecifier = true; @@ -435,7 +433,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( return result; } -ASTPointer Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(ASTString const* _contractName) +ASTPointer Parser::parseFunctionDefinitionOrFunctionTypeStateVariable() { RecursionGuard recursionGuard(*this); ASTNodeFactory nodeFactory(*this); @@ -443,7 +441,7 @@ ASTPointer Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A if (m_scanner->currentCommentLiteral() != "") docstring = make_shared(m_scanner->currentCommentLiteral()); - FunctionHeaderParserResult header = parseFunctionHeader(false, true, _contractName); + FunctionHeaderParserResult header = parseFunctionHeader(false, true); if ( header.isConstructor || -- cgit v1.2.3 From 551e0bf47cd0a1d1cb24a878f2309fd9f3253d00 Mon Sep 17 00:00:00 2001 From: Chase McDermott Date: Fri, 17 Aug 2018 18:09:31 -0500 Subject: Rename Location::Default to Location::Unspecified. --- libsolidity/parsing/Parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 0bee2a91..bfa0ad24 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -564,7 +564,7 @@ ASTPointer Parser::parseVariableDeclaration( bool isIndexed = false; bool isDeclaredConst = false; Declaration::Visibility visibility(Declaration::Visibility::Default); - VariableDeclaration::Location location = VariableDeclaration::Location::Default; + VariableDeclaration::Location location = VariableDeclaration::Location::Unspecified; ASTPointer identifier; while (true) @@ -592,7 +592,7 @@ ASTPointer Parser::parseVariableDeclaration( isDeclaredConst = true; else if (_options.allowLocationSpecifier && Token::isLocationSpecifier(token)) { - if (location != VariableDeclaration::Location::Default) + if (location != VariableDeclaration::Location::Unspecified) parserError(string("Location already specified.")); else if (!type) parserError(string("Location specifier needs explicit type name.")); -- cgit v1.2.3 From c458f5988bc4c5bcb61135b5eec217f1be7cd33c Mon Sep 17 00:00:00 2001 From: bakaoh Date: Tue, 28 Aug 2018 11:11:40 +0700 Subject: Fix#4743: Incorrect source location for nameless parameters --- libsolidity/parsing/Parser.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 0bee2a91..7ebcf704 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -572,6 +572,7 @@ ASTPointer Parser::parseVariableDeclaration( Token::Value token = m_scanner->currentToken(); if (_options.isStateVariable && Token::isVariableVisibilitySpecifier(token)) { + nodeFactory.markEndPosition(); if (visibility != Declaration::Visibility::Default) { parserError(string( @@ -616,21 +617,21 @@ ASTPointer Parser::parseVariableDeclaration( } else break; + nodeFactory.markEndPosition(); m_scanner->next(); } } - nodeFactory.markEndPosition(); if (_options.allowEmptyName && m_scanner->currentToken() != Token::Identifier) { identifier = make_shared(""); solAssert(!_options.allowVar, ""); // allowEmptyName && allowVar makes no sense - if (type) - nodeFactory.setEndPositionFromNode(type); - // if type is null this has already caused an error } else + { + nodeFactory.markEndPosition(); identifier = expectIdentifierToken(); + } ASTPointer value; if (_options.allowInitialValue) { -- cgit v1.2.3 From f020f96b6c3f1e74109ed8cd32134a89d78936a9 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 6 Sep 2018 14:55:07 +0200 Subject: More consistently use parse*() functions without argument in the parser. --- libsolidity/parsing/Parser.cpp | 102 ++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 42 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index c9c26f57..0c41e332 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -75,7 +75,7 @@ ASTPointer Parser::parse(shared_ptr const& _scanner) vector> nodes; while (m_scanner->currentToken() != Token::EOS) { - switch (auto token = m_scanner->currentToken()) + switch (m_scanner->currentToken()) { case Token::Pragma: nodes.push_back(parsePragmaDirective()); @@ -86,7 +86,7 @@ ASTPointer Parser::parse(shared_ptr const& _scanner) case Token::Interface: case Token::Contract: case Token::Library: - nodes.push_back(parseContractDefinition(token)); + nodes.push_back(parseContractDefinition()); break; default: fatalParserError(string("Expected pragma, import directive or contract/interface/library definition.")); @@ -198,31 +198,35 @@ ASTPointer Parser::parseImportDirective() return nodeFactory.createNode(path, unitAlias, move(symbolAliases)); } -ContractDefinition::ContractKind Parser::tokenToContractKind(Token::Value _token) +ContractDefinition::ContractKind Parser::parseContractKind() { - switch(_token) + ContractDefinition::ContractKind kind; + switch(m_scanner->currentToken()) { case Token::Interface: - return ContractDefinition::ContractKind::Interface; + kind = ContractDefinition::ContractKind::Interface; + break; case Token::Contract: - return ContractDefinition::ContractKind::Contract; + kind = ContractDefinition::ContractKind::Contract; + break; case Token::Library: - return ContractDefinition::ContractKind::Library; + kind = ContractDefinition::ContractKind::Library; + break; default: - fatalParserError("Unsupported contract type."); + solAssert(false, "Invalid contract kind."); } - // FIXME: fatalParserError is not considered as throwing here - return ContractDefinition::ContractKind::Contract; + m_scanner->next(); + return kind; } -ASTPointer Parser::parseContractDefinition(Token::Value _expectedKind) +ASTPointer Parser::parseContractDefinition() { RecursionGuard recursionGuard(*this); ASTNodeFactory nodeFactory(*this); ASTPointer docString; if (m_scanner->currentCommentLiteral() != "") docString = make_shared(m_scanner->currentCommentLiteral()); - expectToken(_expectedKind); + ContractDefinition::ContractKind contractKind = parseContractKind(); ASTPointer name = expectIdentifierToken(); vector> baseContracts; if (m_scanner->currentToken() == Token::Is) @@ -275,7 +279,7 @@ ASTPointer Parser::parseContractDefinition(Token::Value _exp docString, baseContracts, subNodes, - tokenToContractKind(_expectedKind) + contractKind ); } @@ -297,42 +301,56 @@ ASTPointer Parser::parseInheritanceSpecifier() return nodeFactory.createNode(name, std::move(arguments)); } -Declaration::Visibility Parser::parseVisibilitySpecifier(Token::Value _token) +Declaration::Visibility Parser::parseVisibilitySpecifier() { Declaration::Visibility visibility(Declaration::Visibility::Default); - if (_token == Token::Public) - visibility = Declaration::Visibility::Public; - else if (_token == Token::Internal) - visibility = Declaration::Visibility::Internal; - else if (_token == Token::Private) - visibility = Declaration::Visibility::Private; - else if (_token == Token::External) - visibility = Declaration::Visibility::External; - else - solAssert(false, "Invalid visibility specifier."); + Token::Value token = m_scanner->currentToken(); + switch (token) + { + case Token::Public: + visibility = Declaration::Visibility::Public; + break; + case Token::Internal: + visibility = Declaration::Visibility::Internal; + break; + case Token::Private: + visibility = Declaration::Visibility::Private; + break; + case Token::External: + visibility = Declaration::Visibility::External; + break; + default: + solAssert(false, "Invalid visibility specifier."); + } m_scanner->next(); return visibility; } -StateMutability Parser::parseStateMutability(Token::Value _token) +StateMutability Parser::parseStateMutability() { StateMutability stateMutability(StateMutability::NonPayable); - if (_token == Token::Payable) - stateMutability = StateMutability::Payable; - else if (_token == Token::View) - stateMutability = StateMutability::View; - else if (_token == Token::Pure) - stateMutability = StateMutability::Pure; - else if (_token == Token::Constant) + Token::Value token = m_scanner->currentToken(); + switch(token) { - stateMutability = StateMutability::View; - parserError( - "The state mutability modifier \"constant\" was removed in version 0.5.0. " - "Use \"view\" or \"pure\" instead." - ); + case Token::Payable: + stateMutability = StateMutability::Payable; + break; + case Token::View: + stateMutability = StateMutability::View; + break; + case Token::Pure: + stateMutability = StateMutability::Pure; + break; + case Token::Constant: + stateMutability = StateMutability::View; + parserError( + "The state mutability modifier \"constant\" was removed in version 0.5.0. " + "Use \"view\" or \"pure\" instead." + ); + break; + default: + solAssert(false, "Invalid state mutability specifier."); } - else - solAssert(false, "Invalid state mutability specifier."); m_scanner->next(); return stateMutability; } @@ -403,7 +421,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN m_scanner->next(); } else - result.visibility = parseVisibilitySpecifier(token); + result.visibility = parseVisibilitySpecifier(); } else if (Token::isStateMutabilitySpecifier(token)) { @@ -417,7 +435,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN m_scanner->next(); } else - result.stateMutability = parseStateMutability(token); + result.stateMutability = parseStateMutability(); } else break; @@ -583,7 +601,7 @@ ASTPointer Parser::parseVariableDeclaration( m_scanner->next(); } else - visibility = parseVisibilitySpecifier(token); + visibility = parseVisibilitySpecifier(); } else { -- cgit v1.2.3 From 1ce3581a522a94d9e9a4a84cf8cb63f626e1a14f Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 6 Sep 2018 18:59:50 +0200 Subject: Accept ``address payable`` during parsing. --- libsolidity/parsing/Parser.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 0c41e332..1228b833 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -57,7 +57,7 @@ public: solAssert(m_location.sourceName, ""); if (m_location.end < 0) markEndPosition(); - return make_shared(m_location, forward(_args)...); + return make_shared(m_location, std::forward(_args)...); } private: @@ -813,8 +813,24 @@ ASTPointer Parser::parseTypeName(bool _allowVar) unsigned secondSize; tie(firstSize, secondSize) = m_scanner->currentTokenInfo(); ElementaryTypeNameToken elemTypeName(token, firstSize, secondSize); - type = ASTNodeFactory(*this).createNode(elemTypeName); + ASTNodeFactory nodeFactory(*this); + nodeFactory.markEndPosition(); m_scanner->next(); + auto stateMutability = boost::make_optional(elemTypeName.token() == Token::Address, StateMutability::NonPayable); + if (Token::isStateMutabilitySpecifier(m_scanner->currentToken(), false)) + { + if (elemTypeName.token() == Token::Address) + { + nodeFactory.markEndPosition(); + stateMutability = parseStateMutability(); + } + else + { + parserError("State mutability can only be specified for address types."); + m_scanner->next(); + } + } + type = nodeFactory.createNode(elemTypeName, stateMutability); } else if (token == Token::Var) { @@ -1615,8 +1631,8 @@ Parser::LookAheadInfo Parser::peekStatementType() const // Distinguish between variable declaration (and potentially assignment) and expression statement // (which include assignments to other expressions and pre-declared variables). // We have a variable declaration if we get a keyword that specifies a type name. - // If it is an identifier or an elementary type name followed by an identifier, we also have - // a variable declaration. + // If it is an identifier or an elementary type name followed by an identifier + // or a mutability specifier, we also have a variable declaration. // If we get an identifier followed by a "[" or ".", it can be both ("lib.type[9] a;" or "variable.el[9] = 7;"). // In all other cases, we have an expression statement. Token::Value token(m_scanner->currentToken()); @@ -1627,6 +1643,12 @@ Parser::LookAheadInfo Parser::peekStatementType() const if (mightBeTypeName) { Token::Value next = m_scanner->peekNextToken(); + // So far we only allow ``address payable`` in variable declaration statements and in no other + // kind of statement. This means, for example, that we do not allow type expressions of the form + // ``address payable;``. + // If we want to change this in the future, we need to consider another scanner token here. + if (Token::isElementaryTypeName(token) && Token::isStateMutabilitySpecifier(next, false)) + return LookAheadInfo::VariableDeclaration; if (next == Token::Identifier || Token::isLocationSpecifier(next)) return LookAheadInfo::VariableDeclaration; if (next == Token::LBrack || next == Token::Period) -- cgit v1.2.3 From fa0ce6a7e7abd5bbc9bad1dd15f54ea4e9b11f85 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 9 Oct 2018 04:29:37 +0100 Subject: Use empty() instead of size() == 0 --- libsolidity/parsing/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 1228b833..f81e70a0 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -554,7 +554,7 @@ ASTPointer Parser::parseEnumDefinition() if (m_scanner->currentToken() != Token::Identifier) fatalParserError(string("Expected identifier after ','")); } - if (members.size() == 0) + if (members.empty()) parserError({"enum with no members is not allowed."}); nodeFactory.markEndPosition(); -- cgit v1.2.3 From 4bcd89105cf294d65443cbc7bfe2aaffd571f6d3 Mon Sep 17 00:00:00 2001 From: Lazaridis Date: Mon, 1 Oct 2018 00:27:16 +0300 Subject: provide general hex-literal error message, fixes #1802 dummy --- libsolidity/parsing/Parser.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 1228b833..b390459a 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1554,6 +1554,9 @@ ASTPointer Parser::parsePrimaryExpression() expression = nodeFactory.createNode(components, isArray); break; } + case Token::IllegalHex: + fatalParserError("Expected even number of hex-nibbles within double-quotes."); + break; default: if (Token::isElementaryTypeName(token)) { -- cgit v1.2.3 From 6c3d12d85bc7977817e8dc1c5bd0af4b29406b58 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 9 Oct 2018 19:06:22 +0100 Subject: Do not require ctype/stdio if not needed --- libsolidity/parsing/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index f81e70a0..2c396746 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -20,7 +20,7 @@ * Solidity parser. */ -#include +#include #include #include #include -- cgit v1.2.3 From f112377dd44e8281bff092639bb546ec8a6a39ac Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 22 Oct 2018 16:48:21 +0200 Subject: Refactor `solidity::Token` into an `enum class` with `TokenTraits` helper namespace --- libsolidity/parsing/Parser.cpp | 80 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index ca9a9b57..f99b9ea4 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -112,17 +112,17 @@ ASTPointer Parser::parsePragmaDirective() ASTNodeFactory nodeFactory(*this); expectToken(Token::Pragma); vector literals; - vector tokens; + vector tokens; do { - Token::Value token = m_scanner->currentToken(); + Token token = m_scanner->currentToken(); if (token == Token::Illegal) parserError("Token incompatible with Solidity parser as part of pragma directive."); else { string literal = m_scanner->currentLiteral(); - if (literal.empty() && Token::toString(token)) - literal = Token::toString(token); + if (literal.empty() && TokenTraits::toString(token)) + literal = TokenTraits::toString(token); literals.push_back(literal); tokens.push_back(token); } @@ -240,7 +240,7 @@ ASTPointer Parser::parseContractDefinition() expectToken(Token::LBrace); while (true) { - Token::Value currentTokenValue = m_scanner->currentToken(); + Token currentTokenValue = m_scanner->currentToken(); if (currentTokenValue == Token::RBrace) break; else if (currentTokenValue == Token::Function || currentTokenValue == Token::Constructor) @@ -254,7 +254,7 @@ ASTPointer Parser::parseContractDefinition() else if ( currentTokenValue == Token::Identifier || currentTokenValue == Token::Mapping || - Token::isElementaryTypeName(currentTokenValue) + TokenTraits::isElementaryTypeName(currentTokenValue) ) { VarDeclParserOptions options; @@ -304,7 +304,7 @@ ASTPointer Parser::parseInheritanceSpecifier() Declaration::Visibility Parser::parseVisibilitySpecifier() { Declaration::Visibility visibility(Declaration::Visibility::Default); - Token::Value token = m_scanner->currentToken(); + Token token = m_scanner->currentToken(); switch (token) { case Token::Public: @@ -329,7 +329,7 @@ Declaration::Visibility Parser::parseVisibilitySpecifier() StateMutability Parser::parseStateMutability() { StateMutability stateMutability(StateMutability::NonPayable); - Token::Value token = m_scanner->currentToken(); + Token token = m_scanner->currentToken(); switch(token) { case Token::Payable: @@ -386,7 +386,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN result.parameters = parseParameterList(options); while (true) { - Token::Value token = m_scanner->currentToken(); + Token token = m_scanner->currentToken(); if (_allowModifiers && token == Token::Identifier) { // If the name is empty (and this is not a constructor), @@ -401,7 +401,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN else result.modifiers.push_back(parseModifierInvocation()); } - else if (Token::isVisibilitySpecifier(token)) + else if (TokenTraits::isVisibilitySpecifier(token)) { if (result.visibility != Declaration::Visibility::Default) { @@ -423,7 +423,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN else result.visibility = parseVisibilitySpecifier(); } - else if (Token::isStateMutabilitySpecifier(token)) + else if (TokenTraits::isStateMutabilitySpecifier(token)) { if (result.stateMutability != StateMutability::NonPayable) { @@ -587,8 +587,8 @@ ASTPointer Parser::parseVariableDeclaration( while (true) { - Token::Value token = m_scanner->currentToken(); - if (_options.isStateVariable && Token::isVariableVisibilitySpecifier(token)) + Token token = m_scanner->currentToken(); + if (_options.isStateVariable && TokenTraits::isVariableVisibilitySpecifier(token)) { nodeFactory.markEndPosition(); if (visibility != Declaration::Visibility::Default) @@ -609,7 +609,7 @@ ASTPointer Parser::parseVariableDeclaration( isIndexed = true; else if (token == Token::Constant) isDeclaredConst = true; - else if (_options.allowLocationSpecifier && Token::isLocationSpecifier(token)) + else if (_options.allowLocationSpecifier && TokenTraits::isLocationSpecifier(token)) { if (location != VariableDeclaration::Location::Unspecified) parserError(string("Location already specified.")); @@ -806,8 +806,8 @@ ASTPointer Parser::parseTypeName(bool _allowVar) RecursionGuard recursionGuard(*this); ASTNodeFactory nodeFactory(*this); ASTPointer type; - Token::Value token = m_scanner->currentToken(); - if (Token::isElementaryTypeName(token)) + Token token = m_scanner->currentToken(); + if (TokenTraits::isElementaryTypeName(token)) { unsigned firstSize; unsigned secondSize; @@ -817,7 +817,7 @@ ASTPointer Parser::parseTypeName(bool _allowVar) nodeFactory.markEndPosition(); m_scanner->next(); auto stateMutability = boost::make_optional(elemTypeName.token() == Token::Address, StateMutability::NonPayable); - if (Token::isStateMutabilitySpecifier(m_scanner->currentToken(), false)) + if (TokenTraits::isStateMutabilitySpecifier(m_scanner->currentToken(), false)) { if (elemTypeName.token() == Token::Address) { @@ -874,8 +874,8 @@ ASTPointer Parser::parseMapping() expectToken(Token::Mapping); expectToken(Token::LParen); ASTPointer keyType; - Token::Value token = m_scanner->currentToken(); - if (!Token::isElementaryTypeName(token)) + Token token = m_scanner->currentToken(); + if (!TokenTraits::isElementaryTypeName(token)) fatalParserError(string("Expected elementary type name for mapping key type")); unsigned firstSize; unsigned secondSize; @@ -1252,7 +1252,7 @@ pair Parser::tryParseIndexAcce // VariableDeclarationStatement out of it. IndexAccessedPath iap = parseIndexAccessedPath(); - if (m_scanner->currentToken() == Token::Identifier || Token::isLocationSpecifier(m_scanner->currentToken())) + if (m_scanner->currentToken() == Token::Identifier || TokenTraits::isLocationSpecifier(m_scanner->currentToken())) return make_pair(LookAheadInfo::VariableDeclaration, move(iap)); else return make_pair(LookAheadInfo::Expression, move(iap)); @@ -1342,16 +1342,16 @@ ASTPointer Parser::parseExpression( { RecursionGuard recursionGuard(*this); ASTPointer expression = parseBinaryExpression(4, _partiallyParsedExpression); - if (Token::isAssignmentOp(m_scanner->currentToken())) + if (TokenTraits::isAssignmentOp(m_scanner->currentToken())) { - Token::Value assignmentOperator = m_scanner->currentToken(); + Token assignmentOperator = m_scanner->currentToken(); m_scanner->next(); ASTPointer rightHandSide = parseExpression(); ASTNodeFactory nodeFactory(*this, expression); nodeFactory.setEndPositionFromNode(rightHandSide); return nodeFactory.createNode(expression, assignmentOperator, rightHandSide); } - else if (m_scanner->currentToken() == Token::Value::Conditional) + else if (m_scanner->currentToken() == Token::Conditional) { m_scanner->next(); ASTPointer trueExpression = parseExpression(); @@ -1373,11 +1373,11 @@ ASTPointer Parser::parseBinaryExpression( RecursionGuard recursionGuard(*this); ASTPointer expression = parseUnaryExpression(_partiallyParsedExpression); ASTNodeFactory nodeFactory(*this, expression); - int precedence = Token::precedence(m_scanner->currentToken()); + int precedence = TokenTraits::precedence(m_scanner->currentToken()); for (; precedence >= _minPrecedence; --precedence) - while (Token::precedence(m_scanner->currentToken()) == precedence) + while (TokenTraits::precedence(m_scanner->currentToken()) == precedence) { - Token::Value op = m_scanner->currentToken(); + Token op = m_scanner->currentToken(); m_scanner->next(); ASTPointer right = parseBinaryExpression(precedence + 1); nodeFactory.setEndPositionFromNode(right); @@ -1393,8 +1393,8 @@ ASTPointer Parser::parseUnaryExpression( RecursionGuard recursionGuard(*this); ASTNodeFactory nodeFactory = _partiallyParsedExpression ? ASTNodeFactory(*this, _partiallyParsedExpression) : ASTNodeFactory(*this); - Token::Value token = m_scanner->currentToken(); - if (!_partiallyParsedExpression && (Token::isUnaryOp(token) || Token::isCountOp(token))) + Token token = m_scanner->currentToken(); + if (!_partiallyParsedExpression && (TokenTraits::isUnaryOp(token) || TokenTraits::isCountOp(token))) { // prefix expression m_scanner->next(); @@ -1407,7 +1407,7 @@ ASTPointer Parser::parseUnaryExpression( // potential postfix expression ASTPointer subExpression = parseLeftHandSideExpression(_partiallyParsedExpression); token = m_scanner->currentToken(); - if (!Token::isCountOp(token)) + if (!TokenTraits::isCountOp(token)) return subExpression; nodeFactory.markEndPosition(); m_scanner->next(); @@ -1482,7 +1482,7 @@ ASTPointer Parser::parsePrimaryExpression() { RecursionGuard recursionGuard(*this); ASTNodeFactory nodeFactory(*this); - Token::Value token = m_scanner->currentToken(); + Token token = m_scanner->currentToken(); ASTPointer expression; switch (token) @@ -1493,7 +1493,7 @@ ASTPointer Parser::parsePrimaryExpression() expression = nodeFactory.createNode(token, getLiteralAndAdvance()); break; case Token::Number: - if (Token::isEtherSubdenomination(m_scanner->peekNextToken())) + if (TokenTraits::isEtherSubdenomination(m_scanner->peekNextToken())) { ASTPointer literal = getLiteralAndAdvance(); nodeFactory.markEndPosition(); @@ -1501,7 +1501,7 @@ ASTPointer Parser::parsePrimaryExpression() m_scanner->next(); expression = nodeFactory.createNode(token, literal, subdenomination); } - else if (Token::isTimeSubdenomination(m_scanner->peekNextToken())) + else if (TokenTraits::isTimeSubdenomination(m_scanner->peekNextToken())) { ASTPointer literal = getLiteralAndAdvance(); nodeFactory.markEndPosition(); @@ -1531,7 +1531,7 @@ ASTPointer Parser::parsePrimaryExpression() // (x,) is one-dimensional tuple, elements in arrays cannot be left out, only in tuples. m_scanner->next(); vector> components; - Token::Value oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack); + Token oppositeToken = (token == Token::LParen ? Token::RParen : Token::RBrack); bool isArray = (token == Token::LBrack); if (m_scanner->currentToken() != oppositeToken) @@ -1558,7 +1558,7 @@ ASTPointer Parser::parsePrimaryExpression() fatalParserError("Expected even number of hex-nibbles within double-quotes."); break; default: - if (Token::isElementaryTypeName(token)) + if (TokenTraits::isElementaryTypeName(token)) { //used for casts unsigned firstSize; @@ -1595,7 +1595,7 @@ pair>, vector>> Parser::pars { RecursionGuard recursionGuard(*this); pair>, vector>> ret; - Token::Value token = m_scanner->currentToken(); + Token token = m_scanner->currentToken(); if (token == Token::LBrace) { // call({arg1 : 1, arg2 : 2 }) @@ -1638,21 +1638,21 @@ Parser::LookAheadInfo Parser::peekStatementType() const // or a mutability specifier, we also have a variable declaration. // If we get an identifier followed by a "[" or ".", it can be both ("lib.type[9] a;" or "variable.el[9] = 7;"). // In all other cases, we have an expression statement. - Token::Value token(m_scanner->currentToken()); - bool mightBeTypeName = (Token::isElementaryTypeName(token) || token == Token::Identifier); + Token token(m_scanner->currentToken()); + bool mightBeTypeName = (TokenTraits::isElementaryTypeName(token) || token == Token::Identifier); if (token == Token::Mapping || token == Token::Function || token == Token::Var) return LookAheadInfo::VariableDeclaration; if (mightBeTypeName) { - Token::Value next = m_scanner->peekNextToken(); + Token next = m_scanner->peekNextToken(); // So far we only allow ``address payable`` in variable declaration statements and in no other // kind of statement. This means, for example, that we do not allow type expressions of the form // ``address payable;``. // If we want to change this in the future, we need to consider another scanner token here. - if (Token::isElementaryTypeName(token) && Token::isStateMutabilitySpecifier(next, false)) + if (TokenTraits::isElementaryTypeName(token) && TokenTraits::isStateMutabilitySpecifier(next, false)) return LookAheadInfo::VariableDeclaration; - if (next == Token::Identifier || Token::isLocationSpecifier(next)) + if (next == Token::Identifier || TokenTraits::isLocationSpecifier(next)) return LookAheadInfo::VariableDeclaration; if (next == Token::LBrack || next == Token::Period) return LookAheadInfo::IndexAccessStructure; -- cgit v1.2.3 From af65bac737ce2f7c1d0311c2bcbbc12f43d122f9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 12 Nov 2018 09:13:14 +0100 Subject: Remove trailing whitespace. --- libsolidity/parsing/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index f99b9ea4..b17dad9a 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1556,7 +1556,7 @@ ASTPointer Parser::parsePrimaryExpression() } case Token::IllegalHex: fatalParserError("Expected even number of hex-nibbles within double-quotes."); - break; + break; default: if (TokenTraits::isElementaryTypeName(token)) { -- cgit v1.2.3