Remove DocStringAnalyzer and DocStringParser class-specific error reporting functions

This commit is contained in:
a3d4 2020-05-21 00:26:14 +02:00
parent 66a8c7d1ab
commit 38e65a909a
4 changed files with 17 additions and 25 deletions

View File

@ -68,13 +68,13 @@ bool DocStringAnalyser::visit(VariableDeclaration const& _variable)
parseDocStrings(_variable, _variable.annotation(), validPublicTags, "non-public state variables"); parseDocStrings(_variable, _variable.annotation(), validPublicTags, "non-public state variables");
if (_variable.annotation().docTags.count("notice") > 0) if (_variable.annotation().docTags.count("notice") > 0)
m_errorReporter.warning( m_errorReporter.warning(
9098_error, _variable.documentation()->location(), 7816_error, _variable.documentation()->location(),
"Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly." "Documentation tag on non-public state variables will be disallowed in 0.7.0. You will need to use the @dev tag explicitly."
); );
} }
if (_variable.annotation().docTags.count("title") > 0 || _variable.annotation().docTags.count("author") > 0) if (_variable.annotation().docTags.count("title") > 0 || _variable.annotation().docTags.count("author") > 0)
m_errorReporter.warning( m_errorReporter.warning(
4822_error, _variable.documentation()->location(), 8532_error, _variable.documentation()->location(),
"Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0." "Documentation tag @title and @author is only allowed on contract definitions. It will be disallowed in 0.7.0."
); );
} }
@ -110,7 +110,8 @@ void DocStringAnalyser::checkParameters(
auto paramRange = _annotation.docTags.equal_range("param"); auto paramRange = _annotation.docTags.equal_range("param");
for (auto i = paramRange.first; i != paramRange.second; ++i) for (auto i = paramRange.first; i != paramRange.second; ++i)
if (!validParams.count(i->second.paramName)) if (!validParams.count(i->second.paramName))
appendError( m_errorReporter.docstringParsingError(
3881_error,
_node.documentation()->location(), _node.documentation()->location(),
"Documented parameter \"" + "Documented parameter \"" +
i->second.paramName + i->second.paramName +
@ -159,7 +160,8 @@ void DocStringAnalyser::parseDocStrings(
for (auto const& docTag: _annotation.docTags) for (auto const& docTag: _annotation.docTags)
{ {
if (!_validTags.count(docTag.first)) if (!_validTags.count(docTag.first))
appendError( m_errorReporter.docstringParsingError(
6546_error,
_node.documentation()->location(), _node.documentation()->location(),
"Documentation tag @" + docTag.first + " not valid for " + _nodeName + "." "Documentation tag @" + docTag.first + " not valid for " + _nodeName + "."
); );
@ -170,12 +172,14 @@ void DocStringAnalyser::parseDocStrings(
if (auto* varDecl = dynamic_cast<VariableDeclaration const*>(&_node)) if (auto* varDecl = dynamic_cast<VariableDeclaration const*>(&_node))
{ {
if (!varDecl->isPublic()) if (!varDecl->isPublic())
appendError( m_errorReporter.docstringParsingError(
9440_error,
_node.documentation()->location(), _node.documentation()->location(),
"Documentation tag \"@" + docTag.first + "\" is only allowed on public state-variables." "Documentation tag \"@" + docTag.first + "\" is only allowed on public state-variables."
); );
if (returnTagsVisited > 1) if (returnTagsVisited > 1)
appendError( m_errorReporter.docstringParsingError(
5256_error,
_node.documentation()->location(), _node.documentation()->location(),
"Documentation tag \"@" + docTag.first + "\" is only allowed once on state-variables." "Documentation tag \"@" + docTag.first + "\" is only allowed once on state-variables."
); );
@ -186,7 +190,8 @@ void DocStringAnalyser::parseDocStrings(
string firstWord = content.substr(0, content.find_first_of(" \t")); string firstWord = content.substr(0, content.find_first_of(" \t"));
if (returnTagsVisited > function->returnParameters().size()) if (returnTagsVisited > function->returnParameters().size())
appendError( m_errorReporter.docstringParsingError(
2604_error,
_node.documentation()->location(), _node.documentation()->location(),
"Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" + "Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" +
" exceeds the number of return parameters." " exceeds the number of return parameters."
@ -195,7 +200,8 @@ void DocStringAnalyser::parseDocStrings(
{ {
auto parameter = function->returnParameters().at(returnTagsVisited - 1); auto parameter = function->returnParameters().at(returnTagsVisited - 1);
if (!parameter->name().empty() && parameter->name() != firstWord) if (!parameter->name().empty() && parameter->name() != firstWord)
appendError( m_errorReporter.docstringParsingError(
5856_error,
_node.documentation()->location(), _node.documentation()->location(),
"Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" + "Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" +
" does not contain the name of its return parameter." " does not contain the name of its return parameter."
@ -205,8 +211,3 @@ void DocStringAnalyser::parseDocStrings(
} }
} }
} }
void DocStringAnalyser::appendError(SourceLocation const& _location, string const& _description)
{
m_errorReporter.docstringParsingError(7816_error, _location, _description);
}

View File

@ -81,8 +81,6 @@ private:
std::string const& _nodeName std::string const& _nodeName
); );
void appendError(langutil::SourceLocation const& _location, std::string const& _description);
langutil::ErrorReporter& m_errorReporter; langutil::ErrorReporter& m_errorReporter;
}; };

View File

@ -96,7 +96,7 @@ void DocStringParser::parse(string const& _docString, ErrorReporter& _errorRepor
auto tagNameEndPos = firstWhitespaceOrNewline(tagPos, end); auto tagNameEndPos = firstWhitespaceOrNewline(tagPos, end);
if (tagNameEndPos == end) if (tagNameEndPos == end)
{ {
appendError("End of tag " + string(tagPos, tagNameEndPos) + " not found"); m_errorReporter->docstringParsingError(9222_error, "End of tag " + string(tagPos, tagNameEndPos) + " not found");
break; break;
} }
@ -138,7 +138,7 @@ DocStringParser::iter DocStringParser::parseDocTagParam(iter _pos, iter _end)
auto nameStartPos = skipWhitespace(_pos, _end); auto nameStartPos = skipWhitespace(_pos, _end);
if (nameStartPos == _end) if (nameStartPos == _end)
{ {
appendError("No param name given"); m_errorReporter->docstringParsingError(3335_error, "No param name given");
return _end; return _end;
} }
auto nameEndPos = firstNonIdentifier(nameStartPos, _end); auto nameEndPos = firstNonIdentifier(nameStartPos, _end);
@ -149,7 +149,7 @@ DocStringParser::iter DocStringParser::parseDocTagParam(iter _pos, iter _end)
if (descStartPos == nlPos) if (descStartPos == nlPos)
{ {
appendError("No description given for param " + paramName); m_errorReporter->docstringParsingError(9942_error, "No description given for param " + paramName);
return _end; return _end;
} }
@ -189,8 +189,3 @@ void DocStringParser::newTag(string const& _tagName)
{ {
m_lastTag = &m_docTags.insert(make_pair(_tagName, DocTag()))->second; m_lastTag = &m_docTags.insert(make_pair(_tagName, DocTag()))->second;
} }
void DocStringParser::appendError(string const& _description)
{
m_errorReporter->docstringParsingError(9440_error, _description);
}

View File

@ -58,8 +58,6 @@ private:
/// Creates and inserts a new tag and adjusts m_lastTag. /// Creates and inserts a new tag and adjusts m_lastTag.
void newTag(std::string const& _tagName); void newTag(std::string const& _tagName);
void appendError(std::string const& _description);
/// Mapping tag name -> content. /// Mapping tag name -> content.
std::multimap<std::string, DocTag> m_docTags; std::multimap<std::string, DocTag> m_docTags;
DocTag* m_lastTag = nullptr; DocTag* m_lastTag = nullptr;