clang-tools 10.0.0

ArgumentCommentCheck.h
Go to the documentation of this file.
1 //===--- ArgumentCommentCheck.h - clang-tidy --------------------*- C++ -*-===//
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
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
11
12 #include "../ClangTidyCheck.h"
13 #include "llvm/Support/Regex.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace bugprone {
18
19 /// Checks that argument comments match parameter names.
20 ///
21 /// The check understands argument comments in the form `/*parameter_name=*/`
22 /// that are placed right before the argument.
23 ///
24 /// \code
25 /// void f(bool foo);
26 ///
27 /// ...
28 /// f(/*bar=*/true);
29 /// // warning: argument name 'bar' in comment does not match parameter name
30 /// 'foo'
31 /// \endcode
32 ///
33 /// The check tries to detect typos and suggest automated fixes for them.
34 class ArgumentCommentCheck : public ClangTidyCheck {
35 public:
36 ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context);
37
38 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
41
42 private:
43 const unsigned StrictMode : 1;
44 const unsigned IgnoreSingleArgument : 1;
45 const unsigned CommentBoolLiterals : 1;
46 const unsigned CommentIntegerLiterals : 1;
47 const unsigned CommentFloatLiterals : 1;
48 const unsigned CommentStringLiterals : 1;
49 const unsigned CommentUserDefinedLiterals : 1;
50 const unsigned CommentCharacterLiterals : 1;
51 const unsigned CommentNullPtrs : 1;
52 llvm::Regex IdentRE;
53
54 void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
55 SourceLocation ArgBeginLoc,
56 llvm::ArrayRef<const Expr *> Args);
57
58 bool shouldAddComment(const Expr *Arg) const;
59 };
60
61 } // namespace bugprone
62 } // namespace tidy
63 } // namespace clang
64
65 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_ARGUMENTCOMMENTCHECK_H
clang::tidy::bugprone::ArgumentCommentCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: ArgumentCommentCheck.cpp:38
clang::tidy::bugprone::ArgumentCommentCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: ArgumentCommentCheck.cpp:329
clang::tidy::bugprone::ArgumentCommentCheck
Definition: ArgumentCommentCheck.h:34
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
Ctx
Context Ctx
Definition: TUScheduler.cpp:237
clang::tidy::bugprone::ArgumentCommentCheck::ArgumentCommentCheck
ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context)
Definition: ArgumentCommentCheck.cpp:23
clang::tidy::bugprone::ArgumentCommentCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: ArgumentCommentCheck.cpp:50
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77