r361643 - [LibTooling] Add Explanation parameter to `makeRule`.
Yitzhak Mandelbaum via cfe-commits
cfe-commits at lists.llvm.org
Fri May 24 08:11:45 PDT 2019
Author: ymandel
Date: Fri May 24 08:11:45 2019
New Revision: 361643
URL: http://llvm.org/viewvc/llvm-project?rev=361643&view=rev
Log:
[LibTooling] Add Explanation parameter to `makeRule`.
Summary:
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.
Reviewers: ilya-biryukov
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62390
Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
cfe/trunk/unittests/Tooling/TransformerTest.cpp
Modified: cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h?rev=361643&r1=361642&r2=361643&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h Fri May 24 08:11:45 2019
@@ -125,14 +125,16 @@ struct RewriteRule {
/// 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.
Modified: cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp?rev=361643&r1=361642&r2=361643&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp Fri May 24 08:11:45 2019
@@ -96,10 +96,10 @@ ASTEdit tooling::change(RangeSelector S,
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
Modified: cfe/trunk/unittests/Tooling/TransformerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/TransformerTest.cpp?rev=361643&r1=361642&r2=361643&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/TransformerTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/TransformerTest.cpp Fri May 24 08:11:45 2019
@@ -147,8 +147,7 @@ static RewriteRule ruleStrlenSize() {
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;
}
More information about the cfe-commits
mailing list