diff options
| author | Jonas Toth <jonas.toth@gmail.com> | 2018-10-22 19:20:01 +0000 |
|---|---|---|
| committer | Jonas Toth <jonas.toth@gmail.com> | 2018-10-22 19:20:01 +0000 |
| commit | 552b62ed1f24dfbed4b5ee733415572ead5b228e (patch) | |
| tree | f389feaa5b77a8c10caef76cc0c923be21a00d6e /clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h | |
| parent | c2e58e726525943ffa6eef3392de42dc0a769470 (diff) | |
| download | bcm5719-llvm-552b62ed1f24dfbed4b5ee733415572ead5b228e.tar.gz bcm5719-llvm-552b62ed1f24dfbed4b5ee733415572ead5b228e.zip | |
[clang-tidy] implement cppcoreguidelines macro rules
Summary:
In short macros are discouraged by multiple rules (and sometimes reference randomly). [Enum.1], [ES.30], [ES.31]
This check allows only headerguards and empty macros for annotation.
Reviewers: aaron.ballman, hokein
Reviewed By: aaron.ballman
Subscribers: jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits
Differential Revision: https://reviews.llvm.org/D41648
llvm-svn: 344940
Diffstat (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h')
| -rw-r--r-- | clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h b/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h new file mode 100644 index 00000000000..ff33310e6e5 --- /dev/null +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.h @@ -0,0 +1,48 @@ +//===--- MacroUsageCheck.h - clang-tidy--------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H + +#include "../ClangTidy.h" +#include "clang/Lex/Preprocessor.h" +#include <string> + +namespace clang { +namespace tidy { +namespace cppcoreguidelines { + +/// Find macro usage that is considered problematic because better language +/// constructs exist for the task. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html +class MacroUsageCheck : public ClangTidyCheck { +public: + MacroUsageCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), + AllowedRegexp(Options.get("AllowedRegexp", "^DEBUG_*")), + CheckCapsOnly(Options.get("CheckCapsOnly", 0)) {} + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void registerPPCallbacks(CompilerInstance &Compiler) override; + void warnMacro(const MacroDirective *MD); + void warnNaming(const MacroDirective *MD); + +private: + /// A regular expression that defines how allowed macros must look like. + std::string AllowedRegexp; + /// Control if only the check shall only test on CAPS_ONLY macros. + bool CheckCapsOnly; +}; + +} // namespace cppcoreguidelines +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H |

