[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-21 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa30d411629d5: Set traversal explicitly where needed in tests 
(authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,8 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -333,9 +334,10 @@
   int foo() { return this->x; }
 };
   )cc";
-  auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  auto StmtMatch = matchStmt(
+  Snippet, traverse(ast_type_traits::TK_AsIs,
+returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope RAII(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,7 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(), ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
Index: clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -507,8 +507,10 @@
 
 TEST_F(RegistryTest, ParenExpr) {
   Matcher Value = constructMatcher("parenExpr").getTypedMatcher();
-  EXPECT_TRUE(matches("int i = (1);", Value));
-  EXPECT_FALSE(matches("int i = 1;", Value));
+  EXPECT_TRUE(
+  matches("int i = (1);", traverse(ast_type_traits::TK_AsIs, Value)));
+  EXPECT_FALSE(
+  matches("int i = 1;", traverse(ast_type_traits::TK_AsIs, Value)));
 }
 
 TEST_F(RegistryTest, EqualsMatcher) {
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -373,7 +373,8 @@
   EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX));
   

[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/unittests/Tooling/StencilTest.cpp:63
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);

steveire wrote:
> aaron.ballman wrote:
> > steveire wrote:
> > > aaron.ballman wrote:
> > > > Was this change made because you didn't want to accept the traversal 
> > > > mode as a parameter to `matchStmt` and force each caller to decide 
> > > > which mode they use? Or is there some other reason why this change was 
> > > > needed?
> > > Yes, the test currently expects `AsIs`. If someone wanted to change that 
> > > in the future, that is an issue for future work.
> > You say "the test" as though there's only one. There are numerous tests 
> > which use `matchStmt`. Do *all* of the tests require `AsIs`? (I think 
> > that's an example of what's causing some of the confusion @shafik and I had 
> > and I'm trying to ensure his question gets answered and that I'm fully 
> > understanding your changes.) From spot-checking, it looks like there are 
> > tests using `matchStmt` that don't need `AsIs` traversal and that this sort 
> > of cleanup work could happen in the future, but for now you're going with 
> > the easiest approach instead of expanding the test coverage for ignoring 
> > implicit nodes; is that correct?
> I said "the" test because there is one `StencilTest` class inside one 
> `StencilTest.cpp`. Perhaps not a word you would use, but that's not something 
> to get stuck on hopefully.
> 
> Yes, it is possible that someone could make `matchStmt` take an explicit 
> `TraversalKind`, but I didn't see the need to do that in this patch. This 
> patch maintains the status quo as much as possible while also making it 
> possible to change the default.
> 
> 
> 
> I said "the" test because there is one StencilTest class inside one 
> StencilTest.cpp. Perhaps not a word you would use, but that's not something 
> to get stuck on hopefully.

Nope, just making sure I understood.

> Yes, it is possible that someone could make matchStmt take an explicit 
> TraversalKind, but I didn't see the need to do that in this patch.

Good to know! FWIW, it would be reasonable to do some of that work in this 
patch, but I don't insist. As with one of the other patches in the set, making 
the changes to handle either traversal kind as appropriate for the situation 
improves the test coverage for your changes and it helps demonstrate why this 
default is more simple (as opposed to making everything look more complex 
because the patch only adds code, doesn't remove any).

> This patch maintains the status quo as much as possible while also making it 
> possible to change the default.

That's good enough for me, thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-18 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked an inline comment as done.
steveire added inline comments.



Comment at: clang/unittests/Tooling/StencilTest.cpp:63
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);

aaron.ballman wrote:
> steveire wrote:
> > aaron.ballman wrote:
> > > Was this change made because you didn't want to accept the traversal mode 
> > > as a parameter to `matchStmt` and force each caller to decide which mode 
> > > they use? Or is there some other reason why this change was needed?
> > Yes, the test currently expects `AsIs`. If someone wanted to change that in 
> > the future, that is an issue for future work.
> You say "the test" as though there's only one. There are numerous tests which 
> use `matchStmt`. Do *all* of the tests require `AsIs`? (I think that's an 
> example of what's causing some of the confusion @shafik and I had and I'm 
> trying to ensure his question gets answered and that I'm fully understanding 
> your changes.) From spot-checking, it looks like there are tests using 
> `matchStmt` that don't need `AsIs` traversal and that this sort of cleanup 
> work could happen in the future, but for now you're going with the easiest 
> approach instead of expanding the test coverage for ignoring implicit nodes; 
> is that correct?
I said "the" test because there is one `StencilTest` class inside one 
`StencilTest.cpp`. Perhaps not a word you would use, but that's not something 
to get stuck on hopefully.

Yes, it is possible that someone could make `matchStmt` take an explicit 
`TraversalKind`, but I didn't see the need to do that in this patch. This patch 
maintains the status quo as much as possible while also making it possible to 
change the default.





Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/unittests/Tooling/StencilTest.cpp:63
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);

steveire wrote:
> aaron.ballman wrote:
> > Was this change made because you didn't want to accept the traversal mode 
> > as a parameter to `matchStmt` and force each caller to decide which mode 
> > they use? Or is there some other reason why this change was needed?
> Yes, the test currently expects `AsIs`. If someone wanted to change that in 
> the future, that is an issue for future work.
You say "the test" as though there's only one. There are numerous tests which 
use `matchStmt`. Do *all* of the tests require `AsIs`? (I think that's an 
example of what's causing some of the confusion @shafik and I had and I'm 
trying to ensure his question gets answered and that I'm fully understanding 
your changes.) From spot-checking, it looks like there are tests using 
`matchStmt` that don't need `AsIs` traversal and that this sort of cleanup work 
could happen in the future, but for now you're going with the easiest approach 
instead of expanding the test coverage for ignoring implicit nodes; is that 
correct?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked an inline comment as done.
steveire added inline comments.



Comment at: clang/unittests/Tooling/StencilTest.cpp:63
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);

aaron.ballman wrote:
> Was this change made because you didn't want to accept the traversal mode as 
> a parameter to `matchStmt` and force each caller to decide which mode they 
> use? Or is there some other reason why this change was needed?
Yes, the test currently expects `AsIs`. If someone wanted to change that in the 
future, that is an issue for future work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D72531#1845686 , @shafik wrote:

> I was looking at the changes to `ASTImporterTest.cpp` and it not obvious to 
> me how you determined where it was needed.


Some of the changes were reasonably obvious to me because they involved 
matching implicit nodes that require the as-is traversal. However, other 
changes did seem to come from out of nowhere (I commented on one such), and 
hopefully @steveire will explain.




Comment at: clang/unittests/Tooling/StencilTest.cpp:63
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);

Was this change made because you didn't want to accept the traversal mode as a 
parameter to `matchStmt` and force each caller to decide which mode they use? 
Or is there some other reason why this change was needed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-05-12 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 263540.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,8 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(
+  traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -333,9 +334,10 @@
   int foo() { return this->x; }
 };
   )cc";
-  auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  auto StmtMatch = matchStmt(
+  Snippet, traverse(ast_type_traits::TK_AsIs,
+returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope RAII(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,7 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(), ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
Index: clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -507,8 +507,10 @@
 
 TEST_F(RegistryTest, ParenExpr) {
   Matcher Value = constructMatcher("parenExpr").getTypedMatcher();
-  EXPECT_TRUE(matches("int i = (1);", Value));
-  EXPECT_FALSE(matches("int i = 1;", Value));
+  EXPECT_TRUE(
+  matches("int i = (1);", traverse(ast_type_traits::TK_AsIs, Value)));
+  EXPECT_FALSE(
+  matches("int i = 1;", traverse(ast_type_traits::TK_AsIs, Value)));
 }
 
 TEST_F(RegistryTest, EqualsMatcher) {
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -373,7 +373,8 @@
   EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX));
   EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX));
 
-  CallMethodX = callExpr(callee(cxxConversionDecl()));
+  

[PATCH] D72531: Set traversal explicitly where needed in tests

2020-01-28 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I was looking at the changes to `ASTImporterTest.cpp` and it not obvious to me 
how you determined where it was needed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72531: Set traversal explicitly where needed in tests

2020-01-28 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 240841.
steveire added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,8 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(traverse(ast_type_traits::TK_AsIs,
+wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -331,8 +332,9 @@
 };
   )cc";
   auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  matchStmt(Snippet, traverse(ast_type_traits::TK_AsIs,
+returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+ hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope RAII(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,7 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(), ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
Index: clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -507,8 +507,10 @@
 
 TEST_F(RegistryTest, ParenExpr) {
   Matcher Value = constructMatcher("parenExpr").getTypedMatcher();
-  EXPECT_TRUE(matches("int i = (1);", Value));
-  EXPECT_FALSE(matches("int i = 1;", Value));
+  EXPECT_TRUE(matches("int i = (1);",
+traverse(ast_type_traits::TK_AsIs, Value)));
+  EXPECT_FALSE(matches("int i = 1;",
+traverse(ast_type_traits::TK_AsIs, Value)));
 }
 
 TEST_F(RegistryTest, EqualsMatcher) {
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -373,7 +373,8 @@
   EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX));
   EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX));
 
-  CallMethodX = callExpr(callee(cxxConversionDecl()));
+  CallMethodX = traverse(ast_type_traits::TK_AsIs,
+

[PATCH] D72531: Set traversal explicitly where needed in tests

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 237418.
steveire added a comment.

Fix case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72531/new/

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,7 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -331,8 +331,8 @@
 };
   )cc";
   auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  matchStmt(Snippet, traverse(ast_type_traits::TK_AsIs, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+ hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope RAII(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
@@ -101,8 +102,8 @@
   decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
  .bind("init")))
   .bind("decl")))
-  .bind("expr")))
-  .bind("stmt");
+  .bind("expr"))
+).bind("stmt");
 
   return Selector(matchCode(Code, Matcher).Result);
 }
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,8 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(),
+ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
@@ -1129,6 +1131,7 @@
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
+  // return;
 
   AST = buildASTFromCode("void f() { int x, y; __typeof(x = 10) z = y; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
@@ -1158,7 +1161,7 @@
 
   AST = buildASTFromCode(
   "void f() { int x; _Generic(x = 10, int: 0, default: 1); }");
-  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  Results = match(traverse(ast_type_traits::TK_AsIs, withEnclosingCompound(declRefTo("x"))), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
 }
 
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ 

[PATCH] D72531: Set traversal explicitly where needed in tests

2020-01-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a reviewer: shafik.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72531

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp
  clang/unittests/Tooling/RefactoringCallbacksTest.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -60,7 +60,7 @@
 return llvm::None;
   }
   ASTContext  = AstUnit->getASTContext();
-  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  auto Matches = ast_matchers::match(traverse(ast_type_traits::TK_AsIs, wrapMatcher(Matcher)), Context);
   // We expect a single, exact match for the statement.
   if (Matches.size() != 1) {
 ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
@@ -331,8 +331,8 @@
 };
   )cc";
   auto StmtMatch =
-  matchStmt(Snippet, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
- hasObjectExpression(expr().bind("obj")));
+  matchStmt(Snippet, traverse(ast_type_traits::TK_AsIs, returnStmt(hasReturnValue(ignoringImplicit(memberExpr(
+ hasObjectExpression(expr().bind("obj";
   ASSERT_TRUE(StmtMatch);
   const Stencil Stencil = access("obj", "field");
   EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Index: clang/unittests/Tooling/RefactoringCallbacksTest.cpp
===
--- clang/unittests/Tooling/RefactoringCallbacksTest.cpp
+++ clang/unittests/Tooling/RefactoringCallbacksTest.cpp
@@ -22,7 +22,7 @@
  const T , RefactoringCallback ) {
   std::map FileToReplace;
   ASTMatchRefactorer Finder(FileToReplace);
-  Finder.addMatcher(AMatcher, );
+  Finder.addMatcher(traverse(ast_type_traits::TK_AsIs, AMatcher), );
   std::unique_ptr Factory(
   tooling::newFrontendActionFactory());
   ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), Code))
Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -46,6 +46,7 @@
   ASTContext  = ASTUnit->getASTContext();
   assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
 
+  TraversalKindScope raii(Context, ast_type_traits::TK_AsIs);
   auto Matches = ast_matchers::match(Matcher, Context);
   // We expect a single, exact match.
   assert(Matches.size() != 0 && "no matches found");
@@ -101,8 +102,8 @@
   decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
  .bind("init")))
   .bind("decl")))
-  .bind("expr")))
-  .bind("stmt");
+  .bind("expr"))
+).bind("stmt");
 
   return Selector(matchCode(Code, Matcher).Result);
 }
Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -54,6 +54,8 @@
 bool isMutated(const SmallVectorImpl , ASTUnit *AST) {
   const auto *const S = selectFirst("stmt", Results);
   const auto *const E = selectFirst("expr", Results);
+  TraversalKindScope RAII(AST->getASTContext(),
+ast_type_traits::TK_AsIs);
   return ExprMutationAnalyzer(*S, AST->getASTContext()).isMutated(E);
 }
 
@@ -1129,6 +1131,7 @@
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
+  // return;
 
   AST = buildASTFromCode("void f() { int x, y; __typeof(x = 10) z = y; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
@@ -1158,7 +1161,7 @@
 
   AST = buildASTFromCode(
   "void f() { int x; _Generic(x = 10, int: 0, default: 1); }");
-  Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
+  Results = match(traverse(ast_type_traits::TK_AsIs, withEnclosingCompound(declRefTo("x"))), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
 }
 
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
---