diff options
-rw-r--r-- | InterfaceHandler.cpp | 69 | ||||
-rw-r--r-- | InterfaceHandler.h | 11 |
2 files changed, 75 insertions, 5 deletions
diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp index c0e07280..a2c52c1f 100644 --- a/InterfaceHandler.cpp +++ b/InterfaceHandler.cpp @@ -5,12 +5,14 @@ namespace dev { namespace solidity { +/* -- public -- */ + InterfaceHandler::InterfaceHandler() { } std::unique_ptr<std::string> InterfaceHandler::getDocumentation(std::shared_ptr<ContractDefinition> _contractDef, - enum documentation_type _type) + enum documentation_type _type) { switch(_type) { @@ -80,8 +82,69 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(std::shared_ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(std::shared_ptr<ContractDefinition> _contractDef) { - //TODO - return nullptr; + Json::Value doc; + Json::Value methods(Json::objectValue); + + for (FunctionDefinition const* f: _contractDef->getInterfaceFunctions()) + { + Json::Value method; + auto strPtr = f->getDocumentation(); + if (strPtr) + { + m_dev.clear(); + parseDocString(*strPtr); + + method["dev"] = Json::Value(m_dev); + methods[f->getName()] = method; + } + } + doc["methods"] = methods; + + return std::unique_ptr<std::string>(new std::string(m_writer.write(doc))); +} + +/* -- private -- */ +size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string const& _tag, size_t _pos) +{ + size_t nlPos = _pos; + if (_tag == "dev") + { + nlPos = _string.find("\n", _pos); + m_dev += _string.substr(_pos, + nlPos == std::string::npos ? + _string.length() : + nlPos - _pos); + } + else if (_tag == "notice") + { + nlPos = _string.find("\n", _pos); + m_notice += _string.substr(_pos, + nlPos == std::string::npos ? + _string.length() : + nlPos - _pos); + } + else + { + //TODO: Some form of warning + } + + return nlPos; +} + +void InterfaceHandler::parseDocString(std::string const& _string, size_t _startPos) +{ + size_t pos2; + size_t pos1 = _string.find("@", _startPos); + + if (pos1 == std::string::npos) + return; // no doxytags found + + pos2 = _string.find(" ", pos1); + if (pos2 == std::string::npos) + return; //no end of tag found + + size_t newPos = parseDocTag(_string, _string.substr(pos1 + 1, pos2 - pos1), pos2); + parseDocString(_string, newPos); } } //solidity NS diff --git a/InterfaceHandler.h b/InterfaceHandler.h index ed6c8ba4..125ecda4 100644 --- a/InterfaceHandler.h +++ b/InterfaceHandler.h @@ -20,7 +20,7 @@ * Takes the parsed AST and produces the Natspec * documentation and the ABI interface * https://github.com/ethereum/wiki/wiki/Ethereum-Natural-Specification-Format - * + * * Can generally deal with JSON files */ @@ -44,7 +44,7 @@ public: /// Get the given type of documentation /// @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 documentation_type /// @return A unique pointer contained string with the json /// representation of provided type @@ -67,7 +67,14 @@ public: std::unique_ptr<std::string> getDevDocumentation(std::shared_ptr<ContractDefinition> _contractDef); private: + void parseDocString(std::string const& _string, size_t _startPos = 0); + size_t parseDocTag(std::string const& _string, std::string const& _tag, size_t _pos); + Json::StyledWriter m_writer; + + // internal state + std::string m_notice; + std::string m_dev; }; } //solidity NS |