clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ArgumentCommentCheck.h
Go to the documentation of this file.
1 //===--- ArgumentCommentCheck.h - clang-tidy --------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ARGUMENTCOMMENTCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ARGUMENTCOMMENTCHECK_H
12
13 #include "../ClangTidy.h"
14 #include "llvm/Support/Regex.h"
15
16 namespace clang {
17 namespace tidy {
18 namespace misc {
19
20 /// Checks that argument comments match parameter names.
21 ///
22 /// The check understands argument comments in the form `/*parameter_name=*/`
23 /// that are placed right before the argument.
24 ///
25 /// \code
26 /// void f(bool foo);
27 ///
28 /// ...
29 /// f(/*bar=*/true);
30 /// // warning: argument name 'bar' in comment does not match parameter name '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
41 private:
42 llvm::Regex IdentRE;
43
44 bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params, StringRef ArgName,
45 unsigned ArgIndex);
46 std::vector<std::pair<SourceLocation, StringRef>>
47 getCommentsInRange(ASTContext *Ctx, SourceRange Range);
48 void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
49 SourceLocation ArgBeginLoc,
50 llvm::ArrayRef<const Expr *> Args);
51 };
52
53 } // namespace misc
54 } // namespace tidy
55 } // namespace clang
56
57 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ARGUMENTCOMMENTCHECK_H
clang::tidy::misc::ArgumentCommentCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition: ArgumentCommentCheck.cpp:27
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
clang::tidy::misc::ArgumentCommentCheck
Definition: ArgumentCommentCheck.h:34
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::misc::ArgumentCommentCheck::ArgumentCommentCheck
ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context)
Definition: ArgumentCommentCheck.cpp:22
clang::tidy::misc::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:167
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:35
Context
ClangTidyContext & Context
Definition: ClangTidy.cpp:93
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121