[clang-tools-extra] bde3293 - [clang-tidy] Update TransformerClangTidyCheck to use new Transformer bindings.
Yitzhak Mandelbaum via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 6 07:14:26 PST 2019
Author: Yitzhak Mandelbaum
Date: 2019-11-06T10:13:33-05:00
New Revision: bde32933027a096b6cfe14b0e9385ac1005fc28a
URL: https://github.com/llvm/llvm-project/commit/bde32933027a096b6cfe14b0e9385ac1005fc28a
DIFF: https://github.com/llvm/llvm-project/commit/bde32933027a096b6cfe14b0e9385ac1005fc28a.diff
LOG: [clang-tidy] Update TransformerClangTidyCheck to use new Transformer bindings.
Summary:
Updates the relevant source files to use bindings in `clang::transformer` rather
than `clang::tooling`.
Reviewers: gribozavr
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69804
Added:
Modified:
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
index 06899108ea36..1c31cf56c68a 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -12,7 +12,7 @@
namespace clang {
namespace tidy {
namespace utils {
-using tooling::RewriteRule;
+using transformer::RewriteRule;
#ifndef NDEBUG
static bool hasExplanation(const RewriteRule::Case &C) {
@@ -62,7 +62,7 @@ void TransformerClangTidyCheck::registerPPCallbacks(
void TransformerClangTidyCheck::registerMatchers(
ast_matchers::MatchFinder *Finder) {
if (Rule)
- for (auto &Matcher : tooling::detail::buildMatchers(*Rule))
+ for (auto &Matcher : transformer::detail::buildMatchers(*Rule))
Finder->addDynamicMatcher(Matcher, this);
}
@@ -72,9 +72,9 @@ void TransformerClangTidyCheck::check(
return;
assert(Rule && "check() should not fire if Rule is None");
- RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, *Rule);
- Expected<SmallVector<tooling::detail::Transformation, 1>> Transformations =
- tooling::detail::translateEdits(Result, Case.Edits);
+ RewriteRule::Case Case = transformer::detail::findSelectedCase(Result, *Rule);
+ Expected<SmallVector<transformer::detail::Transformation, 1>>
+ Transformations = transformer::detail::translateEdits(Result, Case.Edits);
if (!Transformations) {
llvm::errs() << "Rewrite failed: "
<< llvm::toString(Transformations.takeError()) << "\n";
@@ -102,7 +102,7 @@ void TransformerClangTidyCheck::check(
auto &Header = I.first;
if (Optional<FixItHint> Fix = Inserter->CreateIncludeInsertion(
Result.SourceManager->getMainFileID(), Header,
- /*IsAngled=*/I.second == tooling::IncludeFormat::Angled)) {
+ /*IsAngled=*/I.second == transformer::IncludeFormat::Angled)) {
Diag << *Fix;
}
}
diff --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
index bcbc41507db2..e411a3f6f0f5 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -44,14 +44,14 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
// no explanation is desired, indicate that explicitly (for example, by
// passing `text("no explanation")` to `makeRule` as the `Explanation`
// argument).
- TransformerClangTidyCheck(std::function<Optional<tooling::RewriteRule>(
+ TransformerClangTidyCheck(std::function<Optional<transformer::RewriteRule>(
const LangOptions &, const OptionsView &)>
MakeRule,
StringRef Name, ClangTidyContext *Context);
// Convenience overload of the constructor when the rule doesn't depend on any
// of the language or clang-tidy options.
- TransformerClangTidyCheck(tooling::RewriteRule R, StringRef Name,
+ TransformerClangTidyCheck(transformer::RewriteRule R, StringRef Name,
ClangTidyContext *Context);
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
@@ -60,7 +60,7 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
private:
- Optional<tooling::RewriteRule> Rule;
+ Optional<transformer::RewriteRule> Rule;
std::unique_ptr<clang::tidy::utils::IncludeInserter> Inserter;
};
diff --git a/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp b/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
index c8e65e9bf988..28ea7e229f35 100644
--- a/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -20,13 +20,12 @@ namespace utils {
namespace {
using namespace ::clang::ast_matchers;
-using tooling::change;
-using tooling::IncludeFormat;
-using tooling::node;
-using tooling::RewriteRule;
-using tooling::statement;
-using tooling::text;
-using tooling::stencil::cat;
+using transformer::cat;
+using transformer::change;
+using transformer::IncludeFormat;
+using transformer::node;
+using transformer::RewriteRule;
+using transformer::statement;
// Invert the code of an if-statement, while maintaining its semantics.
RewriteRule invertIf() {
@@ -37,7 +36,7 @@ RewriteRule invertIf() {
change(
statement(RewriteRule::RootID),
cat("if(!(", node(C), ")) ", statement(E), " else ", statement(T))),
- text("negate condition and reverse `then` and `else` branches"));
+ cat("negate condition and reverse `then` and `else` branches"));
return Rule;
}
@@ -71,8 +70,8 @@ class IntLitCheck : public TransformerClangTidyCheck {
public:
IntLitCheck(StringRef Name, ClangTidyContext *Context)
: TransformerClangTidyCheck(tooling::makeRule(integerLiteral(),
- change(text("LIT")),
- text("no message")),
+ change(cat("LIT")),
+ cat("no message")),
Name, Context) {}
};
@@ -97,7 +96,7 @@ class BinOpCheck : public TransformerClangTidyCheck {
: TransformerClangTidyCheck(
tooling::makeRule(
binaryOperator(hasOperatorName("+"), hasRHS(expr().bind("r"))),
- change(node("r"), text("RIGHT")), text("no message")),
+ change(node("r"), cat("RIGHT")), cat("no message")),
Name, Context) {}
};
@@ -123,7 +122,7 @@ Optional<RewriteRule> needsObjC(const LangOptions &LangOpts,
if (!LangOpts.ObjC)
return None;
return tooling::makeRule(clang::ast_matchers::functionDecl(),
- change(cat("void changed() {}")), text("no message"));
+ change(cat("void changed() {}")), cat("no message"));
}
class NeedsObjCCheck : public TransformerClangTidyCheck {
@@ -148,7 +147,7 @@ Optional<RewriteRule> noSkip(const LangOptions &LangOpts,
if (Options.get("Skip", "false") == "true")
return None;
return tooling::makeRule(clang::ast_matchers::functionDecl(),
- change(cat("void nothing()")), text("no message"));
+ change(cat("void nothing()")), cat("no message"));
}
class ConfigurableCheck : public TransformerClangTidyCheck {
@@ -176,7 +175,7 @@ RewriteRule replaceCall(IncludeFormat Format) {
using namespace ::clang::ast_matchers;
RewriteRule Rule =
tooling::makeRule(callExpr(callee(functionDecl(hasName("f")))),
- change(text("other()")), text("no message"));
+ change(cat("other()")), cat("no message"));
addInclude(Rule, "clang/OtherLib.h", Format);
return Rule;
}
More information about the cfe-commits
mailing list