aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-03-06 21:12:20 +0800
committerchriseth <c@ethdev.com>2017-03-06 21:12:42 +0800
commitf300bdb020ca55b05f1725dc2157fb636c1e4801 (patch)
tree25bbe9e6a2e8f9196236b3650939f2ddec71cf63 /libsolidity
parentca4e2933dd9b149653070815dd6255e3b8735d6d (diff)
downloaddexon-solidity-f300bdb020ca55b05f1725dc2157fb636c1e4801.tar.gz
dexon-solidity-f300bdb020ca55b05f1725dc2157fb636c1e4801.tar.zst
dexon-solidity-f300bdb020ca55b05f1725dc2157fb636c1e4801.zip
Move public constructor property into AST itself.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp4
-rw-r--r--libsolidity/ast/AST.cpp6
-rw-r--r--libsolidity/ast/AST.h2
-rw-r--r--libsolidity/ast/ASTAnnotations.h2
-rw-r--r--libsolidity/interface/CompilerStack.cpp2
5 files changed, 10 insertions, 6 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index ff55ef1f..a9a2c82f 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -77,8 +77,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
FunctionDefinition const* function = _contract.constructor();
if (function)
{
- if (!function->isPublic())
- _contract.annotation().hasPublicConstructor = false;
if (!function->returnParameters().empty())
typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
if (function->isDeclaredConst())
@@ -1290,7 +1288,7 @@ void TypeChecker::endVisit(NewExpression const& _newExpression)
fatalTypeError(_newExpression.location(), "Identifier is not a contract.");
if (!contract->annotation().isFullyImplemented)
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.");
solAssert(!!m_scope, "");
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index 8d137bac..03112d2d 100644
--- a/libsolidity/ast/AST.cpp
+++ b/libsolidity/ast/AST.cpp
@@ -132,6 +132,12 @@ FunctionDefinition const* ContractDefinition::constructor() const
return nullptr;
}
+bool ContractDefinition::constructorIsPublic() const
+{
+ FunctionDefinition const* f = constructor();
+ return !f || f->isPublic();
+}
+
FunctionDefinition const* ContractDefinition::fallbackFunction() const
{
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index 743fdaa1..8031760d 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -356,6 +356,8 @@ public:
/// Returns the constructor or nullptr if no constructor was specified.
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.
FunctionDefinition const* fallbackFunction() const;
diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h
index 61e97a55..9c4c3ae8 100644
--- a/libsolidity/ast/ASTAnnotations.h
+++ b/libsolidity/ast/ASTAnnotations.h
@@ -80,8 +80,6 @@ struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnota
{
/// Whether all functions are implemented.
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
/// base, including the contract itself.
std::vector<ContractDefinition const*> linearizedBaseContracts;
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 9d8d872f..edfca094 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -628,7 +628,7 @@ void CompilerStack::compileContract(
if (
_compiledContracts.count(&_contract) ||
!_contract.annotation().isFullyImplemented ||
- !_contract.annotation().hasPublicConstructor
+ !_contract.constructorIsPublic()
)
return;
for (auto const* dependency: _contract.annotation().contractDependencies)