From 0a632011be455d108eebc8a338346cfa2d40e527 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Jun 2018 17:04:22 +0200 Subject: CompilerStack absolutePath/sanitizePath can be made static --- libsolidity/interface/CompilerStack.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 13c9cc7a..018c61ec 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -273,9 +273,9 @@ private: std::string applyRemapping(std::string const& _path, std::string const& _context); void resolveImports(); /// @returns the absolute path corresponding to @a _path relative to @a _reference. - std::string absolutePath(std::string const& _path, std::string const& _reference) const; + static std::string absolutePath(std::string const& _path, std::string const& _reference); /// Helper function to return path converted strings. - std::string sanitizePath(std::string const& _path) const { return boost::filesystem::path(_path).generic_string(); } + static std::string sanitizePath(std::string const& _path) { return boost::filesystem::path(_path).generic_string(); } /// @returns true if the contract is requested to be compiled. bool isRequestedContract(ContractDefinition const& _contract) const; -- cgit v1.2.3 From 3fc7da11db2b03e63a66e22b72df2d18e534c4e9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 22 Jun 2018 12:02:50 +0200 Subject: Pull out createCBORMetadata helper --- libsolidity/interface/CompilerStack.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 018c61ec..baaeafa0 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -295,6 +295,8 @@ private: ContractDefinition const& contractDefinition(std::string const& _contractName) const; std::string createMetadata(Contract const& _contract) const; + /// @returns the metadata CBOR for the given serialised metadata JSON. + static bytes createCBORMetadata(std::string _metadata, bool _experimentalMode); std::string computeSourceMapping(eth::AssemblyItems const& _items) const; Json::Value const& contractABI(Contract const&) const; Json::Value const& natspecUser(Contract const&) const; -- cgit v1.2.3 From 5aa8c7ed1a82c80fd556ef474079cf6fffea7f97 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Jun 2018 21:46:31 +0200 Subject: Document the internal API of CompilerStack --- libsolidity/interface/CompilerStack.h | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index baaeafa0..4359c3fa 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -122,6 +122,8 @@ public: m_optimizeRuns = _runs; } + /// Set the EVM version used before running compile. + /// When called without an argument it will revert to the default version. void setEVMVersion(EVMVersion _version = EVMVersion{}); /// Sets the list of requested contract names. If empty, no filtering is performed and every contract @@ -240,9 +242,7 @@ public: Json::Value gasEstimates(std::string const& _contractName) const; private: - /** - * Information pertaining to one source unit, filled gradually during parsing and compilation. - */ + /// The state per source unit. Filled gradually during parsing. struct Source { std::shared_ptr scanner; @@ -251,13 +251,14 @@ private: void reset() { scanner.reset(); ast.reset(); } }; + /// The state per contract. Filled gradually during compilation. struct Contract { ContractDefinition const* contract = nullptr; std::shared_ptr compiler; - eth::LinkerObject object; - eth::LinkerObject runtimeObject; - eth::LinkerObject cloneObject; + eth::LinkerObject object; ///< Deployment object (includes the runtime sub-object). + eth::LinkerObject runtimeObject; ///< Runtime object. + eth::LinkerObject cloneObject; ///< Clone object (deprecated). std::string metadata; ///< The metadata json that will be hashed into the chain. mutable std::unique_ptr abi; mutable std::unique_ptr userDocumentation; @@ -272,8 +273,10 @@ private: StringMap loadMissingSources(SourceUnit const& _ast, std::string const& _path); std::string applyRemapping(std::string const& _path, std::string const& _context); void resolveImports(); + /// @returns the absolute path corresponding to @a _path relative to @a _reference. static std::string absolutePath(std::string const& _path, std::string const& _reference); + /// Helper function to return path converted strings. static std::string sanitizePath(std::string const& _path) { return boost::filesystem::path(_path).generic_string(); } @@ -285,21 +288,42 @@ private: ContractDefinition const& _contract, std::map& _compiledContracts ); + + /// Links all the known library addresses in the available objects. Any unknown + /// library will still be kept as an unlinked placeholder in the objects. void link(); + /// @returns the contract object for the given @a _contractName. + /// Can only be called after state is CompilationSuccessful. Contract const& contract(std::string const& _contractName) const; + + /// @returns the source object for the given @a _sourceName. + /// Can only be called after state is SourcesSet. Source const& source(std::string const& _sourceName) const; /// @returns the parsed contract with the supplied name. Throws an exception if the contract /// does not exist. ContractDefinition const& contractDefinition(std::string const& _contractName) const; + /// @returns the metadata JSON as a compact string for the given contract. std::string createMetadata(Contract const& _contract) const; + /// @returns the metadata CBOR for the given serialised metadata JSON. static bytes createCBORMetadata(std::string _metadata, bool _experimentalMode); + + /// @returns the computer source mapping string. std::string computeSourceMapping(eth::AssemblyItems const& _items) const; + + /// @returns the contract ABI as a JSON object. + /// This will generate the JSON object and store it in the Contract object if it is not present yet. Json::Value const& contractABI(Contract const&) const; + + /// @returns the Natspec User documentation as a JSON object. + /// This will generate the JSON object and store it in the Contract object if it is not present yet. Json::Value const& natspecUser(Contract const&) const; + + /// @returns the Natspec Developer documentation as a JSON object. + /// This will generate the JSON object and store it in the Contract object if it is not present yet. Json::Value const& natspecDev(Contract const&) const; /// @returns the offset of the entry point of the given function into the list of assembly items -- cgit v1.2.3 From 140dbfdbd8f4319d1d02339feea0a8636a3738e5 Mon Sep 17 00:00:00 2001 From: Cryptomental Date: Tue, 10 Jul 2018 09:18:59 +0200 Subject: Code, Changelog, ReleaseChecklist: Fix typos. Refs: #4442 --- libsolidity/interface/CompilerStack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 4359c3fa..0578ac86 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -93,7 +93,7 @@ public: m_errorList(), m_errorReporter(m_errorList) {} - /// @returns the list of errors that occured during parsing and type checking. + /// @returns the list of errors that occurred during parsing and type checking. ErrorList const& errors() const { return m_errorReporter.errors(); } /// @returns the current state. -- cgit v1.2.3 From f74cff622dd0eb8d4e64c014731e00fb9ea1d078 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 19 Jun 2018 19:30:38 +0200 Subject: Properly explain all the analsys steps in CompilerStack --- libsolidity/interface/CompilerStack.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 0578ac86..7b144660 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -352,8 +352,9 @@ private: std::vector m_remappings; std::map m_sources; std::shared_ptr m_globalContext; - std::map> m_scopes; std::vector m_sourceOrder; + /// This is updated during compilation. + std::map> m_scopes; std::map m_contracts; ErrorList m_errorList; ErrorReporter m_errorReporter; -- cgit v1.2.3 From 3de0b8b7f002bdc76e629f89df73523b36a169f5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 27 Jun 2018 18:08:49 +0200 Subject: Move absolutePath/sanitizePath helpers from CompilerStack to libdevcore --- libsolidity/interface/CompilerStack.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 7b144660..fa9fe9b0 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -36,7 +36,6 @@ #include #include -#include #include #include @@ -274,12 +273,6 @@ private: std::string applyRemapping(std::string const& _path, std::string const& _context); void resolveImports(); - /// @returns the absolute path corresponding to @a _path relative to @a _reference. - static std::string absolutePath(std::string const& _path, std::string const& _reference); - - /// Helper function to return path converted strings. - static std::string sanitizePath(std::string const& _path) { return boost::filesystem::path(_path).generic_string(); } - /// @returns true if the contract is requested to be compiled. bool isRequestedContract(ContractDefinition const& _contract) const; -- cgit v1.2.3 From 71e26f6adb7d6b28400a6607570bb1e17da24feb Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Aug 2018 18:32:18 +0200 Subject: Remove clone feature. --- libsolidity/interface/CompilerStack.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 7b144660..b7d07ca7 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -190,12 +190,6 @@ public: /// @returns the runtime object for the contract. eth::LinkerObject const& runtimeObject(std::string const& _contractName) const; - /// @returns the bytecode of a contract that uses an already deployed contract via DELEGATECALL. - /// The returned bytes will contain a sequence of 20 bytes of the format "XXX...XXX" which have to - /// substituted by the actual address. Note that this sequence starts end ends in three X - /// characters but can contain anything in between. - eth::LinkerObject const& cloneObject(std::string const& _contractName) const; - /// @returns normal contract assembly items eth::AssemblyItems const* assemblyItems(std::string const& _contractName) const; @@ -258,7 +252,6 @@ private: std::shared_ptr compiler; eth::LinkerObject object; ///< Deployment object (includes the runtime sub-object). eth::LinkerObject runtimeObject; ///< Runtime object. - eth::LinkerObject cloneObject; ///< Clone object (deprecated). std::string metadata; ///< The metadata json that will be hashed into the chain. mutable std::unique_ptr abi; mutable std::unique_ptr userDocumentation; -- cgit v1.2.3 From 954d7433bd8c10bce917326f70070077f0cfc165 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 9 Aug 2018 20:37:49 +0200 Subject: Disallow remappings with empty prefix. --- libsolidity/interface/CompilerStack.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'libsolidity/interface/CompilerStack.h') diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 2234a8c9..9a15fbf0 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -84,6 +84,13 @@ public: CompilationSuccessful }; + struct Remapping + { + std::string context; + std::string prefix; + std::string target; + }; + /// Creates a new compiler stack. /// @param _readFile callback to used to read files for import statements. Must return /// and must not emit exceptions. @@ -103,8 +110,11 @@ public: /// All settings, with the exception of remappings, are reset. void reset(bool _keepSources = false); - /// Sets path remappings in the format "context:prefix=target" - void setRemappings(std::vector const& _remappings); + // Parses a remapping of the format "context:prefix=target". + static boost::optional parseRemapping(std::string const& _remapping); + + /// Sets path remappings. + void setRemappings(std::vector const& _remappings); /// Sets library addresses. Addresses are cleared iff @a _libraries is missing. /// Will not take effect before running compile. @@ -319,13 +329,6 @@ private: FunctionDefinition const& _function ) const; - struct Remapping - { - std::string context; - std::string prefix; - std::string target; - }; - ReadCallback::Callback m_readFile; ReadCallback::Callback m_smtQuery; bool m_optimize = false; -- cgit v1.2.3