[PATCH] D62390: [LibTooling] Add Explanation parameter to `makeRule`.
Yitzhak Mandelbaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 24 07:07:00 PDT 2019
ymandel created this revision.
ymandel added a reviewer: ilya-biryukov.
Herald added a project: clang.
Conceptually, a single-case RewriteRule has a matcher, edit(s) and an (optional)
explanation. `makeRule` previously only took the matcher and edit(s). This
change adds (optional) support for the explanation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D62390
Files:
clang/include/clang/Tooling/Refactoring/Transformer.h
clang/lib/Tooling/Refactoring/Transformer.cpp
clang/unittests/Tooling/TransformerTest.cpp
Index: clang/unittests/Tooling/TransformerTest.cpp
===================================================================
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -147,8 +147,7 @@
on(expr(hasType(isOrPointsTo(StringType)))
.bind(StringExpr)),
callee(cxxMethodDecl(hasName("c_str")))))),
- change(text("REPLACED")));
- R.Cases[0].Explanation = text("Use size() method directly on string.");
+ change(text("REPLACED")), text("Use size() method directly on string."));
return R;
}
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===================================================================
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -96,10 +96,10 @@
return E;
}
-RewriteRule tooling::makeRule(DynTypedMatcher M,
- SmallVector<ASTEdit, 1> Edits) {
- return RewriteRule{
- {RewriteRule::Case{std::move(M), std::move(Edits), nullptr}}};
+RewriteRule tooling::makeRule(DynTypedMatcher M, SmallVector<ASTEdit, 1> Edits,
+ TextGenerator Explanation) {
+ return RewriteRule{{RewriteRule::Case{std::move(M), std::move(Edits),
+ std::move(Explanation)}}};
}
// Determines whether A is a base type of B in the class hierarchy, including
Index: clang/include/clang/Tooling/Refactoring/Transformer.h
===================================================================
--- clang/include/clang/Tooling/Refactoring/Transformer.h
+++ clang/include/clang/Tooling/Refactoring/Transformer.h
@@ -125,14 +125,16 @@
/// Convenience function for constructing a simple \c RewriteRule.
RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M,
- SmallVector<ASTEdit, 1> Edits);
+ SmallVector<ASTEdit, 1> Edits,
+ TextGenerator Explanation = nullptr);
/// Convenience overload of \c makeRule for common case of only one edit.
inline RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M,
- ASTEdit Edit) {
+ ASTEdit Edit,
+ TextGenerator Explanation = nullptr) {
SmallVector<ASTEdit, 1> Edits;
Edits.emplace_back(std::move(Edit));
- return makeRule(std::move(M), std::move(Edits));
+ return makeRule(std::move(M), std::move(Edits), std::move(Explanation));
}
/// Applies the first rule whose pattern matches; other rules are ignored.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62390.201229.patch
Type: text/x-patch
Size: 2651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190524/fd0f7dac/attachment-0001.bin>
More information about the cfe-commits
mailing list