@@ -47,6 +47,66 @@ bool DocStringTagParser::parseDocStrings(SourceUnit const& _sourceUnit)
4747 return errorWatcher.ok ();
4848}
4949
50+ bool DocStringTagParser::validateDocStringsUsingTypes (SourceUnit const & _sourceUnit)
51+ {
52+ auto errorWatcher = m_errorReporter.errorWatcher ();
53+
54+ SimpleASTVisitor visitReturns (
55+ [](ASTNode const &) { return true ; },
56+ [&](ASTNode const & _node)
57+ {
58+ if (auto const * annotation = dynamic_cast <StructurallyDocumentedAnnotation const *>(&_node.annotation ()))
59+ {
60+ auto const & documentationNode = dynamic_cast <StructurallyDocumented const &>(_node);
61+
62+ size_t returnTagsVisited = 0 ;
63+
64+ for (auto const & [tagName, tagValue]: annotation->docTags )
65+ if (tagName == " return" )
66+ {
67+ returnTagsVisited++;
68+ if (auto const * varDecl = dynamic_cast <VariableDeclaration const *>(&_node))
69+ {
70+ solAssert (varDecl->isPublic (), " @return is only allowed on public state-variables." );
71+ if (returnTagsVisited > 1 )
72+ m_errorReporter.docstringParsingError (
73+ 5256_error,
74+ documentationNode.documentation ()->location (),
75+ " Documentation tag \" @" + tagName + " \" is only allowed once on state-variables."
76+ );
77+ }
78+ else if (auto const * function = dynamic_cast <FunctionDefinition const *>(&_node))
79+ {
80+ string content = tagValue.content ;
81+ string firstWord = content.substr (0 , content.find_first_of (" \t " ));
82+
83+ if (returnTagsVisited > function->returnParameters ().size ())
84+ m_errorReporter.docstringParsingError (
85+ 2604_error,
86+ documentationNode.documentation ()->location (),
87+ " Documentation tag \" @" + tagName + " " + tagValue.content + " \" " +
88+ " exceeds the number of return parameters."
89+ );
90+ else
91+ {
92+ auto parameter = function->returnParameters ().at (returnTagsVisited - 1 );
93+ if (!parameter->name ().empty () && parameter->name () != firstWord)
94+ m_errorReporter.docstringParsingError (
95+ 5856_error,
96+ documentationNode.documentation ()->location (),
97+ " Documentation tag \" @" + tagName + " " + tagValue.content + " \" " +
98+ " does not contain the name of its return parameter."
99+ );
100+ }
101+ }
102+ }
103+ }
104+ });
105+
106+ _sourceUnit.accept (visitReturns);
107+ return errorWatcher.ok ();
108+ }
109+
50110bool DocStringTagParser::visit (ContractDefinition const & _contract)
51111{
52112 static set<string> const validTags = set<string>{" author" , " title" , " dev" , " notice" };
@@ -169,7 +229,6 @@ void DocStringTagParser::parseDocStrings(
169229
170230 _annotation.docTags = DocStringParser{*_node.documentation (), m_errorReporter}.parse ();
171231
172- size_t returnTagsVisited = 0 ;
173232 for (auto const & [tagName, tagValue]: _annotation.docTags )
174233 {
175234 string static const customPrefix (" custom:" );
@@ -196,43 +255,6 @@ void DocStringTagParser::parseDocStrings(
196255 _node.documentation ()->location (),
197256 " Documentation tag @" + tagName + " not valid for " + _nodeName + " ."
198257 );
199- else if (tagName == " return" )
200- {
201- returnTagsVisited++;
202- if (auto const * varDecl = dynamic_cast <VariableDeclaration const *>(&_node))
203- {
204- solAssert (varDecl->isPublic (), " @return is only allowed on public state-variables." );
205- if (returnTagsVisited > 1 )
206- m_errorReporter.docstringParsingError (
207- 5256_error,
208- _node.documentation ()->location (),
209- " Documentation tag \" @" + tagName + " \" is only allowed once on state-variables."
210- );
211- }
212- else if (auto const * function = dynamic_cast <FunctionDefinition const *>(&_node))
213- {
214- string content = tagValue.content ;
215- string firstWord = content.substr (0 , content.find_first_of (" \t " ));
216-
217- if (returnTagsVisited > function->returnParameters ().size ())
218- m_errorReporter.docstringParsingError (
219- 2604_error,
220- _node.documentation ()->location (),
221- " Documentation tag \" @" + tagName + " " + tagValue.content + " \" " +
222- " exceeds the number of return parameters."
223- );
224- else
225- {
226- auto parameter = function->returnParameters ().at (returnTagsVisited - 1 );
227- if (!parameter->name ().empty () && parameter->name () != firstWord)
228- m_errorReporter.docstringParsingError (
229- 5856_error,
230- _node.documentation ()->location (),
231- " Documentation tag \" @" + tagName + " " + tagValue.content + " \" " +
232- " does not contain the name of its return parameter."
233- );
234- }
235- }
236- }
237258 }
238259}
260+
0 commit comments