Yitzhak Mandelbaum | 9df7ce5 | 2019-05-22 18:56:18 +0000 | [diff] [blame] | 1 | //===---------- TransformerClangTidyCheck.h - clang-tidy ------------------===// |
| 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_TRANSFORMER_CLANG_TIDY_CHECK_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H |
| 11 | |
| 12 | #include "../ClangTidy.h" |
| 13 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 14 | #include "clang/Tooling/Refactoring/Transformer.h" |
| 15 | #include <deque> |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace clang { |
| 19 | namespace tidy { |
| 20 | namespace utils { |
| 21 | |
| 22 | // A base class for defining a ClangTidy check based on a `RewriteRule`. |
| 23 | // |
| 24 | // For example, given a rule `MyCheckAsRewriteRule`, one can define a tidy check |
| 25 | // as follows: |
| 26 | // |
| 27 | // class MyCheck : public TransformerClangTidyCheck { |
| 28 | // public: |
| 29 | // MyCheck(StringRef Name, ClangTidyContext *Context) |
| 30 | // : TransformerClangTidyCheck(MyCheckAsRewriteRule, Name, Context) {} |
| 31 | // }; |
| 32 | class TransformerClangTidyCheck : public ClangTidyCheck { |
| 33 | public: |
Yitzhak Mandelbaum | 5b33554 | 2019-05-24 16:32:03 +0000 | [diff] [blame^] | 34 | // All cases in \p R must have a non-null \c Explanation, even though \c |
| 35 | // Explanation is optional for RewriteRule in general. Because the primary |
| 36 | // purpose of clang-tidy checks is to provide users with diagnostics, we |
| 37 | // assume that a missing explanation is a bug. If no explanation is desired, |
| 38 | // indicate that explicitly (for example, by passing `text("no explanation")` |
| 39 | // to `makeRule` as the `Explanation` argument). |
Yitzhak Mandelbaum | 9df7ce5 | 2019-05-22 18:56:18 +0000 | [diff] [blame] | 40 | TransformerClangTidyCheck(tooling::RewriteRule R, StringRef Name, |
Yitzhak Mandelbaum | 5b33554 | 2019-05-24 16:32:03 +0000 | [diff] [blame^] | 41 | ClangTidyContext *Context); |
Yitzhak Mandelbaum | 9df7ce5 | 2019-05-22 18:56:18 +0000 | [diff] [blame] | 42 | void registerMatchers(ast_matchers::MatchFinder *Finder) final; |
| 43 | void check(const ast_matchers::MatchFinder::MatchResult &Result) final; |
| 44 | |
| 45 | private: |
| 46 | tooling::RewriteRule Rule; |
| 47 | }; |
| 48 | |
| 49 | } // namespace utils |
| 50 | } // namespace tidy |
| 51 | } // namespace clang |
| 52 | |
| 53 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H |