clang-tools 6.0.0

LambdaFunctionNameCheck.h
Go to the documentation of this file.
1 //===--- LambdaFunctionNameCheck.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_LAMBDA_FUNCTION_NAME_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace misc {
18
19 /// Detect when __func__ or __FUNCTION__ is being used from within a lambda. In
20 /// that context, those expressions expand to the name of the call operator
21 /// (i.e., `operator()`).
22 ///
23 /// For the user-facing documentation see:
24 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-lambda-function-name.html
25 class LambdaFunctionNameCheck : public ClangTidyCheck {
26 public:
27 struct SourceRangeLessThan {
28 bool operator()(const SourceRange &L, const SourceRange &R) const {
29 if (L.getBegin() == R.getBegin()) {
30 return L.getEnd() < R.getEnd();
31 }
32 return L.getBegin() < R.getBegin();
33 }
34 };
35 using SourceRangeSet = std::set<SourceRange, SourceRangeLessThan>;
36
37 LambdaFunctionNameCheck(StringRef Name, ClangTidyContext *Context)
38 : ClangTidyCheck(Name, Context) {}
39 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
40 void registerPPCallbacks(CompilerInstance &Compiler) override;
41 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
42
43 private:
44 SourceRangeSet SuppressMacroExpansions;
45 };
46
47 } // namespace misc
48 } // namespace tidy
49 } // namespace clang
50
51 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
clang::tidy::misc::LambdaFunctionNameCheck::SourceRangeLessThan::operator()
bool operator()(const SourceRange &L, const SourceRange &R) const
Definition: LambdaFunctionNameCheck.h:28
clang::tidy::misc::LambdaFunctionNameCheck::LambdaFunctionNameCheck
LambdaFunctionNameCheck(StringRef Name, ClangTidyContext *Context)
Definition: LambdaFunctionNameCheck.h:37
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::misc::LambdaFunctionNameCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: LambdaFunctionNameCheck.cpp:62
clang::tidy::misc::LambdaFunctionNameCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: LambdaFunctionNameCheck.cpp:74
clang::tidy::misc::LambdaFunctionNameCheck::registerPPCallbacks
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Definition: LambdaFunctionNameCheck.cpp:68
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::misc::LambdaFunctionNameCheck::SourceRangeLessThan
Definition: LambdaFunctionNameCheck.h:27
clang::tidy::misc::LambdaFunctionNameCheck::SourceRangeSet
std::set< SourceRange, SourceRangeLessThan > SourceRangeSet
Definition: LambdaFunctionNameCheck.h:35
clang::tidy::misc::LambdaFunctionNameCheck
Detect when func or FUNCTION is being used from within a lambda.
Definition: LambdaFunctionNameCheck.h:25
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104