clang-tools 10.0.0

MacroUsageCheck.h
Go to the documentation of this file.
1 //===--- MacroUsageCheck.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_CPPCOREGUIDELINES_MACROUSAGECHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
11
12 #include "../ClangTidy.h"
13 #include "clang/Lex/Preprocessor.h"
14 #include <string>
15
16 namespace clang {
17 namespace tidy {
18 namespace cppcoreguidelines {
19
20 /// Find macro usage that is considered problematic because better language
21 /// constructs exist for the task.
22 ///
23 /// For the user-facing documentation see:
24 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
25 class MacroUsageCheck : public ClangTidyCheck {
26 public:
27 MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
28 : ClangTidyCheck(Name, Context),
29 AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")),
30 CheckCapsOnly(Options.get("CheckCapsOnly", 0)),
31 IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", 1)) {}
32 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
34 Preprocessor *ModuleExpanderPP) 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::cppcoreguidelines::MacroUsageCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: MacroUsageCheck.cpp:71
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:184
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::tidy::cppcoreguidelines::MacroUsageCheck
Find macro usage that is considered problematic because better language constructs exist for the task...
Definition: MacroUsageCheck.h:25
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: ApplyReplacements.h:27
clang::doc::MD
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
clang::tidy::cppcoreguidelines::MacroUsageCheck::MacroUsageCheck
MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
Definition: MacroUsageCheck.h:27