aboutsummaryrefslogtreecommitdiffstats
path: root/InterfaceHandler.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-12-04 00:46:04 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-12-04 00:46:04 +0800
commita0ff2179d46404e265226981f8f7cd99c7aba5d1 (patch)
treec8064c27d4369d498bd4bab9d82dc78f611bdad4 /InterfaceHandler.cpp
parentd25581de7cc89470a060625c043dba8cf9ae293f (diff)
downloaddexon-solidity-a0ff2179d46404e265226981f8f7cd99c7aba5d1.tar.gz
dexon-solidity-a0ff2179d46404e265226981f8f7cd99c7aba5d1.tar.zst
dexon-solidity-a0ff2179d46404e265226981f8f7cd99c7aba5d1.zip
Work in progress for parsing natspec doxytags
Diffstat (limited to 'InterfaceHandler.cpp')
-rw-r--r--InterfaceHandler.cpp69
1 files changed, 66 insertions, 3 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