mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Reports source location for structured documentation errors.
This commit is contained in:
parent
ec4f9d0ed8
commit
b43751d65e
@ -244,3 +244,12 @@ void ErrorReporter::docstringParsingError(string const& _description)
|
|||||||
_description
|
_description
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ErrorReporter::docstringParsingError(SourceLocation const& _location, string const& _description)
|
||||||
|
{
|
||||||
|
error(
|
||||||
|
Error::Type::DocstringParsingError,
|
||||||
|
_location,
|
||||||
|
_description
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -107,6 +107,7 @@ public:
|
|||||||
void fatalTypeError(SourceLocation const& _location, SecondarySourceLocation const& _secondLocation, std::string const& _description);
|
void fatalTypeError(SourceLocation const& _location, SecondarySourceLocation const& _secondLocation, std::string const& _description);
|
||||||
|
|
||||||
void docstringParsingError(std::string const& _description);
|
void docstringParsingError(std::string const& _description);
|
||||||
|
void docstringParsingError(SourceLocation const& _location, std::string const& _description);
|
||||||
|
|
||||||
ErrorList const& errors() const;
|
ErrorList const& errors() const;
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ bool DocStringAnalyser::visit(EventDefinition const& _event)
|
|||||||
|
|
||||||
void DocStringAnalyser::checkParameters(
|
void DocStringAnalyser::checkParameters(
|
||||||
CallableDeclaration const& _callable,
|
CallableDeclaration const& _callable,
|
||||||
|
StructurallyDocumented const& _node,
|
||||||
StructurallyDocumentedAnnotation& _annotation
|
StructurallyDocumentedAnnotation& _annotation
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -86,6 +87,7 @@ void DocStringAnalyser::checkParameters(
|
|||||||
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(
|
appendError(
|
||||||
|
_node.documentation()->location(),
|
||||||
"Documented parameter \"" +
|
"Documented parameter \"" +
|
||||||
i->second.paramName +
|
i->second.paramName +
|
||||||
"\" not found in the parameter list of the function."
|
"\" not found in the parameter list of the function."
|
||||||
@ -101,7 +103,7 @@ void DocStringAnalyser::handleConstructor(
|
|||||||
{
|
{
|
||||||
static set<string> const validTags = set<string>{"author", "dev", "notice", "param"};
|
static set<string> const validTags = set<string>{"author", "dev", "notice", "param"};
|
||||||
parseDocStrings(_node, _annotation, validTags, "constructor");
|
parseDocStrings(_node, _annotation, validTags, "constructor");
|
||||||
checkParameters(_callable, _annotation);
|
checkParameters(_callable, _node, _annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocStringAnalyser::handleCallable(
|
void DocStringAnalyser::handleCallable(
|
||||||
@ -112,7 +114,7 @@ void DocStringAnalyser::handleCallable(
|
|||||||
{
|
{
|
||||||
static set<string> const validTags = set<string>{"author", "dev", "notice", "return", "param"};
|
static set<string> const validTags = set<string>{"author", "dev", "notice", "return", "param"};
|
||||||
parseDocStrings(_node, _annotation, validTags, "functions");
|
parseDocStrings(_node, _annotation, validTags, "functions");
|
||||||
checkParameters(_callable, _annotation);
|
checkParameters(_callable, _node, _annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocStringAnalyser::parseDocStrings(
|
void DocStringAnalyser::parseDocStrings(
|
||||||
@ -134,7 +136,10 @@ 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("Documentation tag @" + docTag.first + " not valid for " + _nodeName + ".");
|
appendError(
|
||||||
|
_node.documentation()->location(),
|
||||||
|
"Documentation tag @" + docTag.first + " not valid for " + _nodeName + "."
|
||||||
|
);
|
||||||
else
|
else
|
||||||
if (docTag.first == "return")
|
if (docTag.first == "return")
|
||||||
{
|
{
|
||||||
@ -145,14 +150,18 @@ 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("Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" +
|
appendError(
|
||||||
|
_node.documentation()->location(),
|
||||||
|
"Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" +
|
||||||
" exceedes the number of return parameters."
|
" exceedes the number of return parameters."
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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("Documentation tag \"@" + docTag.first + " " + docTag.second.content + "\"" +
|
appendError(
|
||||||
|
_node.documentation()->location(),
|
||||||
|
"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."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -161,8 +170,8 @@ void DocStringAnalyser::parseDocStrings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocStringAnalyser::appendError(string const& _description)
|
void DocStringAnalyser::appendError(SourceLocation const& _location, string const& _description)
|
||||||
{
|
{
|
||||||
m_errorOccured = true;
|
m_errorOccured = true;
|
||||||
m_errorReporter.docstringParsingError(_description);
|
m_errorReporter.docstringParsingError(_location, _description);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ private:
|
|||||||
|
|
||||||
void checkParameters(
|
void checkParameters(
|
||||||
CallableDeclaration const& _callable,
|
CallableDeclaration const& _callable,
|
||||||
|
StructurallyDocumented const& _node,
|
||||||
StructurallyDocumentedAnnotation& _annotation
|
StructurallyDocumentedAnnotation& _annotation
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ private:
|
|||||||
std::string const& _nodeName
|
std::string const& _nodeName
|
||||||
);
|
);
|
||||||
|
|
||||||
void appendError(std::string const& _description);
|
void appendError(langutil::SourceLocation const& _location, std::string const& _description);
|
||||||
|
|
||||||
bool m_errorOccured = false;
|
bool m_errorOccured = false;
|
||||||
langutil::ErrorReporter& m_errorReporter;
|
langutil::ErrorReporter& m_errorReporter;
|
||||||
|
Loading…
Reference in New Issue
Block a user