diff --git a/clang/lib/Tooling/Transformer/RewriteRule.cpp b/clang/lib/Tooling/Transformer/RewriteRule.cpp --- a/clang/lib/Tooling/Transformer/RewriteRule.cpp +++ b/clang/lib/Tooling/Transformer/RewriteRule.cpp @@ -345,14 +345,13 @@ // Each anyOf explicitly controls the traversal kind. The anyOf itself is set // to `TK_AsIs` to ensure no nodes are skipped, thereby deferring to the kind // of the branches. Then, each branch is either left as is, if the kind is - // already set, or explicitly set to `TK_IgnoreUnlessSpelledInSource`. We - // choose this setting, because we think it is the one most friendly to - // beginners, who are (largely) the target audience of Transformer. + // already set, or explicitly set to `TK_AsIs`. We choose this setting because + // it is the default interpretation of matchers. std::vector Matchers; for (const auto &Bucket : Buckets) { DynTypedMatcher M = DynTypedMatcher::constructVariadic( DynTypedMatcher::VO_AnyOf, Bucket.first, - taggedMatchers("Tag", Bucket.second, TK_IgnoreUnlessSpelledInSource)); + taggedMatchers("Tag", Bucket.second, TK_AsIs)); M.setAllowBind(true); // `tryBind` is guaranteed to succeed, because `AllowBind` was set to true. Matchers.push_back(M.tryBind(RootID)->withTraversalKind(TK_AsIs)); diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -878,10 +878,8 @@ } // Verifies that a rule with a top-level matcher for an implicit node (like -// `implicitCastExpr`) does not change the code, when the AST traversal skips -// implicit nodes. In this test, only the rule with the explicit-node matcher -// will fire. -TEST_F(TransformerTest, OrderedRuleImplicitIgnored) { +// `implicitCastExpr`) works correctly -- the implicit nodes are not skipped. +TEST_F(TransformerTest, OrderedRuleImplicitMatched) { std::string Input = R"cc( void f1(); int f2(); @@ -892,7 +890,7 @@ void f1(); int f2(); void call_f1() { REPLACE_F1; } - float call_f2() { return f2(); } + float call_f2() { return REPLACE_F2; } )cc"; RewriteRule ReplaceF1 = @@ -904,32 +902,6 @@ testRule(applyFirst({ReplaceF1, ReplaceF2}), Input, Expected); } -// Verifies that explicitly setting the traversal kind fixes the problem in the -// previous test. -TEST_F(TransformerTest, OrderedRuleImplicitMatched) { - std::string Input = R"cc( - void f1(); - int f2(); - void call_f1() { f1(); } - float call_f2() { return f2(); } - )cc"; - std::string Expected = R"cc( - void f1(); - int f2(); - void call_f1() { REPLACE_F1; } - float call_f2() { return REPLACE_F2; } - )cc"; - - RewriteRule ReplaceF1 = makeRule( - traverse(clang::TK_AsIs, callExpr(callee(functionDecl(hasName("f1"))))), - changeTo(cat("REPLACE_F1"))); - RewriteRule ReplaceF2 = - makeRule(traverse(clang::TK_AsIs, - implicitCastExpr(hasSourceExpression(callExpr()))), - changeTo(cat("REPLACE_F2"))); - testRule(applyFirst({ReplaceF1, ReplaceF2}), Input, Expected); -} - // // Negative tests (where we expect no transformation to occur). //