[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D85621#2205944 , @njames93 wrote:

> In D85621#2205856 , @nridge wrote:
>
>> In D85621#2205803 , @hokein wrote:
>>
>>> Please run `clang/docs/tools/dump_ast_matchers.py` script to update the 
>>> `LibASTMatchersReference.html` file.
>>
>> Done. Note, it looks like this script needs to be run with python 2. Should 
>> we document this somewhere?
>
> Given that python2 is EOL I think the correct course of action is to make it 
> work with python3.

Filed https://bugs.llvm.org/show_bug.cgi?id=47102 for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85621

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


[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-10 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D85621#2205856 , @nridge wrote:

> In D85621#2205803 , @hokein wrote:
>
>> Please run `clang/docs/tools/dump_ast_matchers.py` script to update the 
>> `LibASTMatchersReference.html` file.
>
> Done. Note, it looks like this script needs to be run with python 2. Should 
> we document this somewhere?

Given that python2 is EOL I think the correct course of action is to make it 
work with python3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85621

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


[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-10 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb1c7f84643ff: [clang] Allow DynTypedNode to store a 
TemplateArgumentLoc (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85621

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2637,6 +2637,19 @@
 std::make_unique>("x", 1)));
 }
 
+TEST(TemplateArgumentLoc, Matches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  R"cpp(
+template  class C> class X {};
+class A {};
+const int B = 42;
+template  class C {};
+X x;
+  )cpp",
+  templateArgumentLoc().bind("x"),
+  std::make_unique>("x", 3)));
+}
+
 TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) {
   // Those matchers cover all the cases where an inner matcher is called
   // and there is not a 1:1 relationship between the match of the outer
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -734,6 +734,7 @@
 accessSpecDecl;
 const internal::VariadicAllOfMatcher cxxCtorInitializer;
 const internal::VariadicAllOfMatcher templateArgument;
+const internal::VariadicAllOfMatcher templateArgumentLoc;
 const internal::VariadicAllOfMatcher templateName;
 const internal::VariadicDynCastAllOfMatcher
 nonTypeTemplateParmDecl;
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -128,6 +128,9 @@
   traverse(*T);
 else if (const auto *C = DynNode.get())
   traverse(*C);
+else if (const TemplateArgumentLoc *TALoc =
+ DynNode.get())
+  traverse(*TALoc);
 // FIXME: Add other base types after adding tests.
 
 // It's OK to always overwrite the bound nodes, as if there was
@@ -224,6 +227,10 @@
 ScopedIncrement ScopedDepth();
 return traverse(*CtorInit);
   }
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL) {
+ScopedIncrement ScopedDepth();
+return traverse(TAL);
+  }
   bool TraverseLambdaExpr(LambdaExpr *Node) {
 if (Finder->getASTContext().getParentMapContext().getTraversalKind() !=
 TK_IgnoreUnlessSpelledInSource)
@@ -304,6 +311,9 @@
 return VisitorBase::TraverseConstructorInitializer(
 const_cast());
   }
+  bool baseTraverse(TemplateArgumentLoc TAL) {
+return VisitorBase::TraverseTemplateArgumentLoc(TAL);
+  }
 
   // Sets 'Matched' to true if 'Matcher' matches 'Node' and:
   //   0 < CurrentDepth <= MaxDepth.
@@ -447,6 +457,7 @@
   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
   bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL);
 
   // Matches children or descendants of 'Node' with 'BaseMatcher'.
   bool memoizedMatchesRecursively(const DynTypedNode , ASTContext ,
@@ -557,6 +568,8 @@
   match(*N);
 } else if (auto *N = Node.get()) {
   match(*N);
+} else if (auto *N = Node.get()) {
+  match(*N);
 }
   }
 
@@ -680,6 +693,9 @@
   void matchDispatch(const CXXCtorInitializer *Node) {
 matchWithoutFilter(*Node, Matchers->CtorInit);
   }
+  void matchDispatch(const TemplateArgumentLoc *Node) {
+matchWithoutFilter(*Node, Matchers->TemplateArgumentLoc);
+  }
   void matchDispatch(const void *) { /* Do nothing. */ }
   /// @}
 
@@ -1035,6 +1051,11 @@
   CtorInit);
 }
 
+bool MatchASTVisitor::TraverseTemplateArgumentLoc(TemplateArgumentLoc Loc) {
+  match(Loc);
+  return RecursiveASTVisitor::TraverseTemplateArgumentLoc(Loc);
+}
+
 class MatchASTConsumer : public ASTConsumer {
 public:
   MatchASTConsumer(MatchFinder *Finder,
@@ -,6 +1132,12 @@
   Matchers.AllCallbacks.insert(Action);
 }
 
+void MatchFinder::addMatcher(const TemplateArgumentLocMatcher ,
+ MatchCallback *Action) {
+  Matchers.TemplateArgumentLoc.emplace_back(NodeMatch, Action);
+  

[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D85621#2205803 , @hokein wrote:

> Please run `clang/docs/tools/dump_ast_matchers.py` script to update the 
> `LibASTMatchersReference.html` file.

Done. Note, it looks like this script needs to be run with python 2. Should we 
document this somewhere?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85621

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


[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 284264.
nridge added a comment.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Run script to update AST matcher docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85621

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2637,6 +2637,19 @@
 std::make_unique>("x", 1)));
 }
 
+TEST(TemplateArgumentLoc, Matches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  R"cpp(
+template  class C> class X {};
+class A {};
+const int B = 42;
+template  class C {};
+X x;
+  )cpp",
+  templateArgumentLoc().bind("x"),
+  std::make_unique>("x", 3)));
+}
+
 TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) {
   // Those matchers cover all the cases where an inner matcher is called
   // and there is not a 1:1 relationship between the match of the outer
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -734,6 +734,7 @@
 accessSpecDecl;
 const internal::VariadicAllOfMatcher cxxCtorInitializer;
 const internal::VariadicAllOfMatcher templateArgument;
+const internal::VariadicAllOfMatcher templateArgumentLoc;
 const internal::VariadicAllOfMatcher templateName;
 const internal::VariadicDynCastAllOfMatcher
 nonTypeTemplateParmDecl;
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -128,6 +128,9 @@
   traverse(*T);
 else if (const auto *C = DynNode.get())
   traverse(*C);
+else if (const TemplateArgumentLoc *TALoc =
+ DynNode.get())
+  traverse(*TALoc);
 // FIXME: Add other base types after adding tests.
 
 // It's OK to always overwrite the bound nodes, as if there was
@@ -224,6 +227,10 @@
 ScopedIncrement ScopedDepth();
 return traverse(*CtorInit);
   }
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL) {
+ScopedIncrement ScopedDepth();
+return traverse(TAL);
+  }
   bool TraverseLambdaExpr(LambdaExpr *Node) {
 if (Finder->getASTContext().getParentMapContext().getTraversalKind() !=
 TK_IgnoreUnlessSpelledInSource)
@@ -304,6 +311,9 @@
 return VisitorBase::TraverseConstructorInitializer(
 const_cast());
   }
+  bool baseTraverse(TemplateArgumentLoc TAL) {
+return VisitorBase::TraverseTemplateArgumentLoc(TAL);
+  }
 
   // Sets 'Matched' to true if 'Matcher' matches 'Node' and:
   //   0 < CurrentDepth <= MaxDepth.
@@ -447,6 +457,7 @@
   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
   bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL);
 
   // Matches children or descendants of 'Node' with 'BaseMatcher'.
   bool memoizedMatchesRecursively(const DynTypedNode , ASTContext ,
@@ -557,6 +568,8 @@
   match(*N);
 } else if (auto *N = Node.get()) {
   match(*N);
+} else if (auto *N = Node.get()) {
+  match(*N);
 }
   }
 
@@ -680,6 +693,9 @@
   void matchDispatch(const CXXCtorInitializer *Node) {
 matchWithoutFilter(*Node, Matchers->CtorInit);
   }
+  void matchDispatch(const TemplateArgumentLoc *Node) {
+matchWithoutFilter(*Node, Matchers->TemplateArgumentLoc);
+  }
   void matchDispatch(const void *) { /* Do nothing. */ }
   /// @}
 
@@ -1035,6 +1051,11 @@
   CtorInit);
 }
 
+bool MatchASTVisitor::TraverseTemplateArgumentLoc(TemplateArgumentLoc Loc) {
+  match(Loc);
+  return RecursiveASTVisitor::TraverseTemplateArgumentLoc(Loc);
+}
+
 class MatchASTConsumer : public ASTConsumer {
 public:
   MatchASTConsumer(MatchFinder *Finder,
@@ -,6 +1132,12 @@
   Matchers.AllCallbacks.insert(Action);
 }
 
+void MatchFinder::addMatcher(const TemplateArgumentLocMatcher ,
+ MatchCallback *Action) {
+  Matchers.TemplateArgumentLoc.emplace_back(NodeMatch, Action);
+  Matchers.AllCallbacks.insert(Action);
+}
+
 bool MatchFinder::addDynamicMatcher(const 

[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks.

Please run `clang/docs/tools/dump_ast_matchers.py` script to update the 
`LibASTMatchersReference.html` file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85621

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


[PATCH] D85621: [clang] Allow DynTypedNode to store a TemplateArgumentLoc

2020-08-09 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: hokein.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nridge requested review of this revision.

The patch also adds a templateArgumentLoc() AST matcher.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85621

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2637,6 +2637,19 @@
 std::make_unique>("x", 1)));
 }
 
+TEST(TemplateArgumentLoc, Matches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  R"cpp(
+template  class C> class X {};
+class A {};
+const int B = 42;
+template  class C {};
+X x;
+  )cpp",
+  templateArgumentLoc().bind("x"),
+  std::make_unique>("x", 3)));
+}
+
 TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) {
   // Those matchers cover all the cases where an inner matcher is called
   // and there is not a 1:1 relationship between the match of the outer
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -734,6 +734,7 @@
 accessSpecDecl;
 const internal::VariadicAllOfMatcher cxxCtorInitializer;
 const internal::VariadicAllOfMatcher templateArgument;
+const internal::VariadicAllOfMatcher templateArgumentLoc;
 const internal::VariadicAllOfMatcher templateName;
 const internal::VariadicDynCastAllOfMatcher
 nonTypeTemplateParmDecl;
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -128,6 +128,9 @@
   traverse(*T);
 else if (const auto *C = DynNode.get())
   traverse(*C);
+else if (const TemplateArgumentLoc *TALoc =
+ DynNode.get())
+  traverse(*TALoc);
 // FIXME: Add other base types after adding tests.
 
 // It's OK to always overwrite the bound nodes, as if there was
@@ -224,6 +227,10 @@
 ScopedIncrement ScopedDepth();
 return traverse(*CtorInit);
   }
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL) {
+ScopedIncrement ScopedDepth();
+return traverse(TAL);
+  }
   bool TraverseLambdaExpr(LambdaExpr *Node) {
 if (Finder->getASTContext().getParentMapContext().getTraversalKind() !=
 TK_IgnoreUnlessSpelledInSource)
@@ -304,6 +311,9 @@
 return VisitorBase::TraverseConstructorInitializer(
 const_cast());
   }
+  bool baseTraverse(TemplateArgumentLoc TAL) {
+return VisitorBase::TraverseTemplateArgumentLoc(TAL);
+  }
 
   // Sets 'Matched' to true if 'Matcher' matches 'Node' and:
   //   0 < CurrentDepth <= MaxDepth.
@@ -447,6 +457,7 @@
   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
   bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL);
 
   // Matches children or descendants of 'Node' with 'BaseMatcher'.
   bool memoizedMatchesRecursively(const DynTypedNode , ASTContext ,
@@ -557,6 +568,8 @@
   match(*N);
 } else if (auto *N = Node.get()) {
   match(*N);
+} else if (auto *N = Node.get()) {
+  match(*N);
 }
   }
 
@@ -680,6 +693,9 @@
   void matchDispatch(const CXXCtorInitializer *Node) {
 matchWithoutFilter(*Node, Matchers->CtorInit);
   }
+  void matchDispatch(const TemplateArgumentLoc *Node) {
+matchWithoutFilter(*Node, Matchers->TemplateArgumentLoc);
+  }
   void matchDispatch(const void *) { /* Do nothing. */ }
   /// @}
 
@@ -1035,6 +1051,11 @@
   CtorInit);
 }
 
+bool MatchASTVisitor::TraverseTemplateArgumentLoc(TemplateArgumentLoc Loc) {
+  match(Loc);
+  return RecursiveASTVisitor::TraverseTemplateArgumentLoc(Loc);
+}
+
 class MatchASTConsumer : public ASTConsumer {
 public:
   MatchASTConsumer(MatchFinder *Finder,
@@ -,6 +1132,12 @@
   Matchers.AllCallbacks.insert(Action);
 }
 
+void MatchFinder::addMatcher(const TemplateArgumentLocMatcher ,
+ MatchCallback *Action) {
+  Matchers.TemplateArgumentLoc.emplace_back(NodeMatch, Action);
+  Matchers.AllCallbacks.insert(Action);
+}
+
 bool MatchFinder::addDynamicMatcher(const internal::DynTypedMatcher ,