diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-11-15 09:04:00 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2016-11-15 23:55:25 +0800 |
commit | 9719cf38e662e428ace8f3ebce9774a5338f0ce5 (patch) | |
tree | 07e441be8419b3161cedf449c2808bee082fe539 /libsolidity | |
parent | 0072160d7772b2f30c2c6af4428728cb31641696 (diff) | |
download | dexon-solidity-9719cf38e662e428ace8f3ebce9774a5338f0ce5.tar.gz dexon-solidity-9719cf38e662e428ace8f3ebce9774a5338f0ce5.tar.zst dexon-solidity-9719cf38e662e428ace8f3ebce9774a5338f0ce5.zip |
Move InterfaceHandler from string to JSON
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/AST.cpp | 8 | ||||
-rw-r--r-- | libsolidity/ast/AST.h | 13 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 8 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 14 | ||||
-rw-r--r-- | libsolidity/interface/InterfaceHandler.cpp | 17 | ||||
-rw-r--r-- | libsolidity/interface/InterfaceHandler.h | 16 |
6 files changed, 37 insertions, 39 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index 695d9881..305668e7 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -160,22 +160,22 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::inter return *m_interfaceFunctionList; } -string const& ContractDefinition::devDocumentation() const +Json::Value const& ContractDefinition::devDocumentation() const { return m_devDocumentation; } -string const& ContractDefinition::userDocumentation() const +Json::Value const& ContractDefinition::userDocumentation() const { return m_userDocumentation; } -void ContractDefinition::setDevDocumentation(string const& _devDocumentation) +void ContractDefinition::setDevDocumentation(Json::Value const& _devDocumentation) { m_devDocumentation = _devDocumentation; } -void ContractDefinition::setUserDocumentation(string const& _userDocumentation) +void ContractDefinition::setUserDocumentation(Json::Value const& _userDocumentation) { m_userDocumentation = _userDocumentation; } diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 6c3f52bc..1b42c499 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -35,6 +35,7 @@ #include <libsolidity/ast/Types.h> #include <libsolidity/interface/Exceptions.h> #include <libsolidity/ast/ASTAnnotations.h> +#include <json/json.h> namespace dev { @@ -343,11 +344,11 @@ public: /// Returns the fallback function or nullptr if no fallback function was specified. FunctionDefinition const* fallbackFunction() const; - std::string const& userDocumentation() const; - void setUserDocumentation(std::string const& _userDocumentation); + Json::Value const& userDocumentation() const; + void setUserDocumentation(Json::Value const& _userDocumentation); - std::string const& devDocumentation() const; - void setDevDocumentation(std::string const& _devDocumentation); + Json::Value const& devDocumentation() const; + void setDevDocumentation(Json::Value const& _devDocumentation); virtual TypePointer type() const override; @@ -359,8 +360,8 @@ private: bool m_isLibrary; // parsed Natspec documentation of the contract. - std::string m_userDocumentation; - std::string m_devDocumentation; + Json::Value m_userDocumentation; + Json::Value m_devDocumentation; std::vector<ContractDefinition const*> m_linearizedBaseContracts; mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList; diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index efbbd237..519027bc 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -345,17 +345,17 @@ map<string, unsigned> CompilerStack::sourceIndices() const return indices; } -string const& CompilerStack::interface(string const& _contractName) const +Json::Value const& CompilerStack::interface(string const& _contractName) const { return metadata(_contractName, DocumentationType::ABIInterface); } -string const& CompilerStack::metadata(string const& _contractName, DocumentationType _type) const +Json::Value const& CompilerStack::metadata(string const& _contractName, DocumentationType _type) const { if (!m_parseSuccessful) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful.")); - std::unique_ptr<string const>* doc; + std::unique_ptr<Json::Value const>* doc; Contract const& currentContract = contract(_contractName); // checks wheather we already have the documentation @@ -376,7 +376,7 @@ string const& CompilerStack::metadata(string const& _contractName, Documentation // caches the result if (!*doc) - doc->reset(new string(InterfaceHandler::documentation(*currentContract.contract, _type))); + doc->reset(new Json::Value(InterfaceHandler::documentation(*currentContract.contract, _type))); return *(*doc); } diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index da479638..1fd30c4d 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -162,14 +162,14 @@ public: /// @returns a mapping assigning each source name its index inside the vector returned /// by sourceNames(). std::map<std::string, unsigned> sourceIndices() const; - /// @returns a string representing the contract interface in JSON. + /// @returns a JSON representing the contract interface. /// Prerequisite: Successful call to parse or compile. - std::string const& interface(std::string const& _contractName = "") const; - /// @returns a string representing the contract's documentation in JSON. + Json::Value const& interface(std::string const& _contractName = "") const; + /// @returns a JSON representing the contract's documentation. /// Prerequisite: Successful call to parse or compile. /// @param type The type of the documentation to get. /// Can be one of 4 types defined at @c DocumentationType - std::string const& metadata(std::string const& _contractName, DocumentationType _type) const; + Json::Value const& metadata(std::string const& _contractName, DocumentationType _type) const; /// @returns the previously used scanner, useful for counting lines during error reporting. Scanner const& scanner(std::string const& _sourceName = "") const; @@ -213,9 +213,9 @@ private: eth::LinkerObject object; eth::LinkerObject runtimeObject; eth::LinkerObject cloneObject; - mutable std::unique_ptr<std::string const> interface; - mutable std::unique_ptr<std::string const> userDocumentation; - mutable std::unique_ptr<std::string const> devDocumentation; + mutable std::unique_ptr<Json::Value const> interface; + mutable std::unique_ptr<Json::Value const> userDocumentation; + mutable std::unique_ptr<Json::Value const> devDocumentation; mutable std::unique_ptr<std::string const> sourceMapping; mutable std::unique_ptr<std::string const> runtimeSourceMapping; }; diff --git a/libsolidity/interface/InterfaceHandler.cpp b/libsolidity/interface/InterfaceHandler.cpp index 1686f9ea..5705856c 100644 --- a/libsolidity/interface/InterfaceHandler.cpp +++ b/libsolidity/interface/InterfaceHandler.cpp @@ -8,7 +8,7 @@ using namespace std; using namespace dev; using namespace dev::solidity; -string InterfaceHandler::documentation( +Json::Value InterfaceHandler::documentation( ContractDefinition const& _contractDef, DocumentationType _type ) @@ -24,10 +24,9 @@ string InterfaceHandler::documentation( } BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type")); - return ""; } -string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef) +Json::Value InterfaceHandler::abiInterface(ContractDefinition const& _contractDef) { Json::Value abi(Json::arrayValue); @@ -104,12 +103,10 @@ string InterfaceHandler::abiInterface(ContractDefinition const& _contractDef) abi.append(event); } - Json::FastWriter writer; - writer.omitEndingLineFeed(); - return writer.write(abi); + return abi; } -string InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef) +Json::Value InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef) { Json::Value doc; Json::Value methods(Json::objectValue); @@ -129,10 +126,10 @@ string InterfaceHandler::userDocumentation(ContractDefinition const& _contractDe } doc["methods"] = methods; - return Json::StyledWriter().write(doc); + return doc; } -string InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef) +Json::Value InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef) { Json::Value doc; Json::Value methods(Json::objectValue); @@ -178,7 +175,7 @@ string InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef } doc["methods"] = methods; - return Json::StyledWriter().write(doc); + return doc; } string InterfaceHandler::extractDoc(multimap<string, DocTag> const& _tags, string const& _name) diff --git a/libsolidity/interface/InterfaceHandler.h b/libsolidity/interface/InterfaceHandler.h index 54199e4e..d4f2eaf4 100644 --- a/libsolidity/interface/InterfaceHandler.h +++ b/libsolidity/interface/InterfaceHandler.h @@ -64,24 +64,24 @@ public: /// @param _contractDef The contract definition /// @param _type The type of the documentation. Can be one of the /// types provided by @c DocumentationType - /// @return A string with the json representation of provided type - static std::string documentation( + /// @return A JSON representation of provided type + static Json::Value documentation( ContractDefinition const& _contractDef, DocumentationType _type ); /// Get the ABI Interface of the contract /// @param _contractDef The contract definition - /// @return A string with the json representation of the contract's ABI Interface - static std::string abiInterface(ContractDefinition const& _contractDef); + /// @return A JSONrepresentation of the contract's ABI Interface + static Json::Value abiInterface(ContractDefinition const& _contractDef); /// Get the User documentation of the contract /// @param _contractDef The contract definition - /// @return A string with the json representation of the contract's user documentation - static std::string userDocumentation(ContractDefinition const& _contractDef); + /// @return A JSON representation of the contract's user documentation + static Json::Value userDocumentation(ContractDefinition const& _contractDef); /// Genereates the Developer's documentation of the contract /// @param _contractDef The contract definition - /// @return A string with the json representation + /// @return A JSON representation /// of the contract's developer documentation - static std::string devDocumentation(ContractDefinition const& _contractDef); + static Json::Value devDocumentation(ContractDefinition const& _contractDef); private: /// @returns concatenation of all content under the given tag name. |