clang-tools 8.0.0

MacroUsageCheck.h
Go to the documentation of this file.
1 //===--- MacroUsageCheck.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_CPPCOREGUIDELINES_MACROUSAGECHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
12
13 #include "../ClangTidy.h"
14 #include "clang/Lex/Preprocessor.h"
15 #include <string>
16
17 namespace clang {
18 namespace tidy {
19 namespace cppcoreguidelines {
20
21 /// Find macro usage that is considered problematic because better language
22 /// constructs exist for the task.
23 ///
24 /// For the user-facing documentation see:
25 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
26 class MacroUsageCheck : public ClangTidyCheck {
27 public:
28 MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
29 : ClangTidyCheck(Name, Context),
30 AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")),
31 CheckCapsOnly(Options.get("CheckCapsOnly", 0)),
32 IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", 1)) {}
33 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
34 void registerPPCallbacks(CompilerInstance &Compiler) override;
35 void warnMacro(const MacroDirective *MD, StringRef MacroName);
36 void warnNaming(const MacroDirective *MD, StringRef MacroName);
37
38 private:
39 /// A regular expression that defines how allowed macros must look like.
40 std::string AllowedRegexp;
41 /// Control if only the check shall only test on CAPS_ONLY macros.
42 bool CheckCapsOnly;
43 /// Should the macros without a valid location be diagnosed?
44 bool IgnoreCommandLineMacros;
45 };
46
47 } // namespace cppcoreguidelines
48 } // namespace tidy
49 } // namespace clang
50
51 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
clang::tidy::cppcoreguidelines::MacroUsageCheck::warnNaming
void warnNaming(const MacroDirective *MD, StringRef MacroName)
Definition: MacroUsageCheck.cpp:99
clang::tidy::cppcoreguidelines::MacroUsageCheck::warnMacro
void warnMacro(const MacroDirective *MD, StringRef MacroName)
Definition: MacroUsageCheck.cpp:81
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidy.h:183
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
clang::tidy::cppcoreguidelines::MacroUsageCheck
Find macro usage that is considered problematic because better language constructs exist for the task...
Definition: MacroUsageCheck.h:26
clang::tidy::cppcoreguidelines::MacroUsageCheck::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: MacroUsageCheck.cpp:65
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::doc::MD
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:100
clang::tidy::cppcoreguidelines::MacroUsageCheck::MacroUsageCheck
MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
Definition: MacroUsageCheck.h:28
clang::tidy::cppcoreguidelines::MacroUsageCheck::registerPPCallbacks
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Definition: MacroUsageCheck.cpp:71