Add ContractDefinition::isInterface.

This commit is contained in:
Daniel Kirchner 2019-01-17 12:59:11 +01:00
parent 7c07e94986
commit a766efc79f
4 changed files with 8 additions and 8 deletions

View File

@ -262,7 +262,7 @@ bool SyntaxChecker::visit(PlaceholderStatement const&)
bool SyntaxChecker::visit(ContractDefinition const& _contract)
{
m_isInterface = _contract.contractKind() == ContractDefinition::ContractKind::Interface;
m_isInterface = _contract.isInterface();
ASTString const& contractName = _contract.name();
for (FunctionDefinition const* function: _contract.definedFunctions())

View File

@ -204,7 +204,7 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
auto base = dynamic_cast<ContractDefinition const*>(&dereference(_inheritance.name()));
solAssert(base, "Base contract not available.");
if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface)
if (m_scope->isInterface())
m_errorReporter.typeError(_inheritance.location(), "Interfaces cannot inherit.");
if (base->isLibrary())
@ -212,7 +212,7 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
auto const& arguments = _inheritance.arguments();
TypePointers parameterTypes;
if (base->contractKind() != ContractDefinition::ContractKind::Interface)
if (!base->isInterface())
// Interfaces do not have constructors, so there are zero parameters.
parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
@ -325,7 +325,6 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
"This type is only supported in the new experimental ABI encoder. "
"Use \"pragma experimental ABIEncoderV2;\" to enable the feature."
);
var->accept(*this);
}
set<Declaration const*> modifiers;
@ -346,7 +345,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
else
modifiers.insert(decl);
}
if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface)
if (m_scope->isInterface())
{
if (_function.isImplemented())
m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot have an implementation.");
@ -375,7 +374,7 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
// * a function's input/output parameters,
// * or inside of a struct definition.
if (
m_scope->contractKind() == ContractDefinition::ContractKind::Interface
m_scope->isInterface()
&& !_variable.isCallableParameter()
&& !m_insideStruct
)
@ -1862,7 +1861,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
if (!contract)
m_errorReporter.fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
if (contract->contractKind() == ContractDefinition::ContractKind::Interface)
if (contract->isInterface())
m_errorReporter.fatalTypeError(_newExpression.location(), "Cannot instantiate an interface.");
if (!contract->annotation().unimplementedFunctions.empty())
{

View File

@ -394,6 +394,7 @@ public:
std::vector<FunctionDefinition const*> definedFunctions() const { return filteredNodes<FunctionDefinition>(m_subNodes); }
std::vector<EventDefinition const*> events() const { return filteredNodes<EventDefinition>(m_subNodes); }
std::vector<EventDefinition const*> const& interfaceEvents() const;
bool isInterface() const { return m_contractKind == ContractKind::Interface; }
bool isLibrary() const { return m_contractKind == ContractKind::Library; }
/// @returns a map of canonical function signatures to FunctionDefinitions

View File

@ -2525,7 +2525,7 @@ FunctionTypePointer FunctionType::newExpressionType(ContractDefinition const& _c
strings parameterNames;
StateMutability stateMutability = StateMutability::NonPayable;
solAssert(_contract.contractKind() != ContractDefinition::ContractKind::Interface, "");
solAssert(!_contract.isInterface(), "");
if (constructor)
{