diff options
author | chriseth <chris@ethereum.org> | 2017-08-22 18:43:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-22 18:43:19 +0800 |
commit | f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4 (patch) | |
tree | fb0f04a445940004a8a45e03bc98d149c5cc71a7 /libevmasm | |
parent | 2c2ae74217521aae93b9c7b058ce8687046c648c (diff) | |
parent | 9897c56b2cacf162f8fd41d60e91b7f71863f8d5 (diff) | |
download | dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.tar dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.tar.gz dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.tar.bz2 dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.tar.lz dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.tar.xz dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.tar.zst dexon-solidity-f874fc28d1cb657b6d4e04fa9d93bd8d061f30c4.zip |
Merge pull request #2772 from ethereum/cppcheck
Improvements found by Cppcheck (const/static functions and explicit constructors)
Diffstat (limited to 'libevmasm')
-rw-r--r-- | libevmasm/BlockDeduplicator.h | 2 | ||||
-rw-r--r-- | libevmasm/CommonSubexpressionEliminator.h | 2 | ||||
-rw-r--r-- | libevmasm/ConstantOptimiser.cpp | 10 | ||||
-rw-r--r-- | libevmasm/ConstantOptimiser.h | 24 | ||||
-rw-r--r-- | libevmasm/PathGasMeter.h | 2 |
5 files changed, 20 insertions, 20 deletions
diff --git a/libevmasm/BlockDeduplicator.h b/libevmasm/BlockDeduplicator.h index 797c2476..5640984b 100644 --- a/libevmasm/BlockDeduplicator.h +++ b/libevmasm/BlockDeduplicator.h @@ -45,7 +45,7 @@ using AssemblyItems = std::vector<AssemblyItem>; class BlockDeduplicator { public: - BlockDeduplicator(AssemblyItems& _items): m_items(_items) {} + explicit BlockDeduplicator(AssemblyItems& _items): m_items(_items) {} /// @returns true if something was changed bool deduplicate(); /// @returns the tags that were replaced. diff --git a/libevmasm/CommonSubexpressionEliminator.h b/libevmasm/CommonSubexpressionEliminator.h index 83fc9732..f2473200 100644 --- a/libevmasm/CommonSubexpressionEliminator.h +++ b/libevmasm/CommonSubexpressionEliminator.h @@ -61,7 +61,7 @@ public: using Id = ExpressionClasses::Id; using StoreOperation = KnownState::StoreOperation; - CommonSubexpressionEliminator(KnownState const& _state): m_initialState(_state), m_state(_state) {} + explicit CommonSubexpressionEliminator(KnownState const& _state): m_initialState(_state), m_state(_state) {} /// Feeds AssemblyItems into the eliminator and @returns the iterator pointing at the first /// item that must be fed into a new instance of the eliminator. diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp index 2ecbfa7f..2efd2dc9 100644 --- a/libevmasm/ConstantOptimiser.cpp +++ b/libevmasm/ConstantOptimiser.cpp @@ -124,7 +124,7 @@ void ConstantOptimisationMethod::replaceConstants( _items = std::move(replaced); } -bigint LiteralMethod::gasNeeded() +bigint LiteralMethod::gasNeeded() const { return combineGas( simpleRunGas({Instruction::PUSH1}), @@ -139,7 +139,7 @@ CodeCopyMethod::CodeCopyMethod(Params const& _params, u256 const& _value): { } -bigint CodeCopyMethod::gasNeeded() +bigint CodeCopyMethod::gasNeeded() const { return combineGas( // Run gas: we ignore memory increase costs @@ -151,7 +151,7 @@ bigint CodeCopyMethod::gasNeeded() ); } -AssemblyItems CodeCopyMethod::execute(Assembly& _assembly) +AssemblyItems CodeCopyMethod::execute(Assembly& _assembly) const { bytes data = toBigEndian(m_value); AssemblyItems actualCopyRoutine = copyRoutine(); @@ -159,7 +159,7 @@ AssemblyItems CodeCopyMethod::execute(Assembly& _assembly) return actualCopyRoutine; } -AssemblyItems const& CodeCopyMethod::copyRoutine() const +AssemblyItems const& CodeCopyMethod::copyRoutine() { AssemblyItems static copyRoutine{ u256(0), @@ -282,7 +282,7 @@ bool ComputeMethod::checkRepresentation(u256 const& _value, AssemblyItems const& return stack.size() == 1 && stack.front() == _value; } -bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine) +bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine) const { size_t numExps = count(_routine.begin(), _routine.end(), Instruction::EXP); return combineGas( diff --git a/libevmasm/ConstantOptimiser.h b/libevmasm/ConstantOptimiser.h index 85bdabac..82982e25 100644 --- a/libevmasm/ConstantOptimiser.h +++ b/libevmasm/ConstantOptimiser.h @@ -63,11 +63,11 @@ public: explicit ConstantOptimisationMethod(Params const& _params, u256 const& _value): m_params(_params), m_value(_value) {} - virtual bigint gasNeeded() = 0; + virtual bigint gasNeeded() const = 0; /// Executes the method, potentially appending to the assembly and returns a vector of /// assembly items the constant should be relpaced with in one sweep. /// If the vector is empty, the constants will not be deleted. - virtual AssemblyItems execute(Assembly& _assembly) = 0; + virtual AssemblyItems execute(Assembly& _assembly) const = 0; protected: size_t dataSize() const { return std::max<size_t>(1, dev::bytesRequired(m_value)); } @@ -84,7 +84,7 @@ protected: bigint const& _runGas, bigint const& _repeatedDataGas, bigint const& _uniqueDataGas - ) + ) const { // _runGas is not multiplied by _multiplicity because the runs are "per opcode" return m_params.runs * _runGas + m_params.multiplicity * _repeatedDataGas + _uniqueDataGas; @@ -106,8 +106,8 @@ class LiteralMethod: public ConstantOptimisationMethod public: explicit LiteralMethod(Params const& _params, u256 const& _value): ConstantOptimisationMethod(_params, _value) {} - virtual bigint gasNeeded() override; - virtual AssemblyItems execute(Assembly&) override { return AssemblyItems{}; } + virtual bigint gasNeeded() const override; + virtual AssemblyItems execute(Assembly&) const override { return AssemblyItems{}; } }; /** @@ -117,11 +117,11 @@ class CodeCopyMethod: public ConstantOptimisationMethod { public: explicit CodeCopyMethod(Params const& _params, u256 const& _value); - virtual bigint gasNeeded() override; - virtual AssemblyItems execute(Assembly& _assembly) override; + virtual bigint gasNeeded() const override; + virtual AssemblyItems execute(Assembly& _assembly) const override; protected: - AssemblyItems const& copyRoutine() const; + static AssemblyItems const& copyRoutine(); }; /** @@ -141,8 +141,8 @@ public: ); } - virtual bigint gasNeeded() override { return gasNeeded(m_routine); } - virtual AssemblyItems execute(Assembly&) override + virtual bigint gasNeeded() const override { return gasNeeded(m_routine); } + virtual AssemblyItems execute(Assembly&) const override { return m_routine; } @@ -151,8 +151,8 @@ protected: /// Tries to recursively find a way to compute @a _value. AssemblyItems findRepresentation(u256 const& _value); /// Recomputes the value from the calculated representation and checks for correctness. - bool checkRepresentation(u256 const& _value, AssemblyItems const& _routine); - bigint gasNeeded(AssemblyItems const& _routine); + static bool checkRepresentation(u256 const& _value, AssemblyItems const& _routine); + bigint gasNeeded(AssemblyItems const& _routine) const; /// Counter for the complexity of optimization, will stop when it reaches zero. size_t m_maxSteps = 10000; diff --git a/libevmasm/PathGasMeter.h b/libevmasm/PathGasMeter.h index 0a0fe5d0..4826eac2 100644 --- a/libevmasm/PathGasMeter.h +++ b/libevmasm/PathGasMeter.h @@ -50,7 +50,7 @@ struct GasPath class PathGasMeter { public: - PathGasMeter(AssemblyItems const& _items); + explicit PathGasMeter(AssemblyItems const& _items); GasMeter::GasConsumption estimateMax(size_t _startIndex, std::shared_ptr<KnownState> const& _state); |