2014-12-04 16:19:47 +00:00
|
|
|
|
2014-12-03 15:40:37 +00:00
|
|
|
#include <libsolidity/InterfaceHandler.h>
|
|
|
|
#include <libsolidity/AST.h>
|
|
|
|
#include <libsolidity/CompilerStack.h>
|
2015-01-08 23:22:06 +00:00
|
|
|
using namespace std;
|
2014-12-03 15:40:37 +00:00
|
|
|
|
2014-12-04 22:55:47 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
2014-12-03 15:40:37 +00:00
|
|
|
|
2014-12-03 16:46:04 +00:00
|
|
|
/* -- public -- */
|
|
|
|
|
2014-12-03 15:40:37 +00:00
|
|
|
InterfaceHandler::InterfaceHandler()
|
|
|
|
{
|
2015-02-09 13:12:36 +00:00
|
|
|
m_lastTag = DocTagType::None;
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
unique_ptr<string> InterfaceHandler::getDocumentation(
|
|
|
|
ContractDefinition const& _contractDef,
|
|
|
|
DocumentationType _type
|
|
|
|
)
|
2014-12-03 15:40:37 +00:00
|
|
|
{
|
|
|
|
switch(_type)
|
|
|
|
{
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocumentationType::NatspecUser:
|
2015-06-15 13:21:23 +00:00
|
|
|
return userDocumentation(_contractDef);
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocumentationType::NatspecDev:
|
2015-06-15 13:21:23 +00:00
|
|
|
return devDocumentation(_contractDef);
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocumentationType::ABIInterface:
|
2014-12-03 15:40:37 +00:00
|
|
|
return getABIInterface(_contractDef);
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocumentationType::ABISolidityInterface:
|
2015-01-08 23:22:06 +00:00
|
|
|
return getABISolidityInterface(_contractDef);
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 11:08:26 +00:00
|
|
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
|
2014-12-03 15:40:37 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
unique_ptr<string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
2014-12-03 15:40:37 +00:00
|
|
|
{
|
2015-01-31 13:41:11 +00:00
|
|
|
Json::Value abi(Json::arrayValue);
|
2015-04-17 13:26:12 +00:00
|
|
|
|
2015-04-22 15:00:22 +00:00
|
|
|
auto populateParameters = [](vector<string> const& _paramNames, vector<string> const& _paramTypes)
|
2015-04-17 13:26:12 +00:00
|
|
|
{
|
2015-04-22 15:00:22 +00:00
|
|
|
Json::Value params(Json::arrayValue);
|
|
|
|
solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
|
|
|
|
for (unsigned i = 0; i < _paramNames.size(); ++i)
|
|
|
|
{
|
|
|
|
Json::Value param;
|
|
|
|
param["name"] = _paramNames[i];
|
|
|
|
param["type"] = _paramTypes[i];
|
|
|
|
params.append(param);
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
};
|
2015-04-17 13:26:12 +00:00
|
|
|
|
2015-04-22 15:00:22 +00:00
|
|
|
for (auto it: _contractDef.getInterfaceFunctions())
|
2015-01-31 16:23:58 +00:00
|
|
|
{
|
2015-05-11 11:47:21 +00:00
|
|
|
auto externalFunctionType = it.second->externalFunctionType();
|
2015-01-31 16:23:58 +00:00
|
|
|
Json::Value method;
|
2015-04-22 15:00:22 +00:00
|
|
|
method["type"] = "function";
|
2015-01-29 17:44:14 +00:00
|
|
|
method["name"] = it.second->getDeclaration().getName();
|
2015-01-29 15:39:30 +00:00
|
|
|
method["constant"] = it.second->isConstant();
|
2015-05-11 14:24:04 +00:00
|
|
|
method["inputs"] = populateParameters(
|
|
|
|
externalFunctionType->getParameterNames(),
|
|
|
|
externalFunctionType->getParameterTypeNames()
|
|
|
|
);
|
|
|
|
method["outputs"] = populateParameters(
|
|
|
|
externalFunctionType->getReturnParameterNames(),
|
|
|
|
externalFunctionType->getReturnParameterTypeNames()
|
|
|
|
);
|
2015-01-31 13:41:11 +00:00
|
|
|
abi.append(method);
|
2015-04-22 15:00:22 +00:00
|
|
|
}
|
|
|
|
if (_contractDef.getConstructor())
|
|
|
|
{
|
|
|
|
Json::Value method;
|
|
|
|
method["type"] = "constructor";
|
|
|
|
auto externalFunction = FunctionType(*_contractDef.getConstructor()).externalFunctionType();
|
|
|
|
solAssert(!!externalFunction, "");
|
|
|
|
method["inputs"] = populateParameters(
|
|
|
|
externalFunction->getParameterNames(),
|
|
|
|
externalFunction->getParameterTypeNames()
|
|
|
|
);
|
|
|
|
abi.append(method);
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
2015-01-31 13:41:11 +00:00
|
|
|
|
|
|
|
for (auto const& it: _contractDef.getInterfaceEvents())
|
|
|
|
{
|
|
|
|
Json::Value event;
|
|
|
|
event["type"] = "event";
|
|
|
|
event["name"] = it->getName();
|
2015-03-17 10:34:56 +00:00
|
|
|
event["anonymous"] = it->isAnonymous();
|
2015-01-31 13:41:11 +00:00
|
|
|
Json::Value params(Json::arrayValue);
|
|
|
|
for (auto const& p: it->getParameters())
|
|
|
|
{
|
|
|
|
Json::Value input;
|
|
|
|
input["name"] = p->getName();
|
2015-06-09 12:26:08 +00:00
|
|
|
input["type"] = p->getType()->toString(true);
|
2015-01-31 13:41:11 +00:00
|
|
|
input["indexed"] = p->isIndexed();
|
|
|
|
params.append(input);
|
|
|
|
}
|
|
|
|
event["inputs"] = params;
|
|
|
|
abi.append(event);
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
2015-06-09 11:20:42 +00:00
|
|
|
return unique_ptr<string>(new string(Json::FastWriter().write(abi)));
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 23:22:06 +00:00
|
|
|
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
|
|
|
{
|
|
|
|
string ret = "contract " + _contractDef.getName() + "{";
|
2015-05-19 13:24:33 +00:00
|
|
|
|
2015-05-20 16:37:09 +00:00
|
|
|
auto populateParameters = [](vector<string> const& _paramNames, vector<string> const& _paramTypes)
|
2015-05-19 13:24:33 +00:00
|
|
|
{
|
|
|
|
string r = "";
|
|
|
|
solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
|
|
|
|
for (unsigned i = 0; i < _paramNames.size(); ++i)
|
|
|
|
r += (r.size() ? "," : "(") + _paramTypes[i] + " " + _paramNames[i];
|
|
|
|
return r.size() ? r + ")" : "()";
|
|
|
|
};
|
|
|
|
if (_contractDef.getConstructor())
|
|
|
|
{
|
|
|
|
auto externalFunction = FunctionType(*_contractDef.getConstructor()).externalFunctionType();
|
|
|
|
solAssert(!!externalFunction, "");
|
2015-05-19 13:33:08 +00:00
|
|
|
ret +=
|
|
|
|
"function " +
|
|
|
|
_contractDef.getName() +
|
|
|
|
populateParameters(externalFunction->getParameterNames(), externalFunction->getParameterTypeNames()) +
|
|
|
|
";";
|
2015-05-19 13:24:33 +00:00
|
|
|
}
|
2015-01-09 10:51:52 +00:00
|
|
|
for (auto const& it: _contractDef.getInterfaceFunctions())
|
2015-01-08 23:22:06 +00:00
|
|
|
{
|
2015-01-29 17:44:14 +00:00
|
|
|
ret += "function " + it.second->getDeclaration().getName() +
|
2015-01-29 15:39:30 +00:00
|
|
|
populateParameters(it.second->getParameterNames(), it.second->getParameterTypeNames()) +
|
|
|
|
(it.second->isConstant() ? "constant " : "");
|
|
|
|
if (it.second->getReturnParameterTypes().size())
|
|
|
|
ret += "returns" + populateParameters(it.second->getReturnParameterNames(), it.second->getReturnParameterTypeNames());
|
2015-01-08 23:22:06 +00:00
|
|
|
else if (ret.back() == ' ')
|
|
|
|
ret.pop_back();
|
2015-04-23 12:45:50 +00:00
|
|
|
ret += ";";
|
2015-01-08 23:22:06 +00:00
|
|
|
}
|
2015-01-31 13:41:11 +00:00
|
|
|
|
2015-01-08 23:22:06 +00:00
|
|
|
return unique_ptr<string>(new string(ret + "}"));
|
|
|
|
}
|
|
|
|
|
2015-06-15 13:21:23 +00:00
|
|
|
void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDef)
|
2014-12-03 15:40:37 +00:00
|
|
|
{
|
|
|
|
Json::Value doc;
|
|
|
|
Json::Value methods(Json::objectValue);
|
|
|
|
|
2015-01-08 23:27:26 +00:00
|
|
|
for (auto const& it: _contractDef.getInterfaceFunctions())
|
2014-12-03 15:40:37 +00:00
|
|
|
{
|
|
|
|
Json::Value user;
|
2015-01-29 15:39:30 +00:00
|
|
|
auto strPtr = it.second->getDocumentation();
|
2014-12-03 15:40:37 +00:00
|
|
|
if (strPtr)
|
|
|
|
{
|
2014-12-04 16:19:47 +00:00
|
|
|
resetUser();
|
2015-02-09 13:12:36 +00:00
|
|
|
parseDocString(*strPtr, CommentOwner::Function);
|
2014-12-04 17:12:52 +00:00
|
|
|
if (!m_notice.empty())
|
|
|
|
{// since @notice is the only user tag if missing function should not appear
|
|
|
|
user["notice"] = Json::Value(m_notice);
|
2015-03-24 10:11:27 +00:00
|
|
|
methods[it.second->externalSignature()] = user;
|
2014-12-04 17:12:52 +00:00
|
|
|
}
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
doc["methods"] = methods;
|
|
|
|
|
2015-06-18 12:57:43 +00:00
|
|
|
_contractDef.setUserDocumentation(Json::StyledWriter().write(doc));
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 13:21:23 +00:00
|
|
|
unique_ptr<string> InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef)
|
|
|
|
{
|
|
|
|
return _contractDef.userDocumentation();
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<string> InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef)
|
|
|
|
{
|
|
|
|
return _contractDef.devDocumentation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef)
|
2014-12-03 15:40:37 +00:00
|
|
|
{
|
2014-12-04 17:12:52 +00:00
|
|
|
// LTODO: Somewhere in this function warnings for mismatch of param names
|
|
|
|
// should be thrown
|
2014-12-03 16:46:04 +00:00
|
|
|
Json::Value doc;
|
|
|
|
Json::Value methods(Json::objectValue);
|
|
|
|
|
2014-12-10 12:13:12 +00:00
|
|
|
auto contractDoc = _contractDef.getDocumentation();
|
|
|
|
if (contractDoc)
|
|
|
|
{
|
|
|
|
m_contractAuthor.clear();
|
|
|
|
m_title.clear();
|
2015-02-09 13:12:36 +00:00
|
|
|
parseDocString(*contractDoc, CommentOwner::Contract);
|
2014-12-10 12:13:12 +00:00
|
|
|
|
|
|
|
if (!m_contractAuthor.empty())
|
|
|
|
doc["author"] = m_contractAuthor;
|
|
|
|
|
|
|
|
if (!m_title.empty())
|
|
|
|
doc["title"] = m_title;
|
|
|
|
}
|
|
|
|
|
2015-01-08 23:27:26 +00:00
|
|
|
for (auto const& it: _contractDef.getInterfaceFunctions())
|
2014-12-03 16:46:04 +00:00
|
|
|
{
|
|
|
|
Json::Value method;
|
2015-01-29 15:39:30 +00:00
|
|
|
auto strPtr = it.second->getDocumentation();
|
2014-12-03 16:46:04 +00:00
|
|
|
if (strPtr)
|
|
|
|
{
|
2014-12-04 16:19:47 +00:00
|
|
|
resetDev();
|
2015-02-09 13:12:36 +00:00
|
|
|
parseDocString(*strPtr, CommentOwner::Function);
|
2014-12-03 16:46:04 +00:00
|
|
|
|
2014-12-04 17:12:52 +00:00
|
|
|
if (!m_dev.empty())
|
|
|
|
method["details"] = Json::Value(m_dev);
|
2014-12-10 12:13:12 +00:00
|
|
|
|
|
|
|
if (!m_author.empty())
|
|
|
|
method["author"] = m_author;
|
|
|
|
|
2014-12-04 16:19:47 +00:00
|
|
|
Json::Value params(Json::objectValue);
|
2015-06-09 11:20:42 +00:00
|
|
|
vector<string> paramNames = it.second->getParameterNames();
|
2014-12-04 16:19:47 +00:00
|
|
|
for (auto const& pair: m_params)
|
2015-03-30 13:14:59 +00:00
|
|
|
{
|
|
|
|
if (find(paramNames.begin(), paramNames.end(), pair.first) == paramNames.end())
|
|
|
|
// LTODO: mismatching parameter name, throw some form of warning and not just an exception
|
|
|
|
BOOST_THROW_EXCEPTION(
|
|
|
|
DocstringParsingError() <<
|
2015-06-15 13:21:23 +00:00
|
|
|
errinfo_comment("documented parameter \"" + pair.first + "\" not found in the parameter list of the function.")
|
2015-03-30 13:14:59 +00:00
|
|
|
);
|
2014-12-04 16:19:47 +00:00
|
|
|
params[pair.first] = pair.second;
|
2015-03-30 13:14:59 +00:00
|
|
|
}
|
2014-12-04 22:55:47 +00:00
|
|
|
|
2014-12-04 17:12:52 +00:00
|
|
|
if (!m_params.empty())
|
|
|
|
method["params"] = params;
|
2014-12-10 12:13:12 +00:00
|
|
|
|
2014-12-04 17:12:52 +00:00
|
|
|
if (!m_return.empty())
|
|
|
|
method["return"] = m_return;
|
|
|
|
|
|
|
|
if (!method.empty()) // add the function, only if we have any documentation to add
|
2015-03-24 10:11:27 +00:00
|
|
|
methods[it.second->externalSignature()] = method;
|
2014-12-03 16:46:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
doc["methods"] = methods;
|
|
|
|
|
2015-06-18 12:57:43 +00:00
|
|
|
_contractDef.setDevDocumentation(Json::StyledWriter().write(doc));
|
2014-12-03 16:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -- private -- */
|
2014-12-04 16:19:47 +00:00
|
|
|
void InterfaceHandler::resetUser()
|
|
|
|
{
|
|
|
|
m_notice.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceHandler::resetDev()
|
|
|
|
{
|
|
|
|
m_dev.clear();
|
2014-12-10 12:13:12 +00:00
|
|
|
m_author.clear();
|
2014-12-04 17:12:52 +00:00
|
|
|
m_return.clear();
|
2014-12-04 16:19:47 +00:00
|
|
|
m_params.clear();
|
|
|
|
}
|
|
|
|
|
2015-06-09 11:22:36 +00:00
|
|
|
static inline string::const_iterator skipLineOrEOS(
|
|
|
|
string::const_iterator _nlPos,
|
|
|
|
string::const_iterator _end
|
|
|
|
)
|
2014-12-04 16:19:47 +00:00
|
|
|
{
|
2014-12-05 01:10:54 +00:00
|
|
|
return (_nlPos == _end) ? _end : ++_nlPos;
|
2014-12-04 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
string::const_iterator InterfaceHandler::parseDocTagLine(
|
|
|
|
string::const_iterator _pos,
|
|
|
|
string::const_iterator _end,
|
|
|
|
string& _tagString,
|
|
|
|
DocTagType _tagType,
|
|
|
|
bool _appending
|
|
|
|
)
|
2014-12-04 16:19:47 +00:00
|
|
|
{
|
2015-06-09 11:20:42 +00:00
|
|
|
auto nlPos = find(_pos, _end, '\n');
|
2014-12-18 15:27:17 +00:00
|
|
|
if (_appending && _pos < _end && *_pos != ' ')
|
2014-12-18 13:43:35 +00:00
|
|
|
_tagString += " ";
|
2015-06-09 11:20:42 +00:00
|
|
|
copy(_pos, nlPos, back_inserter(_tagString));
|
2014-12-04 16:19:47 +00:00
|
|
|
m_lastTag = _tagType;
|
2014-12-05 01:10:54 +00:00
|
|
|
return skipLineOrEOS(nlPos, _end);
|
2014-12-04 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
string::const_iterator InterfaceHandler::parseDocTagParam(
|
|
|
|
string::const_iterator _pos,
|
|
|
|
string::const_iterator _end
|
|
|
|
)
|
2014-12-04 16:19:47 +00:00
|
|
|
{
|
|
|
|
// find param name
|
2015-06-09 11:20:42 +00:00
|
|
|
auto currPos = find(_pos, _end, ' ');
|
2014-12-05 01:10:54 +00:00
|
|
|
if (currPos == _end)
|
2015-06-09 11:20:42 +00:00
|
|
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("End of param name not found" + string(_pos, _end)));
|
2014-12-04 22:55:47 +00:00
|
|
|
|
2014-12-04 16:19:47 +00:00
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
auto paramName = string(_pos, currPos);
|
2014-12-04 16:19:47 +00:00
|
|
|
|
|
|
|
currPos += 1;
|
2015-06-09 11:20:42 +00:00
|
|
|
auto nlPos = find(currPos, _end, '\n');
|
|
|
|
auto paramDesc = string(currPos, nlPos);
|
|
|
|
m_params.push_back(make_pair(paramName, paramDesc));
|
2014-12-04 16:19:47 +00:00
|
|
|
|
2015-02-09 13:12:36 +00:00
|
|
|
m_lastTag = DocTagType::Param;
|
2014-12-05 01:10:54 +00:00
|
|
|
return skipLineOrEOS(nlPos, _end);
|
2014-12-04 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
string::const_iterator InterfaceHandler::appendDocTagParam(
|
|
|
|
string::const_iterator _pos,
|
|
|
|
string::const_iterator _end
|
|
|
|
)
|
2014-12-04 16:19:47 +00:00
|
|
|
{
|
|
|
|
// Should never be called with an empty vector
|
2014-12-17 15:23:18 +00:00
|
|
|
solAssert(!m_params.empty(), "Internal: Tried to append to empty parameter");
|
2014-12-05 01:10:54 +00:00
|
|
|
|
2014-12-04 16:19:47 +00:00
|
|
|
auto pair = m_params.back();
|
2014-12-18 15:27:17 +00:00
|
|
|
if (_pos < _end && *_pos != ' ')
|
2014-12-18 13:43:35 +00:00
|
|
|
pair.second += " ";
|
2015-06-09 11:20:42 +00:00
|
|
|
auto nlPos = find(_pos, _end, '\n');
|
|
|
|
copy(_pos, nlPos, back_inserter(pair.second));
|
2014-12-04 16:19:47 +00:00
|
|
|
|
|
|
|
m_params.at(m_params.size() - 1) = pair;
|
|
|
|
|
2014-12-05 01:10:54 +00:00
|
|
|
return skipLineOrEOS(nlPos, _end);
|
2014-12-04 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
string::const_iterator InterfaceHandler::parseDocTag(
|
|
|
|
string::const_iterator _pos,
|
|
|
|
string::const_iterator _end,
|
|
|
|
string const& _tag,
|
|
|
|
CommentOwner _owner
|
|
|
|
)
|
2014-12-03 16:46:04 +00:00
|
|
|
{
|
2014-12-04 17:12:52 +00:00
|
|
|
// LTODO: need to check for @(start of a tag) between here and the end of line
|
2014-12-10 15:44:54 +00:00
|
|
|
// for all cases. Also somehow automate list of acceptable tags for each
|
|
|
|
// language construct since current way does not scale well.
|
2015-02-09 13:12:36 +00:00
|
|
|
if (m_lastTag == DocTagType::None || _tag != "")
|
2014-12-03 16:46:04 +00:00
|
|
|
{
|
2014-12-04 08:42:38 +00:00
|
|
|
if (_tag == "dev")
|
2015-02-09 13:12:36 +00:00
|
|
|
return parseDocTagLine(_pos, _end, m_dev, DocTagType::Dev, false);
|
2014-12-04 08:42:38 +00:00
|
|
|
else if (_tag == "notice")
|
2015-02-09 13:12:36 +00:00
|
|
|
return parseDocTagLine(_pos, _end, m_notice, DocTagType::Notice, false);
|
2014-12-04 17:12:52 +00:00
|
|
|
else if (_tag == "return")
|
2015-02-09 13:12:36 +00:00
|
|
|
return parseDocTagLine(_pos, _end, m_return, DocTagType::Return, false);
|
2014-12-10 12:13:12 +00:00
|
|
|
else if (_tag == "author")
|
|
|
|
{
|
2015-02-09 13:12:36 +00:00
|
|
|
if (_owner == CommentOwner::Contract)
|
|
|
|
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::Author, false);
|
|
|
|
else if (_owner == CommentOwner::Function)
|
|
|
|
return parseDocTagLine(_pos, _end, m_author, DocTagType::Author, false);
|
2014-12-10 12:13:12 +00:00
|
|
|
else
|
|
|
|
// LTODO: for now this else makes no sense but later comments will go to more language constructs
|
|
|
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag is legal only for contracts"));
|
|
|
|
}
|
|
|
|
else if (_tag == "title")
|
|
|
|
{
|
2015-02-09 13:12:36 +00:00
|
|
|
if (_owner == CommentOwner::Contract)
|
|
|
|
return parseDocTagLine(_pos, _end, m_title, DocTagType::Title, false);
|
2014-12-10 12:13:12 +00:00
|
|
|
else
|
|
|
|
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
|
|
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag is legal only for contracts"));
|
|
|
|
}
|
2014-12-04 16:19:47 +00:00
|
|
|
else if (_tag == "param")
|
2014-12-05 01:10:54 +00:00
|
|
|
return parseDocTagParam(_pos, _end);
|
2014-12-04 08:42:38 +00:00
|
|
|
else
|
2014-12-05 01:10:54 +00:00
|
|
|
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
2014-12-05 11:08:26 +00:00
|
|
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("Unknown tag " + _tag + " encountered"));
|
2014-12-03 16:46:04 +00:00
|
|
|
}
|
|
|
|
else
|
2014-12-10 12:13:12 +00:00
|
|
|
return appendDocTag(_pos, _end, _owner);
|
2014-12-04 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
string::const_iterator InterfaceHandler::appendDocTag(
|
|
|
|
string::const_iterator _pos,
|
|
|
|
string::const_iterator _end,
|
|
|
|
CommentOwner _owner
|
|
|
|
)
|
2014-12-04 16:19:47 +00:00
|
|
|
{
|
2014-12-04 22:55:47 +00:00
|
|
|
switch (m_lastTag)
|
2014-12-03 16:46:04 +00:00
|
|
|
{
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocTagType::Dev:
|
|
|
|
return parseDocTagLine(_pos, _end, m_dev, DocTagType::Dev, true);
|
|
|
|
case DocTagType::Notice:
|
|
|
|
return parseDocTagLine(_pos, _end, m_notice, DocTagType::Notice, true);
|
|
|
|
case DocTagType::Return:
|
|
|
|
return parseDocTagLine(_pos, _end, m_return, DocTagType::Return, true);
|
|
|
|
case DocTagType::Author:
|
|
|
|
if (_owner == CommentOwner::Contract)
|
|
|
|
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::Author, true);
|
|
|
|
else if (_owner == CommentOwner::Function)
|
|
|
|
return parseDocTagLine(_pos, _end, m_author, DocTagType::Author, true);
|
2014-12-10 12:13:12 +00:00
|
|
|
else
|
|
|
|
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
|
|
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag in illegal comment"));
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocTagType::Title:
|
|
|
|
if (_owner == CommentOwner::Contract)
|
|
|
|
return parseDocTagLine(_pos, _end, m_title, DocTagType::Title, true);
|
2014-12-10 12:13:12 +00:00
|
|
|
else
|
|
|
|
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
|
|
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag in illegal comment"));
|
2015-02-09 13:12:36 +00:00
|
|
|
case DocTagType::Param:
|
2014-12-10 12:13:12 +00:00
|
|
|
return appendDocTagParam(_pos, _end);
|
|
|
|
default:
|
|
|
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Illegal documentation tag type"));
|
|
|
|
break;
|
2014-12-05 01:10:54 +00:00
|
|
|
}
|
2014-12-03 16:46:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
static inline string::const_iterator getFirstSpaceOrNl(
|
|
|
|
string::const_iterator _pos,
|
|
|
|
string::const_iterator _end
|
|
|
|
)
|
2014-12-05 11:27:18 +00:00
|
|
|
{
|
2015-06-09 11:20:42 +00:00
|
|
|
auto spacePos = find(_pos, _end, ' ');
|
|
|
|
auto nlPos = find(_pos, _end, '\n');
|
2014-12-05 11:27:18 +00:00
|
|
|
return (spacePos < nlPos) ? spacePos : nlPos;
|
|
|
|
}
|
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
void InterfaceHandler::parseDocString(string const& _string, CommentOwner _owner)
|
2014-12-03 16:46:04 +00:00
|
|
|
{
|
2014-12-05 01:10:54 +00:00
|
|
|
auto currPos = _string.begin();
|
|
|
|
auto end = _string.end();
|
2014-12-03 16:46:04 +00:00
|
|
|
|
2014-12-05 01:10:54 +00:00
|
|
|
while (currPos != end)
|
2014-12-04 08:42:38 +00:00
|
|
|
{
|
2015-06-09 11:20:42 +00:00
|
|
|
auto tagPos = find(currPos, end, '@');
|
|
|
|
auto nlPos = find(currPos, end, '\n');
|
2014-12-03 16:46:04 +00:00
|
|
|
|
2014-12-05 01:10:54 +00:00
|
|
|
if (tagPos != end && tagPos < nlPos)
|
|
|
|
{
|
|
|
|
// we found a tag
|
2014-12-05 11:27:18 +00:00
|
|
|
auto tagNameEndPos = getFirstSpaceOrNl(tagPos, end);
|
2014-12-05 01:10:54 +00:00
|
|
|
if (tagNameEndPos == end)
|
2015-06-09 11:20:42 +00:00
|
|
|
BOOST_THROW_EXCEPTION(
|
|
|
|
DocstringParsingError() <<
|
|
|
|
errinfo_comment("End of tag " + string(tagPos, tagNameEndPos) + "not found"));
|
2014-12-05 01:10:54 +00:00
|
|
|
|
2015-06-09 11:20:42 +00:00
|
|
|
currPos = parseDocTag(tagNameEndPos + 1, end, string(tagPos + 1, tagNameEndPos), _owner);
|
2014-12-05 01:10:54 +00:00
|
|
|
}
|
2015-02-09 13:12:36 +00:00
|
|
|
else if (m_lastTag != DocTagType::None) // continuation of the previous tag
|
2014-12-18 13:43:35 +00:00
|
|
|
currPos = appendDocTag(currPos, end, _owner);
|
2015-01-12 14:29:44 +00:00
|
|
|
else if (currPos != end)
|
|
|
|
{
|
2015-01-20 12:15:43 +00:00
|
|
|
// if it begins without a tag then consider it as @notice
|
|
|
|
if (currPos == _string.begin())
|
|
|
|
{
|
2015-02-09 13:12:36 +00:00
|
|
|
currPos = parseDocTag(currPos, end, "notice", CommentOwner::Function);
|
2015-01-20 12:15:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (nlPos == end) //end of text
|
2015-01-12 14:29:44 +00:00
|
|
|
return;
|
2015-01-20 12:15:43 +00:00
|
|
|
// else skip the line if a newline was found and we get here
|
2014-12-05 11:08:26 +00:00
|
|
|
currPos = nlPos + 1;
|
2015-01-12 14:29:44 +00:00
|
|
|
}
|
2014-12-04 08:42:38 +00:00
|
|
|
}
|
2014-12-03 15:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} //solidity NS
|
|
|
|
} // dev NS
|