mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2126 from LianaHus/sol_Natspec_warnings_instead_of_exceptions
Some style fixes.
This commit is contained in:
commit
3588709e4e
@ -16,8 +16,10 @@ InterfaceHandler::InterfaceHandler()
|
|||||||
m_lastTag = DocTagType::None;
|
m_lastTag = DocTagType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefinition const& _contractDef,
|
unique_ptr<string> InterfaceHandler::getDocumentation(
|
||||||
DocumentationType _type)
|
ContractDefinition const& _contractDef,
|
||||||
|
DocumentationType _type
|
||||||
|
)
|
||||||
{
|
{
|
||||||
switch(_type)
|
switch(_type)
|
||||||
{
|
{
|
||||||
@ -35,7 +37,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefiniti
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
unique_ptr<string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
Json::Value abi(Json::arrayValue);
|
Json::Value abi(Json::arrayValue);
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
|
|||||||
event["inputs"] = params;
|
event["inputs"] = params;
|
||||||
abi.append(event);
|
abi.append(event);
|
||||||
}
|
}
|
||||||
return std::unique_ptr<std::string>(new std::string(Json::FastWriter().write(abi)));
|
return unique_ptr<string>(new string(Json::FastWriter().write(abi)));
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
||||||
@ -141,7 +143,7 @@ unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition
|
|||||||
return unique_ptr<string>(new string(ret + "}"));
|
return unique_ptr<string>(new string(ret + "}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefinition const& _contractDef)
|
unique_ptr<string> InterfaceHandler::getUserDocumentation(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
Json::Value doc;
|
Json::Value doc;
|
||||||
Json::Value methods(Json::objectValue);
|
Json::Value methods(Json::objectValue);
|
||||||
@ -163,10 +165,10 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefi
|
|||||||
}
|
}
|
||||||
doc["methods"] = methods;
|
doc["methods"] = methods;
|
||||||
|
|
||||||
return std::unique_ptr<std::string>(new std::string(Json::FastWriter().write(doc)));
|
return unique_ptr<string>(new string(Json::FastWriter().write(doc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefinition const& _contractDef)
|
unique_ptr<string> InterfaceHandler::getDevDocumentation(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
// LTODO: Somewhere in this function warnings for mismatch of param names
|
// LTODO: Somewhere in this function warnings for mismatch of param names
|
||||||
// should be thrown
|
// should be thrown
|
||||||
@ -203,7 +205,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
|
|||||||
method["author"] = m_author;
|
method["author"] = m_author;
|
||||||
|
|
||||||
Json::Value params(Json::objectValue);
|
Json::Value params(Json::objectValue);
|
||||||
std::vector<std::string> paramNames = it.second->getParameterNames();
|
vector<string> paramNames = it.second->getParameterNames();
|
||||||
for (auto const& pair: m_params)
|
for (auto const& pair: m_params)
|
||||||
{
|
{
|
||||||
if (find(paramNames.begin(), paramNames.end(), pair.first) == paramNames.end())
|
if (find(paramNames.begin(), paramNames.end(), pair.first) == paramNames.end())
|
||||||
@ -227,7 +229,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
|
|||||||
}
|
}
|
||||||
doc["methods"] = methods;
|
doc["methods"] = methods;
|
||||||
|
|
||||||
return std::unique_ptr<std::string>(new std::string(Json::FastWriter().write(doc)));
|
return unique_ptr<string>(new string(Json::FastWriter().write(doc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- private -- */
|
/* -- private -- */
|
||||||
@ -244,48 +246,56 @@ void InterfaceHandler::resetDev()
|
|||||||
m_params.clear();
|
m_params.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string::const_iterator skipLineOrEOS(std::string::const_iterator _nlPos,
|
static inline string::const_iterator skipLineOrEOS(
|
||||||
std::string::const_iterator _end)
|
string::const_iterator _nlPos,
|
||||||
|
string::const_iterator _end
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return (_nlPos == _end) ? _end : ++_nlPos;
|
return (_nlPos == _end) ? _end : ++_nlPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::const_iterator InterfaceHandler::parseDocTagLine(std::string::const_iterator _pos,
|
string::const_iterator InterfaceHandler::parseDocTagLine(
|
||||||
std::string::const_iterator _end,
|
string::const_iterator _pos,
|
||||||
std::string& _tagString,
|
string::const_iterator _end,
|
||||||
DocTagType _tagType,
|
string& _tagString,
|
||||||
bool _appending)
|
DocTagType _tagType,
|
||||||
|
bool _appending
|
||||||
|
)
|
||||||
{
|
{
|
||||||
auto nlPos = std::find(_pos, _end, '\n');
|
auto nlPos = find(_pos, _end, '\n');
|
||||||
if (_appending && _pos < _end && *_pos != ' ')
|
if (_appending && _pos < _end && *_pos != ' ')
|
||||||
_tagString += " ";
|
_tagString += " ";
|
||||||
std::copy(_pos, nlPos, back_inserter(_tagString));
|
copy(_pos, nlPos, back_inserter(_tagString));
|
||||||
m_lastTag = _tagType;
|
m_lastTag = _tagType;
|
||||||
return skipLineOrEOS(nlPos, _end);
|
return skipLineOrEOS(nlPos, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::const_iterator InterfaceHandler::parseDocTagParam(std::string::const_iterator _pos,
|
string::const_iterator InterfaceHandler::parseDocTagParam(
|
||||||
std::string::const_iterator _end)
|
string::const_iterator _pos,
|
||||||
|
string::const_iterator _end
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// find param name
|
// find param name
|
||||||
auto currPos = std::find(_pos, _end, ' ');
|
auto currPos = find(_pos, _end, ' ');
|
||||||
if (currPos == _end)
|
if (currPos == _end)
|
||||||
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("End of param name not found" + std::string(_pos, _end)));
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("End of param name not found" + string(_pos, _end)));
|
||||||
|
|
||||||
|
|
||||||
auto paramName = std::string(_pos, currPos);
|
auto paramName = string(_pos, currPos);
|
||||||
|
|
||||||
currPos += 1;
|
currPos += 1;
|
||||||
auto nlPos = std::find(currPos, _end, '\n');
|
auto nlPos = find(currPos, _end, '\n');
|
||||||
auto paramDesc = std::string(currPos, nlPos);
|
auto paramDesc = string(currPos, nlPos);
|
||||||
m_params.push_back(std::make_pair(paramName, paramDesc));
|
m_params.push_back(make_pair(paramName, paramDesc));
|
||||||
|
|
||||||
m_lastTag = DocTagType::Param;
|
m_lastTag = DocTagType::Param;
|
||||||
return skipLineOrEOS(nlPos, _end);
|
return skipLineOrEOS(nlPos, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::const_iterator InterfaceHandler::appendDocTagParam(std::string::const_iterator _pos,
|
string::const_iterator InterfaceHandler::appendDocTagParam(
|
||||||
std::string::const_iterator _end)
|
string::const_iterator _pos,
|
||||||
|
string::const_iterator _end
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Should never be called with an empty vector
|
// Should never be called with an empty vector
|
||||||
solAssert(!m_params.empty(), "Internal: Tried to append to empty parameter");
|
solAssert(!m_params.empty(), "Internal: Tried to append to empty parameter");
|
||||||
@ -293,18 +303,20 @@ std::string::const_iterator InterfaceHandler::appendDocTagParam(std::string::con
|
|||||||
auto pair = m_params.back();
|
auto pair = m_params.back();
|
||||||
if (_pos < _end && *_pos != ' ')
|
if (_pos < _end && *_pos != ' ')
|
||||||
pair.second += " ";
|
pair.second += " ";
|
||||||
auto nlPos = std::find(_pos, _end, '\n');
|
auto nlPos = find(_pos, _end, '\n');
|
||||||
std::copy(_pos, nlPos, back_inserter(pair.second));
|
copy(_pos, nlPos, back_inserter(pair.second));
|
||||||
|
|
||||||
m_params.at(m_params.size() - 1) = pair;
|
m_params.at(m_params.size() - 1) = pair;
|
||||||
|
|
||||||
return skipLineOrEOS(nlPos, _end);
|
return skipLineOrEOS(nlPos, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_iterator _pos,
|
string::const_iterator InterfaceHandler::parseDocTag(
|
||||||
std::string::const_iterator _end,
|
string::const_iterator _pos,
|
||||||
std::string const& _tag,
|
string::const_iterator _end,
|
||||||
CommentOwner _owner)
|
string const& _tag,
|
||||||
|
CommentOwner _owner
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// LTODO: need to check for @(start of a tag) between here and the end of line
|
// LTODO: need to check for @(start of a tag) between here and the end of line
|
||||||
// for all cases. Also somehow automate list of acceptable tags for each
|
// for all cases. Also somehow automate list of acceptable tags for each
|
||||||
@ -345,9 +357,11 @@ std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_ite
|
|||||||
return appendDocTag(_pos, _end, _owner);
|
return appendDocTag(_pos, _end, _owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::const_iterator InterfaceHandler::appendDocTag(std::string::const_iterator _pos,
|
string::const_iterator InterfaceHandler::appendDocTag(
|
||||||
std::string::const_iterator _end,
|
string::const_iterator _pos,
|
||||||
CommentOwner _owner)
|
string::const_iterator _end,
|
||||||
|
CommentOwner _owner
|
||||||
|
)
|
||||||
{
|
{
|
||||||
switch (m_lastTag)
|
switch (m_lastTag)
|
||||||
{
|
{
|
||||||
@ -379,33 +393,36 @@ std::string::const_iterator InterfaceHandler::appendDocTag(std::string::const_it
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string::const_iterator getFirstSpaceOrNl(std::string::const_iterator _pos,
|
static inline string::const_iterator getFirstSpaceOrNl(
|
||||||
std::string::const_iterator _end)
|
string::const_iterator _pos,
|
||||||
|
string::const_iterator _end
|
||||||
|
)
|
||||||
{
|
{
|
||||||
auto spacePos = std::find(_pos, _end, ' ');
|
auto spacePos = find(_pos, _end, ' ');
|
||||||
auto nlPos = std::find(_pos, _end, '\n');
|
auto nlPos = find(_pos, _end, '\n');
|
||||||
return (spacePos < nlPos) ? spacePos : nlPos;
|
return (spacePos < nlPos) ? spacePos : nlPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfaceHandler::parseDocString(std::string const& _string, CommentOwner _owner)
|
void InterfaceHandler::parseDocString(string const& _string, CommentOwner _owner)
|
||||||
{
|
{
|
||||||
auto currPos = _string.begin();
|
auto currPos = _string.begin();
|
||||||
auto end = _string.end();
|
auto end = _string.end();
|
||||||
|
|
||||||
while (currPos != end)
|
while (currPos != end)
|
||||||
{
|
{
|
||||||
auto tagPos = std::find(currPos, end, '@');
|
auto tagPos = find(currPos, end, '@');
|
||||||
auto nlPos = std::find(currPos, end, '\n');
|
auto nlPos = find(currPos, end, '\n');
|
||||||
|
|
||||||
if (tagPos != end && tagPos < nlPos)
|
if (tagPos != end && tagPos < nlPos)
|
||||||
{
|
{
|
||||||
// we found a tag
|
// we found a tag
|
||||||
auto tagNameEndPos = getFirstSpaceOrNl(tagPos, end);
|
auto tagNameEndPos = getFirstSpaceOrNl(tagPos, end);
|
||||||
if (tagNameEndPos == end)
|
if (tagNameEndPos == end)
|
||||||
BOOST_THROW_EXCEPTION(DocstringParsingError() <<
|
BOOST_THROW_EXCEPTION(
|
||||||
errinfo_comment("End of tag " + std::string(tagPos, tagNameEndPos) + "not found"));
|
DocstringParsingError() <<
|
||||||
|
errinfo_comment("End of tag " + string(tagPos, tagNameEndPos) + "not found"));
|
||||||
|
|
||||||
currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos + 1, tagNameEndPos), _owner);
|
currPos = parseDocTag(tagNameEndPos + 1, end, string(tagPos + 1, tagNameEndPos), _owner);
|
||||||
}
|
}
|
||||||
else if (m_lastTag != DocTagType::None) // continuation of the previous tag
|
else if (m_lastTag != DocTagType::None) // continuation of the previous tag
|
||||||
currPos = appendDocTag(currPos, end, _owner);
|
currPos = appendDocTag(currPos, end, _owner);
|
||||||
|
@ -67,8 +67,10 @@ public:
|
|||||||
/// types provided by @c DocumentationType
|
/// types provided by @c DocumentationType
|
||||||
/// @return A unique pointer contained string with the json
|
/// @return A unique pointer contained string with the json
|
||||||
/// representation of provided type
|
/// representation of provided type
|
||||||
std::unique_ptr<std::string> getDocumentation(ContractDefinition const& _contractDef,
|
std::unique_ptr<std::string> getDocumentation(
|
||||||
DocumentationType _type);
|
ContractDefinition const& _contractDef,
|
||||||
|
DocumentationType _type
|
||||||
|
);
|
||||||
/// Get the ABI Interface of the contract
|
/// Get the ABI Interface of the contract
|
||||||
/// @param _contractDef The contract definition
|
/// @param _contractDef The contract definition
|
||||||
/// @return A unique pointer contained string with the json
|
/// @return A unique pointer contained string with the json
|
||||||
@ -90,23 +92,33 @@ private:
|
|||||||
void resetUser();
|
void resetUser();
|
||||||
void resetDev();
|
void resetDev();
|
||||||
|
|
||||||
std::string::const_iterator parseDocTagLine(std::string::const_iterator _pos,
|
std::string::const_iterator parseDocTagLine(
|
||||||
std::string::const_iterator _end,
|
std::string::const_iterator _pos,
|
||||||
std::string& _tagString,
|
std::string::const_iterator _end,
|
||||||
DocTagType _tagType,
|
std::string& _tagString,
|
||||||
bool _appending);
|
DocTagType _tagType,
|
||||||
std::string::const_iterator parseDocTagParam(std::string::const_iterator _pos,
|
bool _appending
|
||||||
std::string::const_iterator _end);
|
);
|
||||||
std::string::const_iterator appendDocTagParam(std::string::const_iterator _pos,
|
std::string::const_iterator parseDocTagParam(
|
||||||
std::string::const_iterator _end);
|
std::string::const_iterator _pos,
|
||||||
|
std::string::const_iterator _end
|
||||||
|
);
|
||||||
|
std::string::const_iterator appendDocTagParam(
|
||||||
|
std::string::const_iterator _pos,
|
||||||
|
std::string::const_iterator _end
|
||||||
|
);
|
||||||
void parseDocString(std::string const& _string, CommentOwner _owner);
|
void parseDocString(std::string const& _string, CommentOwner _owner);
|
||||||
std::string::const_iterator appendDocTag(std::string::const_iterator _pos,
|
std::string::const_iterator appendDocTag(
|
||||||
std::string::const_iterator _end,
|
std::string::const_iterator _pos,
|
||||||
CommentOwner _owner);
|
std::string::const_iterator _end,
|
||||||
std::string::const_iterator parseDocTag(std::string::const_iterator _pos,
|
CommentOwner _owner
|
||||||
std::string::const_iterator _end,
|
);
|
||||||
std::string const& _tag,
|
std::string::const_iterator parseDocTag(
|
||||||
CommentOwner _owner);
|
std::string::const_iterator _pos,
|
||||||
|
std::string::const_iterator _end,
|
||||||
|
std::string const& _tag,
|
||||||
|
CommentOwner _owner
|
||||||
|
);
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
DocTagType m_lastTag;
|
DocTagType m_lastTag;
|
||||||
|
Loading…
Reference in New Issue
Block a user