diff options
author | chriseth <chris@ethereum.org> | 2018-08-15 01:13:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-15 01:13:25 +0800 |
commit | 8f27fb1f4a14f369e8feb3ea22a38d50998cad5c (patch) | |
tree | ef6d1a3de53c84688c9db123b68836a366a9249d /libsolidity/interface/Natspec.cpp | |
parent | cc2dcf5c312bbc8cd7ad5e2b4dfbdb084f77fe03 (diff) | |
parent | f76d4d59197db344613de18d1bfcead34a5e42ba (diff) | |
download | dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.gz dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.bz2 dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.lz dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.xz dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.zst dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.zip |
Merge pull request #4542 from aarlt/constructor_natspec
Fix: natspec annotations on constructors
Diffstat (limited to 'libsolidity/interface/Natspec.cpp')
-rw-r--r-- | libsolidity/interface/Natspec.cpp | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/libsolidity/interface/Natspec.cpp b/libsolidity/interface/Natspec.cpp index 29a5b798..a8716862 100644 --- a/libsolidity/interface/Natspec.cpp +++ b/libsolidity/interface/Natspec.cpp @@ -36,6 +36,15 @@ Json::Value Natspec::userDocumentation(ContractDefinition const& _contractDef) Json::Value doc; Json::Value methods(Json::objectValue); + auto constructorDefinition(_contractDef.constructor()); + if (constructorDefinition) + { + string value = extractDoc(constructorDefinition->annotation().docTags, "notice"); + if (!value.empty()) + // add the constructor, only if we have any documentation to add + methods["constructor"] = Json::Value(value); + } + string notice = extractDoc(_contractDef.annotation().docTags, "notice"); if (!notice.empty()) doc["notice"] = Json::Value(notice); @@ -73,33 +82,21 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef) if (!dev.empty()) doc["details"] = Json::Value(dev); + auto constructorDefinition(_contractDef.constructor()); + if (constructorDefinition) { + Json::Value constructor(devDocumentation(constructorDefinition->annotation().docTags)); + if (!constructor.empty()) + // add the constructor, only if we have any documentation to add + methods["constructor"] = constructor; + } + for (auto const& it: _contractDef.interfaceFunctions()) { if (!it.second->hasDeclaration()) continue; - Json::Value method; if (auto fun = dynamic_cast<FunctionDefinition const*>(&it.second->declaration())) { - auto dev = extractDoc(fun->annotation().docTags, "dev"); - if (!dev.empty()) - method["details"] = Json::Value(dev); - - auto author = extractDoc(fun->annotation().docTags, "author"); - if (!author.empty()) - method["author"] = author; - - auto ret = extractDoc(fun->annotation().docTags, "return"); - if (!ret.empty()) - method["return"] = ret; - - Json::Value params(Json::objectValue); - auto paramRange = fun->annotation().docTags.equal_range("param"); - for (auto i = paramRange.first; i != paramRange.second; ++i) - params[i->second.paramName] = Json::Value(i->second.content); - - if (!params.empty()) - method["params"] = params; - + Json::Value method(devDocumentation(fun->annotation().docTags)); if (!method.empty()) // add the function, only if we have any documentation to add methods[it.second->externalSignature()] = method; @@ -118,3 +115,31 @@ string Natspec::extractDoc(multimap<string, DocTag> const& _tags, string const& value += i->second.content; return value; } + +Json::Value Natspec::devDocumentation(std::multimap<std::string, DocTag> const &_tags) +{ + Json::Value json(Json::objectValue); + auto dev = extractDoc(_tags, "dev"); + if (!dev.empty()) + json["details"] = Json::Value(dev); + + auto author = extractDoc(_tags, "author"); + if (!author.empty()) + 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); + auto paramRange = _tags.equal_range("param"); + for (auto i = paramRange.first; i != paramRange.second; ++i) + params[i->second.paramName] = Json::Value(i->second.content); + + if (!params.empty()) + json["params"] = params; + + return json; +} |