mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
contract documentation is now parsing during compilation and not by request.
This commit is contained in:
parent
54fa8ed7a6
commit
43398adc99
21
AST.cpp
21
AST.cpp
@ -382,6 +382,27 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
|
||||
return *m_interfaceFunctionList;
|
||||
}
|
||||
|
||||
unique_ptr<string> ContractDefinition::devDocumentation() const
|
||||
{
|
||||
return unique_ptr<string>(new string(m_devDocumentation));
|
||||
}
|
||||
|
||||
void ContractDefinition::setDevDocumentation(string const& _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)
|
||||
{
|
||||
m_userDocumentation = _userDocumentation;
|
||||
}
|
||||
|
||||
|
||||
vector<Declaration const*> const& ContractDefinition::getInheritableMembers() const
|
||||
{
|
||||
if (!m_inheritableMembers)
|
||||
|
10
AST.h
10
AST.h
@ -281,6 +281,12 @@ public:
|
||||
/// Returns the fallback function or nullptr if no fallback function was specified.
|
||||
FunctionDefinition const* getFallbackFunction() const;
|
||||
|
||||
std::unique_ptr<std::string> userDocumentation() const;
|
||||
void setUserDocumentation(std::string const& _userDocumentation);
|
||||
|
||||
std::unique_ptr<std::string> devDocumentation() const;
|
||||
void setDevDocumentation(std::string const& _devDocumentation);
|
||||
|
||||
private:
|
||||
/// Checks that two functions defined in this contract with the same name have different
|
||||
/// arguments and that there is at most one constructor.
|
||||
@ -302,6 +308,10 @@ private:
|
||||
std::vector<ASTPointer<ModifierDefinition>> m_functionModifiers;
|
||||
std::vector<ASTPointer<EventDefinition>> m_events;
|
||||
|
||||
// parsed Natspec documentation of the contract.
|
||||
std::string m_userDocumentation;
|
||||
std::string m_devDocumentation;
|
||||
|
||||
std::vector<ContractDefinition const*> m_linearizedBaseContracts;
|
||||
mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
|
||||
mutable std::unique_ptr<std::vector<ASTPointer<EventDefinition>>> m_interfaceEvents;
|
||||
|
@ -124,10 +124,18 @@ void CompilerStack::parse()
|
||||
resolver.updateDeclaration(*m_globalContext->getCurrentThis());
|
||||
resolver.checkTypeRequirements(*contract);
|
||||
m_contracts[contract->getName()].contract = contract;
|
||||
parseNatspecDocumentation(*contract);
|
||||
}
|
||||
m_parseSuccessful = true;
|
||||
}
|
||||
|
||||
void CompilerStack::parseNatspecDocumentation(ContractDefinition& _contract)
|
||||
{
|
||||
InterfaceHandler interfaceHandler;
|
||||
interfaceHandler.generateDevDocumentation(_contract);
|
||||
interfaceHandler.generateUserDocumentation(_contract);
|
||||
}
|
||||
|
||||
void CompilerStack::parse(string const& _sourceCode)
|
||||
{
|
||||
setSource(_sourceCode);
|
||||
|
@ -148,6 +148,9 @@ public:
|
||||
/// start line, start column, end line, end column
|
||||
std::tuple<int, int, int, int> positionFromSourceLocation(SourceLocation const& _sourceLocation) const;
|
||||
|
||||
/// Parses Natspec documentations. Throws exceptions in case of wrong documented contract
|
||||
void parseNatspecDocumentation(dev::solidity::ContractDefinition& _contract);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Information pertaining to one source unit, filled gradually during parsing and compilation.
|
||||
|
@ -24,9 +24,9 @@ unique_ptr<string> InterfaceHandler::getDocumentation(
|
||||
switch(_type)
|
||||
{
|
||||
case DocumentationType::NatspecUser:
|
||||
return getUserDocumentation(_contractDef);
|
||||
return userDocumentation(_contractDef);
|
||||
case DocumentationType::NatspecDev:
|
||||
return getDevDocumentation(_contractDef);
|
||||
return devDocumentation(_contractDef);
|
||||
case DocumentationType::ABIInterface:
|
||||
return getABIInterface(_contractDef);
|
||||
case DocumentationType::ABISolidityInterface:
|
||||
@ -143,7 +143,7 @@ unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition
|
||||
return unique_ptr<string>(new string(ret + "}"));
|
||||
}
|
||||
|
||||
unique_ptr<string> InterfaceHandler::getUserDocumentation(ContractDefinition const& _contractDef)
|
||||
void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDef)
|
||||
{
|
||||
Json::Value doc;
|
||||
Json::Value methods(Json::objectValue);
|
||||
@ -165,10 +165,20 @@ unique_ptr<string> InterfaceHandler::getUserDocumentation(ContractDefinition con
|
||||
}
|
||||
doc["methods"] = methods;
|
||||
|
||||
return unique_ptr<string>(new string(Json::FastWriter().write(doc)));
|
||||
_contractDef.setUserDocumentation(string(Json::FastWriter().write(doc)));
|
||||
}
|
||||
|
||||
unique_ptr<string> InterfaceHandler::getDevDocumentation(ContractDefinition const& _contractDef)
|
||||
unique_ptr<string> InterfaceHandler::userDocumentation(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
|
||||
// should be thrown
|
||||
@ -212,7 +222,7 @@ unique_ptr<string> InterfaceHandler::getDevDocumentation(ContractDefinition cons
|
||||
// LTODO: mismatching parameter name, throw some form of warning and not just an exception
|
||||
BOOST_THROW_EXCEPTION(
|
||||
DocstringParsingError() <<
|
||||
errinfo_comment("documented parameter \"" + pair.first + "\" not found found in the function")
|
||||
errinfo_comment("documented parameter \"" + pair.first + "\" not found in the parameter list of the function.")
|
||||
);
|
||||
params[pair.first] = pair.second;
|
||||
}
|
||||
@ -229,7 +239,7 @@ unique_ptr<string> InterfaceHandler::getDevDocumentation(ContractDefinition cons
|
||||
}
|
||||
doc["methods"] = methods;
|
||||
|
||||
return unique_ptr<string>(new string(Json::FastWriter().write(doc)));
|
||||
_contractDef.setDevDocumentation(string(Json::FastWriter().write(doc)));
|
||||
}
|
||||
|
||||
/* -- private -- */
|
||||
|
@ -77,16 +77,22 @@ public:
|
||||
/// representation of the contract's ABI Interface
|
||||
std::unique_ptr<std::string> getABIInterface(ContractDefinition const& _contractDef);
|
||||
std::unique_ptr<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
|
||||
/// @param _contractDef The contract definition
|
||||
/// @return A unique pointer contained string with the json
|
||||
/// representation of the contract's user documentation
|
||||
std::unique_ptr<std::string> getUserDocumentation(ContractDefinition const& _contractDef);
|
||||
/// Get the Developer's documentation of the contract
|
||||
std::unique_ptr<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
|
||||
/// @param _contractDef The contract definition
|
||||
/// @return A unique pointer contained string with the json
|
||||
/// representation of the contract's developer documentation
|
||||
std::unique_ptr<std::string> getDevDocumentation(ContractDefinition const& _contractDef);
|
||||
std::unique_ptr<std::string> devDocumentation(ContractDefinition const& _contractDef);
|
||||
|
||||
private:
|
||||
void resetUser();
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <libsolidity/Parser.h>
|
||||
#include <libsolidity/Scanner.h>
|
||||
#include <libsolidity/Exceptions.h>
|
||||
#include <libsolidity/InterfaceHandler.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user