clang-tools  11.0.0git
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 "../ClangTidyCheck.h"
13 #include "clang/Lex/MacroInfo.h"
14 #include <string>
15 
16 namespace clang {
17 class MacroDirective;
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
27 public:
28  MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
29  : ClangTidyCheck(Name, Context),
30  AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")),
31  CheckCapsOnly(Options.get("CheckCapsOnly", false)),
32  IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", true)) {}
33  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
34  return LangOpts.CPlusPlus11;
35  }
36  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
37  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
38  Preprocessor *ModuleExpanderPP) override;
39  void warnMacro(const MacroDirective *MD, StringRef MacroName);
40  void warnNaming(const MacroDirective *MD, StringRef MacroName);
41 
42 private:
43  /// A regular expression that defines how allowed macros must look like.
44  std::string AllowedRegexp;
45  /// Control if only the check shall only test on CAPS_ONLY macros.
46  bool CheckCapsOnly;
47  /// Should the macros without a valid location be diagnosed?
48  bool IgnoreCommandLineMacros;
49 };
50 
51 } // namespace cppcoreguidelines
52 } // namespace tidy
53 } // namespace clang
54 
55 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
void warnNaming(const MacroDirective *MD, StringRef MacroName)
void warnMacro(const MacroDirective *MD, StringRef MacroName)
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Base class for all clang-tidy checks.
static constexpr llvm::StringLiteral Name
Find macro usage that is considered problematic because better language constructs exist for the task...
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
std::map< std::string, ClangTidyValue > OptionMap