[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've committed on your behalf in d5dfd1350efb80f9674db322999dd883fb36a6ad 
, thank 
you for the patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-28 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat added a comment.

In D73464#1845511 , @aaron.ballman 
wrote:

> In D73464#1844402 , @f00kat wrote:
>
> > In D73464#1844310 , @aaron.ballman 
> > wrote:
> >
> > > LGTM! Do you need someone to commit on your behalf?
> >
> >
> > Yes, please. I don`t know how :)
>
>
> I'm happy to do so, but I'm not certain what email address you'd like me to 
> use for you (I can't quite suss it out from the phab emails). Can you let me 
> know what address you'd like me to use for the commit attribution?


Yeah, sure. "cc.t...@gmail.com".
I forget to verify email in Phabricator settings.
Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D73464#1844402 , @f00kat wrote:

> In D73464#1844310 , @aaron.ballman 
> wrote:
>
> > LGTM! Do you need someone to commit on your behalf?
>
>
> Yes, please. I don`t know how :)


I'm happy to do so, but I'm not certain what email address you'd like me to use 
for you (I can't quite suss it out from the phab emails). Can you let me know 
what address you'd like me to use for the commit attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-28 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat marked an inline comment as done.
f00kat added a comment.

In D73464#1844310 , @aaron.ballman 
wrote:

> LGTM! Do you need someone to commit on your behalf?


Yes, please. I don`t know how :)




Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:212
+  REGISTER_MATCHER(tagDecl);
+  REGISTER_MATCHER(tagType);
   REGISTER_MATCHER(enumConstantDecl);

alexfh wrote:
> There's already `tagType` registration on the line 497. And yes, should the 
> list be sorted, that would be obvious.
Fixed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-28 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! Do you need someone to commit on your behalf?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-27 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat updated this revision to Diff 240779.
f00kat added a comment.

1. Fix Registry.cpp
2. Generate AST Matchers doc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -184,6 +184,13 @@
   EXPECT_TRUE(notMatches("enum X {};", Matcher));
 }
 
+TEST(TagDecl, MatchesTagDecls) {
+  EXPECT_TRUE(matches("struct X {};", tagDecl(hasName("X";
+  EXPECT_TRUE(matches("class C {};", tagDecl(hasName("C";
+  EXPECT_TRUE(matches("union U {};", tagDecl(hasName("U";
+  EXPECT_TRUE(matches("enum E {};", tagDecl(hasName("E";
+}
+
 TEST(Matcher, UnresolvedLookupExpr) {
   // FIXME: The test is known to be broken on Windows with delayed template
   // parsing.
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2504,6 +2504,13 @@
   EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped(;
 }
 
+TEST(TagDeclKind, MatchesTagDeclKind) {
+  EXPECT_TRUE(matches("struct X {};", tagDecl(isStruct(;
+  EXPECT_TRUE(matches("class C {};", tagDecl(isClass(;
+  EXPECT_TRUE(matches("union U {};", tagDecl(isUnion(;
+  EXPECT_TRUE(matches("enum E {};", tagDecl(isEnum(;
+}
+
 TEST(HasTrailingReturn, MatchesTrailingReturn) {
   EXPECT_TRUE(matches("auto Y() -> int { return 0; }",
   functionDecl(hasTrailingReturn(;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -492,6 +492,7 @@
   REGISTER_MATCHER(substTemplateTypeParmType);
   REGISTER_MATCHER(switchCase);
   REGISTER_MATCHER(switchStmt);
+  REGISTER_MATCHER(tagDecl);
   REGISTER_MATCHER(tagType);
   REGISTER_MATCHER(templateArgument);
   REGISTER_MATCHER(templateArgumentCountIs);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -647,6 +647,7 @@
 const internal::VariadicDynCastAllOfMatcher enumDecl;
 const internal::VariadicDynCastAllOfMatcher
 enumConstantDecl;
+const internal::VariadicDynCastAllOfMatcher tagDecl;
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1194,6 +1194,20 @@
 extern const internal::VariadicDynCastAllOfMatcher
 enumConstantDecl;
 
+/// Matches tag declarations.
+///
+/// Example matches X, Z, U, S, E
+/// \code
+///   class X;
+///   template class Z {};
+///   struct S {};
+///   union U {};
+///   enum E {
+/// A, B, C
+///   };
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher tagDecl;
+
 /// Matches method declarations.
 ///
 /// Example matches y
@@ -4845,42 +4859,58 @@
   return InnerMatcher.matches(Node.getType(), Finder, Builder);
 }
 
-/// Matches RecordDecl object that are spelled with "struct."
+/// Matches TagDecl object that are spelled with "struct."
 ///
-/// Example matches S, but not C or U.
+/// Example matches S, but not C, U or E.
 /// \code
 ///   struct S {};
 ///   class C {};
 ///   union U {};
+///   enum E {};
 /// \endcode
-AST_MATCHER(RecordDecl, isStruct) {
+AST_MATCHER(TagDecl, isStruct) {
   return Node.isStruct();
 }
 
-/// Matches RecordDecl object that are spelled with "union."
+/// Matches TagDecl object that are spelled with "union."
 ///
-/// Example matches U, but not C or S.
+/// Example matches U, but not C, S or E.
 /// \code
 ///   struct S {};
 ///   class C {};
 ///   union U {};
+///   enum E {};
 /// \endcode
-AST_MATCHER(RecordDecl, isUnion) {
+AST_MATCHER(TagDecl, isUnion) {
   return Node.isUnion();
 }
 
-/// Matches RecordDecl object that are spelled with "class."
+/// Matches TagDecl object that are spelled with "class."
 ///
-/// Example matches C, but not S or U.
+/// Example matches C, but not S, U or E.
 /// \code
 ///   struct S {};
 ///   class C {};
 ///   union U 

[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-27 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

A drive-by comment.




Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:212
+  REGISTER_MATCHER(tagDecl);
+  REGISTER_MATCHER(tagType);
   REGISTER_MATCHER(enumConstantDecl);

There's already `tagType` registration on the line 497. And yes, should the 
list be sorted, that would be obvious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

You should also regenerate the AST matcher documentation by running 
`clang\docs\tools\dump_ast_matchers.py`




Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:211-212
   REGISTER_MATCHER(elaboratedType);
+  REGISTER_MATCHER(tagDecl);
+  REGISTER_MATCHER(tagType);
   REGISTER_MATCHER(enumConstantDecl);

Please keep this list in alphabetical order.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73464



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


[PATCH] D73464: [clang] Add TagDecl AST matcher

2020-01-27 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat created this revision.
f00kat added reviewers: aaron.ballman, alexfh, hokein, JonasToth.
f00kat added a project: clang.
Herald added a subscriber: cfe-commits.

In this case https://reviews.llvm.org/D73090#1840501 @aaron.ballman suggest to 
add new AST matcher for tagDecl to avoid using recordDecl and enumDecl together.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73464

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -184,6 +184,13 @@
   EXPECT_TRUE(notMatches("enum X {};", Matcher));
 }
 
+TEST(TagDecl, MatchesTagDecls) {
+  EXPECT_TRUE(matches("struct X {};", tagDecl(hasName("X";
+  EXPECT_TRUE(matches("class C {};", tagDecl(hasName("C";
+  EXPECT_TRUE(matches("union U {};", tagDecl(hasName("U";
+  EXPECT_TRUE(matches("enum E {};", tagDecl(hasName("E";
+}
+
 TEST(Matcher, UnresolvedLookupExpr) {
   // FIXME: The test is known to be broken on Windows with delayed template
   // parsing.
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2504,6 +2504,13 @@
   EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped(;
 }
 
+TEST(TagDeclKind, MatchesTagDeclKind) {
+  EXPECT_TRUE(matches("struct X {};", tagDecl(isStruct(;
+  EXPECT_TRUE(matches("class C {};", tagDecl(isClass(;
+  EXPECT_TRUE(matches("union U {};", tagDecl(isUnion(;
+  EXPECT_TRUE(matches("enum E {};", tagDecl(isEnum(;
+}
+
 TEST(HasTrailingReturn, MatchesTrailingReturn) {
   EXPECT_TRUE(matches("auto Y() -> int { return 0; }",
   functionDecl(hasTrailingReturn(;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -208,6 +208,8 @@
   REGISTER_MATCHER(doStmt);
   REGISTER_MATCHER(eachOf);
   REGISTER_MATCHER(elaboratedType);
+  REGISTER_MATCHER(tagDecl);
+  REGISTER_MATCHER(tagType);
   REGISTER_MATCHER(enumConstantDecl);
   REGISTER_MATCHER(enumDecl);
   REGISTER_MATCHER(enumType);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -647,6 +647,7 @@
 const internal::VariadicDynCastAllOfMatcher enumDecl;
 const internal::VariadicDynCastAllOfMatcher
 enumConstantDecl;
+const internal::VariadicDynCastAllOfMatcher tagDecl;
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1194,6 +1194,20 @@
 extern const internal::VariadicDynCastAllOfMatcher
 enumConstantDecl;
 
+/// Matches tag declarations.
+///
+/// Example matches X, Z, U, S, E
+/// \code
+///   class X;
+///   template class Z {};
+///   struct S {};
+///   union U {};
+///   enum E {
+/// A, B, C
+///   };
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher tagDecl;
+
 /// Matches method declarations.
 ///
 /// Example matches y
@@ -4845,42 +4859,58 @@
   return InnerMatcher.matches(Node.getType(), Finder, Builder);
 }
 
-/// Matches RecordDecl object that are spelled with "struct."
+/// Matches TagDecl object that are spelled with "struct."
 ///
-/// Example matches S, but not C or U.
+/// Example matches S, but not C, U or E.
 /// \code
 ///   struct S {};
 ///   class C {};
 ///   union U {};
+///   enum E {};
 /// \endcode
-AST_MATCHER(RecordDecl, isStruct) {
+AST_MATCHER(TagDecl, isStruct) {
   return Node.isStruct();
 }
 
-/// Matches RecordDecl object that are spelled with "union."
+/// Matches TagDecl object that are spelled with "union."
 ///
-/// Example matches U, but not C or S.
+/// Example matches U, but not C, S or E.
 /// \code
 ///   struct S {};
 ///   class C {};
 ///   union U {};
+///   enum E {};
 /// \endcode
-AST_MATCHER(RecordDecl, isUnion) {
+AST_MATCHER(TagDecl, isUnion) {
   return Node.isUnion();
 }
 
-/// Matches RecordDecl object that are spelled with "class."
+/// Matches TagDecl object that are spelled with "class."
 ///
-/// Example matches C, but not S or U.
+///