mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Changes in InterfaceHandler to deal with multiline natspec
- Also now Solidity scanner considers Carriage Return as whitespace - Tests for Natspec generation with the new multiline comments
This commit is contained in:
parent
f73278c8b2
commit
a6b0fba227
@ -166,9 +166,12 @@ static inline std::string::const_iterator skipLineOrEOS(std::string::const_itera
|
||||
std::string::const_iterator InterfaceHandler::parseDocTagLine(std::string::const_iterator _pos,
|
||||
std::string::const_iterator _end,
|
||||
std::string& _tagString,
|
||||
DocTagType _tagType)
|
||||
DocTagType _tagType,
|
||||
bool _appending)
|
||||
{
|
||||
auto nlPos = std::find(_pos, _end, '\n');
|
||||
if (_appending && *_pos != ' ')
|
||||
_tagString += " ";
|
||||
std::copy(_pos, nlPos, back_inserter(_tagString));
|
||||
m_lastTag = _tagType;
|
||||
return skipLineOrEOS(nlPos, _end);
|
||||
@ -201,7 +204,8 @@ std::string::const_iterator InterfaceHandler::appendDocTagParam(std::string::con
|
||||
solAssert(!m_params.empty(), "Internal: Tried to append to empty parameter");
|
||||
|
||||
auto pair = m_params.back();
|
||||
pair.second += " ";
|
||||
if (*_pos != ' ')
|
||||
pair.second += " ";
|
||||
auto nlPos = std::find(_pos, _end, '\n');
|
||||
std::copy(_pos, nlPos, back_inserter(pair.second));
|
||||
|
||||
@ -221,17 +225,17 @@ std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_ite
|
||||
if (m_lastTag == DocTagType::NONE || _tag != "")
|
||||
{
|
||||
if (_tag == "dev")
|
||||
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV);
|
||||
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV, false);
|
||||
else if (_tag == "notice")
|
||||
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE);
|
||||
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE, false);
|
||||
else if (_tag == "return")
|
||||
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN);
|
||||
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN, false);
|
||||
else if (_tag == "author")
|
||||
{
|
||||
if (_owner == CommentOwner::CONTRACT)
|
||||
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR);
|
||||
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR, false);
|
||||
else if (_owner == CommentOwner::FUNCTION)
|
||||
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR);
|
||||
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR, false);
|
||||
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"));
|
||||
@ -239,7 +243,7 @@ std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_ite
|
||||
else if (_tag == "title")
|
||||
{
|
||||
if (_owner == CommentOwner::CONTRACT)
|
||||
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE);
|
||||
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE, false);
|
||||
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"));
|
||||
@ -261,34 +265,22 @@ std::string::const_iterator InterfaceHandler::appendDocTag(std::string::const_it
|
||||
switch (m_lastTag)
|
||||
{
|
||||
case DocTagType::DEV:
|
||||
m_dev += " ";
|
||||
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV);
|
||||
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV, true);
|
||||
case DocTagType::NOTICE:
|
||||
m_notice += " ";
|
||||
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE);
|
||||
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE, true);
|
||||
case DocTagType::RETURN:
|
||||
m_return += " ";
|
||||
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN);
|
||||
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN, true);
|
||||
case DocTagType::AUTHOR:
|
||||
if (_owner == CommentOwner::CONTRACT)
|
||||
{
|
||||
m_contractAuthor += " ";
|
||||
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR);
|
||||
}
|
||||
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR, true);
|
||||
else if (_owner == CommentOwner::FUNCTION)
|
||||
{
|
||||
m_author += " ";
|
||||
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR);
|
||||
}
|
||||
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR, true);
|
||||
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"));
|
||||
case DocTagType::TITLE:
|
||||
if (_owner == CommentOwner::CONTRACT)
|
||||
{
|
||||
m_title += " ";
|
||||
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE);
|
||||
}
|
||||
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE, true);
|
||||
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"));
|
||||
@ -329,7 +321,7 @@ void InterfaceHandler::parseDocString(std::string const& _string, CommentOwner _
|
||||
currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos + 1, tagNameEndPos), _owner);
|
||||
}
|
||||
else if (m_lastTag != DocTagType::NONE) // continuation of the previous tag
|
||||
currPos = appendDocTag(currPos + 1, end, _owner);
|
||||
currPos = appendDocTag(currPos, end, _owner);
|
||||
else if (currPos != end) // skip the line if a newline was found
|
||||
currPos = nlPos + 1;
|
||||
}
|
||||
|
@ -92,7 +92,8 @@ private:
|
||||
std::string::const_iterator parseDocTagLine(std::string::const_iterator _pos,
|
||||
std::string::const_iterator _end,
|
||||
std::string& _tagString,
|
||||
DocTagType _tagType);
|
||||
DocTagType _tagType,
|
||||
bool _appending);
|
||||
std::string::const_iterator parseDocTagParam(std::string::const_iterator _pos,
|
||||
std::string::const_iterator _end);
|
||||
std::string::const_iterator appendDocTagParam(std::string::const_iterator _pos,
|
||||
|
@ -80,7 +80,7 @@ bool isLineTerminator(char c)
|
||||
}
|
||||
bool isWhiteSpace(char c)
|
||||
{
|
||||
return c == ' ' || c == '\n' || c == '\t';
|
||||
return c == ' ' || c == '\n' || c == '\t' || c == '\r';
|
||||
}
|
||||
bool isIdentifierStart(char c)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user