25
25
#include < libsolidity/analysis/DocStringAnalyser.h>
26
26
27
27
#include < libsolidity/ast/AST.h>
28
+ #include < libsolidity/ast/TypeProvider.h>
28
29
#include < liblangutil/ErrorReporter.h>
29
30
30
31
#include < boost/algorithm/string.hpp>
@@ -37,20 +38,14 @@ using namespace solidity::frontend;
37
38
namespace
38
39
{
39
40
40
- void copyMissingTags (set<CallableDeclaration const *> const & _baseFunctions, StructurallyDocumentedAnnotation& _target, CallableDeclaration const * _declaration = nullptr )
41
+ void copyMissingTags (set<CallableDeclaration const *> const & _baseFunctions, StructurallyDocumentedAnnotation& _target, FunctionType const * _functionType = nullptr )
41
42
{
42
43
// Only copy if there is exactly one direct base function.
43
44
if (_baseFunctions.size () != 1 )
44
45
return ;
45
46
46
47
CallableDeclaration const & baseFunction = **_baseFunctions.begin ();
47
48
48
- auto hasReturnParameter = [](CallableDeclaration const & declaration, size_t _n)
49
- {
50
- return declaration.returnParameterList () &&
51
- declaration.returnParameters ().size () > _n;
52
- };
53
-
54
49
auto & sourceDoc = dynamic_cast <StructurallyDocumentedAnnotation const &>(baseFunction.annotation ());
55
50
56
51
for (auto it = sourceDoc.docTags .begin (); it != sourceDoc.docTags .end ();)
@@ -70,21 +65,22 @@ void copyMissingTags(set<CallableDeclaration const*> const& _baseFunctions, Stru
70
65
DocTag content = it->second ;
71
66
72
67
// Update the parameter name for @return tags
73
- if (_declaration && tag == " return" )
68
+ if (_functionType && tag == " return" )
74
69
{
75
70
size_t docParaNameEndPos = content.content .find_first_of (" \t " );
76
71
string const docParameterName = content.content .substr (0 , docParaNameEndPos);
77
72
78
73
if (
79
- hasReturnParameter (*_declaration, n) &&
80
- docParameterName != _declaration-> returnParameters ().at (n)-> name ( )
74
+ _functionType-> returnParameterNames (). size () > n &&
75
+ docParameterName != _functionType-> returnParameterNames ().at (n)
81
76
)
82
77
{
83
78
bool baseHasNoName =
84
- hasReturnParameter (baseFunction, n) &&
79
+ baseFunction.returnParameterList () &&
80
+ baseFunction.returnParameters ().size () > n &&
85
81
baseFunction.returnParameters ().at (n)->name ().empty ();
86
82
87
- string paramName = _declaration-> returnParameters ().at (n)-> name ( );
83
+ string paramName = _functionType-> returnParameterNames ().at (n);
88
84
content.content =
89
85
(paramName.empty () ? " " : std::move (paramName) + " " ) + (
90
86
string::npos == docParaNameEndPos || baseHasNoName ?
@@ -127,7 +123,7 @@ bool DocStringAnalyser::analyseDocStrings(SourceUnit const& _sourceUnit)
127
123
bool DocStringAnalyser::visit (FunctionDefinition const & _function)
128
124
{
129
125
if (!_function.isConstructor ())
130
- handleCallable (_function, _function, _function.annotation ());
126
+ handleCallable (_function, _function, _function.annotation (), TypeProvider::function (_function) );
131
127
return true ;
132
128
}
133
129
@@ -136,10 +132,12 @@ bool DocStringAnalyser::visit(VariableDeclaration const& _variable)
136
132
if (!_variable.isStateVariable () && !_variable.isFileLevelVariable ())
137
133
return false ;
138
134
135
+ auto const * getterType = TypeProvider::function (_variable);
136
+
139
137
if (CallableDeclaration const * baseFunction = resolveInheritDoc (_variable.annotation ().baseFunctions , _variable, _variable.annotation ()))
140
- copyMissingTags ({baseFunction}, _variable.annotation ());
138
+ copyMissingTags ({baseFunction}, _variable.annotation (), getterType );
141
139
else if (_variable.annotation ().docTags .empty ())
142
- copyMissingTags (_variable.annotation ().baseFunctions , _variable.annotation ());
140
+ copyMissingTags (_variable.annotation ().baseFunctions , _variable.annotation (), getterType );
143
141
144
142
return false ;
145
143
}
@@ -168,17 +166,18 @@ bool DocStringAnalyser::visit(ErrorDefinition const& _error)
168
166
void DocStringAnalyser::handleCallable (
169
167
CallableDeclaration const & _callable,
170
168
StructurallyDocumented const & _node,
171
- StructurallyDocumentedAnnotation& _annotation
169
+ StructurallyDocumentedAnnotation& _annotation,
170
+ FunctionType const * _functionType
172
171
)
173
172
{
174
173
if (CallableDeclaration const * baseFunction = resolveInheritDoc (_callable.annotation ().baseFunctions , _node, _annotation))
175
- copyMissingTags ({baseFunction}, _annotation, &_callable );
174
+ copyMissingTags ({baseFunction}, _annotation, _functionType );
176
175
else if (
177
176
_annotation.docTags .empty () &&
178
177
_callable.annotation ().baseFunctions .size () == 1 &&
179
178
parameterNamesEqual (_callable, **_callable.annotation ().baseFunctions .begin ())
180
179
)
181
- copyMissingTags (_callable.annotation ().baseFunctions , _annotation, &_callable );
180
+ copyMissingTags (_callable.annotation ().baseFunctions , _annotation, _functionType );
182
181
}
183
182
184
183
CallableDeclaration const * DocStringAnalyser::resolveInheritDoc (
0 commit comments