Move InterfaceHandler from string to JSON

This commit is contained in:
Alex Beregszaszi
2016-11-15 15:55:25 +00:00
parent 0072160d77
commit 9719cf38e6
8 changed files with 71 additions and 48 deletions
+4 -4
View File
@@ -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;
}
+7 -6
View File
@@ -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;
+4 -4
View File
@@ -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);
}
+7 -7
View File
@@ -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;
};
+7 -10
View File
@@ -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)
+8 -8
View File
@@ -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.