aboutsummaryrefslogtreecommitdiffstats
path: root/InterfaceHandler.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-12-04 16:42:38 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-12-04 16:42:38 +0800
commit3e803b40e1b22daf8e3ac45593aec6798d365ccb (patch)
treebdb86065381d516026512929277a9b834567e94f /InterfaceHandler.cpp
parentba27dc74214d70a4ce8dcfcbb0b15a829f2b050d (diff)
downloaddexon-solidity-3e803b40e1b22daf8e3ac45593aec6798d365ccb.tar.gz
dexon-solidity-3e803b40e1b22daf8e3ac45593aec6798d365ccb.tar.zst
dexon-solidity-3e803b40e1b22daf8e3ac45593aec6798d365ccb.zip
Parsing notice and dev doxytags.
- Only initial work done. Still need to refine the logic and incorporate all the other types of tags. - Added/Modified some tests - Work in progress
Diffstat (limited to 'InterfaceHandler.cpp')
-rw-r--r--InterfaceHandler.cpp90
1 files changed, 67 insertions, 23 deletions
diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp
index 61570b8d..e7da5e6d 100644
--- a/InterfaceHandler.cpp
+++ b/InterfaceHandler.cpp
@@ -9,6 +9,7 @@ namespace solidity {
InterfaceHandler::InterfaceHandler()
{
+ m_lastTag = DOCTAG_NONE;
}
std::unique_ptr<std::string> InterfaceHandler::getDocumentation(std::shared_ptr<ContractDefinition> _contractDef,
@@ -71,7 +72,9 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(std::shared_
auto strPtr = f->getDocumentation();
if (strPtr)
{
- user["notice"] = Json::Value(*strPtr);
+ m_notice.clear();
+ parseDocString(*strPtr);
+ user["notice"] = Json::Value(m_notice);
methods[f->getName()] = user;
}
}
@@ -94,7 +97,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(std::shared_p
m_dev.clear();
parseDocString(*strPtr);
- method["dev"] = Json::Value(m_dev);
+ method["details"] = Json::Value(m_dev);
methods[f->getName()] = method;
}
}
@@ -106,26 +109,55 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(std::shared_p
/* -- private -- */
size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string const& _tag, size_t _pos)
{
+ //TODO: This is pretty naive at the moment. e.g. need to check for
+ // '@' between _pos and \n, remove redundancy e.t.c.
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")
+ if (m_lastTag == DOCTAG_NONE || _tag != "")
{
- nlPos = _string.find("\n", _pos);
- m_notice += _string.substr(_pos,
- nlPos == std::string::npos ?
- _string.length() :
- nlPos - _pos);
+ if (_tag == "dev")
+ {
+ nlPos = _string.find("\n", _pos);
+ m_dev += _string.substr(_pos,
+ nlPos == std::string::npos ?
+ _string.length() :
+ nlPos - _pos);
+ m_lastTag = DOCTAG_DEV;
+ }
+ else if (_tag == "notice")
+ {
+ nlPos = _string.find("\n", _pos);
+ m_notice += _string.substr(_pos,
+ nlPos == std::string::npos ?
+ _string.length() :
+ nlPos - _pos);
+ m_lastTag = DOCTAG_NOTICE;
+ }
+ else
+ {
+ //TODO: Some form of warning
+ }
}
else
{
- //TODO: Some form of warning
+ switch(m_lastTag)
+ {
+ case DOCTAG_DEV:
+ nlPos = _string.find("\n", _pos);
+ m_dev += _string.substr(_pos,
+ nlPos == std::string::npos ?
+ _string.length() :
+ nlPos - _pos);
+ break;
+ case DOCTAG_NOTICE:
+ nlPos = _string.find("\n", _pos);
+ m_notice += _string.substr(_pos,
+ nlPos == std::string::npos ?
+ _string.length() :
+ nlPos - _pos);
+ break;
+ default:
+ break;
+ }
}
return nlPos;
@@ -134,16 +166,28 @@ size_t InterfaceHandler::parseDocTag(std::string const& _string, std::string con
void InterfaceHandler::parseDocString(std::string const& _string, size_t _startPos)
{
size_t pos2;
+ size_t newPos = _startPos;
size_t pos1 = _string.find("@", _startPos);
- if (pos1 == std::string::npos)
- return; // no doxytags found
+ if (pos1 != std::string::npos)
+ {
+ // we found a tag
+ pos2 = _string.find(" ", pos1);
+ if (pos2 == std::string::npos)
+ {
+ BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of tag not found"));
+ return; //no end of tag found
+ }
- pos2 = _string.find(" ", pos1);
- if (pos2 == std::string::npos)
- return; //no end of tag found
+ newPos = parseDocTag(_string, _string.substr(pos1 + 1, pos2 - pos1 - 1), pos2 + 1);
+ }
+ else
+ {
+ newPos = parseDocTag(_string, "", _startPos + 1);
+ }
- size_t newPos = parseDocTag(_string, _string.substr(pos1 + 1, pos2 - pos1), pos2);
+ if (newPos == std::string::npos)
+ return; // EOS
parseDocString(_string, newPos);
}