diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-02-15 19:40:29 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-03-18 01:06:52 +0800 |
commit | f8da9a8fd5e2c709aa940402155faa30139ec9e1 (patch) | |
tree | 43e8e9501f409d6eb58fc1faae8fe29d000b0570 /libsolidity/parsing | |
parent | 3f1468142badd2717596a4cd78f6f347b78010d7 (diff) | |
download | dexon-solidity-f8da9a8fd5e2c709aa940402155faa30139ec9e1.tar.gz dexon-solidity-f8da9a8fd5e2c709aa940402155faa30139ec9e1.tar.zst dexon-solidity-f8da9a8fd5e2c709aa940402155faa30139ec9e1.zip |
Factor out tokenToContractKind
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 32 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 1 |
2 files changed, 18 insertions, 15 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 4cf6f0a6..b5130c8a 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -194,28 +194,30 @@ ASTPointer<ImportDirective> Parser::parseImportDirective() return nodeFactory.createNode<ImportDirective>(path, unitAlias, move(symbolAliases)); } -ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _expectedKind) +ContractDefinition::ContractKind Parser::tokenToContractKind(Token::Value _token) { - ASTNodeFactory nodeFactory(*this); - ASTPointer<ASTString> docString; - if (m_scanner->currentCommentLiteral() != "") - docString = make_shared<ASTString>(m_scanner->currentCommentLiteral()); - expectToken(_expectedKind); - ContractDefinition::ContractKind contractKind; - switch(_expectedKind) + switch(_token) { case Token::Interface: - contractKind = ContractDefinition::ContractKind::Interface; - break; + return ContractDefinition::ContractKind::Interface; case Token::Contract: - contractKind = ContractDefinition::ContractKind::Contract; - break; + return ContractDefinition::ContractKind::Contract; case Token::Library: - contractKind = ContractDefinition::ContractKind::Library; - break; + return ContractDefinition::ContractKind::Library; default: fatalParserError("Unsupported contract type."); } + // FIXME: fatalParserError is not considered as throwing here + return ContractDefinition::ContractKind::Contract; +} + +ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _expectedKind) +{ + ASTNodeFactory nodeFactory(*this); + ASTPointer<ASTString> docString; + if (m_scanner->currentCommentLiteral() != "") + docString = make_shared<ASTString>(m_scanner->currentCommentLiteral()); + expectToken(_expectedKind); ASTPointer<ASTString> name = expectIdentifierToken(); vector<ASTPointer<InheritanceSpecifier>> baseContracts; if (m_scanner->currentToken() == Token::Is) @@ -268,7 +270,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _exp docString, baseContracts, subNodes, - contractKind + tokenToContractKind(_expectedKind) ); } diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index bf972c65..282617ab 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -69,6 +69,7 @@ private: ///@name Parsing functions for the AST nodes ASTPointer<PragmaDirective> parsePragmaDirective(); ASTPointer<ImportDirective> parseImportDirective(); + ContractDefinition::ContractKind tokenToContractKind(Token::Value _token); ASTPointer<ContractDefinition> parseContractDefinition(Token::Value _expectedKind); ASTPointer<InheritanceSpecifier> parseInheritanceSpecifier(); Declaration::Visibility parseVisibilitySpecifier(Token::Value _token); |