clang-tools 24.0.0git
ArgumentCommentCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/Lex/Lexer.h"
13#include "clang/Lex/Token.h"
14#include "llvm/Support/YAMLParser.h"
15
16#include "../utils/LexerUtils.h"
18
19using namespace clang::ast_matchers;
20
21namespace clang::tidy {
23
24llvm::ArrayRef<std::pair<IntegerLiteralKind, StringRef>>
26 static constexpr std::pair<IntegerLiteralKind, StringRef> Mapping[] = {
27 {IntegerLiteralKind::None, "None"},
28 {IntegerLiteralKind::ZeroOnly, "ZeroOnly"},
29 {IntegerLiteralKind::All, "All"}};
30 return {Mapping};
31}
32} // namespace clang::tidy
33
35
37namespace {
38AST_MATCHER(Decl, isFromStdNamespaceOrSystemHeader) {
39 if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext();
40 D && D->isStdNamespace())
41 return true;
42 if (Node.getLocation().isInvalid())
43 return false;
44 return Node.getASTContext().getSourceManager().isInSystemHeader(
45 Node.getLocation());
46}
47} // namespace
48
49// CommentIntegerLiterals used to be a boolean option, so existing `.clang-tidy`
50// files set it to `true` or `false`. Accept the spellings that
51// OptionsView::get<bool>() accepts, as All and None.
53getCommentIntegerLiterals(const ClangTidyCheck::OptionsView &Options) {
54 if (const std::optional<StringRef> Value =
55 Options.get("CommentIntegerLiterals")) {
56 if (const std::optional<bool> Bool = llvm::yaml::parseBool(*Value))
57 return *Bool ? IntegerLiteralKind::All : IntegerLiteralKind::None;
58 long long Number = 0;
59 if (!Value->getAsInteger(10, Number))
60 return Number != 0 ? IntegerLiteralKind::All : IntegerLiteralKind::None;
61 }
62 return Options.get("CommentIntegerLiterals", IntegerLiteralKind::None);
63}
64
66 ClangTidyContext *Context)
67 : ClangTidyCheck(Name, Context),
68 StrictMode(Options.get("StrictMode", false)),
69 IgnoreMacros(Options.get("IgnoreMacros", true)),
70 IgnoreSingleArgument(Options.get("IgnoreSingleArgument", false)),
71 CommentAnonymousInitLists(
72 Options.get("CommentAnonymousInitLists", false)),
73 CommentBoolLiterals(Options.get("CommentBoolLiterals", false)),
74 CommentCharacterLiterals(Options.get("CommentCharacterLiterals", false)),
75 CommentFloatLiterals(Options.get("CommentFloatLiterals", false)),
76 CommentNullPtrs(Options.get("CommentNullPtrs", false)),
77 CommentParenthesizedTemporaries(
78 Options.get("CommentParenthesizedTemporaries", false)),
79 CommentStringLiterals(Options.get("CommentStringLiterals", false)),
80 CommentTypedInitLists(Options.get("CommentTypedInitLists", false)),
81 CommentUserDefinedLiterals(
82 Options.get("CommentUserDefinedLiterals", false)),
83 IgnoredParameterNames(utils::options::parseStringList(
84 Options.get("IgnoredParameterNames", ""))),
85 CommentIntegerLiterals(getCommentIntegerLiterals(Options)),
86 NullPtrMacros(utils::options::parseStringList(
87 Options.get("NullPtrMacros", "NULL"))),
88 BoolLiteralMacros(utils::options::parseStringList(
89 Options.get("BoolLiteralMacros", "true;false"))),
90 IdentRE("^(/\\* *)([_A-Za-z][_A-Za-z0-9]*)( *= *\\*/)$") {
91 for (const StringRef Name : IgnoredParameterNames) {
92 llvm::Regex Regex(Name);
93 if (!Regex.isValid()) {
94 configurationDiag("Invalid regular expression '%0' in "
95 "IgnoredParameterNames")
96 << Name;
97 continue;
98 }
99 IgnoredParameterNameRegexes.push_back(std::move(Regex));
100 }
101}
102
104 Options.store(Opts, "StrictMode", StrictMode);
105 Options.store(Opts, "IgnoreMacros", IgnoreMacros);
106 Options.store(Opts, "IgnoreSingleArgument", IgnoreSingleArgument);
107 Options.store(Opts, "CommentAnonymousInitLists", CommentAnonymousInitLists);
108 Options.store(Opts, "CommentBoolLiterals", CommentBoolLiterals);
109 Options.store(Opts, "CommentCharacterLiterals", CommentCharacterLiterals);
110 Options.store(Opts, "CommentFloatLiterals", CommentFloatLiterals);
111 Options.store(Opts, "CommentIntegerLiterals", CommentIntegerLiterals);
112 Options.store(Opts, "CommentNullPtrs", CommentNullPtrs);
113 Options.store(Opts, "CommentParenthesizedTemporaries",
114 CommentParenthesizedTemporaries);
115 Options.store(Opts, "CommentStringLiterals", CommentStringLiterals);
116 Options.store(Opts, "CommentTypedInitLists", CommentTypedInitLists);
117 Options.store(Opts, "CommentUserDefinedLiterals", CommentUserDefinedLiterals);
118 Options.store(Opts, "IgnoredParameterNames",
119 utils::options::serializeStringList(IgnoredParameterNames));
120 Options.store(Opts, "NullPtrMacros",
122 Options.store(Opts, "BoolLiteralMacros",
123 utils::options::serializeStringList(BoolLiteralMacros));
124}
125
126void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
127 Finder->addMatcher(
128 callExpr(unless(cxxOperatorCallExpr()), unless(userDefinedLiteral()),
129 // NewCallback's arguments relate to the pointed function,
130 // don't check them against NewCallback's parameter names.
131 // FIXME: Make this configurable.
132 unless(hasDeclaration(functionDecl(
133 hasAnyName("NewCallback", "NewPermanentCallback")))),
134 // Ignore APIs from the standard library, since their names are
135 // not specified by the standard, and standard library
136 // implementations in practice have to use reserved names to
137 // avoid conflicts with same-named macros.
138 unless(hasDeclaration(isFromStdNamespaceOrSystemHeader())))
139 .bind("expr"),
140 this);
141 Finder->addMatcher(cxxConstructExpr(unless(hasDeclaration(
142 isFromStdNamespaceOrSystemHeader())))
143 .bind("expr"),
144 this);
145}
146
147static std::vector<CommentToken> getCommentsBeforeLoc(ASTContext *Ctx,
148 SourceLocation Loc) {
149 std::vector<CommentToken> Comments;
150 while (Loc.isValid()) {
151 const std::optional<Token> Tok = utils::lexer::getPreviousToken(
152 Loc, Ctx->getSourceManager(), Ctx->getLangOpts(),
153 /*SkipComments=*/false);
154 if (!Tok || Tok->isNot(tok::comment))
155 break;
156 Loc = Tok->getLocation();
157 Comments.emplace_back(CommentToken{
158 Loc,
159 Lexer::getSourceText(CharSourceRange::getCharRange(
160 Loc, Loc.getLocWithOffset(Tok->getLength())),
161 Ctx->getSourceManager(), Ctx->getLangOpts()),
162 });
163 }
164 return Comments;
165}
166
167template <typename NamedDeclRange>
168static bool isLikelyTypo(const NamedDeclRange &Candidates, StringRef ArgName,
169 StringRef TargetName) {
170 const std::string ArgNameLowerStr = ArgName.lower();
171 const StringRef ArgNameLower = ArgNameLowerStr;
172 // The threshold is arbitrary.
173 const unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
174 const unsigned ThisED =
175 ArgNameLower.edit_distance(TargetName.lower(),
176 /*AllowReplacements=*/true, UpperBound);
177 if (ThisED >= UpperBound)
178 return false;
179
180 return llvm::all_of(Candidates, [&](const auto &Candidate) {
181 const IdentifierInfo *II = Candidate->getIdentifier();
182 if (!II)
183 return true;
184
185 // Skip the target itself.
186 if (II->getName() == TargetName)
187 return true;
188
189 const unsigned Threshold = 2;
190 // Other candidates must be an edit distance at least Threshold more away
191 // from this candidate. This gives us greater confidence that this is a
192 // typo of this candidate and not one with a similar name.
193 const unsigned OtherED = ArgNameLower.edit_distance(
194 II->getName().lower(),
195 /*AllowReplacements=*/true, ThisED + Threshold);
196 return OtherED >= ThisED + Threshold;
197 });
198}
199
200static bool sameName(StringRef InComment, StringRef InDecl, bool StrictMode) {
201 if (StrictMode)
202 return InComment == InDecl;
203 InComment = InComment.trim('_');
204 InDecl = InDecl.trim('_');
205 // FIXME: compare_insensitive only works for ASCII.
206 return InComment.compare_insensitive(InDecl) == 0;
207}
208
209static bool looksLikeExpectMethod(const CXXMethodDecl *Expect) {
210 return Expect != nullptr && Expect->getLocation().isMacroID() &&
211 Expect->getNameInfo().getName().isIdentifier() &&
212 Expect->getName().starts_with("gmock_");
213}
214static bool areMockAndExpectMethods(const CXXMethodDecl *Mock,
215 const CXXMethodDecl *Expect) {
216 assert(looksLikeExpectMethod(Expect));
217 return Mock != nullptr && Mock->getNextDeclInContext() == Expect &&
218 Mock->getNumParams() == Expect->getNumParams() &&
219 Mock->getLocation().isMacroID() &&
220 Mock->getNameInfo().getName().isIdentifier() &&
221 Mock->getName() == Expect->getName().substr(strlen("gmock_"));
222}
223
224// This uses implementation details of MOCK_METHODx_ macros: for each mocked
225// method M it defines M() with appropriate signature and a method used to set
226// up expectations - gmock_M() - with each argument's type changed the
227// corresponding matcher. This function returns M when given either M or
228// gmock_M.
229static const CXXMethodDecl *findMockedMethod(const CXXMethodDecl *Method) {
230 if (looksLikeExpectMethod(Method)) {
231 const DeclContext *Ctx = Method->getDeclContext();
232 if (Ctx == nullptr || !Ctx->isRecord())
233 return nullptr;
234 for (const auto *D : Ctx->decls()) {
235 if (D->getNextDeclInContext() == Method) {
236 const auto *Previous = dyn_cast<CXXMethodDecl>(D);
237 return areMockAndExpectMethods(Previous, Method) ? Previous : nullptr;
238 }
239 }
240 return nullptr;
241 }
242 if (const auto *Next =
243 dyn_cast_or_null<CXXMethodDecl>(Method->getNextDeclInContext());
244 Next && looksLikeExpectMethod(Next) &&
245 areMockAndExpectMethods(Method, Next))
246 return Method;
247
248 return nullptr;
249}
250
251// For gmock expectation builder method (the target of the call generated by
252// `EXPECT_CALL(obj, Method(...))`) tries to find the real method being mocked
253// (returns nullptr, if the mock method doesn't override anything). For other
254// functions returns the function itself.
255static const FunctionDecl *resolveMocks(const FunctionDecl *Func) {
256 if (const auto *Method = dyn_cast<CXXMethodDecl>(Func)) {
257 if (const auto *MockedMethod = findMockedMethod(Method)) {
258 // If mocked method overrides the real one, we can use its parameter
259 // names, otherwise we're out of luck.
260 if (MockedMethod->size_overridden_methods() > 0)
261 return *MockedMethod->begin_overridden_methods();
262 return nullptr;
263 }
264 }
265 return Func;
266}
267
268namespace {
269
270enum class InitListKind {
271 None,
272 Anonymous,
273 Typed,
274};
275
276} // namespace
277
278static InitListKind getInitListKind(const Expr *Arg) {
279 Arg = Arg->IgnoreUnlessSpelledInSource();
280
281 if (const auto *StdInit = dyn_cast<CXXStdInitializerListExpr>(Arg))
282 Arg = StdInit->getSubExpr()->IgnoreUnlessSpelledInSource();
283
284 if (isa<InitListExpr>(Arg))
285 return InitListKind::Anonymous;
286
287 if (const auto *Ctor = dyn_cast<CXXConstructExpr>(Arg)) {
288 if (!Ctor->isListInitialization())
289 return InitListKind::None;
290 // CXXTemporaryObjectExpr corresponds to explicit Type{...} syntax.
291 if (isa<CXXTemporaryObjectExpr>(Ctor))
292 return InitListKind::Typed;
293 // Other list-initialized constructions (for example '{}') have no
294 // explicit type at the call site.
295 return InitListKind::Anonymous;
296 }
297
298 // std::initializer_list<T>{...} is represented as a functional cast whose
299 // subexpression carries the list-initialization spelling.
300 if (const auto *FuncCast = dyn_cast<CXXFunctionalCastExpr>(Arg)) {
301 const Expr *SubExpr = FuncCast->getSubExpr()->IgnoreImplicit();
302 if (FuncCast->isListInitialization() ||
303 isa<CXXStdInitializerListExpr>(SubExpr))
304 return InitListKind::Typed;
305 }
306
307 return InitListKind::None;
308}
309
310// Returns the file location of Arg. Returns an invalid location when Arg and
311// the closing parenthesis of the call at CloseLoc don't map to one range of the
312// file that starts at Arg. That happens when a macro body contains Arg or the
313// closing parenthesis, or when Arg is in another macro argument than the
314// closing parenthesis, such as the `0` in `f(ID(0))`.
315static SourceLocation getWrittenArgLoc(const Expr *Arg, SourceLocation CloseLoc,
316 const SourceManager &SM,
317 const LangOptions &LangOpts) {
318 const CharSourceRange Range = Lexer::makeFileCharRange(
319 CharSourceRange::getTokenRange(Arg->getBeginLoc(), CloseLoc), SM,
320 LangOpts);
321 const SourceLocation ArgLoc =
322 SM.getExpansionLoc(SM.getTopMacroCallerLoc(Arg->getBeginLoc()));
323 if (Range.isInvalid() || Range.getBegin() != ArgLoc)
324 return {};
325 return ArgLoc;
326}
327
328static bool isParenthesizedTemporary(const Expr *Arg) {
329 Arg = Arg->IgnoreUnlessSpelledInSource();
330 if (const auto *TempObject = dyn_cast<CXXTemporaryObjectExpr>(Arg))
331 return !TempObject->isListInitialization();
332 // CXXFunctionalCastExpr with CXXParenListInitExpr corresponds to explicit
333 // Type(...) aggregate temporary initialization syntax.
334 const auto *FuncCast = dyn_cast<CXXFunctionalCastExpr>(Arg);
335 return FuncCast &&
336 isa<CXXParenListInitExpr>(FuncCast->getSubExpr()->IgnoreImplicit());
337}
338
339// Given the argument type and the options determine if we should be adding an
340// argument comment and which diagnostic wording to use.
341ArgumentCommentCheck::CommentKind
342ArgumentCommentCheck::shouldAddComment(const Expr *Arg,
343 const ASTContext &Ctx) const {
344 const SourceManager &SM = Ctx.getSourceManager();
345 const InitListKind Kind = getInitListKind(Arg);
346 const bool IsParenthesizedTemporary = isParenthesizedTemporary(Arg);
347
348 // Strip implicit wrappers so brace-init arguments bound to references still
349 // look like list-initialization at this point.
350 Arg = Arg->IgnoreImplicit();
351 // Check the value before stripping the unary operator, because `~0` and `!0`
352 // are not zero.
353 const auto *IntegerLit = dyn_cast<IntegerLiteral>(Arg);
354 const bool IsZero = IntegerLit && IntegerLit->getValue().isZero();
355 if (const auto *UO = dyn_cast<UnaryOperator>(Arg))
356 Arg = UO->getSubExpr()->IgnoreImplicit();
357
358 // C spells the null pointer constant with the macro `NULL`, and the boolean
359 // constants before C23 with the macros `true` and `false`. The options
360 // NullPtrMacros and BoolLiteralMacros contain `NULL`, `true` and `false` by
361 // default. Other macros, such as `MAX_SIZE`, already name their value and
362 // need no comment.
363 if (SM.getTopMacroCallerLoc(Arg->getExprLoc()).isMacroID()) {
364 const StringRef MacroName =
365 Lexer::getSourceText(CharSourceRange::getTokenRange(
366 SM.getTopMacroCallerLoc(Arg->getBeginLoc()),
367 SM.getTopMacroCallerLoc(Arg->getEndLoc())),
368 SM, Ctx.getLangOpts());
369 if ((CommentNullPtrs && llvm::is_contained(NullPtrMacros, MacroName)) ||
370 (CommentBoolLiterals &&
371 llvm::is_contained(BoolLiteralMacros, MacroName)))
372 return CommentKind::Literal;
373 return CommentKind::None;
374 }
375
376 if ((CommentAnonymousInitLists && Kind == InitListKind::Anonymous) ||
377 (CommentTypedInitLists && Kind == InitListKind::Typed) ||
378 (CommentParenthesizedTemporaries && IsParenthesizedTemporary)) {
379 return CommentKind::NonLiteral;
380 }
381
382 const bool CommentInteger =
383 CommentIntegerLiterals == IntegerLiteralKind::All ||
384 (CommentIntegerLiterals == IntegerLiteralKind::ZeroOnly && IsZero);
385 if ((CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
386 (CommentInteger && isa<IntegerLiteral>(Arg)) ||
387 (CommentFloatLiterals && isa<FloatingLiteral>(Arg)) ||
388 (CommentUserDefinedLiterals && isa<UserDefinedLiteral>(Arg)) ||
389 (CommentCharacterLiterals && isa<CharacterLiteral>(Arg)) ||
390 (CommentStringLiterals && isa<StringLiteral>(Arg)) ||
391 (CommentNullPtrs && isa<CXXNullPtrLiteralExpr>(Arg))) {
392 return CommentKind::Literal;
393 }
394
395 return CommentKind::None;
396}
397
398void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
399 const FunctionDecl *OriginalCallee,
400 SourceLocation ArgBeginLoc,
401 SourceLocation CloseLoc,
402 llvm::ArrayRef<const Expr *> Args) {
403 const FunctionDecl *Callee = resolveMocks(OriginalCallee);
404 if (!Callee)
405 return;
406
407 Callee = Callee->getFirstDecl();
408 if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(Callee);
409 Ctor && Ctor->isInheritingConstructor()) {
410 if (const auto *BaseCtor = Ctor->getInheritedConstructor().getConstructor())
411 Callee = BaseCtor->getFirstDecl();
412 }
413 const unsigned NumArgs =
414 std::min<unsigned>(Args.size(), Callee->getNumParams());
415 if ((NumArgs == 0) || (IgnoreSingleArgument && NumArgs == 1))
416 return;
417
418 const SourceManager &SM = Ctx->getSourceManager();
419 // A call whose closing parenthesis is a macro location is in a macro
420 // argument, such as `f(0)` in `ASSERT(f(0))`. getWrittenArgLoc() rejects
421 // calls in a macro body.
422 const bool AddMissingComments = !IgnoreMacros || CloseLoc.isFileID();
423
424 const auto MakeFileCharRange = [Ctx](SourceLocation Begin,
425 SourceLocation End) {
426 return Lexer::makeFileCharRange(CharSourceRange::getCharRange(Begin, End),
427 Ctx->getSourceManager(),
428 Ctx->getLangOpts());
429 };
430
431 for (unsigned I = 0; I < NumArgs; ++I) {
432 const ParmVarDecl *PVD = Callee->getParamDecl(I);
433 const IdentifierInfo *II = PVD->getIdentifier();
434 if (!II || llvm::any_of(IgnoredParameterNameRegexes,
435 [II](const llvm::Regex &Regex) {
436 return Regex.match(II->getName());
437 }))
438 continue;
439 // Don't warn on arguments for parameters instantiated from template
440 // parameter packs. If we find more arguments than the template
441 // definition has, it also means that they correspond to a parameter
442 // pack.
443 if (FunctionDecl *Template = Callee->getTemplateInstantiationPattern();
444 Template && (Template->getNumParams() <= I ||
445 Template->getParamDecl(I)->isParameterPack()))
446 continue;
447
448 const CharSourceRange BeforeArgument =
449 MakeFileCharRange(ArgBeginLoc, Args[I]->getBeginLoc());
450 ArgBeginLoc = Args[I]->getEndLoc();
451
452 std::vector<CommentToken> Comments;
453 if (BeforeArgument.isValid()) {
455 BeforeArgument, Ctx->getSourceManager(), Ctx->getLangOpts());
456 } else {
457 // Fall back to parsing back from the start of the argument. The range
458 // is empty because a range that ends inside a macro expansion, such as
459 // the `)` of `NULL`, has no file range.
460 const CharSourceRange ArgsRange =
461 MakeFileCharRange(Args[I]->getBeginLoc(), Args[I]->getBeginLoc());
462 Comments = getCommentsBeforeLoc(Ctx, ArgsRange.getBegin());
463 }
464
465 for (const auto &Comment : Comments) {
466 SmallVector<StringRef, 2> Matches;
467 if (IdentRE.match(Comment.Text, &Matches) &&
468 !sameName(Matches[2], II->getName(), StrictMode)) {
469 {
470 const DiagnosticBuilder Diag =
471 diag(Comment.Loc, "argument name '%0' in comment does not "
472 "match parameter name %1")
473 << Matches[2] << II;
474 if (isLikelyTypo(Callee->parameters(), Matches[2], II->getName())) {
475 Diag << FixItHint::CreateReplacement(
476 Comment.Loc,
477 llvm::Twine(Matches[1] + II->getName() + Matches[3]).str());
478 }
479 }
480 diag(PVD->getLocation(), "%0 declared here", DiagnosticIDs::Note) << II;
481 if (OriginalCallee != Callee) {
482 diag(OriginalCallee->getLocation(),
483 "actual callee (%0) is declared here", DiagnosticIDs::Note)
484 << OriginalCallee;
485 }
486 }
487 }
488
489 // If the argument comments are missing for configured argument kinds, add
490 // them.
491 if (!AddMissingComments || !Comments.empty())
492 continue;
493 const SourceLocation ArgLoc =
494 getWrittenArgLoc(Args[I], CloseLoc, SM, Ctx->getLangOpts());
495 if (ArgLoc.isInvalid())
496 continue;
497 const CommentKind Kind = shouldAddComment(Args[I], *Ctx);
498 if (Kind != CommentKind::None) {
499 SmallString<32> ArgComment;
500 llvm::Twine(llvm::Twine("/*") + II->getName() + "=*/")
501 .toStringRef(ArgComment);
502 const DiagnosticBuilder Diag =
503 diag(ArgLoc, "argument comment missing for %select{literal argument|"
504 "argument}0 %1")
505 << (Kind == CommentKind::Literal ? 0 : 1) << II
506 << FixItHint::CreateInsertion(ArgLoc, ArgComment);
507 }
508 }
509}
510
511void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) {
512 const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
513 if (const auto *Call = dyn_cast<CallExpr>(E)) {
514 const FunctionDecl *Callee = Call->getDirectCallee();
515 if (!Callee)
516 return;
517
518 checkCallArgs(Result.Context, Callee, Call->getCallee()->getEndLoc(),
519 Call->getEndLoc(),
520 llvm::ArrayRef(Call->getArgs(), Call->getNumArgs()));
521 } else {
522 const auto *Construct = cast<CXXConstructExpr>(E);
523 if (Construct->getNumArgs() > 0 &&
524 Construct->getArg(0)->getSourceRange() == Construct->getSourceRange()) {
525 // Ignore implicit construction.
526 return;
527 }
528 checkCallArgs(
529 Result.Context, Construct->getConstructor(),
530 Construct->getParenOrBraceRange().getBegin(), Construct->getEndLoc(),
531 llvm::ArrayRef(Construct->getArgs(), Construct->getNumArgs()));
532 }
533}
534
535} // namespace clang::tidy::bugprone
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
void registerMatchers(ast_matchers::MatchFinder *Finder) override
static InitListKind getInitListKind(const Expr *Arg)
static SourceLocation getWrittenArgLoc(const Expr *Arg, SourceLocation CloseLoc, const SourceManager &SM, const LangOptions &LangOpts)
static bool sameName(StringRef InComment, StringRef InDecl, bool StrictMode)
static bool isParenthesizedTemporary(const Expr *Arg)
static bool isLikelyTypo(const NamedDeclRange &Candidates, StringRef ArgName, StringRef TargetName)
static IntegerLiteralKind getCommentIntegerLiterals(const ClangTidyCheck::OptionsView &Options)
static bool looksLikeExpectMethod(const CXXMethodDecl *Expect)
static const CXXMethodDecl * findMockedMethod(const CXXMethodDecl *Method)
static const FunctionDecl * resolveMocks(const FunctionDecl *Func)
static std::vector< CommentToken > getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc)
static bool areMockAndExpectMethods(const CXXMethodDecl *Mock, const CXXMethodDecl *Expect)
std::optional< Token > getPreviousToken(SourceLocation Location, const SourceManager &SM, const LangOptions &LangOpts, bool SkipComments)
Returns previous token or std::nullopt if not found.
std::vector< CommentToken > getTrailingCommentsInRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Returns comment tokens found in the given range. If a non-comment token is encountered,...
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
bugprone::ArgumentCommentCheck::IntegerLiteralKind IntegerLiteralKind
llvm::StringMap< ClangTidyValue > OptionMap
static ArrayRef< std::pair< T, StringRef > > getEnumMapping()=delete
static constexpr const char ArgName[]