diff options
author | chriseth <chris@ethereum.org> | 2018-11-30 01:36:26 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-11-30 23:30:20 +0800 |
commit | 33d6a24c47f4cfd95e8bb880d5254fb7dd6ea21a (patch) | |
tree | 310438d5e1cc0aceb60ed07c9a9a9428787dff45 /libsolidity/analysis | |
parent | 4f992298c6381b3c7ea41462bce749850b5846e5 (diff) | |
download | dexon-solidity-33d6a24c47f4cfd95e8bb880d5254fb7dd6ea21a.tar.gz dexon-solidity-33d6a24c47f4cfd95e8bb880d5254fb7dd6ea21a.tar.zst dexon-solidity-33d6a24c47f4cfd95e8bb880d5254fb7dd6ea21a.zip |
Move library related checks.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.cpp | 14 | ||||
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.h | 2 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 14 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 2 |
4 files changed, 16 insertions, 16 deletions
diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index 419ebe93..58dcfe4d 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -44,6 +44,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract) checkFallbackFunction(_contract); checkExternalTypeClashes(_contract); checkHashCollisions(_contract); + checkLibraryRequirements(_contract); return Error::containsOnlyWarnings(m_errorReporter.errors()); } @@ -436,3 +437,16 @@ void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contra hashes.insert(hash); } } + +void ContractLevelChecker::checkLibraryRequirements(ContractDefinition const& _contract) +{ + if (!_contract.isLibrary()) + return; + + if (!_contract.baseContracts().empty()) + m_errorReporter.typeError(_contract.location(), "Library is not allowed to inherit."); + + for (auto const& var: _contract.stateVariables()) + if (!var->isConstant()) + m_errorReporter.typeError(var->location(), "Library cannot have non-constant state variables"); +} diff --git a/libsolidity/analysis/ContractLevelChecker.h b/libsolidity/analysis/ContractLevelChecker.h index f930fb60..15cbf45d 100644 --- a/libsolidity/analysis/ContractLevelChecker.h +++ b/libsolidity/analysis/ContractLevelChecker.h @@ -77,6 +77,8 @@ private: void checkExternalTypeClashes(ContractDefinition const& _contract); /// Checks for hash collisions in external function signatures. void checkHashCollisions(ContractDefinition const& _contract); + /// Checks that all requirements for a library are fulfilled if this is a library. + void checkLibraryRequirements(ContractDefinition const& _contract); langutil::ErrorReporter& m_errorReporter; }; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index e411609c..9350df05 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -93,23 +93,9 @@ bool TypeChecker::visit(ContractDefinition const& _contract) for (auto const& n: _contract.subNodes()) n->accept(*this); - if (_contract.isLibrary()) - checkLibraryRequirements(_contract); - return false; } -void TypeChecker::checkLibraryRequirements(ContractDefinition const& _contract) -{ - solAssert(_contract.isLibrary(), ""); - if (!_contract.baseContracts().empty()) - m_errorReporter.typeError(_contract.location(), "Library is not allowed to inherit."); - - for (auto const& var: _contract.stateVariables()) - if (!var->isConstant()) - m_errorReporter.typeError(var->location(), "Library cannot have non-constant state variables"); -} - void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment) { TupleType const& lhs = dynamic_cast<TupleType const&>(*type(_assignment.leftHandSide())); diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index aabda33c..ebfcdadc 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -66,8 +66,6 @@ public: private: bool visit(ContractDefinition const& _contract) override; - /// Checks that all requirements for a library are fulfilled if this is a library. - void checkLibraryRequirements(ContractDefinition const& _contract); /// Checks (and warns) if a tuple assignment might cause unexpected overwrites in storage. /// Should only be called if the left hand side is tuple-typed. void checkDoubleStorageAssignment(Assignment const& _assignment); |