forked from OSchip/llvm-project
[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
This commit is contained in:
parent
4601df7d6a
commit
bde3293302
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,14 +44,14 @@ public:
|
|||
// 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 @@ public:
|
|||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 @@ public:
|
|||
: 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue