aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsolidity/parsing/Parser.cpp32
-rw-r--r--libsolidity/parsing/Parser.h1
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);