6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
+ #include " IsDefinedInATestFile.h"
10
+
9
11
#include " DocumentationCheck.h"
10
12
#include " clang/AST/ASTContext.h"
11
13
#include " clang/ASTMatchers/ASTMatchFinder.h"
12
14
#include " clang/AST/Comment.h"
13
15
#include " clang/AST/CommentCommandTraits.h"
14
16
15
- #include < iostream>
16
-
17
17
using namespace clang ::ast_matchers;
18
18
19
19
namespace clang {
@@ -81,32 +81,6 @@ bool hasAReturn(
81
81
return false ;
82
82
}
83
83
84
- bool isDefinedInATestFile (
85
- ASTContext const * const Context, Decl const * const D)
86
- {
87
- FullSourceLoc FullLocation = Context->getFullLoc (D->getBeginLoc ());
88
-
89
- auto const File = FullLocation.getFileEntry ();
90
- if (!File)
91
- return false ;
92
-
93
- std::string filename{File->tryGetRealPathName ()};
94
-
95
- const size_t test_folder1 = filename.find (" test/" );
96
- const size_t test_folder2 = filename.find (" test\\ " );
97
- const size_t test_folder3 = filename.find (" tests/" );
98
- const size_t test_folder4 = filename.find (" tests\\ " );
99
- if (std::string::npos != test_folder1 ||
100
- std::string::npos != test_folder2 ||
101
- std::string::npos != test_folder3 ||
102
- std::string::npos != test_folder4)
103
- {
104
- return true ;
105
- }
106
-
107
- return false ;
108
- }
109
-
110
84
clang::comments::ParamCommandComment const * hasExtraParamCommandComment (
111
85
clang::comments::FullComment const * const FC)
112
86
{
@@ -195,7 +169,7 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
195
169
auto const *Context = Result.Context ;
196
170
197
171
if (auto const *FD = Result.Nodes .getNodeAs <FunctionDecl>(" func-decl" )) {
198
- if (isDefinedInATestFile (Context, FD))
172
+ if (isDefinedInATestFile (Context, FD-> getBeginLoc () ))
199
173
return ;
200
174
201
175
if (FD->getMemberSpecializationInfo ())
@@ -204,13 +178,15 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
204
178
if (FD->getTemplateSpecializationInfo ())
205
179
return ;
206
180
181
+ if (auto const *CXXMD = dyn_cast<CXXMethodDecl>(FD)) {
182
+ if (CXXMD->getParent ()->isLambda ())
183
+ return ;
184
+ }
185
+
207
186
if (!hasABrief (Context, FD)) {
208
187
diag (FD->getLocation (), " Function %0 is missing documentation. Are you missing the '@brief' command?" ) << FD;
209
188
}
210
189
211
- if (FD->isDeleted ())
212
- return ;
213
-
214
190
if (isa<CXXDeductionGuideDecl>(FD))
215
191
return ;
216
192
@@ -251,12 +227,15 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
251
227
}
252
228
253
229
if (auto const *CXXRD = Result.Nodes .getNodeAs <CXXRecordDecl>(" class-decl" )) {
254
- if (isDefinedInATestFile (Context, CXXRD))
230
+ if (isDefinedInATestFile (Context, CXXRD-> getBeginLoc () ))
255
231
return ;
256
232
257
233
if (isa<ClassTemplateSpecializationDecl>(CXXRD))
258
234
return ;
259
235
236
+ if (CXXRD->isLambda ())
237
+ return ;
238
+
260
239
if (CXXRD->getDefinition () != CXXRD)
261
240
return ;
262
241
@@ -292,7 +271,7 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
292
271
}
293
272
294
273
if (auto const *VD = Result.Nodes .getNodeAs <VarDecl>(" var-decl" )) {
295
- if (isDefinedInATestFile (Context, VD))
274
+ if (isDefinedInATestFile (Context, VD-> getBeginLoc () ))
296
275
return ;
297
276
298
277
if (VD->getParentFunctionOrMethod ())
@@ -309,7 +288,7 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
309
288
}
310
289
311
290
if (auto const *FD = Result.Nodes .getNodeAs <FieldDecl>(" field-decl" )) {
312
- if (isDefinedInATestFile (Context, FD))
291
+ if (isDefinedInATestFile (Context, FD-> getBeginLoc () ))
313
292
return ;
314
293
315
294
if (!hasABrief (Context, FD)) {
@@ -320,7 +299,7 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
320
299
}
321
300
322
301
if (auto const *TAD = Result.Nodes .getNodeAs <TypeAliasDecl>(" alias-decl" )) {
323
- if (isDefinedInATestFile (Context, TAD))
302
+ if (isDefinedInATestFile (Context, TAD-> getBeginLoc () ))
324
303
return ;
325
304
326
305
if (TAD->getParentFunctionOrMethod ())
@@ -349,7 +328,7 @@ void DocumentationCheck::check(const MatchFinder::MatchResult &Result) {
349
328
}
350
329
351
330
if (auto const *ED = Result.Nodes .getNodeAs <EnumDecl>(" enum-decl" )) {
352
- if (isDefinedInATestFile (Context, ED))
331
+ if (isDefinedInATestFile (Context, ED-> getBeginLoc () ))
353
332
return ;
354
333
355
334
if (!hasABrief (Context, ED)) {
0 commit comments