Move public constructor property into AST itself.

This commit is contained in:
chriseth 2017-03-06 14:12:20 +01:00
parent ca4e2933dd
commit f300bdb020
5 changed files with 10 additions and 6 deletions

View File

@ -77,8 +77,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
FunctionDefinition const* function = _contract.constructor(); FunctionDefinition const* function = _contract.constructor();
if (function) if (function)
{ {
if (!function->isPublic())
_contract.annotation().hasPublicConstructor = false;
if (!function->returnParameters().empty()) if (!function->returnParameters().empty())
typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
if (function->isDeclaredConst()) if (function->isDeclaredConst())
@ -1290,7 +1288,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
fatalTypeError(_newExpression.location(), "Identifier is not a contract."); fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
if (!contract->annotation().isFullyImplemented) if (!contract->annotation().isFullyImplemented)
typeError(_newExpression.location(), "Trying to create an instance of an abstract contract."); typeError(_newExpression.location(), "Trying to create an instance of an abstract contract.");
if (!contract->annotation().hasPublicConstructor) if (!contract->constructorIsPublic())
typeError(_newExpression.location(), "Contract with internal constructor cannot be created directly."); typeError(_newExpression.location(), "Contract with internal constructor cannot be created directly.");
solAssert(!!m_scope, ""); solAssert(!!m_scope, "");

View File

@ -132,6 +132,12 @@ FunctionDefinition const* ContractDefinition::constructor() const
return nullptr; return nullptr;
} }
bool ContractDefinition::constructorIsPublic() const
{
FunctionDefinition const* f = constructor();
return !f || f->isPublic();
}
FunctionDefinition const* ContractDefinition::fallbackFunction() const FunctionDefinition const* ContractDefinition::fallbackFunction() const
{ {
for (ContractDefinition const* contract: annotation().linearizedBaseContracts) for (ContractDefinition const* contract: annotation().linearizedBaseContracts)

View File

@ -356,6 +356,8 @@ public:
/// Returns the constructor or nullptr if no constructor was specified. /// Returns the constructor or nullptr if no constructor was specified.
FunctionDefinition const* constructor() const; FunctionDefinition const* constructor() const;
/// @returns true iff the constructor of this contract is public (or non-existing).
bool constructorIsPublic() const;
/// Returns the fallback function or nullptr if no fallback function was specified. /// Returns the fallback function or nullptr if no fallback function was specified.
FunctionDefinition const* fallbackFunction() const; FunctionDefinition const* fallbackFunction() const;

View File

@ -80,8 +80,6 @@ struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnota
{ {
/// Whether all functions are implemented. /// Whether all functions are implemented.
bool isFullyImplemented = true; bool isFullyImplemented = true;
/// Whether a public constructor (even the default one) is available.
bool hasPublicConstructor = true;
/// List of all (direct and indirect) base contracts in order from derived to /// List of all (direct and indirect) base contracts in order from derived to
/// base, including the contract itself. /// base, including the contract itself.
std::vector<ContractDefinition const*> linearizedBaseContracts; std::vector<ContractDefinition const*> linearizedBaseContracts;

View File

@ -628,7 +628,7 @@ void CompilerStack::compileContract(
if ( if (
_compiledContracts.count(&_contract) || _compiledContracts.count(&_contract) ||
!_contract.annotation().isFullyImplemented || !_contract.annotation().isFullyImplemented ||
!_contract.annotation().hasPublicConstructor !_contract.constructorIsPublic()
) )
return; return;
for (auto const* dependency: _contract.annotation().contractDependencies) for (auto const* dependency: _contract.annotation().contractDependencies)