mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor to have multiple return params
This commit is contained in:
parent
30ea41c36d
commit
b3ae601e88
@ -99,16 +99,54 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef)
|
|||||||
if (auto fun = dynamic_cast<FunctionDefinition const*>(&it.second->declaration()))
|
if (auto fun = dynamic_cast<FunctionDefinition const*>(&it.second->declaration()))
|
||||||
{
|
{
|
||||||
Json::Value method(devDocumentation(fun->annotation().docTags));
|
Json::Value method(devDocumentation(fun->annotation().docTags));
|
||||||
if (!method.empty())
|
|
||||||
// add the function, only if we have any documentation to add
|
// add the function, only if we have any documentation to add
|
||||||
|
if (!method.empty())
|
||||||
|
{
|
||||||
|
Json::Value ret(Json::objectValue);
|
||||||
|
|
||||||
|
// for constructors, the "return" node will never exist. invalid tags
|
||||||
|
// will already generate an error within dev::solidity::DocStringAnalyzer.
|
||||||
|
auto returnParams = fun->returnParameters();
|
||||||
|
auto returnDoc = fun->annotation().docTags.equal_range("return");
|
||||||
|
|
||||||
|
if (!returnParams.empty())
|
||||||
|
{
|
||||||
|
// if there is no name then append subsequent return notices like previous behavior
|
||||||
|
string value;
|
||||||
|
unsigned int n = 0;
|
||||||
|
for (auto i = returnDoc.first; i != returnDoc.second; i++)
|
||||||
|
{
|
||||||
|
string paramName = returnParams.at(n)->name();
|
||||||
|
|
||||||
|
if (!paramName.empty())
|
||||||
|
{
|
||||||
|
ret[paramName] = Json::Value(i->second.content);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value += i->second.content;
|
||||||
|
method["return"] = Json::Value(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret.empty())
|
||||||
|
method["return"] = ret;
|
||||||
|
|
||||||
methods[it.second->externalSignature()] = method;
|
methods[it.second->externalSignature()] = method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doc["methods"] = methods;
|
doc["methods"] = methods;
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string Natspec::extractDoc(multimap<string, DocTag> const& _tags, string const& _name)
|
string Natspec::extractDoc(multimap<string, DocTag> const& _tags, string const& _name)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
@ -129,12 +167,6 @@ Json::Value Natspec::devDocumentation(std::multimap<std::string, DocTag> const&
|
|||||||
if (!author.empty())
|
if (!author.empty())
|
||||||
json["author"] = author;
|
json["author"] = author;
|
||||||
|
|
||||||
// for constructors, the "return" node will never exist. invalid tags
|
|
||||||
// will already generate an error within dev::solidity::DocStringAnalyzer.
|
|
||||||
auto ret = extractDoc(_tags, "return");
|
|
||||||
if (!ret.empty())
|
|
||||||
json["return"] = ret;
|
|
||||||
|
|
||||||
Json::Value params(Json::objectValue);
|
Json::Value params(Json::objectValue);
|
||||||
auto paramRange = _tags.equal_range("param");
|
auto paramRange = _tags.equal_range("param");
|
||||||
for (auto i = paramRange.first; i != paramRange.second; ++i)
|
for (auto i = paramRange.first; i != paramRange.second; ++i)
|
||||||
|
@ -416,6 +416,41 @@ BOOST_AUTO_TEST_CASE(dev_return_desc_after_nl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(dev_return_desc_multiple)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract test {
|
||||||
|
/// @dev Multiplies a number by 7 and adds second parameter
|
||||||
|
/// @param a Documentation for the first parameter starts here.
|
||||||
|
/// Since it's a really complicated parameter we need 2 lines
|
||||||
|
/// @param second Documentation for the second parameter
|
||||||
|
/// @return The result of the multiplication
|
||||||
|
/// @return And cookies with nutella
|
||||||
|
function mul(uint a, uint second) public returns (uint d, uint f) {
|
||||||
|
uint mul = a * 7;
|
||||||
|
return (mul, second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
char const* natspec = "{"
|
||||||
|
"\"methods\":{"
|
||||||
|
" \"mul(uint256,uint256)\":{ \n"
|
||||||
|
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
|
||||||
|
" \"params\": {\n"
|
||||||
|
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
|
||||||
|
" \"second\": \"Documentation for the second parameter\"\n"
|
||||||
|
" },\n"
|
||||||
|
" \"return\": {\n"
|
||||||
|
" \"d\": \"The result of the multiplication\",\n"
|
||||||
|
" \"f\": \"And cookies with nutella\"\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
"}}";
|
||||||
|
|
||||||
|
checkNatspec(sourceCode, "test", natspec, false);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(dev_multiline_return)
|
BOOST_AUTO_TEST_CASE(dev_multiline_return)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user