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
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
void warnNaming(const MacroDirective *MD, StringRef MacroName)
void warnMacro(const MacroDirective *MD, StringRef MacroName)
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
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.
MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.