aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
authorLiana Husikyan <liana@ethdev.com>2015-02-28 00:41:22 +0800
committerLiana Husikyan <liana@ethdev.com>2015-03-02 21:28:08 +0800
commite9238e15b4058bf9b84c3c9c59720f255843de75 (patch)
treea3dab94130e93a6223f86f31f623b6089b5e07d8 /AST.cpp
parent32e210eccad6ea951feaa3441a6aefb9938f8a90 (diff)
downloaddexon-solidity-e9238e15b4058bf9b84c3c9c59720f255843de75.tar.gz
dexon-solidity-e9238e15b4058bf9b84c3c9c59720f255843de75.tar.zst
dexon-solidity-e9238e15b4058bf9b84c3c9c59720f255843de75.zip
Implemented passing arguments to the base constructor.
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/AST.cpp b/AST.cpp
index 4c6db6a2..00660c5d 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -308,7 +308,9 @@ void FunctionDefinition::checkTypeRequirements()
if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
for (ASTPointer<ModifierInvocation> const& modifier: m_functionModifiers)
- modifier->checkTypeRequirements();
+ modifier->checkTypeRequirements(isConstructor() ?
+ dynamic_cast<ContractDefinition const&>(*getScope()).getBaseContracts() :
+ vector<ASTPointer<InheritanceSpecifier>>());
m_body->checkTypeRequirements();
}
@@ -351,19 +353,34 @@ void ModifierDefinition::checkTypeRequirements()
m_body->checkTypeRequirements();
}
-void ModifierInvocation::checkTypeRequirements()
+void ModifierInvocation::checkTypeRequirements(std::vector<ASTPointer<InheritanceSpecifier>> const& _bases)
{
m_modifierName->checkTypeRequirements();
for (ASTPointer<Expression> const& argument: m_arguments)
argument->checkTypeRequirements();
- ModifierDefinition const* modifier = dynamic_cast<ModifierDefinition const*>(m_modifierName->getReferencedDeclaration());
- solAssert(modifier, "Function modifier not found.");
- vector<ASTPointer<VariableDeclaration>> const& parameters = modifier->getParameters();
- if (parameters.size() != m_arguments.size())
+ auto declaration = m_modifierName->getReferencedDeclaration();
+ vector<ASTPointer<VariableDeclaration>> emptyParameterList;
+ vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr;
+ if (auto modifier = dynamic_cast<ModifierDefinition const*>(declaration))
+ parameters = &modifier->getParameters();
+ else
+ for (auto const& base: _bases)
+ if (declaration == base->getName()->getReferencedDeclaration())
+ {
+ m_referencedConstructor = dynamic_cast<ContractDefinition const&>(*declaration).getConstructor();
+ if (m_referencedConstructor)
+ parameters = &m_referencedConstructor->getParameters();
+ else
+ parameters = &emptyParameterList;
+ break;
+ }
+ if (!parameters)
+ BOOST_THROW_EXCEPTION(createTypeError("Referenced declaration is neither modifier nor base class."));
+ if (parameters->size() != m_arguments.size())
BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for modifier invocation."));
for (size_t i = 0; i < m_arguments.size(); ++i)
- if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameters[i]->getType()))
+ if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*(*parameters)[i]->getType()))
BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in modifier invocation."));
}