Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:19

0001 //===--- MacroUsageCheck.h - clang-tidy--------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "clang/Lex/MacroInfo.h"
0014 #include <string>
0015 
0016 namespace clang {
0017 class MacroDirective;
0018 namespace tidy::cppcoreguidelines {
0019 
0020 /// Find macro usage that is considered problematic because better language
0021 /// constructs exist for the task.
0022 ///
0023 /// For the user-facing documentation see:
0024 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/macro-usage.html
0025 class MacroUsageCheck : public ClangTidyCheck {
0026 public:
0027   MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
0028       : ClangTidyCheck(Name, Context),
0029         AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")),
0030         CheckCapsOnly(Options.get("CheckCapsOnly", false)),
0031         IgnoreCommandLineMacros(Options.get("IgnoreCommandLineMacros", true)) {}
0032   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0033     return LangOpts.CPlusPlus11;
0034   }
0035   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0036   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0037                            Preprocessor *ModuleExpanderPP) override;
0038   void warnMacro(const MacroDirective *MD, StringRef MacroName);
0039   void warnNaming(const MacroDirective *MD, StringRef MacroName);
0040 
0041 private:
0042   /// A regular expression that defines how allowed macros must look like.
0043   std::string AllowedRegexp;
0044   /// Control if only the check shall only test on CAPS_ONLY macros.
0045   bool CheckCapsOnly;
0046   /// Should the macros without a valid location be diagnosed?
0047   bool IgnoreCommandLineMacros;
0048 };
0049 
0050 } // namespace tidy::cppcoreguidelines
0051 } // namespace clang
0052 
0053 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H