diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 270ec3ed7..5b85989b9 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -382,19 +382,19 @@ vector, FunctionTypePointer>> const& ContractDefinition::getIn return *m_interfaceFunctionList; } -unique_ptr ContractDefinition::devDocumentation() const +string const& ContractDefinition::devDocumentation() const { - return unique_ptr(new string(m_devDocumentation)); + return m_devDocumentation; } -void ContractDefinition::setDevDocumentation(string const& _devDocumentation) +string const& ContractDefinition::userDocumentation() const { - m_devDocumentation = _devDocumentation; + return m_userDocumentation; } -std::unique_ptr ContractDefinition::userDocumentation() const +void ContractDefinition::setDevDocumentation(string const& _devDocumentation) { - return unique_ptr(new string(m_userDocumentation)); + m_devDocumentation = _devDocumentation; } void ContractDefinition::setUserDocumentation(string const& _userDocumentation) diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 38262d009..fb83d4e11 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -281,10 +281,10 @@ public: /// Returns the fallback function or nullptr if no fallback function was specified. FunctionDefinition const* getFallbackFunction() const; - std::unique_ptr userDocumentation() const; + std::string const& userDocumentation() const; void setUserDocumentation(std::string const& _userDocumentation); - std::unique_ptr devDocumentation() const; + std::string const& devDocumentation() const; void setDevDocumentation(std::string const& _devDocumentation); private: diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index 7cd8316c7..6013c00d1 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -129,11 +129,12 @@ void CompilerStack::parse() m_parseSuccessful = true; } -void CompilerStack::parseNatspecDocumentation(ContractDefinition& _contract) +void CompilerStack::parseNatspecDocumentation(ContractDefinition const& _contract) { InterfaceHandler interfaceHandler; - interfaceHandler.generateDevDocumentation(_contract); - interfaceHandler.generateUserDocumentation(_contract); + string devDoc =_contract.devDocumentation(); + devDoc = interfaceHandler.devDocumentation(_contract); + //interfaceHandler.generateUserDocumentation(_contract); } void CompilerStack::parse(string const& _sourceCode) @@ -256,8 +257,11 @@ string const& CompilerStack::getMetadata(string const& _contractName, Documentat default: BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type.")); } + auto resPtr = ((*doc) ? *(*doc) : contract.interfaceHandler->getDocumentation(*contract.contract, _type)); + if (!*doc) - *doc = contract.interfaceHandler->getDocumentation(*contract.contract, _type); + *doc = (unique_ptr(new string(contract.interfaceHandler->getDocumentation(*contract.contract, _type)))); + return *(*doc); } diff --git a/libsolidity/CompilerStack.h b/libsolidity/CompilerStack.h index ff2b0069c..dd0498854 100644 --- a/libsolidity/CompilerStack.h +++ b/libsolidity/CompilerStack.h @@ -149,7 +149,7 @@ public: std::tuple positionFromSourceLocation(SourceLocation const& _sourceLocation) const; /// Parses Natspec documentations. Throws exceptions in case of wrong documented contract - void parseNatspecDocumentation(ContractDefinition& _contract); + void parseNatspecDocumentation(dev::solidity::ContractDefinition const& _contract); private: /** diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index fecdb3ece..c6f8553d8 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -16,7 +16,7 @@ InterfaceHandler::InterfaceHandler() m_lastTag = DocTagType::None; } -unique_ptr InterfaceHandler::getDocumentation( +string InterfaceHandler::getDocumentation( ContractDefinition const& _contractDef, DocumentationType _type ) @@ -34,10 +34,10 @@ unique_ptr InterfaceHandler::getDocumentation( } BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type")); - return nullptr; + return ""; } -unique_ptr InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef) +string InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef) { Json::Value abi(Json::arrayValue); @@ -103,10 +103,10 @@ unique_ptr InterfaceHandler::getABIInterface(ContractDefinition const& _ event["inputs"] = params; abi.append(event); } - return unique_ptr(new string(Json::FastWriter().write(abi))); + return Json::FastWriter().write(abi); } -unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef) +string InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef) { string ret = "contract " + _contractDef.getName() + "{"; @@ -140,10 +140,10 @@ unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition ret += ";"; } - return unique_ptr(new string(ret + "}")); + return ret + "}"; } -void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDef) +string InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef) { Json::Value doc; Json::Value methods(Json::objectValue); @@ -165,20 +165,10 @@ void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDe } doc["methods"] = methods; - _contractDef.setUserDocumentation(Json::StyledWriter().write(doc)); + return Json::StyledWriter().write(doc); } -unique_ptr InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef) -{ - return _contractDef.userDocumentation(); -} - -unique_ptr InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef) -{ - return _contractDef.devDocumentation(); -} - -void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef) +string InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef) { // LTODO: Somewhere in this function warnings for mismatch of param names // should be thrown @@ -239,7 +229,7 @@ void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef } doc["methods"] = methods; - _contractDef.setDevDocumentation(Json::StyledWriter().write(doc)); + return Json::StyledWriter().write(doc); } /* -- private -- */ diff --git a/libsolidity/InterfaceHandler.h b/libsolidity/InterfaceHandler.h index 1cc20c444..222db5a0e 100644 --- a/libsolidity/InterfaceHandler.h +++ b/libsolidity/InterfaceHandler.h @@ -65,9 +65,8 @@ 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 unique pointer contained string with the json - /// representation of provided type - std::unique_ptr getDocumentation( + /// @return A string with the json representation of provided type + std::string getDocumentation( ContractDefinition const& _contractDef, DocumentationType _type ); @@ -75,24 +74,18 @@ public: /// @param _contractDef The contract definition /// @return A unique pointer contained string with the json /// representation of the contract's ABI Interface - std::unique_ptr getABIInterface(ContractDefinition const& _contractDef); - std::unique_ptr getABISolidityInterface(ContractDefinition const& _contractDef); - /// Generate the User documentation of the contract - /// @param _contractDef The contract definition - void generateUserDocumentation(ContractDefinition& _contractDef); + std::string getABIInterface(ContractDefinition const& _contractDef); + std::string getABISolidityInterface(ContractDefinition const& _contractDef); /// Get the User documentation of the contract /// @param _contractDef The contract definition /// @return A unique pointer contained string with the json /// representation of the contract's user documentation - std::unique_ptr userDocumentation(ContractDefinition const& _contractDef); - /// Genereates the Developer's documentation of the contract - /// @param _contractDef The contract definition - void generateDevDocumentation(ContractDefinition& _contractDef); + std::string userDocumentation(ContractDefinition const& _contractDef); /// Genereates the Developer's documentation of the contract /// @param _contractDef The contract definition /// @return A unique pointer contained string with the json /// representation of the contract's developer documentation - std::unique_ptr devDocumentation(ContractDefinition const& _contractDef); + std::string devDocumentation(ContractDefinition const& _contractDef); private: void resetUser(); diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index 082745cfe..213c1c1ee 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -157,7 +157,7 @@ CompiledContract::CompiledContract(const dev::solidity::CompilerStack& _compiler m_bytes = _compiler.getBytecode(_contractName.toStdString()); dev::solidity::InterfaceHandler interfaceHandler; - m_contractInterface = QString::fromStdString(*interfaceHandler.getABIInterface(contractDefinition)); + m_contractInterface = QString::fromStdString(interfaceHandler.getABIInterface(contractDefinition)); if (m_contractInterface.isEmpty()) m_contractInterface = "[]"; if (contractDefinition.getLocation().sourceName.get())