From c212d7c2e6b16063191d85471871eeddf0e6510d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 1 Jun 2017 13:28:05 +0100 Subject: [PATCH 1/2] Remove unused functions from CompilerStack --- libsolidity/interface/CompilerStack.cpp | 35 ------------------------- libsolidity/interface/CompilerStack.h | 13 --------- 2 files changed, 48 deletions(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 442204023..c3fcc1ef2 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -400,15 +400,6 @@ eth::LinkerObject const& CompilerStack::cloneObject(string const& _contractName) return contract(_contractName).cloneObject; } -dev::h256 CompilerStack::contractCodeHash(string const& _contractName) const -{ - auto const& obj = runtimeObject(_contractName); - if (obj.bytecode.empty() || !obj.linkReferences.empty()) - return dev::h256(); - else - return dev::keccak256(obj.bytecode); -} - Json::Value CompilerStack::streamAssembly(ostream& _outStream, string const& _contractName, StringMap _sourceCodes, bool _inJsonFormat) const { Contract const& currentContract = contract(_contractName); @@ -522,24 +513,6 @@ ContractDefinition const& CompilerStack::contractDefinition(string const& _contr return *contract(_contractName).contract; } -size_t CompilerStack::functionEntryPoint( - std::string const& _contractName, - FunctionDefinition const& _function -) const -{ - shared_ptr const& compiler = contract(_contractName).compiler; - if (!compiler) - return 0; - eth::AssemblyItem tag = compiler->functionEntryLabel(_function); - if (tag.type() == eth::UndefinedItem) - return 0; - eth::AssemblyItems const& items = compiler->runtimeAssemblyItems(); - for (size_t i = 0; i < items.size(); ++i) - if (items.at(i).type() == eth::Tag && items.at(i).data() == tag.data()) - return i; - return 0; -} - tuple CompilerStack::positionFromSourceLocation(SourceLocation const& _sourceLocation) const { int startLine; @@ -744,14 +717,6 @@ void CompilerStack::compileContract( } } -std::string CompilerStack::defaultContractName() const -{ - if (m_stackState != CompilationSuccessful) - BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Compilation was not successful.")); - - return contract("").contract->name(); -} - CompilerStack::Contract const& CompilerStack::contract(string const& _contractName) const { if (m_contracts.empty()) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 76d36c7be..d97b3960f 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -117,7 +117,6 @@ public: bool parseAndAnalyze(std::string const& _sourceCode); /// @returns a list of the contract names in the sources. std::vector contractNames() const; - std::string defaultContractName() const; /// Compiles the source units that were previously added and parsed. /// @returns false on error. @@ -159,11 +158,6 @@ public: /// @returns either the contract's name or a mixture of its name and source file, sanitized for filesystem use std::string const filesystemFriendlyName(std::string const& _contractName) const; - /// @returns hash of the runtime bytecode for the contract, i.e. the code that is - /// returned by the constructor or the zero-h256 if the contract still needs to be linked or - /// does not have runtime code. - dev::h256 contractCodeHash(std::string const& _contractName = "") const; - /// Streams a verbose version of the assembly to @a _outStream. /// @arg _sourceCodes is the map of input files to source code strings /// @arg _inJsonFromat shows whether the out should be in Json format @@ -197,13 +191,6 @@ public: /// does not exist. ContractDefinition const& contractDefinition(std::string const& _contractName) const; - /// @returns the offset of the entry point of the given function into the list of assembly items - /// or zero if it is not found or does not exist. - size_t functionEntryPoint( - std::string const& _contractName, - FunctionDefinition const& _function - ) const; - /// Helper function for logs printing. Do only use in error cases, it's quite expensive. /// line and columns are numbered starting from 1 with following order: /// start line, start column, end line, end column From 998ca552b8966d67bbbc7482e972563efade9a80 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 1 Jun 2017 13:28:32 +0100 Subject: [PATCH 2/2] Fix state after CompilerStack.reset() --- libsolidity/interface/CompilerStack.cpp | 20 +++++++++++++++++++- libsolidity/interface/CompilerStack.h | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index c3fcc1ef2..aca9ce39e 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -85,6 +85,7 @@ void CompilerStack::reset(bool _keepSources) } else { + m_stackState = Empty; m_sources.clear(); } m_optimize = false; @@ -94,7 +95,6 @@ void CompilerStack::reset(bool _keepSources) m_sourceOrder.clear(); m_contracts.clear(); m_errorReporter.clear(); - m_stackState = Empty; } bool CompilerStack::addSource(string const& _name, string const& _content, bool _isLibrary) @@ -513,6 +513,24 @@ ContractDefinition const& CompilerStack::contractDefinition(string const& _contr return *contract(_contractName).contract; } +size_t CompilerStack::functionEntryPoint( + std::string const& _contractName, + FunctionDefinition const& _function +) const +{ + shared_ptr const& compiler = contract(_contractName).compiler; + if (!compiler) + return 0; + eth::AssemblyItem tag = compiler->functionEntryLabel(_function); + if (tag.type() == eth::UndefinedItem) + return 0; + eth::AssemblyItems const& items = compiler->runtimeAssemblyItems(); + for (size_t i = 0; i < items.size(); ++i) + if (items.at(i).type() == eth::Tag && items.at(i).data() == tag.data()) + return i; + return 0; +} + tuple CompilerStack::positionFromSourceLocation(SourceLocation const& _sourceLocation) const { int startLine; diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index d97b3960f..bffdeabd4 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -259,6 +259,13 @@ private: Json::Value const& contractABI(Contract const&) const; Json::Value const& natspec(Contract const&, DocumentationType _type) const; + /// @returns the offset of the entry point of the given function into the list of assembly items + /// or zero if it is not found or does not exist. + size_t functionEntryPoint( + std::string const& _contractName, + FunctionDefinition const& _function + ) const; + struct Remapping { std::string context;