aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/Parser.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-03-22 00:54:05 +0800
committerGitHub <noreply@github.com>2017-03-22 00:54:05 +0800
commit6fb27dee635748110a27654a5a2c322d865b8578 (patch)
tree67b44c12852f074d93497d8f7129b95d89e43c73 /libsolidity/parsing/Parser.cpp
parent2cde2f9203f05b26bc0ffa45cb77c84a991f7d76 (diff)
parent5ced3af3a0579e4e0d5e0d923b3e9d3f21197bfa (diff)
downloaddexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.gz
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.zst
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.zip
Merge pull request #1688 from ethereum/interface-keyword
Support strict interface contracts
Diffstat (limited to 'libsolidity/parsing/Parser.cpp')
-rw-r--r--libsolidity/parsing/Parser.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index e26e2908..b5130c8a 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -82,9 +82,10 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
case Token::Import:
nodes.push_back(parseImportDirective());
break;
+ case Token::Interface:
case Token::Contract:
case Token::Library:
- nodes.push_back(parseContractDefinition(token == Token::Library));
+ nodes.push_back(parseContractDefinition(token));
break;
default:
fatalParserError(string("Expected import directive or contract definition."));
@@ -193,13 +194,30 @@ ASTPointer<ImportDirective> Parser::parseImportDirective()
return nodeFactory.createNode<ImportDirective>(path, unitAlias, move(symbolAliases));
}
-ASTPointer<ContractDefinition> Parser::parseContractDefinition(bool _isLibrary)
+ContractDefinition::ContractKind Parser::tokenToContractKind(Token::Value _token)
+{
+ switch(_token)
+ {
+ case Token::Interface:
+ return ContractDefinition::ContractKind::Interface;
+ case Token::Contract:
+ return ContractDefinition::ContractKind::Contract;
+ case Token::Library:
+ 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(_isLibrary ? Token::Library : Token::Contract);
+ expectToken(_expectedKind);
ASTPointer<ASTString> name = expectIdentifierToken();
vector<ASTPointer<InheritanceSpecifier>> baseContracts;
if (m_scanner->currentToken() == Token::Is)
@@ -252,7 +270,7 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition(bool _isLibrary)
docString,
baseContracts,
subNodes,
- _isLibrary
+ tokenToContractKind(_expectedKind)
);
}