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 InterfaceHandler::parseDocTagLine(std::string::const_iterator _pos,
|
||||||
std::string::const_iterator _end,
|
std::string::const_iterator _end,
|
||||||
std::string& _tagString,
|
std::string& _tagString,
|
||||||
DocTagType _tagType)
|
DocTagType _tagType,
|
||||||
|
bool _appending)
|
||||||
{
|
{
|
||||||
auto nlPos = std::find(_pos, _end, '\n');
|
auto nlPos = std::find(_pos, _end, '\n');
|
||||||
|
if (_appending && *_pos != ' ')
|
||||||
|
_tagString += " ";
|
||||||
std::copy(_pos, nlPos, back_inserter(_tagString));
|
std::copy(_pos, nlPos, back_inserter(_tagString));
|
||||||
m_lastTag = _tagType;
|
m_lastTag = _tagType;
|
||||||
return skipLineOrEOS(nlPos, _end);
|
return skipLineOrEOS(nlPos, _end);
|
||||||
@ -201,6 +204,7 @@ std::string::const_iterator InterfaceHandler::appendDocTagParam(std::string::con
|
|||||||
solAssert(!m_params.empty(), "Internal: Tried to append to empty parameter");
|
solAssert(!m_params.empty(), "Internal: Tried to append to empty parameter");
|
||||||
|
|
||||||
auto pair = m_params.back();
|
auto pair = m_params.back();
|
||||||
|
if (*_pos != ' ')
|
||||||
pair.second += " ";
|
pair.second += " ";
|
||||||
auto nlPos = std::find(_pos, _end, '\n');
|
auto nlPos = std::find(_pos, _end, '\n');
|
||||||
std::copy(_pos, nlPos, back_inserter(pair.second));
|
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 (m_lastTag == DocTagType::NONE || _tag != "")
|
||||||
{
|
{
|
||||||
if (_tag == "dev")
|
if (_tag == "dev")
|
||||||
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV);
|
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV, false);
|
||||||
else if (_tag == "notice")
|
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")
|
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")
|
else if (_tag == "author")
|
||||||
{
|
{
|
||||||
if (_owner == CommentOwner::CONTRACT)
|
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)
|
else if (_owner == CommentOwner::FUNCTION)
|
||||||
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR);
|
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR, false);
|
||||||
else
|
else
|
||||||
// LTODO: for now this else makes no sense but later comments will go to more language constructs
|
// 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"));
|
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")
|
else if (_tag == "title")
|
||||||
{
|
{
|
||||||
if (_owner == CommentOwner::CONTRACT)
|
if (_owner == CommentOwner::CONTRACT)
|
||||||
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE);
|
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE, false);
|
||||||
else
|
else
|
||||||
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
// 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"));
|
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)
|
switch (m_lastTag)
|
||||||
{
|
{
|
||||||
case DocTagType::DEV:
|
case DocTagType::DEV:
|
||||||
m_dev += " ";
|
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV, true);
|
||||||
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV);
|
|
||||||
case DocTagType::NOTICE:
|
case DocTagType::NOTICE:
|
||||||
m_notice += " ";
|
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE, true);
|
||||||
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE);
|
|
||||||
case DocTagType::RETURN:
|
case DocTagType::RETURN:
|
||||||
m_return += " ";
|
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN, true);
|
||||||
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN);
|
|
||||||
case DocTagType::AUTHOR:
|
case DocTagType::AUTHOR:
|
||||||
if (_owner == CommentOwner::CONTRACT)
|
if (_owner == CommentOwner::CONTRACT)
|
||||||
{
|
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR, true);
|
||||||
m_contractAuthor += " ";
|
|
||||||
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR);
|
|
||||||
}
|
|
||||||
else if (_owner == CommentOwner::FUNCTION)
|
else if (_owner == CommentOwner::FUNCTION)
|
||||||
{
|
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR, true);
|
||||||
m_author += " ";
|
|
||||||
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
||||||
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag in illegal comment"));
|
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag in illegal comment"));
|
||||||
case DocTagType::TITLE:
|
case DocTagType::TITLE:
|
||||||
if (_owner == CommentOwner::CONTRACT)
|
if (_owner == CommentOwner::CONTRACT)
|
||||||
{
|
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE, true);
|
||||||
m_title += " ";
|
|
||||||
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
// LTODO: Unknown tag, throw some form of warning and not just an exception
|
||||||
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag in illegal comment"));
|
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);
|
currPos = parseDocTag(tagNameEndPos + 1, end, std::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 + 1, end, _owner);
|
currPos = appendDocTag(currPos, end, _owner);
|
||||||
else if (currPos != end) // skip the line if a newline was found
|
else if (currPos != end) // skip the line if a newline was found
|
||||||
currPos = nlPos + 1;
|
currPos = nlPos + 1;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,8 @@ private:
|
|||||||
std::string::const_iterator parseDocTagLine(std::string::const_iterator _pos,
|
std::string::const_iterator parseDocTagLine(std::string::const_iterator _pos,
|
||||||
std::string::const_iterator _end,
|
std::string::const_iterator _end,
|
||||||
std::string& _tagString,
|
std::string& _tagString,
|
||||||
DocTagType _tagType);
|
DocTagType _tagType,
|
||||||
|
bool _appending);
|
||||||
std::string::const_iterator parseDocTagParam(std::string::const_iterator _pos,
|
std::string::const_iterator parseDocTagParam(std::string::const_iterator _pos,
|
||||||
std::string::const_iterator _end);
|
std::string::const_iterator _end);
|
||||||
std::string::const_iterator appendDocTagParam(std::string::const_iterator _pos,
|
std::string::const_iterator appendDocTagParam(std::string::const_iterator _pos,
|
||||||
|
@ -80,7 +80,7 @@ bool isLineTerminator(char c)
|
|||||||
}
|
}
|
||||||
bool isWhiteSpace(char c)
|
bool isWhiteSpace(char c)
|
||||||
{
|
{
|
||||||
return c == ' ' || c == '\n' || c == '\t';
|
return c == ' ' || c == '\n' || c == '\t' || c == '\r';
|
||||||
}
|
}
|
||||||
bool isIdentifierStart(char c)
|
bool isIdentifierStart(char c)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user