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