mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
changed implementation according to notes from code review
This commit is contained in:
parent
0111d3d4c4
commit
dc605218da
14
AST.cpp
14
AST.cpp
@ -382,9 +382,14 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
|
|||||||
return *m_interfaceFunctionList;
|
return *m_interfaceFunctionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> ContractDefinition::devDocumentation() const
|
string const& ContractDefinition::devDocumentation() const
|
||||||
{
|
{
|
||||||
return unique_ptr<string>(new string(m_devDocumentation));
|
return m_devDocumentation;
|
||||||
|
}
|
||||||
|
|
||||||
|
string const& ContractDefinition::userDocumentation() const
|
||||||
|
{
|
||||||
|
return m_userDocumentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContractDefinition::setDevDocumentation(string const& _devDocumentation)
|
void ContractDefinition::setDevDocumentation(string const& _devDocumentation)
|
||||||
@ -392,11 +397,6 @@ void ContractDefinition::setDevDocumentation(string const& _devDocumentation)
|
|||||||
m_devDocumentation = _devDocumentation;
|
m_devDocumentation = _devDocumentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<string> ContractDefinition::userDocumentation() const
|
|
||||||
{
|
|
||||||
return unique_ptr<string>(new string(m_userDocumentation));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContractDefinition::setUserDocumentation(string const& _userDocumentation)
|
void ContractDefinition::setUserDocumentation(string const& _userDocumentation)
|
||||||
{
|
{
|
||||||
m_userDocumentation = _userDocumentation;
|
m_userDocumentation = _userDocumentation;
|
||||||
|
4
AST.h
4
AST.h
@ -281,10 +281,10 @@ public:
|
|||||||
/// Returns the fallback function or nullptr if no fallback function was specified.
|
/// Returns the fallback function or nullptr if no fallback function was specified.
|
||||||
FunctionDefinition const* getFallbackFunction() const;
|
FunctionDefinition const* getFallbackFunction() const;
|
||||||
|
|
||||||
std::unique_ptr<std::string> userDocumentation() const;
|
std::string const& userDocumentation() const;
|
||||||
void setUserDocumentation(std::string const& _userDocumentation);
|
void setUserDocumentation(std::string const& _userDocumentation);
|
||||||
|
|
||||||
std::unique_ptr<std::string> devDocumentation() const;
|
std::string const& devDocumentation() const;
|
||||||
void setDevDocumentation(std::string const& _devDocumentation);
|
void setDevDocumentation(std::string const& _devDocumentation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -129,11 +129,12 @@ void CompilerStack::parse()
|
|||||||
m_parseSuccessful = true;
|
m_parseSuccessful = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerStack::parseNatspecDocumentation(ContractDefinition& _contract)
|
void CompilerStack::parseNatspecDocumentation(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
InterfaceHandler interfaceHandler;
|
InterfaceHandler interfaceHandler;
|
||||||
interfaceHandler.generateDevDocumentation(_contract);
|
string devDoc =_contract.devDocumentation();
|
||||||
interfaceHandler.generateUserDocumentation(_contract);
|
devDoc = interfaceHandler.devDocumentation(_contract);
|
||||||
|
//interfaceHandler.generateUserDocumentation(_contract);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerStack::parse(string const& _sourceCode)
|
void CompilerStack::parse(string const& _sourceCode)
|
||||||
@ -256,8 +257,11 @@ string const& CompilerStack::getMetadata(string const& _contractName, Documentat
|
|||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type."));
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type."));
|
||||||
}
|
}
|
||||||
|
auto resPtr = ((*doc) ? *(*doc) : contract.interfaceHandler->getDocumentation(*contract.contract, _type));
|
||||||
|
|
||||||
if (!*doc)
|
if (!*doc)
|
||||||
*doc = contract.interfaceHandler->getDocumentation(*contract.contract, _type);
|
*doc = (unique_ptr<string>(new string(contract.interfaceHandler->getDocumentation(*contract.contract, _type))));
|
||||||
|
|
||||||
return *(*doc);
|
return *(*doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public:
|
|||||||
std::tuple<int, int, int, int> positionFromSourceLocation(SourceLocation const& _sourceLocation) const;
|
std::tuple<int, int, int, int> positionFromSourceLocation(SourceLocation const& _sourceLocation) const;
|
||||||
|
|
||||||
/// Parses Natspec documentations. Throws exceptions in case of wrong documented contract
|
/// Parses Natspec documentations. Throws exceptions in case of wrong documented contract
|
||||||
void parseNatspecDocumentation(ContractDefinition& _contract);
|
void parseNatspecDocumentation(dev::solidity::ContractDefinition const& _contract);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@ InterfaceHandler::InterfaceHandler()
|
|||||||
m_lastTag = DocTagType::None;
|
m_lastTag = DocTagType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::getDocumentation(
|
string InterfaceHandler::getDocumentation(
|
||||||
ContractDefinition const& _contractDef,
|
ContractDefinition const& _contractDef,
|
||||||
DocumentationType _type
|
DocumentationType _type
|
||||||
)
|
)
|
||||||
@ -34,10 +34,10 @@ unique_ptr<string> InterfaceHandler::getDocumentation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
|
||||||
return nullptr;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
string InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
Json::Value abi(Json::arrayValue);
|
Json::Value abi(Json::arrayValue);
|
||||||
|
|
||||||
@ -103,10 +103,10 @@ unique_ptr<string> InterfaceHandler::getABIInterface(ContractDefinition const& _
|
|||||||
event["inputs"] = params;
|
event["inputs"] = params;
|
||||||
abi.append(event);
|
abi.append(event);
|
||||||
}
|
}
|
||||||
return unique_ptr<string>(new string(Json::FastWriter().write(abi)));
|
return Json::FastWriter().write(abi);
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
string InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
string ret = "contract " + _contractDef.getName() + "{";
|
string ret = "contract " + _contractDef.getName() + "{";
|
||||||
|
|
||||||
@ -140,10 +140,10 @@ unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition
|
|||||||
ret += ";";
|
ret += ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
return unique_ptr<string>(new string(ret + "}"));
|
return ret + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDef)
|
string InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
Json::Value doc;
|
Json::Value doc;
|
||||||
Json::Value methods(Json::objectValue);
|
Json::Value methods(Json::objectValue);
|
||||||
@ -165,20 +165,10 @@ void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDe
|
|||||||
}
|
}
|
||||||
doc["methods"] = methods;
|
doc["methods"] = methods;
|
||||||
|
|
||||||
_contractDef.setUserDocumentation(Json::StyledWriter().write(doc));
|
return Json::StyledWriter().write(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef)
|
string InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef)
|
||||||
{
|
|
||||||
return _contractDef.userDocumentation();
|
|
||||||
}
|
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef)
|
|
||||||
{
|
|
||||||
return _contractDef.devDocumentation();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef)
|
|
||||||
{
|
{
|
||||||
// LTODO: Somewhere in this function warnings for mismatch of param names
|
// LTODO: Somewhere in this function warnings for mismatch of param names
|
||||||
// should be thrown
|
// should be thrown
|
||||||
@ -239,7 +229,7 @@ void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef
|
|||||||
}
|
}
|
||||||
doc["methods"] = methods;
|
doc["methods"] = methods;
|
||||||
|
|
||||||
_contractDef.setDevDocumentation(Json::StyledWriter().write(doc));
|
return Json::StyledWriter().write(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- private -- */
|
/* -- private -- */
|
||||||
|
@ -65,9 +65,8 @@ public:
|
|||||||
/// @param _contractDef The contract definition
|
/// @param _contractDef The contract definition
|
||||||
/// @param _type The type of the documentation. Can be one of the
|
/// @param _type The type of the documentation. Can be one of the
|
||||||
/// types provided by @c DocumentationType
|
/// types provided by @c DocumentationType
|
||||||
/// @return A unique pointer contained string with the json
|
/// @return A string with the json representation of provided type
|
||||||
/// representation of provided type
|
std::string getDocumentation(
|
||||||
std::unique_ptr<std::string> getDocumentation(
|
|
||||||
ContractDefinition const& _contractDef,
|
ContractDefinition const& _contractDef,
|
||||||
DocumentationType _type
|
DocumentationType _type
|
||||||
);
|
);
|
||||||
@ -75,24 +74,18 @@ public:
|
|||||||
/// @param _contractDef The contract definition
|
/// @param _contractDef The contract definition
|
||||||
/// @return A unique pointer contained string with the json
|
/// @return A unique pointer contained string with the json
|
||||||
/// representation of the contract's ABI Interface
|
/// representation of the contract's ABI Interface
|
||||||
std::unique_ptr<std::string> getABIInterface(ContractDefinition const& _contractDef);
|
std::string getABIInterface(ContractDefinition const& _contractDef);
|
||||||
std::unique_ptr<std::string> getABISolidityInterface(ContractDefinition const& _contractDef);
|
std::string getABISolidityInterface(ContractDefinition const& _contractDef);
|
||||||
/// Generate the User documentation of the contract
|
|
||||||
/// @param _contractDef The contract definition
|
|
||||||
void generateUserDocumentation(ContractDefinition& _contractDef);
|
|
||||||
/// Get the User documentation of the contract
|
/// Get the User documentation of the contract
|
||||||
/// @param _contractDef The contract definition
|
/// @param _contractDef The contract definition
|
||||||
/// @return A unique pointer contained string with the json
|
/// @return A unique pointer contained string with the json
|
||||||
/// representation of the contract's user documentation
|
/// representation of the contract's user documentation
|
||||||
std::unique_ptr<std::string> userDocumentation(ContractDefinition const& _contractDef);
|
std::string userDocumentation(ContractDefinition const& _contractDef);
|
||||||
/// Genereates the Developer's documentation of the contract
|
|
||||||
/// @param _contractDef The contract definition
|
|
||||||
void generateDevDocumentation(ContractDefinition& _contractDef);
|
|
||||||
/// Genereates the Developer's documentation of the contract
|
/// Genereates the Developer's documentation of the contract
|
||||||
/// @param _contractDef The contract definition
|
/// @param _contractDef The contract definition
|
||||||
/// @return A unique pointer contained string with the json
|
/// @return A unique pointer contained string with the json
|
||||||
/// representation of the contract's developer documentation
|
/// representation of the contract's developer documentation
|
||||||
std::unique_ptr<std::string> devDocumentation(ContractDefinition const& _contractDef);
|
std::string devDocumentation(ContractDefinition const& _contractDef);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resetUser();
|
void resetUser();
|
||||||
|
Loading…
Reference in New Issue
Block a user