diff options
author | chriseth <chris@ethereum.org> | 2019-01-18 03:08:17 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2019-01-18 03:36:48 +0800 |
commit | a9fa2658d8690f18aa14c599a305cf59a5cd4e3c (patch) | |
tree | 7a22383ee804bee3b730db86adb2adf63240b600 | |
parent | 01ad4bffe7e16251efdf17121479369cabe5f993 (diff) | |
download | dexon-solidity-a9fa2658d8690f18aa14c599a305cf59a5cd4e3c.tar.gz dexon-solidity-a9fa2658d8690f18aa14c599a305cf59a5cd4e3c.tar.zst dexon-solidity-a9fa2658d8690f18aa14c599a305cf59a5cd4e3c.zip |
Add helper to show if contract can be deployed.
-rw-r--r-- | libsolidity/ast/AST.cpp | 5 | ||||
-rw-r--r-- | libsolidity/ast/AST.h | 4 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 2 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 6 |
4 files changed, 11 insertions, 6 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index f379d758..4cf8b1e8 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -138,6 +138,11 @@ bool ContractDefinition::constructorIsPublic() const return !f || f->isPublic(); } +bool ContractDefinition::canBeDeployed() const +{ + return constructorIsPublic() && annotation().unimplementedFunctions.empty(); +} + FunctionDefinition const* ContractDefinition::fallbackFunction() const { for (ContractDefinition const* contract: annotation().linearizedBaseContracts) diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 9ac065ea..cd986050 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -408,6 +408,10 @@ public: FunctionDefinition const* constructor() const; /// @returns true iff the constructor of this contract is public (or non-existing). bool constructorIsPublic() const; + /// @returns true iff the contract can be deployed, i.e. is not abstract and has a + /// public constructor. + /// Should only be called after the type checker has run. + bool canBeDeployed() const; /// Returns the fallback function or nullptr if no fallback function was specified. FunctionDefinition const* fallbackFunction() const; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 8f1fe491..081c7fb6 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -3423,7 +3423,7 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const "Only contracts supported for now" ); ContractDefinition const& contract = dynamic_cast<ContractType const&>(*m_typeArgument).contractDefinition(); - if (contract.annotation().unimplementedFunctions.empty() && contract.constructorIsPublic()) + if (contract.canBeDeployed()) return MemberList::MemberMap({ {"creationCode", std::make_shared<ArrayType>(DataLocation::Memory)}, {"runtimeCode", std::make_shared<ArrayType>(DataLocation::Memory)} diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index fc33f755..9e4da62d 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -800,11 +800,7 @@ void CompilerStack::compileContract( { solAssert(m_stackState >= AnalysisSuccessful, ""); - if ( - _otherCompilers.count(&_contract) || - !_contract.annotation().unimplementedFunctions.empty() || - !_contract.constructorIsPublic() - ) + if (_otherCompilers.count(&_contract) || !_contract.canBeDeployed()) return; for (auto const* dependency: _contract.annotation().contractDependencies) compileContract(*dependency, _otherCompilers); |