From 512fb64765c7d61e89531b8ff697a85d815d9a13 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 17 Sep 2015 13:30:52 +0000 Subject: [PATCH] Rename AST node matchers to match the AST node names directly. Part of this rename also splits recordDecl() (which used to match CXXRecordDecl) into recordDecl() (that matches RecordDecl) and cxxRecordDecl (that matches CXXRecordDecl). Also adds isStruct(), isUnion(), and isClass() narrowing matchers for RecordDecl objects. llvm-svn: 247885 --- clang/docs/LibASTMatchersReference.html | 741 ++++++++++-------- clang/include/clang/ASTMatchers/ASTMatchers.h | 303 ++++--- clang/lib/ASTMatchers/Dynamic/Registry.cpp | 58 +- .../unittests/AST/ASTContextParentMapTest.cpp | 26 +- clang/unittests/AST/DeclPrinterTest.cpp | 46 +- clang/unittests/AST/SourceLocationTest.cpp | 26 +- clang/unittests/AST/StmtPrinterTest.cpp | 4 +- .../unittests/ASTMatchers/ASTMatchersTest.cpp | 524 +++++++------ .../ASTMatchers/Dynamic/ParserTest.cpp | 4 +- .../ASTMatchers/Dynamic/RegistryTest.cpp | 19 +- .../Tooling/RefactoringCallbacksTest.cpp | 4 +- 11 files changed, 954 insertions(+), 801 deletions(-) diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 80f22fa6d17f..47666a13867c 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -100,8 +100,8 @@ recordDecl(decl().bind("id"), hasName("::MyClass")) Return typeNameParameters -Matcher<CXXCtorInitializer>ctorInitializerMatcher<CXXCtorInitializer>... -
Matches constructor initializers.
+Matcher<CXXCtorInitializer>cxxCtorInitializerMatcher<CXXCtorInitializer>...
+
Matches constructor initializers.
 
 Examples matches i(42).
   class C {
@@ -144,8 +144,8 @@ classTemplateSpecializationDecl()
 
-Matcher<Decl>constructorDeclMatcher<CXXConstructorDecl>... -
Matches C++ constructor declarations.
+Matcher<Decl>cxxConstructorDeclMatcher<CXXConstructorDecl>...
+
Matches C++ constructor declarations.
 
 Example matches Foo::Foo() and Foo::Foo(int)
   class Foo {
@@ -157,14 +157,42 @@ Example matches Foo::Foo() and Foo::Foo(int)
 
-Matcher<Decl>conversionDeclMatcher<CXXConversionDecl>... -
Matches conversion operator declarations.
+Matcher<Decl>cxxConversionDeclMatcher<CXXConversionDecl>...
+
Matches conversion operator declarations.
 
 Example matches the operator.
   class X { operator int() const; };
 
+Matcher<Decl>cxxDestructorDeclMatcher<CXXDestructorDecl>... +
Matches explicit C++ destructor declarations.
+
+Example matches Foo::~Foo()
+  class Foo {
+   public:
+    virtual ~Foo();
+  };
+
+ + +Matcher<Decl>cxxMethodDeclMatcher<CXXMethodDecl>... +
Matches method declarations.
+
+Example matches y
+  class X { void y(); };
+
+ + +Matcher<Decl>cxxRecordDeclMatcher<CXXRecordDecl>... +
Matches C++ class declarations.
+
+Example matches X, Z
+  class X;
+  template<class T> class Z {};
+
+ + Matcher<Decl>declMatcher<Decl>...
Matches declarations.
 
@@ -187,17 +215,6 @@ declaratorDecl()
 
-Matcher<Decl>destructorDeclMatcher<CXXDestructorDecl>... -
Matches explicit C++ destructor declarations.
-
-Example matches Foo::~Foo()
-  class Foo {
-   public:
-    virtual ~Foo();
-  };
-
- - Matcher<Decl>enumConstantDeclMatcher<EnumConstantDecl>...
Matches enum constants.
 
@@ -264,14 +281,6 @@ linkageSpecDecl()
 
-Matcher<Decl>methodDeclMatcher<CXXMethodDecl>... -
Matches method declarations.
-
-Example matches y
-  class X { void y(); };
-
- - Matcher<Decl>namedDeclMatcher<NamedDecl>...
Matches a declaration of anything that could have a name.
 
@@ -326,12 +335,14 @@ parmVarDecl()
 
-Matcher<Decl>recordDeclMatcher<CXXRecordDecl>... -
Matches C++ class declarations.
+Matcher<Decl>recordDeclMatcher<RecordDecl>...
+
Matches class, struct, and union declarations.
 
-Example matches X, Z
+Example matches X, Z, U, and S
   class X;
   template<class T> class Z {};
+  struct S {};
+  union U {};
 
@@ -466,14 +477,6 @@ nestedNameSpecifier()
-Matcher<Stmt>CUDAKernelCallExprMatcher<CUDAKernelCallExpr>... -
Matches CUDA kernel call expression.
-
-Example matches,
-  kernel<<<i,j>>>();
-
- - Matcher<Stmt>arraySubscriptExprMatcher<ArraySubscriptExpr>...
Matches array subscript expressions.
 
@@ -502,24 +505,6 @@ Example matches a || b
 
-Matcher<Stmt>bindTemporaryExprMatcher<CXXBindTemporaryExpr>... -
Matches nodes where temporaries are created.
-
-Example matches FunctionTakesString(GetStringByValue())
-    (matcher = bindTemporaryExpr())
-  FunctionTakesString(GetStringByValue());
-  FunctionTakesStringByPointer(GetStringPointer());
-
- - -Matcher<Stmt>boolLiteralMatcher<CXXBoolLiteralExpr>... -
Matches bool literals.
-
-Example matches true
-  true
-
- - Matcher<Stmt>breakStmtMatcher<BreakStmt>...
Matches break statements.
 
@@ -571,15 +556,6 @@ but does not match
 
-Matcher<Stmt>catchStmtMatcher<CXXCatchStmt>... -
Matches catch statements.
-
-  try {} catch(int i) {}
-catchStmt()
-  matches 'catch(int i)'
-
- - Matcher<Stmt>characterLiteralMatcher<CharacterLiteral>...
Matches character literals (also matches wchar_t).
 
@@ -615,8 +591,53 @@ Example matches a ? b : c
 
-Matcher<Stmt>constCastExprMatcher<CXXConstCastExpr>... -
Matches a const_cast expression.
+Matcher<Stmt>continueStmtMatcher<ContinueStmt>...
+
Matches continue statements.
+
+Given
+  while (true) { continue; }
+continueStmt()
+  matches 'continue'
+
+ + +Matcher<Stmt>cudaKernelCallExprMatcher<CUDAKernelCallExpr>... +
Matches CUDA kernel call expression.
+
+Example matches,
+  kernel<<<i,j>>>();
+
+ + +Matcher<Stmt>cxxBindTemporaryExprMatcher<CXXBindTemporaryExpr>... +
Matches nodes where temporaries are created.
+
+Example matches FunctionTakesString(GetStringByValue())
+    (matcher = cxxBindTemporaryExpr())
+  FunctionTakesString(GetStringByValue());
+  FunctionTakesStringByPointer(GetStringPointer());
+
+ + +Matcher<Stmt>cxxBoolLiteralMatcher<CXXBoolLiteralExpr>... +
Matches bool literals.
+
+Example matches true
+  true
+
+ + +Matcher<Stmt>cxxCatchStmtMatcher<CXXCatchStmt>... +
Matches catch statements.
+
+  try {} catch(int i) {}
+cxxCatchStmt()
+  matches 'catch(int i)'
+
+ + +Matcher<Stmt>cxxConstCastExprMatcher<CXXConstCastExpr>... +
Matches a const_cast expression.
 
 Example: Matches const_cast<int*>(&r) in
   int n = 42;
@@ -625,11 +646,11 @@ Example: Matches const_cast<int*>(&r) in
 
-Matcher<Stmt>constructExprMatcher<CXXConstructExpr>... -
Matches constructor call expressions (including implicit ones).
+Matcher<Stmt>cxxConstructExprMatcher<CXXConstructExpr>...
+
Matches constructor call expressions (including implicit ones).
 
 Example matches string(ptr, n) and ptr within arguments of f
-    (matcher = constructExpr())
+    (matcher = cxxConstructExpr())
   void f(const string &a, const string &b);
   char *ptr;
   int n;
@@ -637,13 +658,172 @@ Example matches string(ptr, n) and ptr within arguments of f
 
-Matcher<Stmt>continueStmtMatcher<ContinueStmt>... -
Matches continue statements.
+Matcher<Stmt>cxxDefaultArgExprMatcher<CXXDefaultArgExpr>...
+
Matches the value of a default argument at the call site.
+
+Example matches the CXXDefaultArgExpr placeholder inserted for the
+    default value of the second parameter in the call expression f(42)
+    (matcher = cxxDefaultArgExpr())
+  void f(int x, int y = 0);
+  f(42);
+
+ + +Matcher<Stmt>cxxDeleteExprMatcher<CXXDeleteExpr>... +
Matches delete expressions.
 
 Given
-  while (true) { continue; }
-continueStmt()
-  matches 'continue'
+  delete X;
+cxxDeleteExpr()
+  matches 'delete X'.
+
+ + +Matcher<Stmt>cxxDynamicCastExprMatcher<CXXDynamicCastExpr>... +
Matches a dynamic_cast expression.
+
+Example:
+  cxxDynamicCastExpr()
+matches
+  dynamic_cast<D*>(&b);
+in
+  struct B { virtual ~B() {} }; struct D : B {};
+  B b;
+  D* p = dynamic_cast<D*>(&b);
+
+ + +Matcher<Stmt>cxxForRangeStmtMatcher<CXXForRangeStmt>... +
Matches range-based for statements.
+
+cxxForRangeStmt() matches 'for (auto a : i)'
+  int i[] =  {1, 2, 3}; for (auto a : i);
+  for(int j = 0; j < 5; ++j);
+
+ + +Matcher<Stmt>cxxFunctionalCastExprMatcher<CXXFunctionalCastExpr>... +
Matches functional cast expressions
+
+Example: Matches Foo(bar);
+  Foo f = bar;
+  Foo g = (Foo) bar;
+  Foo h = Foo(bar);
+
+ + +Matcher<Stmt>cxxMemberCallExprMatcher<CXXMemberCallExpr>... +
Matches member call expressions.
+
+Example matches x.y()
+  X x;
+  x.y();
+
+ + +Matcher<Stmt>cxxNewExprMatcher<CXXNewExpr>... +
Matches new expressions.
+
+Given
+  new X;
+cxxNewExpr()
+  matches 'new X'.
+
+ + +Matcher<Stmt>cxxNullPtrLiteralExprMatcher<CXXNullPtrLiteralExpr>... +
Matches nullptr literal.
+
+ + +Matcher<Stmt>cxxOperatorCallExprMatcher<CXXOperatorCallExpr>... +
Matches overloaded operator calls.
+
+Note that if an operator isn't overloaded, it won't match. Instead, use
+binaryOperator matcher.
+Currently it does not match operators such as new delete.
+FIXME: figure out why these do not match?
+
+Example matches both operator<<((o << b), c) and operator<<(o, b)
+    (matcher = cxxOperatorCallExpr())
+  ostream &operator<< (ostream &out, int i) { };
+  ostream &o; int b = 1, c = 1;
+  o << b << c;
+
+ + +Matcher<Stmt>cxxReinterpretCastExprMatcher<CXXReinterpretCastExpr>... +
Matches a reinterpret_cast expression.
+
+Either the source expression or the destination type can be matched
+using has(), but hasDestinationType() is more specific and can be
+more readable.
+
+Example matches reinterpret_cast<char*>(&p) in
+  void* p = reinterpret_cast<char*>(&p);
+
+ + +Matcher<Stmt>cxxStaticCastExprMatcher<CXXStaticCastExpr>... +
Matches a C++ static_cast expression.
+
+hasDestinationType
+reinterpretCast
+
+Example:
+  cxxStaticCastExpr()
+matches
+  static_cast<long>(8)
+in
+  long eight(static_cast<long>(8));
+
+ + +Matcher<Stmt>cxxTemporaryObjectExprMatcher<CXXTemporaryObjectExpr>... +
Matches functional cast expressions having N != 1 arguments
+
+Example: Matches Foo(bar, bar)
+  Foo h = Foo(bar, bar);
+
+ + +Matcher<Stmt>cxxThisExprMatcher<CXXThisExpr>... +
Matches implicit and explicit this expressions.
+
+Example matches the implicit this expression in "return i".
+    (matcher = cxxThisExpr())
+struct foo {
+  int i;
+  int f() { return i; }
+};
+
+ + +Matcher<Stmt>cxxThrowExprMatcher<CXXThrowExpr>... +
Matches throw expressions.
+
+  try { throw 5; } catch(int i) {}
+cxxThrowExpr()
+  matches 'throw 5'
+
+ + +Matcher<Stmt>cxxTryStmtMatcher<CXXTryStmt>... +
Matches try statements.
+
+  try {} catch(int i) {}
+cxxTryStmt()
+  matches 'try {}'
+
+ + +Matcher<Stmt>cxxUnresolvedConstructExprMatcher<CXXUnresolvedConstructExpr>... +
Matches unresolved constructor call expressions.
+
+Example matches T(t) in return statement of f
+    (matcher = cxxUnresolvedConstructExpr())
+  template <typename T>
+  void f(const T& t) { return T(t); }
 
@@ -666,17 +846,6 @@ declStmt()
-Matcher<Stmt>defaultArgExprMatcher<CXXDefaultArgExpr>... -
Matches the value of a default argument at the call site.
-
-Example matches the CXXDefaultArgExpr placeholder inserted for the
-    default value of the second parameter in the call expression f(42)
-    (matcher = defaultArgExpr())
-  void f(int x, int y = 0);
-  f(42);
-
- - Matcher<Stmt>defaultStmtMatcher<DefaultStmt>...
Matches default statements inside switch statements.
 
@@ -687,16 +856,6 @@ defaultStmt()
 
-Matcher<Stmt>deleteExprMatcher<CXXDeleteExpr>... -
Matches delete expressions.
-
-Given
-  delete X;
-deleteExpr()
-  matches 'delete X'.
-
- - Matcher<Stmt>doStmtMatcher<DoStmt>...
Matches do statements.
 
@@ -707,20 +866,6 @@ doStmt()
 
-Matcher<Stmt>dynamicCastExprMatcher<CXXDynamicCastExpr>... -
Matches a dynamic_cast expression.
-
-Example:
-  dynamicCastExpr()
-matches
-  dynamic_cast<D*>(&b);
-in
-  struct B { virtual ~B() {} }; struct D : B {};
-  B b;
-  D* p = dynamic_cast<D*>(&b);
-
- - Matcher<Stmt>explicitCastExprMatcher<ExplicitCastExpr>...
Matches explicit cast expressions.
 
@@ -768,15 +913,6 @@ Does not match implicit conversions such as
 
-Matcher<Stmt>forRangeStmtMatcher<CXXForRangeStmt>... -
Matches range-based for statements.
-
-forRangeStmt() matches 'for (auto a : i)'
-  int i[] =  {1, 2, 3}; for (auto a : i);
-  for(int j = 0; j < 5; ++j);
-
- - Matcher<Stmt>forStmtMatcher<ForStmt>...
Matches for statements.
 
@@ -786,16 +922,6 @@ Example matches 'for (;;) {}'
 
-Matcher<Stmt>functionalCastExprMatcher<CXXFunctionalCastExpr>... -
Matches functional cast expressions
-
-Example: Matches Foo(bar);
-  Foo f = bar;
-  Foo g = (Foo) bar;
-  Foo h = Foo(bar);
-
- - Matcher<Stmt>gnuNullExprMatcher<GNUNullExpr>...
Matches GNU __null expression.
 
@@ -883,15 +1009,6 @@ but does not match
-Matcher<Stmt>memberCallExprMatcher<CXXMemberCallExpr>... -
Matches member call expressions.
-
-Example matches x.y()
-  X x;
-  x.y();
-
- - Matcher<Stmt>memberExprMatcher<MemberExpr>...
Matches member expressions.
 
@@ -905,21 +1022,6 @@ memberExpr()
 
-Matcher<Stmt>newExprMatcher<CXXNewExpr>... -
Matches new expressions.
-
-Given
-  new X;
-newExpr()
-  matches 'new X'.
-
- - -Matcher<Stmt>nullPtrLiteralExprMatcher<CXXNullPtrLiteralExpr>... -
Matches nullptr literal.
-
- - Matcher<Stmt>nullStmtMatcher<NullStmt>...
Matches null statements.
 
@@ -940,34 +1042,6 @@ NSString's "alloc". This matcher should match both message sends.
 
-Matcher<Stmt>operatorCallExprMatcher<CXXOperatorCallExpr>... -
Matches overloaded operator calls.
-
-Note that if an operator isn't overloaded, it won't match. Instead, use
-binaryOperator matcher.
-Currently it does not match operators such as new delete.
-FIXME: figure out why these do not match?
-
-Example matches both operator<<((o << b), c) and operator<<(o, b)
-    (matcher = operatorCallExpr())
-  ostream &operator<< (ostream &out, int i) { };
-  ostream &o; int b = 1, c = 1;
-  o << b << c;
-
- - -Matcher<Stmt>reinterpretCastExprMatcher<CXXReinterpretCastExpr>... -
Matches a reinterpret_cast expression.
-
-Either the source expression or the destination type can be matched
-using has(), but hasDestinationType() is more specific and can be
-more readable.
-
-Example matches reinterpret_cast<char*>(&p) in
-  void* p = reinterpret_cast<char*>(&p);
-
- - Matcher<Stmt>returnStmtMatcher<ReturnStmt>...
Matches return statements.
 
@@ -978,21 +1052,6 @@ returnStmt()
 
-Matcher<Stmt>staticCastExprMatcher<CXXStaticCastExpr>... -
Matches a C++ static_cast expression.
-
-hasDestinationType
-reinterpretCast
-
-Example:
-  staticCastExpr()
-matches
-  static_cast<long>(8)
-in
-  long eight(static_cast<long>(8));
-
- - Matcher<Stmt>stmtMatcher<Stmt>...
Matches statements.
 
@@ -1043,44 +1102,6 @@ switchStmt()
 
-Matcher<Stmt>temporaryObjectExprMatcher<CXXTemporaryObjectExpr>... -
Matches functional cast expressions having N != 1 arguments
-
-Example: Matches Foo(bar, bar)
-  Foo h = Foo(bar, bar);
-
- - -Matcher<Stmt>thisExprMatcher<CXXThisExpr>... -
Matches implicit and explicit this expressions.
-
-Example matches the implicit this expression in "return i".
-    (matcher = thisExpr())
-struct foo {
-  int i;
-  int f() { return i; }
-};
-
- - -Matcher<Stmt>throwExprMatcher<CXXThrowExpr>... -
Matches throw expressions.
-
-  try { throw 5; } catch(int i) {}
-throwExpr()
-  matches 'throw 5'
-
- - -Matcher<Stmt>tryStmtMatcher<CXXTryStmt>... -
Matches try statements.
-
-  try {} catch(int i) {}
-tryStmt()
-  matches 'try {}'
-
- - Matcher<Stmt>unaryExprOrTypeTraitExprMatcher<UnaryExprOrTypeTraitExpr>...
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
 
@@ -1100,16 +1121,6 @@ Example matches !a
 
-Matcher<Stmt>unresolvedConstructExprMatcher<CXXUnresolvedConstructExpr>... -
Matches unresolved constructor call expressions.
-
-Example matches T(t) in return statement of f
-    (matcher = unresolvedConstructExpr())
-  template <typename T>
-  void f(const T& t) { return T(t); }
-
- - Matcher<Stmt>userDefinedLiteralMatcher<UserDefinedLiteral>...
Matches user defined literal operator call.
 
@@ -1537,7 +1548,7 @@ Usable as: Any Matcher
 Matcher<*>unlessMatcher<*>
 
Matches if the provided matcher does not match.
 
-Example matches Y (matcher = recordDecl(unless(hasName("X"))))
+Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))
   class X {};
   class Y {};
 
@@ -1557,7 +1568,7 @@ Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
 Matcher<CXXBoolLiteral>equalsValueT  Value
 
Matches literals that are equal to the given value.
 
-Example matches true (matcher = boolLiteral(equals(true)))
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
   true
 
 Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
@@ -1577,7 +1588,7 @@ Given
     ...
   }
 endcode
-catchStmt(isCatchAll()) matches catch(...) but not catch(int).
+cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
 
@@ -1605,7 +1616,7 @@ Given S(const S &); #2 S(S &&); #3 }; -constructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. +cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
@@ -1618,7 +1629,7 @@ Given S(const S &); #2 S(S &&); #3 }; -constructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. +cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
@@ -1633,8 +1644,8 @@ Given operator int(); #3 explicit operator bool(); #4 }; -constructorDecl(isExplicit()) will match #2, but not #1. -conversionDecl(isExplicit()) will match #4, but not #3. +cxxConstructorDecl(isExplicit()) will match #2, but not #1. +cxxConversionDecl(isExplicit()) will match #4, but not #3.
@@ -1647,7 +1658,7 @@ Given S(const S &); #2 S(S &&); #3 }; -constructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. +cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
@@ -1662,8 +1673,8 @@ Given operator int(); #3 explicit operator bool(); #4 }; -constructorDecl(isExplicit()) will match #2, but not #1. -conversionDecl(isExplicit()) will match #4, but not #3. +cxxConstructorDecl(isExplicit()) will match #2, but not #1. +cxxConversionDecl(isExplicit()) will match #4, but not #3.
@@ -1680,7 +1691,7 @@ Given struct E : B { E() : B() {} }; -constructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) +cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) will match E(), but not match D(int).
@@ -1698,7 +1709,7 @@ Given struct E : B { E() : B() {} }; -constructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) +cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) will match D(int), but not match E(). @@ -1713,7 +1724,7 @@ Given Foo(int) : foo_("A") { } string foo_; }; -constructorDecl(hasAnyConstructorInitializer(isWritten())) +cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) will match Foo(int), but not Foo() @@ -1727,7 +1738,7 @@ struct A { void bar(); }; -methodDecl(isConst()) matches A::foo() but not A::bar() +cxxMethodDecl(isConst()) matches A::foo() but not A::bar() @@ -1800,9 +1811,10 @@ Given: A a; a << a; <-- This matches -operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified -line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches -the declaration of A. +cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the +specified line and +cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) +matches the declaration of A. Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl> @@ -1858,13 +1870,13 @@ Given template <typename T> class X {}; class A {}; X<A> x; or template <typename T> class X {}; class A {}; template class X<A>; -recordDecl(hasName("::X"), isTemplateInstantiation()) +cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) matches the template instantiation of X<A>. But given template <typename T> class X {}; class A {}; template <> class X<A> {}; X<A> x; -recordDecl(hasName("::X"), isTemplateInstantiation()) +cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) does not match, as X<A> is an explicit template specialization. Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl> @@ -1884,7 +1896,7 @@ Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) Matcher<CharacterLiteral>equalsValueT Value
Matches literals that are equal to the given value.
 
-Example matches true (matcher = boolLiteral(equals(true)))
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
   true
 
 Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
@@ -1947,7 +1959,7 @@ Matches a node if it equals the node previously bound to ID.
 
 Given
   class X { int a; int b; };
-recordDecl(
+cxxRecordDecl(
     has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
     has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
   matches the class X, as a and b have the same type.
@@ -1979,7 +1991,7 @@ passed as a quoted string. e.g., hasAttr("attr::CUDADevice").
 partially matching a given regex.
 
 Example matches Y but not X
-    (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
+    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
   #include "ASTMatcher.h"
   class X {};
 ASTMatcher.h:
@@ -1992,7 +2004,8 @@ Usable as: Matcher<Decl>isExpansionInMainFile
 
Matches AST nodes that were expanded within the main-file.
 
-Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
+Example matches X but not Y
+  (matcher = cxxRecordDecl(isExpansionInMainFile())
   #include <Y.h>
   class X {};
 Y.h:
@@ -2006,7 +2019,7 @@ Usable as: Matcher<
Matches AST nodes that were expanded within system-header-files.
 
 Example matches Y but not X
-    (matcher = recordDecl(isExpansionInSystemHeader())
+    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
   #include <SystemHeader.h>
   class X {};
 SystemHeader.h:
@@ -2067,7 +2080,7 @@ fieldDecl(isPublic())
 Matcher<FloatingLiteral>equalsValueT  Value
 
Matches literals that are equal to the given value.
 
-Example matches true (matcher = boolLiteral(equals(true)))
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
   true
 
 Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
@@ -2087,9 +2100,10 @@ Given:
   A a;
   a << a;   <-- This matches
 
-operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified
-line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches
-the declaration of A.
+cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
+specified line and
+cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
+matches the declaration of A.
 
 Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
 
@@ -2183,13 +2197,13 @@ Given template <typename T> class X {}; class A {}; X<A> x; or template <typename T> class X {}; class A {}; template class X<A>; -recordDecl(hasName("::X"), isTemplateInstantiation()) +cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) matches the template instantiation of X<A>. But given template <typename T> class X {}; class A {}; template <> class X<A> {}; X<A> x; -recordDecl(hasName("::X"), isTemplateInstantiation()) +cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) does not match, as X<A> is an explicit template specialization. Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl> @@ -2210,7 +2224,7 @@ functionDecl(parameterCountIs(2)) Matcher<IntegerLiteral>equalsValueT Value
Matches literals that are equal to the given value.
 
-Example matches true (matcher = boolLiteral(equals(true)))
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
   true
 
 Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
@@ -2303,7 +2317,17 @@ Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
 
 
 Matcher<ObjCMessageExpr>hasKeywordSelector
-

+
Matches when the selector is a keyword selector
+
+objCMessageExpr(hasKeywordSelector()) matches the generated setFrame
+message expression in
+
+  UIWebView *webView = ...;
+  CGRect bodyFrame = webView.frame;
+  bodyFrame.size.height = self.bodyContentHeight;
+  webView.frame = bodyFrame;
+      ^---- matches here
+
Matcher<ObjCMessageExpr>hasNullSelector @@ -2362,7 +2386,7 @@ a substring matched by the given RegExp. Given class Y { public: void x(); }; void z() { Y* y; y->x(); } -memberCallExpr(on(hasType(asString("class Y *")))) +cxxMemberCallExpr(on(hasType(asString("class Y *")))) matches y->x()
@@ -2374,7 +2398,7 @@ Matches a node if it equals the node previously bound to ID. Given class X { int a; int b; }; -recordDecl( +cxxRecordDecl( has(fieldDecl(hasName("a"), hasType(type().bind("t")))), has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) matches the class X, as a and b have the same type. @@ -2434,6 +2458,36 @@ matches "a(int)", "b(long)", but not "c(double)".
+Matcher<RecordDecl>isClass +
Matches RecordDecl object that are spelled with "class."
+
+Example matches C, but not S or U.
+  struct S {};
+  class C {};
+  union U {};
+
+ + +Matcher<RecordDecl>isStruct +
Matches RecordDecl object that are spelled with "struct."
+
+Example matches S, but not C or U.
+  struct S {};
+  class C {};
+  union U {};
+
+ + +Matcher<RecordDecl>isUnion +
Matches RecordDecl object that are spelled with "union."
+
+Example matches U, but not C or S.
+  struct S {};
+  class C {};
+  union U {};
+
+ + Matcher<Stmt>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
 
@@ -2441,7 +2495,7 @@ Matches a node if it equals the node previously bound to ID.
 
 Given
   class X { int a; int b; };
-recordDecl(
+cxxRecordDecl(
     has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
     has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
   matches the class X, as a and b have the same type.
@@ -2462,7 +2516,7 @@ and reference to that variable declaration within a compound statement.
 partially matching a given regex.
 
 Example matches Y but not X
-    (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
+    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
   #include "ASTMatcher.h"
   class X {};
 ASTMatcher.h:
@@ -2475,7 +2529,8 @@ Usable as: Matcher<Stmt>isExpansionInMainFile
 
Matches AST nodes that were expanded within the main-file.
 
-Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
+Example matches X but not Y
+  (matcher = cxxRecordDecl(isExpansionInMainFile())
   #include <Y.h>
   class X {};
 Y.h:
@@ -2489,7 +2544,7 @@ Usable as: Matcher<
Matches AST nodes that were expanded within system-header-files.
 
 Example matches Y but not X
-    (matcher = recordDecl(isExpansionInSystemHeader())
+    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
   #include <SystemHeader.h>
   class X {};
 SystemHeader.h:
@@ -2559,7 +2614,7 @@ classTemplateSpecializationDecl(templateArgumentCountIs(1))
 partially matching a given regex.
 
 Example matches Y but not X
-    (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
+    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
   #include "ASTMatcher.h"
   class X {};
 ASTMatcher.h:
@@ -2572,7 +2627,8 @@ Usable as: Matcher<TypeLoc>isExpansionInMainFile
 
Matches AST nodes that were expanded within the main-file.
 
-Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
+Example matches X but not Y
+  (matcher = cxxRecordDecl(isExpansionInMainFile())
   #include <Y.h>
   class X {};
 Y.h:
@@ -2586,7 +2642,7 @@ Usable as: Matcher<
Matches AST nodes that were expanded within system-header-files.
 
 Example matches Y but not X
-    (matcher = recordDecl(isExpansionInSystemHeader())
+    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
   #include <SystemHeader.h>
   class X {};
 SystemHeader.h:
@@ -2603,7 +2659,7 @@ Matches a node if it equals the node previously bound to ID.
 
 Given
   class X { int a; int b; };
-recordDecl(
+cxxRecordDecl(
     has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
     has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
   matches the class X, as a and b have the same type.
@@ -2737,13 +2793,13 @@ Given
   template <typename T> class X {}; class A {}; X<A> x;
 or
   template <typename T> class X {}; class A {}; template class X<A>;
-recordDecl(hasName("::X"), isTemplateInstantiation())
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
   matches the template instantiation of X<A>.
 
 But given
   template <typename T>  class X {}; class A {};
   template <> class X<A> {}; X<A> x;
-recordDecl(hasName("::X"), isTemplateInstantiation())
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
   does not match, as X<A> is an explicit template specialization.
 
 Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
@@ -2805,8 +2861,8 @@ matching submatcher.
 For example, in:
   class A { int a; int b; };
 The matcher:
-  recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
-                    has(fieldDecl(hasName("b")).bind("v"))))
+  cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
+                       has(fieldDecl(hasName("b")).bind("v"))))
 will generate two results binding "v", the first of which binds
 the field declaration of a, the second the field declaration of
 b.
@@ -2820,7 +2876,7 @@ Usable as: Any Matcher
 provided matcher.
 
 Example matches X, A, B, C
-    (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))
+  (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X")))))
   class X {};  Matches X, because X::X is a class of name X inside X.
   class A { class X {}; };
   class B { class C { class X {}; }; };
@@ -2831,7 +2887,9 @@ As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
 each result that matches instead of only on the first one.
 
 Note: Recursively combined ForEachDescendant can cause many matches:
-  recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl()))))
+  cxxRecordDecl(forEachDescendant(cxxRecordDecl(
+    forEachDescendant(cxxRecordDecl())
+  )))
 will match 10 times (plus injected class name matches) on:
   class A { class B { class C { class D { class E {}; }; }; }; };
 
@@ -2843,7 +2901,8 @@ Usable as: Any Matcher
 
Matches AST nodes that have child AST nodes that match the
 provided matcher.
 
-Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))
+Example matches X, Y
+  (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))
   class X {};  Matches X, because X::X is a class of name X inside X.
   class Y { class X {}; };
   class Z { class Y { class X {}; }; };  Does not match Z.
@@ -2875,7 +2934,7 @@ Usable as: Any Matcher
 provided matcher.
 
 Example matches X, Y, Z
-    (matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))
+    (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X")))))
   class X {};  Matches X, because X::X is a class of name X inside X.
   class Y { class X {}; };
   class Z { class Y { class X {}; }; };
@@ -2890,7 +2949,8 @@ Usable as: Any Matcher
 
Matches AST nodes that have child AST nodes that match the
 provided matcher.
 
-Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
+Example matches X, Y
+  (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X")))
   class X {};  Matches X, because X::X is a class of name X inside X.
   class Y { class X {}; };
   class Z { class Y { class X {}; }; };  Does not match Z.
@@ -3117,7 +3177,9 @@ Usable as: Matcher<
 
@@ -3130,7 +3192,9 @@ Given
     Foo() : foo_(1) { }
     int foo_;
   };
-recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything()))))
+cxxRecordDecl(has(cxxConstructorDecl(
+  hasAnyConstructorInitializer(anything())
+)))
   record matches Foo, hasAnyConstructorInitializer matches foo_(1)
 
@@ -3143,7 +3207,7 @@ Given Foo() : foo_(1) { } int foo_; }; -recordDecl(has(constructorDecl(hasAnyConstructorInitializer( +cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( forField(hasName("foo_")))))) matches Foo with forField matching foo_ @@ -3158,7 +3222,7 @@ Given Foo() : foo_(1) { } int foo_; }; -recordDecl(has(constructorDecl(hasAnyConstructorInitializer( +cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( withInitializer(integerLiteral(equals(1))))))) matches Foo with withInitializer matching (1) @@ -3206,7 +3270,7 @@ matches 'a' in
Matches on the implicit object argument of a member call expression.
 
 Example matches y.x()
-  (matcher = memberCallExpr(on(hasType(recordDecl(hasName("Y"))))))
+  (matcher = cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))))
   class Y { public: void x(); };
   void z() { Y y; y.x(); }",
 
@@ -3234,7 +3298,7 @@ FIXME: What other kind of declarations would we need to generalize
 this to?
 
 Example matches A() in the last line
-    (matcher = constructExpr(hasDeclaration(methodDecl(
+    (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl(
         ofClass(hasName("A"))))))
   class A {
    public:
@@ -3251,8 +3315,8 @@ Given:
   class A { void func(); };
   class B { void member(); };
 
-recordDecl(hasMethod(hasName("func"))) matches the declaration of A
-but not B.
+cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of
+A but not B.
 
@@ -3287,7 +3351,8 @@ match Base.
Matches if the call expression's callee's declaration matches the
 given matcher.
 
-Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))
+Example matches y.x() (matcher = callExpr(callee(
+                                   cxxMethodDecl(hasName("x")))))
   class Y { public: void x(); };
   void z() { Y y; y.x(); }
 
@@ -3376,7 +3441,7 @@ caseStmt(hasCaseConstant(integerLiteral()))
Matches if the cast's source expression matches the given matcher.
 
 Example: matches "a string" (matcher =
-                                 hasSourceExpression(constructExpr()))
+                                 hasSourceExpression(cxxConstructExpr()))
 class URL { URL(string); };
 URL url = "a string";
 
@@ -3457,7 +3522,7 @@ with compoundStmt()
Matches the condition expression of an if statement, for loop,
 or conditional operator.
 
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
   if (true) {}
 
@@ -3579,7 +3644,7 @@ Given } } -recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the +cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the declaration of class D.
@@ -3601,7 +3666,7 @@ with compoundStmt()
Matches the condition expression of an if statement, for loop,
 or conditional operator.
 
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
   if (true) {}
 
@@ -3676,12 +3741,12 @@ declaration's type. In case of a value declaration (for example a variable declaration), this resolves one layer of indirection. For example, in the value -declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, -while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration -of x." +declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of +X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the +declaration of x. -Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) - and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) +Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) + and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) class X {}; void y(X &x) { x; X z; } @@ -3693,8 +3758,8 @@ Usable as: Matcher<
Matches if the expression's or declaration's type matches a type
 matcher.
 
-Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
-            and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
+            and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
  class X {};
  void y(X &x) { x; X z; }
 
@@ -3782,7 +3847,7 @@ with compoundStmt()
Matches the condition expression of an if statement, for loop,
 or conditional operator.
 
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
   if (true) {}
 
@@ -3814,7 +3879,7 @@ Does not match the 'this' parameter of a method. Given class X { void f(int x, int y, int z) {} }; -methodDecl(hasAnyParameter(hasName("y"))) +cxxMethodDecl(hasAnyParameter(hasName("y"))) matches f(int x, int y, int z) {} with hasAnyParameter(...) matching int y @@ -3826,7 +3891,7 @@ with hasAnyParameter(...) Given class X { void f(int x) {} }; -methodDecl(hasParameter(0, hasType(varDecl()))) +cxxMethodDecl(hasParameter(0, hasType(varDecl()))) matches f(int x) {} with hasParameter(...) matching int x @@ -3838,7 +3903,7 @@ with hasParameter(...) Given: class X { int f() { return 1; } }; -methodDecl(returns(asString("int"))) +cxxMethodDecl(returns(asString("int"))) matches int f() { return 1; }
@@ -3847,7 +3912,7 @@ methodDecl(returns(asString("int")))
Matches the condition expression of an if statement, for loop,
 or conditional operator.
 
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
   if (true) {}
 
@@ -3866,7 +3931,7 @@ hasConditionVariableStatement(...)
Matches the else-statement of an if statement.
 
 Examples matches the if statement
-  (matcher = ifStmt(hasElse(boolLiteral(equals(true)))))
+  (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true)))))
   if (false) false; else true;
 
@@ -3875,7 +3940,7 @@ Examples matches the if statement
Matches the then-statement of an if statement.
 
 Examples matches the if statement
-  (matcher = ifStmt(hasThen(boolLiteral(equals(true)))))
+  (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true)))))
   if (false) true; else false;
 
@@ -3961,7 +4026,7 @@ matched by a given matcher. Given struct X { int m; }; void f(X x) { x.m; m; } -memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))) +memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))))) matches "x.m" and "m" with hasObjectExpression(...) matching "x" and the implicit object expression of "m" which has type X*. @@ -4033,7 +4098,7 @@ Given struct A { struct B { struct C {}; }; }; A::B::C c; nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( - hasDeclaration(recordDecl(hasName("A"))))))) + hasDeclaration(cxxRecordDecl(hasName("A"))))))) matches "A::"
@@ -4068,7 +4133,9 @@ given QualType matcher without qualifiers. Given struct A { struct B { struct C {}; }; }; A::B::C c; -nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A"))))) +nestedNameSpecifier(specifiesType( + hasDeclaration(cxxRecordDecl(hasName("A"))) +)) matches "A::"
@@ -4186,8 +4253,8 @@ Usable as: Matcher< @@ -4203,7 +4270,7 @@ Example matches y->x() type matches the specified matcher. Example matches X &x and const X &y - (matcher = varDecl(hasType(references(recordDecl(hasName("X")))))) + (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) class X { void a(X b) { X &x = b; @@ -4448,7 +4515,8 @@ Generates results for each match. For example, in: class A { class B {}; class C {}; }; The matcher: - recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("m"))) + cxxRecordDecl(hasName("::A"), + findAll(cxxRecordDecl(isDefinition()).bind("m"))) will generate results for A, B and C. Usable as: Any Matcher @@ -4490,7 +4558,8 @@ unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) Matcher<UnaryOperator>hasUnaryOperandMatcher<Expr> InnerMatcher
Matches if the operand of a unary operator matches.
 
-Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true))))
+Example matches true (matcher = hasUnaryOperand(
+                                  cxxBoolLiteral(equals(true))))
   !true
 
@@ -4545,12 +4614,12 @@ declaration's type. In case of a value declaration (for example a variable declaration), this resolves one layer of indirection. For example, in the value -declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, -while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration -of x." +declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of +X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the +declaration of x. -Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) - and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) +Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) + and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) class X {}; void y(X &x) { x; X z; } @@ -4562,8 +4631,8 @@ Usable as: Matcher<
Matches if the expression's or declaration's type matches a type
 matcher.
 
-Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
-            and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
+            and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
  class X {};
  void y(X &x) { x; X z; }
 
@@ -4610,7 +4679,7 @@ with compoundStmt()
Matches the condition expression of an if statement, for loop,
 or conditional operator.
 
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
   if (true) {}
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index ad21d1f3afdf..5a14eef72a8f 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -14,7 +14,7 @@ // a functional in-language DSL to express queries over the C++ AST. // // For example, to match a class with a certain name, one would call: -// recordDecl(hasName("MyClass")) +// cxxRecordDecl(hasName("MyClass")) // which returns a matcher that can be used to find all AST nodes that declare // a class named 'MyClass'. // @@ -25,13 +25,13 @@ // // For example, when we're interested in child classes of a certain class, we // would write: -// recordDecl(hasName("MyClass"), hasChild(id("child", recordDecl()))) +// cxxRecordDecl(hasName("MyClass"), hasChild(id("child", recordDecl()))) // When the match is found via the MatchFinder, a user provided callback will // be called with a BoundNodes instance that contains a mapping from the // strings that we provided for the id(...) calls to the nodes that were // matched. // In the given example, each time our matcher finds a match we get a callback -// where "child" is bound to the CXXRecordDecl node of the matching child +// where "child" is bound to the RecordDecl node of the matching child // class declaration. // // See ASTMatchersInternal.h for a more in-depth explanation of the @@ -170,7 +170,8 @@ const internal::VariadicDynCastAllOfMatcher typedefDecl; /// \brief Matches AST nodes that were expanded within the main-file. /// -/// Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile()) +/// Example matches X but not Y +/// (matcher = cxxRecordDecl(isExpansionInMainFile()) /// \code /// #include /// class X {}; @@ -191,7 +192,7 @@ AST_POLYMORPHIC_MATCHER(isExpansionInMainFile, /// \brief Matches AST nodes that were expanded within system-header-files. /// /// Example matches Y but not X -/// (matcher = recordDecl(isExpansionInSystemHeader()) +/// (matcher = cxxRecordDecl(isExpansionInSystemHeader()) /// \code /// #include /// class X {}; @@ -216,7 +217,7 @@ AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader, /// partially matching a given regex. /// /// Example matches Y but not X -/// (matcher = recordDecl(isExpansionInFileMatching("AST.*")) +/// (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) /// \code /// #include "ASTMatcher.h" /// class X {}; @@ -304,6 +305,19 @@ const internal::VariadicDynCastAllOfMatcher namespaceDecl; const internal::VariadicDynCastAllOfMatcher namespaceAliasDecl; +/// \brief Matches class, struct, and union declarations. +/// +/// Example matches \c X, \c Z, \c U, and \c S +/// \code +/// class X; +/// template class Z {}; +/// struct S {}; +/// union U {}; +/// \endcode +const internal::VariadicDynCastAllOfMatcher< + Decl, + RecordDecl> recordDecl; + /// \brief Matches C++ class declarations. /// /// Example matches \c X, \c Z @@ -313,7 +327,7 @@ const internal::VariadicDynCastAllOfMatcher /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - CXXRecordDecl> recordDecl; + CXXRecordDecl> cxxRecordDecl; /// \brief Matches C++ class template declarations. /// @@ -385,7 +399,7 @@ const internal::VariadicDynCastAllOfMatcher< /// int i; /// }; /// \endcode -const internal::VariadicAllOfMatcher ctorInitializer; +const internal::VariadicAllOfMatcher cxxCtorInitializer; /// \brief Matches template arguments. /// @@ -724,7 +738,7 @@ const internal::VariadicDynCastAllOfMatcher valueDecl; /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - CXXConstructorDecl> constructorDecl; + CXXConstructorDecl> cxxConstructorDecl; /// \brief Matches explicit C++ destructor declarations. /// @@ -737,7 +751,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - CXXDestructorDecl> destructorDecl; + CXXDestructorDecl> cxxDestructorDecl; /// \brief Matches enum declarations. /// @@ -767,7 +781,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// class X { void y(); }; /// \endcode -const internal::VariadicDynCastAllOfMatcher methodDecl; +const internal::VariadicDynCastAllOfMatcher cxxMethodDecl; /// \brief Matches conversion operator declarations. /// @@ -776,7 +790,7 @@ const internal::VariadicDynCastAllOfMatcher methodDecl; /// class X { operator int() const; }; /// \endcode const internal::VariadicDynCastAllOfMatcher - conversionDecl; + cxxConversionDecl; /// \brief Matches variable declarations. /// @@ -889,7 +903,7 @@ const internal::VariadicDynCastAllOfMatcher lambdaExpr; /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXMemberCallExpr> memberCallExpr; + CXXMemberCallExpr> cxxMemberCallExpr; /// \brief Matches ObjectiveC Message invocation expressions. /// @@ -922,8 +936,9 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// const std::string str = std::string(); /// \endcode -const internal::VariadicDynCastAllOfMatcher -exprWithCleanups; +const internal::VariadicDynCastAllOfMatcher< + Stmt, + ExprWithCleanups> exprWithCleanups; /// \brief Matches init list expressions. /// @@ -947,8 +962,9 @@ const internal::VariadicDynCastAllOfMatcher initListExpr; /// \endcode /// substNonTypeTemplateParmExpr() /// matches "N" in the right-hand side of "static const int n = N;" -const internal::VariadicDynCastAllOfMatcher -substNonTypeTemplateParmExpr; +const internal::VariadicDynCastAllOfMatcher< + Stmt, + SubstNonTypeTemplateParmExpr> substNonTypeTemplateParmExpr; /// \brief Matches using declarations. /// @@ -970,8 +986,9 @@ const internal::VariadicDynCastAllOfMatcher usingDecl; /// \endcode /// usingDirectiveDecl() /// matches \code using namespace X \endcode -const internal::VariadicDynCastAllOfMatcher - usingDirectiveDecl; +const internal::VariadicDynCastAllOfMatcher< + Decl, + UsingDirectiveDecl> usingDirectiveDecl; /// \brief Matches unresolved using value declarations. /// @@ -1010,7 +1027,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \brief Matches constructor call expressions (including implicit ones). /// /// Example matches string(ptr, n) and ptr within arguments of f -/// (matcher = constructExpr()) +/// (matcher = cxxConstructExpr()) /// \code /// void f(const string &a, const string &b); /// char *ptr; @@ -1019,43 +1036,43 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXConstructExpr> constructExpr; + CXXConstructExpr> cxxConstructExpr; /// \brief Matches unresolved constructor call expressions. /// /// Example matches T(t) in return statement of f -/// (matcher = unresolvedConstructExpr()) +/// (matcher = cxxUnresolvedConstructExpr()) /// \code /// template /// void f(const T& t) { return T(t); } /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXUnresolvedConstructExpr> unresolvedConstructExpr; + CXXUnresolvedConstructExpr> cxxUnresolvedConstructExpr; /// \brief Matches implicit and explicit this expressions. /// /// Example matches the implicit this expression in "return i". -/// (matcher = thisExpr()) +/// (matcher = cxxThisExpr()) /// \code /// struct foo { /// int i; /// int f() { return i; } /// }; /// \endcode -const internal::VariadicDynCastAllOfMatcher thisExpr; +const internal::VariadicDynCastAllOfMatcher cxxThisExpr; /// \brief Matches nodes where temporaries are created. /// /// Example matches FunctionTakesString(GetStringByValue()) -/// (matcher = bindTemporaryExpr()) +/// (matcher = cxxBindTemporaryExpr()) /// \code /// FunctionTakesString(GetStringByValue()); /// FunctionTakesStringByPointer(GetStringPointer()); /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXBindTemporaryExpr> bindTemporaryExpr; + CXXBindTemporaryExpr> cxxBindTemporaryExpr; /// \brief Matches nodes where temporaries are materialized. /// @@ -1085,9 +1102,9 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// new X; /// \endcode -/// newExpr() +/// cxxNewExpr() /// matches 'new X'. -const internal::VariadicDynCastAllOfMatcher newExpr; +const internal::VariadicDynCastAllOfMatcher cxxNewExpr; /// \brief Matches delete expressions. /// @@ -1095,9 +1112,9 @@ const internal::VariadicDynCastAllOfMatcher newExpr; /// \code /// delete X; /// \endcode -/// deleteExpr() +/// cxxDeleteExpr() /// matches 'delete X'. -const internal::VariadicDynCastAllOfMatcher deleteExpr; +const internal::VariadicDynCastAllOfMatcher cxxDeleteExpr; /// \brief Matches array subscript expressions. /// @@ -1115,14 +1132,14 @@ const internal::VariadicDynCastAllOfMatcher< /// /// Example matches the CXXDefaultArgExpr placeholder inserted for the /// default value of the second parameter in the call expression f(42) -/// (matcher = defaultArgExpr()) +/// (matcher = cxxDefaultArgExpr()) /// \code /// void f(int x, int y = 0); /// f(42); /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXDefaultArgExpr> defaultArgExpr; + CXXDefaultArgExpr> cxxDefaultArgExpr; /// \brief Matches overloaded operator calls. /// @@ -1132,7 +1149,7 @@ const internal::VariadicDynCastAllOfMatcher< /// FIXME: figure out why these do not match? /// /// Example matches both operator<<((o << b), c) and operator<<(o, b) -/// (matcher = operatorCallExpr()) +/// (matcher = cxxOperatorCallExpr()) /// \code /// ostream &operator<< (ostream &out, int i) { }; /// ostream &o; int b = 1, c = 1; @@ -1140,7 +1157,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXOperatorCallExpr> operatorCallExpr; + CXXOperatorCallExpr> cxxOperatorCallExpr; /// \brief Matches expressions. /// @@ -1207,12 +1224,14 @@ AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher, /// \brief Matches range-based for statements. /// -/// forRangeStmt() matches 'for (auto a : i)' +/// cxxForRangeStmt() matches 'for (auto a : i)' /// \code /// int i[] = {1, 2, 3}; for (auto a : i); /// for(int j = 0; j < 5; ++j); /// \endcode -const internal::VariadicDynCastAllOfMatcher forRangeStmt; +const internal::VariadicDynCastAllOfMatcher< + Stmt, + CXXForRangeStmt> cxxForRangeStmt; /// \brief Matches the initialization statement of a for loop. /// @@ -1367,27 +1386,27 @@ const internal::VariadicDynCastAllOfMatcher compoundStmt; /// \code /// try {} catch(int i) {} /// \endcode -/// catchStmt() +/// cxxCatchStmt() /// matches 'catch(int i)' -const internal::VariadicDynCastAllOfMatcher catchStmt; +const internal::VariadicDynCastAllOfMatcher cxxCatchStmt; /// \brief Matches try statements. /// /// \code /// try {} catch(int i) {} /// \endcode -/// tryStmt() +/// cxxTryStmt() /// matches 'try {}' -const internal::VariadicDynCastAllOfMatcher tryStmt; +const internal::VariadicDynCastAllOfMatcher cxxTryStmt; /// \brief Matches throw expressions. /// /// \code /// try { throw 5; } catch(int i) {} /// \endcode -/// throwExpr() +/// cxxThrowExpr() /// matches 'throw 5' -const internal::VariadicDynCastAllOfMatcher throwExpr; +const internal::VariadicDynCastAllOfMatcher cxxThrowExpr; /// \brief Matches null statements. /// @@ -1416,7 +1435,7 @@ const internal::VariadicDynCastAllOfMatcher asmStmt; /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXBoolLiteralExpr> boolLiteral; + CXXBoolLiteralExpr> cxxBoolLiteral; /// \brief Matches string literals (also matches wide string literals). /// @@ -1480,7 +1499,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \brief Matches nullptr literal. const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXNullPtrLiteralExpr> nullPtrLiteralExpr; + CXXNullPtrLiteralExpr> cxxNullPtrLiteralExpr; /// \brief Matches GNU __null expression. const internal::VariadicDynCastAllOfMatcher< @@ -1546,7 +1565,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXReinterpretCastExpr> reinterpretCastExpr; + CXXReinterpretCastExpr> cxxReinterpretCastExpr; /// \brief Matches a C++ static_cast expression. /// @@ -1554,7 +1573,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \see reinterpretCast /// /// Example: -/// staticCastExpr() +/// cxxStaticCastExpr() /// matches /// static_cast(8) /// in @@ -1563,12 +1582,12 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXStaticCastExpr> staticCastExpr; + CXXStaticCastExpr> cxxStaticCastExpr; /// \brief Matches a dynamic_cast expression. /// /// Example: -/// dynamicCastExpr() +/// cxxDynamicCastExpr() /// matches /// dynamic_cast(&b); /// in @@ -1579,7 +1598,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXDynamicCastExpr> dynamicCastExpr; + CXXDynamicCastExpr> cxxDynamicCastExpr; /// \brief Matches a const_cast expression. /// @@ -1591,7 +1610,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXConstCastExpr> constCastExpr; + CXXConstCastExpr> cxxConstCastExpr; /// \brief Matches a C-style cast expression. /// @@ -1661,7 +1680,7 @@ const internal::VariadicDynCastAllOfMatcher castExpr; /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXFunctionalCastExpr> functionalCastExpr; + CXXFunctionalCastExpr> cxxFunctionalCastExpr; /// \brief Matches functional cast expressions having N != 1 arguments /// @@ -1671,7 +1690,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXTemporaryObjectExpr> temporaryObjectExpr; + CXXTemporaryObjectExpr> cxxTemporaryObjectExpr; /// \brief Matches \c QualTypes in the clang AST. const internal::VariadicAllOfMatcher qualType; @@ -1693,8 +1712,8 @@ const internal::VariadicAllOfMatcher typeLoc; /// \endcode /// The matcher: /// \code -/// recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), -/// has(fieldDecl(hasName("b")).bind("v")))) +/// cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), +/// has(fieldDecl(hasName("b")).bind("v")))) /// \endcode /// will generate two results binding "v", the first of which binds /// the field declaration of \c a, the second the field declaration of @@ -1830,9 +1849,10 @@ AST_MATCHER_P(NamedDecl, matchesName, std::string, RegExp) { /// a << a; // <-- This matches /// \endcode /// -/// \c operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified -/// line and \c recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches -/// the declaration of \c A. +/// \c cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the +/// specified line and +/// \c cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) +/// matches the declaration of \c A. /// /// Usable as: Matcher, Matcher inline internal::PolymorphicMatcherWithParam1< @@ -1901,8 +1921,8 @@ AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, std::string, /// class B { void member(); }; /// \endcode /// -/// \c recordDecl(hasMethod(hasName("func"))) matches the declaration of \c A -/// but not \c B. +/// \c cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of +/// \c A but not \c B. AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.method_begin(), @@ -1912,7 +1932,8 @@ AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher, /// \brief Matches AST nodes that have child AST nodes that match the /// provided matcher. /// -/// Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X"))) +/// Example matches X, Y +/// (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; @@ -1929,7 +1950,7 @@ LLVM_ATTRIBUTE_UNUSED has = {}; /// provided matcher. /// /// Example matches X, Y, Z -/// (matcher = recordDecl(hasDescendant(recordDecl(hasName("X"))))) +/// (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; @@ -1945,7 +1966,8 @@ LLVM_ATTRIBUTE_UNUSED hasDescendant = {}; /// \brief Matches AST nodes that have child AST nodes that match the /// provided matcher. /// -/// Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X"))) +/// Example matches X, Y +/// (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; @@ -1965,7 +1987,7 @@ LLVM_ATTRIBUTE_UNUSED forEach = {}; /// provided matcher. /// /// Example matches X, A, B, C -/// (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X"))))) +/// (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class A { class X {}; }; @@ -1978,7 +2000,9 @@ LLVM_ATTRIBUTE_UNUSED forEach = {}; /// each result that matches instead of only on the first one. /// /// Note: Recursively combined ForEachDescendant can cause many matches: -/// recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl())))) +/// cxxRecordDecl(forEachDescendant(cxxRecordDecl( +/// forEachDescendant(cxxRecordDecl()) +/// ))) /// will match 10 times (plus injected class name matches) on: /// \code /// class A { class B { class C { class D { class E {}; }; }; }; }; @@ -1998,7 +2022,8 @@ LLVM_ATTRIBUTE_UNUSED forEachDescendant = {}; /// \endcode /// The matcher: /// \code -/// recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("m"))) +/// cxxRecordDecl(hasName("::A"), +/// findAll(cxxRecordDecl(isDefinition()).bind("m"))) /// \endcode /// will generate results for \c A, \c B and \c C. /// @@ -2039,7 +2064,7 @@ const internal::ArgumentAdaptingMatcherFunc< /// \brief Matches if the provided matcher does not match. /// -/// Example matches Y (matcher = recordDecl(unless(hasName("X")))) +/// Example matches Y (matcher = cxxRecordDecl(unless(hasName("X")))) /// \code /// class X {}; /// class Y {}; @@ -2080,7 +2105,7 @@ hasDeclaration(const internal::Matcher &InnerMatcher) { /// \brief Matches on the implicit object argument of a member call expression. /// /// Example matches y.x() -/// (matcher = memberCallExpr(on(hasType(recordDecl(hasName("Y")))))) +/// (matcher = cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y")))))) /// \code /// class Y { public: void x(); }; /// void z() { Y y; y.x(); }", @@ -2120,7 +2145,7 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher, /// \code /// [self.bodyView loadHTMLString:html baseURL:NULL]; /// \endcode - AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) { +AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) { Selector Sel = Node.getSelector(); return BaseName.compare(Sel.getAsString()) == 0; } @@ -2173,7 +2198,6 @@ AST_MATCHER(ObjCMessageExpr, hasUnarySelector) { /// webView.frame = bodyFrame; /// // ^---- matches here /// \endcode - AST_MATCHER(ObjCMessageExpr, hasKeywordSelector) { return Node.getSelector().isKeywordSelector(); } @@ -2219,7 +2243,8 @@ AST_MATCHER_P(CallExpr, callee, internal::Matcher, /// \brief Matches if the call expression's callee's declaration matches the /// given matcher. /// -/// Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x"))))) +/// Example matches y.x() (matcher = callExpr(callee( +/// cxxMethodDecl(hasName("x"))))) /// \code /// class Y { public: void x(); }; /// void z() { Y y; y.x(); } @@ -2232,8 +2257,8 @@ AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher, InnerMatcher, /// \brief Matches if the expression's or declaration's type matches a type /// matcher. /// -/// Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) -/// and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) +/// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) +/// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) /// \code /// class X {}; /// void y(X &x) { x; X z; } @@ -2249,12 +2274,12 @@ AST_POLYMORPHIC_MATCHER_P_OVERLOAD( /// /// In case of a value declaration (for example a variable declaration), /// this resolves one layer of indirection. For example, in the value -/// declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, -/// while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration -/// of x." +/// declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of +/// X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the +/// declaration of x. /// -/// Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) -/// and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) +/// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) +/// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) /// \code /// class X {}; /// void y(X &x) { x; X z; } @@ -2292,7 +2317,7 @@ AST_MATCHER_P(DeclaratorDecl, hasTypeLoc, internal::Matcher, Inner) { /// class Y { public: void x(); }; /// void z() { Y* y; y->x(); } /// \endcode -/// memberCallExpr(on(hasType(asString("class Y *")))) +/// cxxMemberCallExpr(on(hasType(asString("class Y *")))) /// matches y->x() AST_MATCHER_P(QualType, asString, std::string, Name) { return Name == Node.getAsString(); @@ -2302,8 +2327,8 @@ AST_MATCHER_P(QualType, asString, std::string, Name) { /// matches the specified matcher. /// /// Example matches y->x() -/// (matcher = memberCallExpr(on(hasType(pointsTo -/// recordDecl(hasName("Y"))))))) +/// (matcher = cxxMemberCallExpr(on(hasType(pointsTo +/// cxxRecordDecl(hasName("Y"))))))) /// \code /// class Y { public: void x(); }; /// void z() { Y *y; y->x(); } @@ -2326,7 +2351,7 @@ AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher, /// type matches the specified matcher. /// /// Example matches X &x and const X &y -/// (matcher = varDecl(hasType(references(recordDecl(hasName("X")))))) +/// (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) /// \code /// class X { /// void a(X b) { @@ -2596,7 +2621,7 @@ AST_MATCHER_P2(DeclStmt, containsDeclaration, unsigned, N, /// // ... /// } /// /endcode -/// catchStmt(isCatchAll()) matches catch(...) but not catch(int). +/// cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int). AST_MATCHER(CXXCatchStmt, isCatchAll) { return Node.getExceptionDecl() == nullptr; } @@ -2610,7 +2635,9 @@ AST_MATCHER(CXXCatchStmt, isCatchAll) { /// int foo_; /// }; /// \endcode -/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything())))) +/// cxxRecordDecl(has(cxxConstructorDecl( +/// hasAnyConstructorInitializer(anything()) +/// ))) /// record matches Foo, hasAnyConstructorInitializer matches foo_(1) AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, internal::Matcher, InnerMatcher) { @@ -2627,7 +2654,7 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, /// int foo_; /// }; /// \endcode -/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer( +/// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( /// forField(hasName("foo_")))))) /// matches Foo /// with forField matching foo_ @@ -2647,7 +2674,7 @@ AST_MATCHER_P(CXXCtorInitializer, forField, /// int foo_; /// }; /// \endcode -/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer( +/// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( /// withInitializer(integerLiteral(equals(1))))))) /// matches Foo /// with withInitializer matching (1) @@ -2669,7 +2696,7 @@ AST_MATCHER_P(CXXCtorInitializer, withInitializer, /// string foo_; /// }; /// \endcode -/// constructorDecl(hasAnyConstructorInitializer(isWritten())) +/// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) /// will match Foo(int), but not Foo() AST_MATCHER(CXXCtorInitializer, isWritten) { return Node.isWritten(); @@ -2689,7 +2716,7 @@ AST_MATCHER(CXXCtorInitializer, isWritten) { /// E() : B() {} /// }; /// \endcode -/// constructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) +/// cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) /// will match E(), but not match D(int). AST_MATCHER(CXXCtorInitializer, isBaseInitializer) { return Node.isBaseInitializer(); @@ -2709,7 +2736,7 @@ AST_MATCHER(CXXCtorInitializer, isBaseInitializer) { /// E() : B() {} /// }; /// \endcode -/// constructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) +/// cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) /// will match D(int), but not match E(). AST_MATCHER(CXXCtorInitializer, isMemberInitializer) { return Node.isMemberInitializer(); @@ -2756,7 +2783,7 @@ AST_MATCHER(CXXConstructExpr, isListInitialization) { /// \code /// class X { void f(int x) {} }; /// \endcode -/// methodDecl(hasParameter(0, hasType(varDecl()))) +/// cxxMethodDecl(hasParameter(0, hasType(varDecl()))) /// matches f(int x) {} /// with hasParameter(...) /// matching int x @@ -2776,7 +2803,7 @@ AST_MATCHER_P2(FunctionDecl, hasParameter, /// \code /// class X { void f(int x, int y, int z) {} }; /// \endcode -/// methodDecl(hasAnyParameter(hasName("y"))) +/// cxxMethodDecl(hasAnyParameter(hasName("y"))) /// matches f(int x, int y, int z) {} /// with hasAnyParameter(...) /// matching int y @@ -2805,7 +2832,7 @@ AST_MATCHER_P(FunctionDecl, parameterCountIs, unsigned, N) { /// \code /// class X { int f() { return 1; } }; /// \endcode -/// methodDecl(returns(asString("int"))) +/// cxxMethodDecl(returns(asString("int"))) /// matches int f() { return 1; } AST_MATCHER_P(FunctionDecl, returns, internal::Matcher, InnerMatcher) { @@ -2859,7 +2886,7 @@ AST_POLYMORPHIC_MATCHER(isConstexpr, /// \brief Matches the condition expression of an if statement, for loop, /// or conditional operator. /// -/// Example matches true (matcher = hasCondition(boolLiteral(equals(true)))) +/// Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) /// \code /// if (true) {} /// \endcode @@ -2876,7 +2903,7 @@ AST_POLYMORPHIC_MATCHER_P(hasCondition, /// \brief Matches the then-statement of an if statement. /// /// Examples matches the if statement -/// (matcher = ifStmt(hasThen(boolLiteral(equals(true))))) +/// (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true))))) /// \code /// if (false) true; else false; /// \endcode @@ -2888,7 +2915,7 @@ AST_MATCHER_P(IfStmt, hasThen, internal::Matcher, InnerMatcher) { /// \brief Matches the else-statement of an if statement. /// /// Examples matches the if statement -/// (matcher = ifStmt(hasElse(boolLiteral(equals(true))))) +/// (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true))))) /// \code /// if (false) false; else true; /// \endcode @@ -2905,7 +2932,7 @@ AST_MATCHER_P(IfStmt, hasElse, internal::Matcher, InnerMatcher) { /// \code /// class X { int a; int b; }; /// \endcode -/// recordDecl( +/// cxxRecordDecl( /// has(fieldDecl(hasName("a"), hasType(type().bind("t")))), /// has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) /// matches the class \c X, as \c a and \c b have the same type. @@ -3037,7 +3064,7 @@ AST_MATCHER_P(CompoundStmt, statementCountIs, unsigned, N) { /// \brief Matches literals that are equal to the given value. /// -/// Example matches true (matcher = boolLiteral(equals(true))) +/// Example matches true (matcher = cxxBoolLiteral(equals(true))) /// \code /// true /// \endcode @@ -3101,7 +3128,8 @@ inline internal::Matcher hasEitherOperand( /// \brief Matches if the operand of a unary operator matches. /// -/// Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true)))) +/// Example matches true (matcher = hasUnaryOperand( +/// cxxBoolLiteral(equals(true)))) /// \code /// !true /// \endcode @@ -3115,7 +3143,7 @@ AST_MATCHER_P(UnaryOperator, hasUnaryOperand, /// \brief Matches if the cast's source expression matches the given matcher. /// /// Example: matches "a string" (matcher = -/// hasSourceExpression(constructExpr())) +/// hasSourceExpression(cxxConstructExpr())) /// \code /// class URL { URL(string); }; /// URL url = "a string"; @@ -3146,6 +3174,42 @@ AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType, return InnerMatcher.matches(Node.getType(), Finder, Builder); } +/// \brief Matches RecordDecl object that are spelled with "struct." +/// +/// Example matches S, but not C or U. +/// \code +/// struct S {}; +/// class C {}; +/// union U {}; +/// \endcode +AST_MATCHER(RecordDecl, isStruct) { + return Node.isStruct(); +} + +/// \brief Matches RecordDecl object that are spelled with "union." +/// +/// Example matches U, but not C or S. +/// \code +/// struct S {}; +/// class C {}; +/// union U {}; +/// \endcode +AST_MATCHER(RecordDecl, isUnion) { + return Node.isUnion(); +} + +/// \brief Matches RecordDecl object that are spelled with "class." +/// +/// Example matches C, but not S or U. +/// \code +/// struct S {}; +/// class C {}; +/// union U {}; +/// \endcode +AST_MATCHER(RecordDecl, isClass) { + return Node.isClass(); +} + /// \brief Matches the true branch expression of a conditional operator. /// /// Example matches a @@ -3199,7 +3263,7 @@ AST_POLYMORPHIC_MATCHER(isDefinition, /// this to? /// /// Example matches A() in the last line -/// (matcher = constructExpr(hasDeclaration(methodDecl( +/// (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl( /// ofClass(hasName("A")))))) /// \code /// class A { @@ -3274,7 +3338,7 @@ AST_MATCHER(CXXMethodDecl, isPure) { /// }; /// \endcode /// -/// methodDecl(isConst()) matches A::foo() but not A::bar() +/// cxxMethodDecl(isConst()) matches A::foo() but not A::bar() AST_MATCHER(CXXMethodDecl, isConst) { return Node.isConst(); } @@ -3391,7 +3455,7 @@ AST_MATCHER_P(MemberExpr, member, /// struct X { int m; }; /// void f(X x) { x.m; m; } /// \endcode -/// memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))) +/// memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))))) /// matches "x.m" and "m" /// with hasObjectExpression(...) /// matching "x" and the implicit object expression of "m" which has type X*. @@ -3443,7 +3507,7 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, /// \code /// template class X {}; class A {}; template class X
; /// \endcode -/// recordDecl(hasName("::X"), isTemplateInstantiation()) +/// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// matches the template instantiation of X. /// /// But given @@ -3451,7 +3515,7 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, /// template class X {}; class A {}; /// template <> class X {}; X x; /// \endcode -/// recordDecl(hasName("::X"), isTemplateInstantiation()) +/// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// does not match, as X is an explicit template specialization. /// /// Usable as: Matcher, Matcher, Matcher @@ -3475,7 +3539,7 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstantiation, /// functionDecl(isInstantiated()) /// matches 'A(int) {...};' and 'A(unsigned) {...}'. AST_MATCHER_FUNCTION(internal::Matcher, isInstantiated) { - auto IsInstantiation = decl(anyOf(recordDecl(isTemplateInstantiation()), + auto IsInstantiation = decl(anyOf(cxxRecordDecl(isTemplateInstantiation()), functionDecl(isTemplateInstantiation()))); return decl(anyOf(IsInstantiation, hasAncestor(IsInstantiation))); } @@ -3496,7 +3560,7 @@ AST_MATCHER_FUNCTION(internal::Matcher, isInstantiated) { /// instantiation. AST_MATCHER_FUNCTION(internal::Matcher, isInTemplateInstantiation) { return stmt( - hasAncestor(decl(anyOf(recordDecl(isTemplateInstantiation()), + hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()), functionDecl(isTemplateInstantiation()))))); } @@ -4045,7 +4109,7 @@ AST_TYPE_MATCHER(InjectedClassNameType, injectedClassNameType); /// } /// \endcode /// -/// \c recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the +/// \c cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the /// declaration of \c class \c D. AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher, InnerMatcher) { const DeclContext *DC = Node.getDeclContext(); @@ -4090,7 +4154,9 @@ AST_MATCHER_FUNCTION_P_OVERLOAD( /// struct A { struct B { struct C {}; }; }; /// A::B::C c; /// \endcode -/// nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A"))))) +/// nestedNameSpecifier(specifiesType( +/// hasDeclaration(cxxRecordDecl(hasName("A"))) +/// )) /// matches "A::" AST_MATCHER_P(NestedNameSpecifier, specifiesType, internal::Matcher, InnerMatcher) { @@ -4108,7 +4174,7 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType, /// A::B::C c; /// \endcode /// nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( -/// hasDeclaration(recordDecl(hasName("A"))))))) +/// hasDeclaration(cxxRecordDecl(hasName("A"))))))) /// matches "A::" AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc, internal::Matcher, InnerMatcher) { @@ -4226,7 +4292,9 @@ AST_MATCHER_P(SwitchStmt, forEachSwitchCase, internal::Matcher, /// \code /// class A { A() : i(42), j(42) {} int i; int j; }; /// \endcode -/// constructorDecl(forEachConstructorInitializer(forField(decl().bind("x")))) +/// cxxConstructorDecl(forEachConstructorInitializer( +/// forField(decl().bind("x")) +/// )) /// will trigger two matches, binding for 'i' and 'j' respectively. AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer, internal::Matcher, InnerMatcher) { @@ -4253,7 +4321,7 @@ AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer, /// S(S &&); // #3 /// }; /// \endcode -/// constructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. +/// cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. AST_MATCHER(CXXConstructorDecl, isCopyConstructor) { return Node.isCopyConstructor(); } @@ -4268,7 +4336,7 @@ AST_MATCHER(CXXConstructorDecl, isCopyConstructor) { /// S(S &&); // #3 /// }; /// \endcode -/// constructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. +/// cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. AST_MATCHER(CXXConstructorDecl, isMoveConstructor) { return Node.isMoveConstructor(); } @@ -4283,7 +4351,7 @@ AST_MATCHER(CXXConstructorDecl, isMoveConstructor) { /// S(S &&); // #3 /// }; /// \endcode -/// constructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. +/// cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. AST_MATCHER(CXXConstructorDecl, isDefaultConstructor) { return Node.isDefaultConstructor(); } @@ -4300,8 +4368,8 @@ AST_MATCHER(CXXConstructorDecl, isDefaultConstructor) { /// explicit operator bool(); // #4 /// }; /// \endcode -/// constructorDecl(isExplicit()) will match #2, but not #1. -/// conversionDecl(isExplicit()) will match #4, but not #3. +/// cxxConstructorDecl(isExplicit()) will match #2, but not #1. +/// cxxConversionDecl(isExplicit()) will match #4, but not #3. AST_POLYMORPHIC_MATCHER(isExplicit, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXConstructorDecl, CXXConversionDecl)) { @@ -4386,8 +4454,9 @@ AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind) { /// \code /// kernel<<>>(); /// \endcode -const internal::VariadicDynCastAllOfMatcher - CUDAKernelCallExpr; +const internal::VariadicDynCastAllOfMatcher< + Stmt, + CUDAKernelCallExpr> cudaKernelCallExpr; } // end namespace ast_matchers } // end namespace clang diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 6b44ef7e5b29..67a9d8abbb41 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -107,15 +107,12 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(atomicType); REGISTER_MATCHER(autoType); REGISTER_MATCHER(binaryOperator); - REGISTER_MATCHER(bindTemporaryExpr); REGISTER_MATCHER(blockPointerType); - REGISTER_MATCHER(boolLiteral); REGISTER_MATCHER(breakStmt); REGISTER_MATCHER(builtinType); REGISTER_MATCHER(callExpr); REGISTER_MATCHER(caseStmt); REGISTER_MATCHER(castExpr); - REGISTER_MATCHER(catchStmt); REGISTER_MATCHER(characterLiteral); REGISTER_MATCHER(classTemplateDecl); REGISTER_MATCHER(classTemplateSpecializationDecl); @@ -124,27 +121,45 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(compoundStmt); REGISTER_MATCHER(conditionalOperator); REGISTER_MATCHER(constantArrayType); - REGISTER_MATCHER(constCastExpr); - REGISTER_MATCHER(constructExpr); - REGISTER_MATCHER(constructorDecl); REGISTER_MATCHER(containsDeclaration); REGISTER_MATCHER(continueStmt); - REGISTER_MATCHER(conversionDecl); REGISTER_MATCHER(cStyleCastExpr); - REGISTER_MATCHER(ctorInitializer); - REGISTER_MATCHER(CUDAKernelCallExpr); + REGISTER_MATCHER(cudaKernelCallExpr); + REGISTER_MATCHER(cxxBindTemporaryExpr); + REGISTER_MATCHER(cxxBoolLiteral); + REGISTER_MATCHER(cxxCatchStmt); + REGISTER_MATCHER(cxxConstCastExpr); + REGISTER_MATCHER(cxxConstructExpr); + REGISTER_MATCHER(cxxConstructorDecl); + REGISTER_MATCHER(cxxConversionDecl); + REGISTER_MATCHER(cxxCtorInitializer); + REGISTER_MATCHER(cxxDefaultArgExpr); + REGISTER_MATCHER(cxxDeleteExpr); + REGISTER_MATCHER(cxxDestructorDecl); + REGISTER_MATCHER(cxxDynamicCastExpr); + REGISTER_MATCHER(cxxForRangeStmt); + REGISTER_MATCHER(cxxFunctionalCastExpr); + REGISTER_MATCHER(cxxMemberCallExpr); + REGISTER_MATCHER(cxxMethodDecl); + REGISTER_MATCHER(cxxNewExpr); + REGISTER_MATCHER(cxxNullPtrLiteralExpr); + REGISTER_MATCHER(cxxOperatorCallExpr); + REGISTER_MATCHER(cxxRecordDecl); + REGISTER_MATCHER(cxxReinterpretCastExpr); + REGISTER_MATCHER(cxxStaticCastExpr); + REGISTER_MATCHER(cxxTemporaryObjectExpr); + REGISTER_MATCHER(cxxThisExpr); + REGISTER_MATCHER(cxxThrowExpr); + REGISTER_MATCHER(cxxTryStmt); + REGISTER_MATCHER(cxxUnresolvedConstructExpr); REGISTER_MATCHER(decl); REGISTER_MATCHER(declaratorDecl); REGISTER_MATCHER(declCountIs); REGISTER_MATCHER(declRefExpr); REGISTER_MATCHER(declStmt); - REGISTER_MATCHER(defaultArgExpr); REGISTER_MATCHER(defaultStmt); - REGISTER_MATCHER(deleteExpr); REGISTER_MATCHER(dependentSizedArrayType); - REGISTER_MATCHER(destructorDecl); REGISTER_MATCHER(doStmt); - REGISTER_MATCHER(dynamicCastExpr); REGISTER_MATCHER(eachOf); REGISTER_MATCHER(elaboratedType); REGISTER_MATCHER(enumConstantDecl); @@ -161,10 +176,8 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(forEachDescendant); REGISTER_MATCHER(forEachSwitchCase); REGISTER_MATCHER(forField); - REGISTER_MATCHER(forRangeStmt); REGISTER_MATCHER(forStmt); REGISTER_MATCHER(friendDecl); - REGISTER_MATCHER(functionalCastExpr); REGISTER_MATCHER(functionDecl); REGISTER_MATCHER(functionTemplateDecl); REGISTER_MATCHER(functionType); @@ -245,6 +258,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(isArrow); REGISTER_MATCHER(isBaseInitializer); REGISTER_MATCHER(isCatchAll); + REGISTER_MATCHER(isClass); REGISTER_MATCHER(isConst); REGISTER_MATCHER(isConstQualified); REGISTER_MATCHER(isCopyConstructor); @@ -274,7 +288,9 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(isProtected); REGISTER_MATCHER(isPublic); REGISTER_MATCHER(isPure); + REGISTER_MATCHER(isStruct); REGISTER_MATCHER(isTemplateInstantiation); + REGISTER_MATCHER(isUnion); REGISTER_MATCHER(isVirtual); REGISTER_MATCHER(isWritten); REGISTER_MATCHER(labelStmt); @@ -284,18 +300,14 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(matchesSelector); REGISTER_MATCHER(materializeTemporaryExpr); REGISTER_MATCHER(member); - REGISTER_MATCHER(memberCallExpr); REGISTER_MATCHER(memberExpr); REGISTER_MATCHER(memberPointerType); - REGISTER_MATCHER(methodDecl); REGISTER_MATCHER(namedDecl); REGISTER_MATCHER(namespaceAliasDecl); REGISTER_MATCHER(namespaceDecl); REGISTER_MATCHER(namesType); REGISTER_MATCHER(nestedNameSpecifier); REGISTER_MATCHER(nestedNameSpecifierLoc); - REGISTER_MATCHER(newExpr); - REGISTER_MATCHER(nullPtrLiteralExpr); REGISTER_MATCHER(nullStmt); REGISTER_MATCHER(numSelectorArgs); REGISTER_MATCHER(ofClass); @@ -304,7 +316,6 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(objcObjectPointerType); REGISTER_MATCHER(on); REGISTER_MATCHER(onImplicitObjectArgument); - REGISTER_MATCHER(operatorCallExpr); REGISTER_MATCHER(parameterCountIs); REGISTER_MATCHER(parenType); REGISTER_MATCHER(parmVarDecl); @@ -317,7 +328,6 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(refersToDeclaration); REGISTER_MATCHER(refersToIntegralType); REGISTER_MATCHER(refersToType); - REGISTER_MATCHER(reinterpretCastExpr); REGISTER_MATCHER(returns); REGISTER_MATCHER(returnStmt); REGISTER_MATCHER(rValueReferenceType); @@ -326,7 +336,6 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(specifiesType); REGISTER_MATCHER(specifiesTypeLoc); REGISTER_MATCHER(statementCountIs); - REGISTER_MATCHER(staticCastExpr); REGISTER_MATCHER(staticAssertDecl); REGISTER_MATCHER(stmt); REGISTER_MATCHER(stringLiteral); @@ -338,13 +347,9 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(templateArgumentCountIs); REGISTER_MATCHER(templateSpecializationType); REGISTER_MATCHER(templateTypeParmType); - REGISTER_MATCHER(temporaryObjectExpr); - REGISTER_MATCHER(thisExpr); REGISTER_MATCHER(throughUsingDecl); - REGISTER_MATCHER(throwExpr); REGISTER_MATCHER(to); REGISTER_MATCHER(translationUnitDecl); - REGISTER_MATCHER(tryStmt); REGISTER_MATCHER(type); REGISTER_MATCHER(typedefDecl); REGISTER_MATCHER(typedefType); @@ -353,7 +358,6 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(unaryOperator); REGISTER_MATCHER(unaryTransformType); REGISTER_MATCHER(unless); - REGISTER_MATCHER(unresolvedConstructExpr); REGISTER_MATCHER(unresolvedUsingTypenameDecl); REGISTER_MATCHER(unresolvedUsingValueDecl); REGISTER_MATCHER(userDefinedLiteral); diff --git a/clang/unittests/AST/ASTContextParentMapTest.cpp b/clang/unittests/AST/ASTContextParentMapTest.cpp index 0dcb175e07b3..94e9735654c2 100644 --- a/clang/unittests/AST/ASTContextParentMapTest.cpp +++ b/clang/unittests/AST/ASTContextParentMapTest.cpp @@ -27,8 +27,9 @@ using clang::tooling::FrontendActionFactory; TEST(GetParents, ReturnsParentForDecl) { MatchVerifier Verifier; - EXPECT_TRUE(Verifier.match("class C { void f(); };", - methodDecl(hasParent(recordDecl(hasName("C")))))); + EXPECT_TRUE( + Verifier.match("class C { void f(); };", + cxxMethodDecl(hasParent(recordDecl(hasName("C")))))); } TEST(GetParents, ReturnsParentForStmt) { @@ -42,19 +43,20 @@ TEST(GetParents, ReturnsParentInsideTemplateInstantiations) { EXPECT_TRUE(DeclVerifier.match( "template struct C { void f() {} };" "void g() { C c; c.f(); }", - methodDecl(hasName("f"), - hasParent(recordDecl(isTemplateInstantiation()))))); + cxxMethodDecl(hasName("f"), + hasParent(cxxRecordDecl(isTemplateInstantiation()))))); EXPECT_TRUE(DeclVerifier.match( "template struct C { void f() {} };" "void g() { C c; c.f(); }", - methodDecl(hasName("f"), - hasParent(recordDecl(unless(isTemplateInstantiation())))))); + cxxMethodDecl(hasName("f"), + hasParent(cxxRecordDecl(unless(isTemplateInstantiation())))))); EXPECT_FALSE(DeclVerifier.match( "template struct C { void f() {} };" "void g() { C c; c.f(); }", - methodDecl(hasName("f"), - allOf(hasParent(recordDecl(unless(isTemplateInstantiation()))), - hasParent(recordDecl(isTemplateInstantiation())))))); + cxxMethodDecl( + hasName("f"), + allOf(hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))), + hasParent(cxxRecordDecl(isTemplateInstantiation())))))); } TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) { @@ -62,9 +64,9 @@ TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) { EXPECT_TRUE(TemplateVerifier.match( "template struct C { void f() {} };" "void g() { C c; c.f(); }", - compoundStmt( - allOf(hasAncestor(recordDecl(isTemplateInstantiation())), - hasAncestor(recordDecl(unless(isTemplateInstantiation()))))))); + compoundStmt(allOf( + hasAncestor(cxxRecordDecl(isTemplateInstantiation())), + hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation()))))))); } } // end namespace ast_matchers diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp index d8cb97709229..d06fbfea6f5e 100644 --- a/clang/unittests/AST/DeclPrinterTest.cpp +++ b/clang/unittests/AST/DeclPrinterTest.cpp @@ -471,7 +471,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl1) { "struct A {" " A();" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A()")); } @@ -480,7 +480,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl2) { "struct A {" " A(int a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(int a)")); } @@ -489,7 +489,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl3) { "struct A {" " A(const A &a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &a)")); } @@ -498,7 +498,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl4) { "struct A {" " A(const A &a, int = 0);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &a, int = 0)")); } @@ -507,7 +507,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl5) { "struct A {" " A(const A &&a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &&a)")); } @@ -516,7 +516,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl6) { "struct A {" " explicit A(int a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "explicit A(int a)")); } @@ -525,7 +525,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl7) { "struct A {" " constexpr A();" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "constexpr A()")); } @@ -534,7 +534,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl8) { "struct A {" " A() = default;" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A() = default")); } @@ -543,7 +543,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl9) { "struct A {" " A() = delete;" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A() = delete")); } @@ -553,7 +553,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl10) { "struct A {" " A(const A &a);" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(const A &a)")); // WRONG; Should be: "A(const A &a);" } @@ -564,7 +564,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl11) { "struct A : public T... {" " A(T&&... ts) : T(ts)... {}" "};", - constructorDecl(ofClass(hasName("A"))).bind("id"), + cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), "A(T &&...ts) : T(ts)...")); // WRONG; Should be: "A(T &&...ts) : T(ts)... {}" } @@ -574,7 +574,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl1) { "struct A {" " ~A();" "};", - destructorDecl(ofClass(hasName("A"))).bind("id"), + cxxDestructorDecl(ofClass(hasName("A"))).bind("id"), "~A()")); } @@ -583,7 +583,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl2) { "struct A {" " virtual ~A();" "};", - destructorDecl(ofClass(hasName("A"))).bind("id"), + cxxDestructorDecl(ofClass(hasName("A"))).bind("id"), "virtual ~A()")); } @@ -592,7 +592,7 @@ TEST(DeclPrinter, TestCXXConversionDecl1) { "struct A {" " operator int();" "};", - methodDecl(ofClass(hasName("A"))).bind("id"), + cxxMethodDecl(ofClass(hasName("A"))).bind("id"), "operator int()")); } @@ -601,7 +601,7 @@ TEST(DeclPrinter, TestCXXConversionDecl2) { "struct A {" " operator bool();" "};", - methodDecl(ofClass(hasName("A"))).bind("id"), + cxxMethodDecl(ofClass(hasName("A"))).bind("id"), "operator bool()")); } @@ -611,7 +611,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) { "struct A {" " operator Z();" "};", - methodDecl(ofClass(hasName("A"))).bind("id"), + cxxMethodDecl(ofClass(hasName("A"))).bind("id"), "operator Z()")); } @@ -621,7 +621,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) { "struct Z {" " void *operator new(std::size_t);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void *operator new(std::size_t)")); // Should be: with semicolon } @@ -632,7 +632,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) { "struct Z {" " void *operator new[](std::size_t);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void *operator new[](std::size_t)")); // Should be: with semicolon } @@ -642,7 +642,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) { "struct Z {" " void operator delete(void *);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete(void *) noexcept")); // Should be: with semicolon, without noexcept? } @@ -652,7 +652,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) { "struct Z {" " void operator delete(void *);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete(void *)")); // Should be: with semicolon } @@ -662,7 +662,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) { "struct Z {" " void operator delete[](void *);" "};", - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete[](void *) noexcept")); // Should be: with semicolon, without noexcept? } @@ -690,7 +690,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator1) { ASSERT_TRUE(PrintedDeclCXX98Matches( Code, - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), Expected)); } } @@ -714,7 +714,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator2) { ASSERT_TRUE(PrintedDeclCXX98Matches( Code, - methodDecl(ofClass(hasName("Z"))).bind("id"), + cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), Expected)); } } diff --git a/clang/unittests/AST/SourceLocationTest.cpp b/clang/unittests/AST/SourceLocationTest.cpp index b0a8f85f0e40..4c77def61bc4 100644 --- a/clang/unittests/AST/SourceLocationTest.cpp +++ b/clang/unittests/AST/SourceLocationTest.cpp @@ -92,13 +92,13 @@ TEST(ParmVarDecl, KNRRange) { TEST(CXXNewExpr, ArrayRange) { RangeVerifier Verifier; Verifier.expectRange(1, 12, 1, 22); - EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", newExpr())); + EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", cxxNewExpr())); } TEST(CXXNewExpr, ParenRange) { RangeVerifier Verifier; Verifier.expectRange(1, 12, 1, 20); - EXPECT_TRUE(Verifier.match("void f() { new int(); }", newExpr())); + EXPECT_TRUE(Verifier.match("void f() { new int(); }", cxxNewExpr())); } TEST(MemberExpr, ImplicitMemberRange) { @@ -221,7 +221,7 @@ TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) { TEST(CXXNewExpr, TypeParenRange) { RangeVerifier Verifier; Verifier.expectRange(1, 10, 1, 18); - EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr())); + EXPECT_TRUE(Verifier.match("int* a = new (int);", cxxNewExpr())); } class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier { @@ -252,7 +252,7 @@ TEST(CXXFunctionalCastExpr, SourceRange) { "int foo() {\n" " return int{};\n" "}", - functionalCastExpr(), Lang_CXX11)); + cxxFunctionalCastExpr(), Lang_CXX11)); } TEST(CXXConstructExpr, SourceRange) { @@ -262,7 +262,7 @@ TEST(CXXConstructExpr, SourceRange) { "struct A { A(int, int); };\n" "void f(A a);\n" "void g() { f({0, 0}); }", - constructExpr(), Lang_CXX11)); + cxxConstructExpr(), Lang_CXX11)); } TEST(CXXTemporaryObjectExpr, SourceRange) { @@ -271,7 +271,7 @@ TEST(CXXTemporaryObjectExpr, SourceRange) { EXPECT_TRUE(Verifier.match( "struct A { A(int, int); };\n" "A a( A{0, 0} );", - temporaryObjectExpr(), Lang_CXX11)); + cxxTemporaryObjectExpr(), Lang_CXX11)); } TEST(CXXUnresolvedConstructExpr, SourceRange) { @@ -284,7 +284,7 @@ TEST(CXXUnresolvedConstructExpr, SourceRange) { "U foo() {\n" " return U{};\n" "}", - unresolvedConstructExpr(), Args, Lang_CXX11)); + cxxUnresolvedConstructExpr(), Args, Lang_CXX11)); } TEST(UsingDecl, SourceRange) { @@ -434,11 +434,11 @@ TEST(FriendDecl, FriendConstructorDestructorLocation) { LocationVerifier ConstructorVerifier; ConstructorVerifier.expectLocation(6, 11); EXPECT_TRUE(ConstructorVerifier.match( - Code, friendDecl(has(constructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B"))))))); LocationVerifier DestructorVerifier; DestructorVerifier.expectLocation(6, 19); EXPECT_TRUE(DestructorVerifier.match( - Code, friendDecl(has(destructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B"))))))); } TEST(FriendDecl, FriendConstructorDestructorRange) { @@ -452,11 +452,11 @@ TEST(FriendDecl, FriendConstructorDestructorRange) { RangeVerifier ConstructorVerifier; ConstructorVerifier.expectRange(6, 1, 6, 13); EXPECT_TRUE(ConstructorVerifier.match( - Code, friendDecl(has(constructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B"))))))); RangeVerifier DestructorVerifier; DestructorVerifier.expectRange(6, 1, 6, 22); EXPECT_TRUE(DestructorVerifier.match( - Code, friendDecl(has(destructorDecl(ofClass(hasName("B"))))))); + Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B"))))))); } TEST(FriendDecl, FriendTemplateFunctionLocation) { @@ -527,7 +527,7 @@ TEST(FriendDecl, InstantiationSourceRange) { " friend void operator+<>(S src);\n" "};\n" "void test(S s) { +s; }", - friendDecl(hasParent(recordDecl(isTemplateInstantiation()))))); + friendDecl(hasParent(cxxRecordDecl(isTemplateInstantiation()))))); } TEST(ObjCMessageExpr, CXXConstructExprRange) { @@ -539,7 +539,7 @@ TEST(ObjCMessageExpr, CXXConstructExprRange) { "+ (void) f1: (A)arg;\n" "@end\n" "void f2() { A a; [B f1: (a)]; }\n", - constructExpr(), Lang_OBJCXX)); + cxxConstructExpr(), Lang_OBJCXX)); } } // end namespace ast_matchers diff --git a/clang/unittests/AST/StmtPrinterTest.cpp b/clang/unittests/AST/StmtPrinterTest.cpp index b1fd2c1eb42c..bc7fd54e4ad9 100644 --- a/clang/unittests/AST/StmtPrinterTest.cpp +++ b/clang/unittests/AST/StmtPrinterTest.cpp @@ -196,7 +196,7 @@ TEST(StmtPrinter, TestCXXConversionDeclImplicit) { "void foo(A a, A b) {" " bar(a & b);" "}", - memberCallExpr(anything()).bind("id"), + cxxMemberCallExpr(anything()).bind("id"), "a & b")); } @@ -210,7 +210,7 @@ TEST(StmtPrinter, TestCXXConversionDeclExplicit) { "void foo(A a, A b) {" " auto x = (a & b).operator void *();" "}", - memberCallExpr(anything()).bind("id"), + cxxMemberCallExpr(anything()).bind("id"), "(a & b)")); // WRONG; Should be: (a & b).operator void *() } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 8f2123ac9c40..7f553513daa9 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -36,7 +36,7 @@ TEST(HasNameDeathTest, DiesOnEmptyPattern) { TEST(IsDerivedFromDeathTest, DiesOnEmptyBaseName) { ASSERT_DEBUG_DEATH({ - DeclarationMatcher IsDerivedFromEmpty = recordDecl(isDerivedFrom("")); + DeclarationMatcher IsDerivedFromEmpty = cxxRecordDecl(isDerivedFrom("")); EXPECT_TRUE(notMatches("class X {};", IsDerivedFromEmpty)); }, ""); } @@ -122,7 +122,7 @@ TEST(DeclarationMatcher, MatchClass) { } TEST(DeclarationMatcher, ClassIsDerived) { - DeclarationMatcher IsDerivedFromX = recordDecl(isDerivedFrom("X")); + DeclarationMatcher IsDerivedFromX = cxxRecordDecl(isDerivedFrom("X")); EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX)); EXPECT_TRUE(notMatches("class X {};", IsDerivedFromX)); @@ -130,7 +130,7 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX)); EXPECT_TRUE(notMatches("", IsDerivedFromX)); - DeclarationMatcher IsAX = recordDecl(isSameOrDerivedFrom("X")); + DeclarationMatcher IsAX = cxxRecordDecl(isSameOrDerivedFrom("X")); EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsAX)); EXPECT_TRUE(matches("class X {};", IsAX)); @@ -139,7 +139,7 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE(notMatches("", IsAX)); DeclarationMatcher ZIsDerivedFromX = - recordDecl(hasName("Z"), isDerivedFrom("X")); + cxxRecordDecl(hasName("Z"), isDerivedFrom("X")); EXPECT_TRUE( matches("class X {}; class Y : public X {}; class Z : public Y {};", ZIsDerivedFromX)); @@ -258,14 +258,14 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE( notMatches("template struct X;" "template struct X : public X {};", - recordDecl(isDerivedFrom(recordDecl(hasName("Some")))))); + cxxRecordDecl(isDerivedFrom(recordDecl(hasName("Some")))))); EXPECT_TRUE(matches( "struct A {};" "template struct X;" "template struct X : public X {};" "template<> struct X<0> : public A {};" "struct B : public X<42> {};", - recordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A")))))); + cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A")))))); // FIXME: Once we have better matchers for template type matching, // get rid of the Variable(...) matching and match the right template @@ -282,15 +282,15 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE(matches( RecursiveTemplateOneParameter, varDecl(hasName("z_float"), - hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"))))))); + hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base1"))))))); EXPECT_TRUE(notMatches( RecursiveTemplateOneParameter, varDecl(hasName("z_float"), - hasInitializer(hasType(recordDecl(isDerivedFrom("Base2"))))))); + hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base2"))))))); EXPECT_TRUE(matches( RecursiveTemplateOneParameter, varDecl(hasName("z_char"), - hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"), + hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base1"), isDerivedFrom("Base2"))))))); const char *RecursiveTemplateTwoParameters = @@ -307,39 +307,39 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE(matches( RecursiveTemplateTwoParameters, varDecl(hasName("z_float"), - hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"))))))); + hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base1"))))))); EXPECT_TRUE(notMatches( RecursiveTemplateTwoParameters, varDecl(hasName("z_float"), - hasInitializer(hasType(recordDecl(isDerivedFrom("Base2"))))))); + hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base2"))))))); EXPECT_TRUE(matches( RecursiveTemplateTwoParameters, varDecl(hasName("z_char"), - hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"), + hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base1"), isDerivedFrom("Base2"))))))); EXPECT_TRUE(matches( "namespace ns { class X {}; class Y : public X {}; }", - recordDecl(isDerivedFrom("::ns::X")))); + cxxRecordDecl(isDerivedFrom("::ns::X")))); EXPECT_TRUE(notMatches( "class X {}; class Y : public X {};", - recordDecl(isDerivedFrom("::ns::X")))); + cxxRecordDecl(isDerivedFrom("::ns::X")))); EXPECT_TRUE(matches( "class X {}; class Y : public X {};", - recordDecl(isDerivedFrom(recordDecl(hasName("X")).bind("test"))))); + cxxRecordDecl(isDerivedFrom(recordDecl(hasName("X")).bind("test"))))); EXPECT_TRUE(matches( "template class X {};" "template using Z = X;" "template class Y : Z {};", - recordDecl(isDerivedFrom(namedDecl(hasName("X")))))); + cxxRecordDecl(isDerivedFrom(namedDecl(hasName("X")))))); } TEST(DeclarationMatcher, hasMethod) { EXPECT_TRUE(matches("class A { void func(); };", - recordDecl(hasMethod(hasName("func"))))); + cxxRecordDecl(hasMethod(hasName("func"))))); EXPECT_TRUE(notMatches("class A { void func(); };", - recordDecl(hasMethod(isPublic())))); + cxxRecordDecl(hasMethod(isPublic())))); } TEST(DeclarationMatcher, ClassDerivedFromDependentTemplateSpecialization) { @@ -349,7 +349,7 @@ TEST(DeclarationMatcher, ClassDerivedFromDependentTemplateSpecialization) { "};" "template struct B : A::template F {};" "B b;", - recordDecl(hasName("B"), isDerivedFrom(recordDecl())))); + cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl())))); } TEST(DeclarationMatcher, hasDeclContext) { @@ -464,10 +464,9 @@ TEST(ConstructVariadic, MismatchedTypes_Regression) { } TEST(DeclarationMatcher, MatchAnyOf) { - DeclarationMatcher YOrZDerivedFromX = - recordDecl(anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z")))); - EXPECT_TRUE( - matches("class X {}; class Z : public X {};", YOrZDerivedFromX)); + DeclarationMatcher YOrZDerivedFromX = cxxRecordDecl( + anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z")))); + EXPECT_TRUE(matches("class X {}; class Z : public X {};", YOrZDerivedFromX)); EXPECT_TRUE(matches("class Y {};", YOrZDerivedFromX)); EXPECT_TRUE( notMatches("class X {}; class W : public X {};", YOrZDerivedFromX)); @@ -495,7 +494,7 @@ TEST(DeclarationMatcher, MatchAnyOf) { EXPECT_TRUE( matches("void f() try { } catch (int) { } catch (...) { }", - catchStmt(anyOf(hasDescendant(varDecl()), isCatchAll())))); + cxxCatchStmt(anyOf(hasDescendant(varDecl()), isCatchAll())))); } TEST(DeclarationMatcher, MatchHas) { @@ -602,7 +601,7 @@ TEST(DeclarationMatcher, MatchHasRecursiveAnyOf) { TEST(DeclarationMatcher, MatchNot) { DeclarationMatcher NotClassX = - recordDecl( + cxxRecordDecl( isDerivedFrom("Y"), unless(hasName("X"))); EXPECT_TRUE(notMatches("", NotClassX)); @@ -719,11 +718,11 @@ TEST(DeclarationMatcher, HasAttr) { TEST(DeclarationMatcher, MatchCudaDecl) { EXPECT_TRUE(matchesWithCuda("__global__ void f() { }" "void g() { f<<<1, 2>>>(); }", - CUDAKernelCallExpr())); + cudaKernelCallExpr())); EXPECT_TRUE(matchesWithCuda("__attribute__((device)) void f() {}", hasAttr(clang::attr::CUDADevice))); EXPECT_TRUE(notMatchesWithCuda("void f() {}", - CUDAKernelCallExpr())); + cudaKernelCallExpr())); EXPECT_FALSE(notMatchesWithCuda("__attribute__((global)) void f() {}", hasAttr(clang::attr::CUDAGlobal))); } @@ -908,7 +907,8 @@ TEST(TypeMatcher, MatchesClassType) { EXPECT_TRUE(matches("class A { public: A *a; };", TypeA)); EXPECT_TRUE(notMatches("class A {};", TypeA)); - TypeMatcher TypeDerivedFromA = hasDeclaration(recordDecl(isDerivedFrom("A"))); + TypeMatcher TypeDerivedFromA = + hasDeclaration(cxxRecordDecl(isDerivedFrom("A"))); EXPECT_TRUE(matches("class A {}; class B : public A { public: B *b; };", TypeDerivedFromA)); @@ -989,7 +989,7 @@ TEST(Matcher, BindMatchedNodes) { new VerifyIdIsBoundTo("b"))); StatementMatcher MethodX = - callExpr(callee(methodDecl(hasName("x")))).bind("x"); + callExpr(callee(cxxMethodDecl(hasName("x")))).bind("x"); EXPECT_TRUE(matchAndVerifyResultTrue("class A { void x() { x(); } };", MethodX, @@ -1103,13 +1103,14 @@ TEST(HasTypeLoc, MatchesDeclaratorDecls) { TEST(Matcher, Call) { // FIXME: Do we want to overload Call() to directly take // Matcher, too? - StatementMatcher MethodX = callExpr(hasDeclaration(methodDecl(hasName("x")))); + StatementMatcher MethodX = + callExpr(hasDeclaration(cxxMethodDecl(hasName("x")))); EXPECT_TRUE(matches("class Y { void x() { x(); } };", MethodX)); EXPECT_TRUE(notMatches("class Y { void x() {} };", MethodX)); StatementMatcher MethodOnY = - memberCallExpr(on(hasType(recordDecl(hasName("Y"))))); + cxxMemberCallExpr(on(hasType(recordDecl(hasName("Y"))))); EXPECT_TRUE( matches("class Y { public: void x(); }; void z() { Y y; y.x(); }", @@ -1128,7 +1129,7 @@ TEST(Matcher, Call) { MethodOnY)); StatementMatcher MethodOnYPointer = - memberCallExpr(on(hasType(pointsTo(recordDecl(hasName("Y")))))); + cxxMemberCallExpr(on(hasType(pointsTo(recordDecl(hasName("Y")))))); EXPECT_TRUE( matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }", @@ -1155,9 +1156,9 @@ TEST(Matcher, Lambda) { TEST(Matcher, ForRange) { EXPECT_TRUE(matches("int as[] = { 1, 2, 3 };" "void f() { for (auto &a : as); }", - forRangeStmt())); + cxxForRangeStmt())); EXPECT_TRUE(notMatches("void f() { for (int i; i<5; ++i); }", - forRangeStmt())); + cxxForRangeStmt())); } TEST(Matcher, SubstNonTypeTemplateParm) { @@ -1191,9 +1192,10 @@ TEST(Matcher, FlowControl) { TEST(HasType, MatchesAsString) { EXPECT_TRUE( matches("class Y { public: void x(); }; void z() {Y* y; y->x(); }", - memberCallExpr(on(hasType(asString("class Y *")))))); - EXPECT_TRUE(matches("class X { void x(int x) {} };", - methodDecl(hasParameter(0, hasType(asString("int")))))); + cxxMemberCallExpr(on(hasType(asString("class Y *")))))); + EXPECT_TRUE( + matches("class X { void x(int x) {} };", + cxxMethodDecl(hasParameter(0, hasType(asString("int")))))); EXPECT_TRUE(matches("namespace ns { struct A {}; } struct B { ns::A a; };", fieldDecl(hasType(asString("ns::A"))))); EXPECT_TRUE(matches("namespace { struct A {}; } struct B { A a; };", @@ -1201,7 +1203,7 @@ TEST(HasType, MatchesAsString) { } TEST(Matcher, OverloadedOperatorCall) { - StatementMatcher OpCall = operatorCallExpr(); + StatementMatcher OpCall = cxxOperatorCallExpr(); // Unary operator EXPECT_TRUE(matches("class Y { }; " "bool operator!(Y x) { return false; }; " @@ -1228,22 +1230,22 @@ TEST(Matcher, OverloadedOperatorCall) { TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) { StatementMatcher OpCallAndAnd = - operatorCallExpr(hasOverloadedOperatorName("&&")); + cxxOperatorCallExpr(hasOverloadedOperatorName("&&")); EXPECT_TRUE(matches("class Y { }; " "bool operator&&(Y x, Y y) { return true; }; " "Y a; Y b; bool c = a && b;", OpCallAndAnd)); StatementMatcher OpCallLessLess = - operatorCallExpr(hasOverloadedOperatorName("<<")); + cxxOperatorCallExpr(hasOverloadedOperatorName("<<")); EXPECT_TRUE(notMatches("class Y { }; " "bool operator&&(Y x, Y y) { return true; }; " "Y a; Y b; bool c = a && b;", OpCallLessLess)); StatementMatcher OpStarCall = - operatorCallExpr(hasOverloadedOperatorName("*")); + cxxOperatorCallExpr(hasOverloadedOperatorName("*")); EXPECT_TRUE(matches("class Y; int operator*(Y &); void f(Y &y) { *y; }", OpStarCall)); DeclarationMatcher ClassWithOpStar = - recordDecl(hasMethod(hasOverloadedOperatorName("*"))); + cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))); EXPECT_TRUE(matches("class Y { int operator*(); };", ClassWithOpStar)); EXPECT_TRUE(notMatches("class Y { void myOperator(); };", @@ -1255,26 +1257,25 @@ TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) { TEST(Matcher, NestedOverloadedOperatorCalls) { EXPECT_TRUE(matchAndVerifyResultTrue( - "class Y { }; " - "Y& operator&&(Y& x, Y& y) { return x; }; " - "Y a; Y b; Y c; Y d = a && b && c;", - operatorCallExpr(hasOverloadedOperatorName("&&")).bind("x"), - new VerifyIdIsBoundTo("x", 2))); - EXPECT_TRUE(matches( - "class Y { }; " - "Y& operator&&(Y& x, Y& y) { return x; }; " - "Y a; Y b; Y c; Y d = a && b && c;", - operatorCallExpr(hasParent(operatorCallExpr())))); - EXPECT_TRUE(matches( - "class Y { }; " - "Y& operator&&(Y& x, Y& y) { return x; }; " - "Y a; Y b; Y c; Y d = a && b && c;", - operatorCallExpr(hasDescendant(operatorCallExpr())))); + "class Y { }; " + "Y& operator&&(Y& x, Y& y) { return x; }; " + "Y a; Y b; Y c; Y d = a && b && c;", + cxxOperatorCallExpr(hasOverloadedOperatorName("&&")).bind("x"), + new VerifyIdIsBoundTo("x", 2))); + EXPECT_TRUE(matches("class Y { }; " + "Y& operator&&(Y& x, Y& y) { return x; }; " + "Y a; Y b; Y c; Y d = a && b && c;", + cxxOperatorCallExpr(hasParent(cxxOperatorCallExpr())))); + EXPECT_TRUE( + matches("class Y { }; " + "Y& operator&&(Y& x, Y& y) { return x; }; " + "Y a; Y b; Y c; Y d = a && b && c;", + cxxOperatorCallExpr(hasDescendant(cxxOperatorCallExpr())))); } TEST(Matcher, ThisPointerType) { StatementMatcher MethodOnY = - memberCallExpr(thisPointerType(recordDecl(hasName("Y")))); + cxxMemberCallExpr(thisPointerType(recordDecl(hasName("Y")))); EXPECT_TRUE( matches("class Y { public: void x(); }; void z() { Y y; y.x(); }", @@ -1306,7 +1307,7 @@ TEST(Matcher, VariableUsage) { StatementMatcher Reference = declRefExpr(to( varDecl(hasInitializer( - memberCallExpr(thisPointerType(recordDecl(hasName("Y")))))))); + cxxMemberCallExpr(thisPointerType(recordDecl(hasName("Y")))))))); EXPECT_TRUE(matches( "class Y {" @@ -1348,7 +1349,7 @@ TEST(Matcher, FindsVarDeclInFunctionParameter) { TEST(Matcher, CalledVariable) { StatementMatcher CallOnVariableY = - memberCallExpr(on(declRefExpr(to(varDecl(hasName("y")))))); + cxxMemberCallExpr(on(declRefExpr(to(varDecl(hasName("y")))))); EXPECT_TRUE(matches( "class Y { public: void x() { Y y; y.x(); } };", CallOnVariableY)); @@ -1459,12 +1460,12 @@ TEST(IsArrow, MatchesMemberCallsViaArrow) { } TEST(Callee, MatchesDeclarations) { - StatementMatcher CallMethodX = callExpr(callee(methodDecl(hasName("x")))); + StatementMatcher CallMethodX = callExpr(callee(cxxMethodDecl(hasName("x")))); EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX)); EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX)); - CallMethodX = callExpr(callee(conversionDecl())); + CallMethodX = callExpr(callee(cxxConversionDecl())); EXPECT_TRUE( matches("struct Y { operator int() const; }; int i = Y();", CallMethodX)); EXPECT_TRUE(notMatches("struct Y { operator int() const; }; Y y = Y();", @@ -1473,9 +1474,9 @@ TEST(Callee, MatchesDeclarations) { TEST(ConversionDeclaration, IsExplicit) { EXPECT_TRUE(matches("struct S { explicit operator int(); };", - conversionDecl(isExplicit()))); + cxxConversionDecl(isExplicit()))); EXPECT_TRUE(notMatches("struct S { operator int(); };", - conversionDecl(isExplicit()))); + cxxConversionDecl(isExplicit()))); } TEST(Callee, MatchesMemberExpressions) { @@ -1613,34 +1614,38 @@ TEST(QualType, hasLocalQualifiers) { TEST(HasParameter, CallsInnerMatcher) { EXPECT_TRUE(matches("class X { void x(int) {} };", - methodDecl(hasParameter(0, varDecl())))); + cxxMethodDecl(hasParameter(0, varDecl())))); EXPECT_TRUE(notMatches("class X { void x(int) {} };", - methodDecl(hasParameter(0, hasName("x"))))); + cxxMethodDecl(hasParameter(0, hasName("x"))))); } TEST(HasParameter, DoesNotMatchIfIndexOutOfBounds) { EXPECT_TRUE(notMatches("class X { void x(int) {} };", - methodDecl(hasParameter(42, varDecl())))); + cxxMethodDecl(hasParameter(42, varDecl())))); } TEST(HasType, MatchesParameterVariableTypesStrictly) { - EXPECT_TRUE(matches("class X { void x(X x) {} };", - methodDecl(hasParameter(0, hasType(recordDecl(hasName("X"))))))); - EXPECT_TRUE(notMatches("class X { void x(const X &x) {} };", - methodDecl(hasParameter(0, hasType(recordDecl(hasName("X"))))))); + EXPECT_TRUE(matches( + "class X { void x(X x) {} };", + cxxMethodDecl(hasParameter(0, hasType(recordDecl(hasName("X"))))))); + EXPECT_TRUE(notMatches( + "class X { void x(const X &x) {} };", + cxxMethodDecl(hasParameter(0, hasType(recordDecl(hasName("X"))))))); EXPECT_TRUE(matches("class X { void x(const X *x) {} };", - methodDecl(hasParameter(0, - hasType(pointsTo(recordDecl(hasName("X")))))))); + cxxMethodDecl(hasParameter( + 0, hasType(pointsTo(recordDecl(hasName("X")))))))); EXPECT_TRUE(matches("class X { void x(const X &x) {} };", - methodDecl(hasParameter(0, - hasType(references(recordDecl(hasName("X")))))))); + cxxMethodDecl(hasParameter( + 0, hasType(references(recordDecl(hasName("X")))))))); } TEST(HasAnyParameter, MatchesIndependentlyOfPosition) { - EXPECT_TRUE(matches("class Y {}; class X { void x(X x, Y y) {} };", - methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); - EXPECT_TRUE(matches("class Y {}; class X { void x(Y y, X x) {} };", - methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); + EXPECT_TRUE(matches( + "class Y {}; class X { void x(X x, Y y) {} };", + cxxMethodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); + EXPECT_TRUE(matches( + "class Y {}; class X { void x(Y y, X x) {} };", + cxxMethodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); } TEST(Returns, MatchesReturnTypes) { @@ -1675,21 +1680,22 @@ TEST(isConstexpr, MatchesConstexprDeclarations) { } TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) { - EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };", - methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); + EXPECT_TRUE(notMatches( + "class Y {}; class X { void x(int) {} };", + cxxMethodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); } TEST(HasAnyParameter, DoesNotMatchThisPointer) { EXPECT_TRUE(notMatches("class Y {}; class X { void x() {} };", - methodDecl(hasAnyParameter(hasType(pointsTo( - recordDecl(hasName("X")))))))); + cxxMethodDecl(hasAnyParameter( + hasType(pointsTo(recordDecl(hasName("X")))))))); } TEST(HasName, MatchesParameterVariableDeclarations) { EXPECT_TRUE(matches("class Y {}; class X { void x(int x) {} };", - methodDecl(hasAnyParameter(hasName("x"))))); + cxxMethodDecl(hasAnyParameter(hasName("x"))))); EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };", - methodDecl(hasAnyParameter(hasName("x"))))); + cxxMethodDecl(hasAnyParameter(hasName("x"))))); } TEST(Matcher, MatchesClassTemplateSpecialization) { @@ -1843,54 +1849,52 @@ TEST(Matcher, MatchesAccessSpecDecls) { } TEST(Matcher, MatchesFinal) { - EXPECT_TRUE(matches("class X final {};", recordDecl(isFinal()))); + EXPECT_TRUE(matches("class X final {};", cxxRecordDecl(isFinal()))); EXPECT_TRUE(matches("class X { virtual void f() final; };", - methodDecl(isFinal()))); - EXPECT_TRUE(notMatches("class X {};", recordDecl(isFinal()))); - EXPECT_TRUE(notMatches("class X { virtual void f(); };", - methodDecl(isFinal()))); + cxxMethodDecl(isFinal()))); + EXPECT_TRUE(notMatches("class X {};", cxxRecordDecl(isFinal()))); + EXPECT_TRUE( + notMatches("class X { virtual void f(); };", cxxMethodDecl(isFinal()))); } TEST(Matcher, MatchesVirtualMethod) { EXPECT_TRUE(matches("class X { virtual int f(); };", - methodDecl(isVirtual(), hasName("::X::f")))); - EXPECT_TRUE(notMatches("class X { int f(); };", - methodDecl(isVirtual()))); + cxxMethodDecl(isVirtual(), hasName("::X::f")))); + EXPECT_TRUE(notMatches("class X { int f(); };", cxxMethodDecl(isVirtual()))); } TEST(Matcher, MatchesPureMethod) { EXPECT_TRUE(matches("class X { virtual int f() = 0; };", - methodDecl(isPure(), hasName("::X::f")))); - EXPECT_TRUE(notMatches("class X { int f(); };", - methodDecl(isPure()))); + cxxMethodDecl(isPure(), hasName("::X::f")))); + EXPECT_TRUE(notMatches("class X { int f(); };", cxxMethodDecl(isPure()))); } TEST(Matcher, MatchesConstMethod) { - EXPECT_TRUE(matches("struct A { void foo() const; };", - methodDecl(isConst()))); - EXPECT_TRUE(notMatches("struct A { void foo(); };", - methodDecl(isConst()))); + EXPECT_TRUE( + matches("struct A { void foo() const; };", cxxMethodDecl(isConst()))); + EXPECT_TRUE( + notMatches("struct A { void foo(); };", cxxMethodDecl(isConst()))); } TEST(Matcher, MatchesOverridingMethod) { EXPECT_TRUE(matches("class X { virtual int f(); }; " "class Y : public X { int f(); };", - methodDecl(isOverride(), hasName("::Y::f")))); + cxxMethodDecl(isOverride(), hasName("::Y::f")))); EXPECT_TRUE(notMatches("class X { virtual int f(); }; " - "class Y : public X { int f(); };", - methodDecl(isOverride(), hasName("::X::f")))); + "class Y : public X { int f(); };", + cxxMethodDecl(isOverride(), hasName("::X::f")))); EXPECT_TRUE(notMatches("class X { int f(); }; " "class Y : public X { int f(); };", - methodDecl(isOverride()))); + cxxMethodDecl(isOverride()))); EXPECT_TRUE(notMatches("class X { int f(); int f(int); }; ", - methodDecl(isOverride()))); + cxxMethodDecl(isOverride()))); EXPECT_TRUE( matches("template struct Y : Base { void f() override;};", - methodDecl(isOverride(), hasName("::Y::f")))); + cxxMethodDecl(isOverride(), hasName("::Y::f")))); } TEST(Matcher, ConstructorCall) { - StatementMatcher Constructor = constructExpr(); + StatementMatcher Constructor = cxxConstructExpr(); EXPECT_TRUE( matches("class X { public: X(); }; void x() { X x; }", Constructor)); @@ -1904,7 +1908,7 @@ TEST(Matcher, ConstructorCall) { } TEST(Matcher, ConstructorArgument) { - StatementMatcher Constructor = constructExpr( + StatementMatcher Constructor = cxxConstructExpr( hasArgument(0, declRefExpr(to(varDecl(hasName("y")))))); EXPECT_TRUE( @@ -1920,7 +1924,7 @@ TEST(Matcher, ConstructorArgument) { notMatches("class X { public: X(int); }; void x() { int z; X x(z); }", Constructor)); - StatementMatcher WrongIndex = constructExpr( + StatementMatcher WrongIndex = cxxConstructExpr( hasArgument(42, declRefExpr(to(varDecl(hasName("y")))))); EXPECT_TRUE( notMatches("class X { public: X(int); }; void x() { int y; X x(y); }", @@ -1928,7 +1932,7 @@ TEST(Matcher, ConstructorArgument) { } TEST(Matcher, ConstructorArgumentCount) { - StatementMatcher Constructor1Arg = constructExpr(argumentCountIs(1)); + StatementMatcher Constructor1Arg = cxxConstructExpr(argumentCountIs(1)); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { X x(0); }", @@ -1945,7 +1949,8 @@ TEST(Matcher, ConstructorArgumentCount) { } TEST(Matcher, ConstructorListInitialization) { - StatementMatcher ConstructorListInit = constructExpr(isListInitialization()); + StatementMatcher ConstructorListInit = + cxxConstructExpr(isListInitialization()); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { X x{0}; }", @@ -1957,13 +1962,13 @@ TEST(Matcher, ConstructorListInitialization) { TEST(Matcher,ThisExpr) { EXPECT_TRUE( - matches("struct X { int a; int f () { return a; } };", thisExpr())); + matches("struct X { int a; int f () { return a; } };", cxxThisExpr())); EXPECT_TRUE( - notMatches("struct X { int f () { int a; return a; } };", thisExpr())); + notMatches("struct X { int f () { int a; return a; } };", cxxThisExpr())); } TEST(Matcher, BindTemporaryExpression) { - StatementMatcher TempExpression = bindTemporaryExpr(); + StatementMatcher TempExpression = cxxBindTemporaryExpr(); std::string ClassString = "class string { public: string(); ~string(); }; "; @@ -2030,76 +2035,76 @@ TEST(MaterializeTemporaryExpr, MatchesTemporary) { TEST(ConstructorDeclaration, SimpleCase) { EXPECT_TRUE(matches("class Foo { Foo(int i); };", - constructorDecl(ofClass(hasName("Foo"))))); + cxxConstructorDecl(ofClass(hasName("Foo"))))); EXPECT_TRUE(notMatches("class Foo { Foo(int i); };", - constructorDecl(ofClass(hasName("Bar"))))); + cxxConstructorDecl(ofClass(hasName("Bar"))))); } TEST(ConstructorDeclaration, IsImplicit) { // This one doesn't match because the constructor is not added by the // compiler (it is not needed). EXPECT_TRUE(notMatches("class Foo { };", - constructorDecl(isImplicit()))); + cxxConstructorDecl(isImplicit()))); // The compiler added the implicit default constructor. EXPECT_TRUE(matches("class Foo { }; Foo* f = new Foo();", - constructorDecl(isImplicit()))); + cxxConstructorDecl(isImplicit()))); EXPECT_TRUE(matches("class Foo { Foo(){} };", - constructorDecl(unless(isImplicit())))); + cxxConstructorDecl(unless(isImplicit())))); // The compiler added an implicit assignment operator. EXPECT_TRUE(matches("struct A { int x; } a = {0}, b = a; void f() { a = b; }", - methodDecl(isImplicit(), hasName("operator=")))); + cxxMethodDecl(isImplicit(), hasName("operator=")))); } TEST(ConstructorDeclaration, IsExplicit) { EXPECT_TRUE(matches("struct S { explicit S(int); };", - constructorDecl(isExplicit()))); + cxxConstructorDecl(isExplicit()))); EXPECT_TRUE(notMatches("struct S { S(int); };", - constructorDecl(isExplicit()))); + cxxConstructorDecl(isExplicit()))); } TEST(ConstructorDeclaration, Kinds) { EXPECT_TRUE(matches("struct S { S(); };", - constructorDecl(isDefaultConstructor()))); + cxxConstructorDecl(isDefaultConstructor()))); EXPECT_TRUE(notMatches("struct S { S(); };", - constructorDecl(isCopyConstructor()))); + cxxConstructorDecl(isCopyConstructor()))); EXPECT_TRUE(notMatches("struct S { S(); };", - constructorDecl(isMoveConstructor()))); + cxxConstructorDecl(isMoveConstructor()))); EXPECT_TRUE(notMatches("struct S { S(const S&); };", - constructorDecl(isDefaultConstructor()))); + cxxConstructorDecl(isDefaultConstructor()))); EXPECT_TRUE(matches("struct S { S(const S&); };", - constructorDecl(isCopyConstructor()))); + cxxConstructorDecl(isCopyConstructor()))); EXPECT_TRUE(notMatches("struct S { S(const S&); };", - constructorDecl(isMoveConstructor()))); + cxxConstructorDecl(isMoveConstructor()))); EXPECT_TRUE(notMatches("struct S { S(S&&); };", - constructorDecl(isDefaultConstructor()))); + cxxConstructorDecl(isDefaultConstructor()))); EXPECT_TRUE(notMatches("struct S { S(S&&); };", - constructorDecl(isCopyConstructor()))); + cxxConstructorDecl(isCopyConstructor()))); EXPECT_TRUE(matches("struct S { S(S&&); };", - constructorDecl(isMoveConstructor()))); + cxxConstructorDecl(isMoveConstructor()))); } TEST(DestructorDeclaration, MatchesVirtualDestructor) { EXPECT_TRUE(matches("class Foo { virtual ~Foo(); };", - destructorDecl(ofClass(hasName("Foo"))))); + cxxDestructorDecl(ofClass(hasName("Foo"))))); } TEST(DestructorDeclaration, DoesNotMatchImplicitDestructor) { EXPECT_TRUE(notMatches("class Foo {};", - destructorDecl(ofClass(hasName("Foo"))))); + cxxDestructorDecl(ofClass(hasName("Foo"))))); } TEST(HasAnyConstructorInitializer, SimpleCase) { - EXPECT_TRUE(notMatches( - "class Foo { Foo() { } };", - constructorDecl(hasAnyConstructorInitializer(anything())))); - EXPECT_TRUE(matches( - "class Foo {" - " Foo() : foo_() { }" - " int foo_;" - "};", - constructorDecl(hasAnyConstructorInitializer(anything())))); + EXPECT_TRUE( + notMatches("class Foo { Foo() { } };", + cxxConstructorDecl(hasAnyConstructorInitializer(anything())))); + EXPECT_TRUE( + matches("class Foo {" + " Foo() : foo_() { }" + " int foo_;" + "};", + cxxConstructorDecl(hasAnyConstructorInitializer(anything())))); } TEST(HasAnyConstructorInitializer, ForField) { @@ -2110,11 +2115,11 @@ TEST(HasAnyConstructorInitializer, ForField) { " Baz foo_;" " Baz bar_;" "};"; - EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( forField(hasType(recordDecl(hasName("Baz")))))))); - EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( forField(hasName("foo_")))))); - EXPECT_TRUE(notMatches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( forField(hasType(recordDecl(hasName("Bar")))))))); } @@ -2124,9 +2129,9 @@ TEST(HasAnyConstructorInitializer, WithInitializer) { " Foo() : foo_(0) { }" " int foo_;" "};"; - EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( withInitializer(integerLiteral(equals(0))))))); - EXPECT_TRUE(notMatches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( withInitializer(integerLiteral(equals(1))))))); } @@ -2138,11 +2143,11 @@ TEST(HasAnyConstructorInitializer, IsWritten) { " Bar foo_;" " Bar bar_;" "};"; - EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( allOf(forField(hasName("foo_")), isWritten()))))); - EXPECT_TRUE(notMatches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( allOf(forField(hasName("bar_")), isWritten()))))); - EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(hasAnyConstructorInitializer( allOf(forField(hasName("bar_")), unless(isWritten())))))); } @@ -2156,22 +2161,22 @@ TEST(HasAnyConstructorInitializer, IsBaseInitializer) { "struct E : B {" " E() : B() {}" "};"; - EXPECT_TRUE(matches(Code, constructorDecl(allOf( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(allOf( hasAnyConstructorInitializer(allOf(isBaseInitializer(), isWritten())), hasName("E"))))); - EXPECT_TRUE(notMatches(Code, constructorDecl(allOf( + EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(allOf( hasAnyConstructorInitializer(allOf(isBaseInitializer(), isWritten())), hasName("D"))))); - EXPECT_TRUE(matches(Code, constructorDecl(allOf( + EXPECT_TRUE(matches(Code, cxxConstructorDecl(allOf( hasAnyConstructorInitializer(allOf(isMemberInitializer(), isWritten())), hasName("D"))))); - EXPECT_TRUE(notMatches(Code, constructorDecl(allOf( + EXPECT_TRUE(notMatches(Code, cxxConstructorDecl(allOf( hasAnyConstructorInitializer(allOf(isMemberInitializer(), isWritten())), hasName("E"))))); } TEST(Matcher, NewExpression) { - StatementMatcher New = newExpr(); + StatementMatcher New = cxxNewExpr(); EXPECT_TRUE(matches("class X { public: X(); }; void x() { new X; }", New)); EXPECT_TRUE( @@ -2182,7 +2187,7 @@ TEST(Matcher, NewExpression) { } TEST(Matcher, NewExpressionArgument) { - StatementMatcher New = constructExpr( + StatementMatcher New = cxxConstructExpr( hasArgument(0, declRefExpr(to(varDecl(hasName("y")))))); EXPECT_TRUE( @@ -2195,7 +2200,7 @@ TEST(Matcher, NewExpressionArgument) { notMatches("class X { public: X(int); }; void x() { int z; new X(z); }", New)); - StatementMatcher WrongIndex = constructExpr( + StatementMatcher WrongIndex = cxxConstructExpr( hasArgument(42, declRefExpr(to(varDecl(hasName("y")))))); EXPECT_TRUE( notMatches("class X { public: X(int); }; void x() { int y; new X(y); }", @@ -2203,7 +2208,7 @@ TEST(Matcher, NewExpressionArgument) { } TEST(Matcher, NewExpressionArgumentCount) { - StatementMatcher New = constructExpr(argumentCountIs(1)); + StatementMatcher New = cxxConstructExpr(argumentCountIs(1)); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { new X(0); }", New)); @@ -2214,11 +2219,11 @@ TEST(Matcher, NewExpressionArgumentCount) { TEST(Matcher, DeleteExpression) { EXPECT_TRUE(matches("struct A {}; void f(A* a) { delete a; }", - deleteExpr())); + cxxDeleteExpr())); } TEST(Matcher, DefaultArgument) { - StatementMatcher Arg = defaultArgExpr(); + StatementMatcher Arg = cxxDefaultArgExpr(); EXPECT_TRUE(matches("void x(int, int = 0) { int y; x(y); }", Arg)); EXPECT_TRUE( @@ -2283,7 +2288,7 @@ TEST(Matcher, FloatLiterals) { } TEST(Matcher, NullPtrLiteral) { - EXPECT_TRUE(matches("int* i = nullptr;", nullPtrLiteralExpr())); + EXPECT_TRUE(matches("int* i = nullptr;", cxxNullPtrLiteralExpr())); } TEST(Matcher, GNUNullExpr) { @@ -2295,7 +2300,8 @@ TEST(Matcher, AsmStatement) { } TEST(Matcher, Conditions) { - StatementMatcher Condition = ifStmt(hasCondition(boolLiteral(equals(true)))); + StatementMatcher Condition = + ifStmt(hasCondition(cxxBoolLiteral(equals(true)))); EXPECT_TRUE(matches("void x() { if (true) {} }", Condition)); EXPECT_TRUE(notMatches("void x() { if (false) {} }", Condition)); @@ -2306,13 +2312,13 @@ TEST(Matcher, Conditions) { TEST(IfStmt, ChildTraversalMatchers) { EXPECT_TRUE(matches("void f() { if (false) true; else false; }", - ifStmt(hasThen(boolLiteral(equals(true)))))); + ifStmt(hasThen(cxxBoolLiteral(equals(true)))))); EXPECT_TRUE(notMatches("void f() { if (false) false; else true; }", - ifStmt(hasThen(boolLiteral(equals(true)))))); + ifStmt(hasThen(cxxBoolLiteral(equals(true)))))); EXPECT_TRUE(matches("void f() { if (false) false; else true; }", - ifStmt(hasElse(boolLiteral(equals(true)))))); + ifStmt(hasElse(cxxBoolLiteral(equals(true)))))); EXPECT_TRUE(notMatches("void f() { if (false) true; else false; }", - ifStmt(hasElse(boolLiteral(equals(true)))))); + ifStmt(hasElse(cxxBoolLiteral(equals(true)))))); } TEST(MatchBinaryOperator, HasOperatorName) { @@ -2324,8 +2330,8 @@ TEST(MatchBinaryOperator, HasOperatorName) { TEST(MatchBinaryOperator, HasLHSAndHasRHS) { StatementMatcher OperatorTrueFalse = - binaryOperator(hasLHS(boolLiteral(equals(true))), - hasRHS(boolLiteral(equals(false)))); + binaryOperator(hasLHS(cxxBoolLiteral(equals(true))), + hasRHS(cxxBoolLiteral(equals(false)))); EXPECT_TRUE(matches("void x() { true || false; }", OperatorTrueFalse)); EXPECT_TRUE(matches("void x() { true && false; }", OperatorTrueFalse)); @@ -2334,7 +2340,7 @@ TEST(MatchBinaryOperator, HasLHSAndHasRHS) { TEST(MatchBinaryOperator, HasEitherOperand) { StatementMatcher HasOperand = - binaryOperator(hasEitherOperand(boolLiteral(equals(false)))); + binaryOperator(hasEitherOperand(cxxBoolLiteral(equals(false)))); EXPECT_TRUE(matches("void x() { true || false; }", HasOperand)); EXPECT_TRUE(matches("void x() { false && true; }", HasOperand)); @@ -2451,7 +2457,7 @@ TEST(MatchUnaryOperator, HasOperatorName) { TEST(MatchUnaryOperator, HasUnaryOperand) { StatementMatcher OperatorOnFalse = - unaryOperator(hasUnaryOperand(boolLiteral(equals(false)))); + unaryOperator(hasUnaryOperand(cxxBoolLiteral(equals(false)))); EXPECT_TRUE(matches("void x() { !false; }", OperatorOnFalse)); EXPECT_TRUE(notMatches("void x() { !true; }", OperatorOnFalse)); @@ -2494,15 +2500,15 @@ TEST(Matcher, UnaryOperatorTypes) { TEST(Matcher, ConditionalOperator) { StatementMatcher Conditional = conditionalOperator( - hasCondition(boolLiteral(equals(true))), - hasTrueExpression(boolLiteral(equals(false)))); + hasCondition(cxxBoolLiteral(equals(true))), + hasTrueExpression(cxxBoolLiteral(equals(false)))); EXPECT_TRUE(matches("void x() { true ? false : true; }", Conditional)); EXPECT_TRUE(notMatches("void x() { false ? false : true; }", Conditional)); EXPECT_TRUE(notMatches("void x() { true ? true : false; }", Conditional)); StatementMatcher ConditionalFalse = conditionalOperator( - hasFalseExpression(boolLiteral(equals(false)))); + hasFalseExpression(cxxBoolLiteral(equals(false)))); EXPECT_TRUE(matches("void x() { true ? true : false; }", ConditionalFalse)); EXPECT_TRUE( @@ -2609,13 +2615,13 @@ TEST(Matcher, IsDefinition) { EXPECT_TRUE(notMatches("extern int a;", DefinitionOfVariableA)); DeclarationMatcher DefinitionOfMethodA = - methodDecl(hasName("a"), isDefinition()); + cxxMethodDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA)); EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA)); } TEST(Matcher, OfClass) { - StatementMatcher Constructor = constructExpr(hasDeclaration(methodDecl( + StatementMatcher Constructor = cxxConstructExpr(hasDeclaration(cxxMethodDecl( ofClass(hasName("X"))))); EXPECT_TRUE( @@ -2633,7 +2639,7 @@ TEST(Matcher, VisitsTemplateInstantiations) { "class A { public: void x(); };" "template class B { public: void y() { T t; t.x(); } };" "void f() { B b; b.y(); }", - callExpr(callee(methodDecl(hasName("x")))))); + callExpr(callee(cxxMethodDecl(hasName("x")))))); EXPECT_TRUE(matches( "class A { public: void x(); };" @@ -2644,8 +2650,8 @@ TEST(Matcher, VisitsTemplateInstantiations) { "void f() {" " C::B b; b.y();" "}", - recordDecl(hasName("C"), - hasDescendant(callExpr(callee(methodDecl(hasName("x")))))))); + recordDecl(hasName("C"), hasDescendant(callExpr( + callee(cxxMethodDecl(hasName("x")))))))); } TEST(Matcher, HandlesNullQualTypes) { @@ -2738,10 +2744,10 @@ TEST(For, ForLoopInternals) { TEST(For, ForRangeLoopInternals) { EXPECT_TRUE(matches("void f(){ int a[] {1, 2}; for (int i : a); }", - forRangeStmt(hasLoopVariable(anything())))); + cxxForRangeStmt(hasLoopVariable(anything())))); EXPECT_TRUE(matches( "void f(){ int a[] {1, 2}; for (int i : a); }", - forRangeStmt(hasRangeInit(declRefExpr(to(varDecl(hasName("a")))))))); + cxxForRangeStmt(hasRangeInit(declRefExpr(to(varDecl(hasName("a")))))))); } TEST(For, NegativeForLoopInternals) { @@ -2781,7 +2787,7 @@ TEST(HasBody, FindsBodyOfForWhileDoLoops) { EXPECT_TRUE(matches("void f() { do {} while(true); }", doStmt(hasBody(compoundStmt())))); EXPECT_TRUE(matches("void f() { int p[2]; for (auto x : p) {} }", - forRangeStmt(hasBody(compoundStmt())))); + cxxForRangeStmt(hasBody(compoundStmt())))); } TEST(HasAnySubstatement, MatchesForTopLevelCompoundStatement) { @@ -2902,16 +2908,16 @@ TEST(Member, MatchesMemberAllocationFunction) { EXPECT_TRUE(matchesConditionally( "namespace std { typedef typeof(sizeof(int)) size_t; }" "class X { void *operator new(std::size_t); };", - methodDecl(ofClass(hasName("X"))), true, "-std=gnu++98")); + cxxMethodDecl(ofClass(hasName("X"))), true, "-std=gnu++98")); EXPECT_TRUE(matches("class X { void operator delete(void*); };", - methodDecl(ofClass(hasName("X"))))); + cxxMethodDecl(ofClass(hasName("X"))))); // Fails in C++11 mode EXPECT_TRUE(matchesConditionally( "namespace std { typedef typeof(sizeof(int)) size_t; }" "class X { void operator delete[](void*, std::size_t); };", - methodDecl(ofClass(hasName("X"))), true, "-std=gnu++98")); + cxxMethodDecl(ofClass(hasName("X"))), true, "-std=gnu++98")); } TEST(HasObjectExpression, DoesNotMatchMember) { @@ -2999,59 +3005,59 @@ TEST(CastExpression, DoesNotMatchNonCasts) { TEST(ReinterpretCast, MatchesSimpleCase) { EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);", - reinterpretCastExpr())); + cxxReinterpretCastExpr())); } TEST(ReinterpretCast, DoesNotMatchOtherCasts) { - EXPECT_TRUE(notMatches("char* p = (char*)(&p);", reinterpretCastExpr())); + EXPECT_TRUE(notMatches("char* p = (char*)(&p);", cxxReinterpretCastExpr())); EXPECT_TRUE(notMatches("char q, *p = const_cast(&q);", - reinterpretCastExpr())); + cxxReinterpretCastExpr())); EXPECT_TRUE(notMatches("void* p = static_cast(&p);", - reinterpretCastExpr())); + cxxReinterpretCastExpr())); EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};" "B b;" "D* p = dynamic_cast(&b);", - reinterpretCastExpr())); + cxxReinterpretCastExpr())); } TEST(FunctionalCast, MatchesSimpleCase) { std::string foo_class = "class Foo { public: Foo(const char*); };"; EXPECT_TRUE(matches(foo_class + "void r() { Foo f = Foo(\"hello world\"); }", - functionalCastExpr())); + cxxFunctionalCastExpr())); } TEST(FunctionalCast, DoesNotMatchOtherCasts) { std::string FooClass = "class Foo { public: Foo(const char*); };"; EXPECT_TRUE( notMatches(FooClass + "void r() { Foo f = (Foo) \"hello world\"; }", - functionalCastExpr())); + cxxFunctionalCastExpr())); EXPECT_TRUE( notMatches(FooClass + "void r() { Foo f = \"hello world\"; }", - functionalCastExpr())); + cxxFunctionalCastExpr())); } TEST(DynamicCast, MatchesSimpleCase) { EXPECT_TRUE(matches("struct B { virtual ~B() {} }; struct D : B {};" "B b;" "D* p = dynamic_cast(&b);", - dynamicCastExpr())); + cxxDynamicCastExpr())); } TEST(StaticCast, MatchesSimpleCase) { EXPECT_TRUE(matches("void* p(static_cast(&p));", - staticCastExpr())); + cxxStaticCastExpr())); } TEST(StaticCast, DoesNotMatchOtherCasts) { - EXPECT_TRUE(notMatches("char* p = (char*)(&p);", staticCastExpr())); + EXPECT_TRUE(notMatches("char* p = (char*)(&p);", cxxStaticCastExpr())); EXPECT_TRUE(notMatches("char q, *p = const_cast(&q);", - staticCastExpr())); + cxxStaticCastExpr())); EXPECT_TRUE(notMatches("void* p = reinterpret_cast(&p);", - staticCastExpr())); + cxxStaticCastExpr())); EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};" "B b;" "D* p = dynamic_cast(&b);", - staticCastExpr())); + cxxStaticCastExpr())); } TEST(CStyleCast, MatchesSimpleCase) { @@ -3070,7 +3076,7 @@ TEST(CStyleCast, DoesNotMatchOtherCasts) { TEST(HasDestinationType, MatchesSimpleCase) { EXPECT_TRUE(matches("char* p = static_cast(0);", - staticCastExpr(hasDestinationType( + cxxStaticCastExpr(hasDestinationType( pointsTo(TypeMatcher(anything())))))); } @@ -3273,7 +3279,7 @@ TEST(HasSourceExpression, MatchesImplicitCasts) { EXPECT_TRUE(matches("class string {}; class URL { public: URL(string s); };" "void r() {string a_string; URL url = a_string; }", implicitCastExpr( - hasSourceExpression(constructExpr())))); + hasSourceExpression(cxxConstructExpr())))); } TEST(HasSourceExpression, MatchesExplicitCasts) { @@ -3445,21 +3451,22 @@ TEST(SwitchCase, MatchesEachCase) { TEST(ForEachConstructorInitializer, MatchesInitializers) { EXPECT_TRUE(matches( "struct X { X() : i(42), j(42) {} int i, j; };", - constructorDecl(forEachConstructorInitializer(ctorInitializer())))); + cxxConstructorDecl(forEachConstructorInitializer(cxxCtorInitializer())))); } TEST(ExceptionHandling, SimpleCases) { - EXPECT_TRUE(matches("void foo() try { } catch(int X) { }", catchStmt())); - EXPECT_TRUE(matches("void foo() try { } catch(int X) { }", tryStmt())); - EXPECT_TRUE(notMatches("void foo() try { } catch(int X) { }", throwExpr())); + EXPECT_TRUE(matches("void foo() try { } catch(int X) { }", cxxCatchStmt())); + EXPECT_TRUE(matches("void foo() try { } catch(int X) { }", cxxTryStmt())); + EXPECT_TRUE( + notMatches("void foo() try { } catch(int X) { }", cxxThrowExpr())); EXPECT_TRUE(matches("void foo() try { throw; } catch(int X) { }", - throwExpr())); + cxxThrowExpr())); EXPECT_TRUE(matches("void foo() try { throw 5;} catch(int X) { }", - throwExpr())); + cxxThrowExpr())); EXPECT_TRUE(matches("void foo() try { throw; } catch(...) { }", - catchStmt(isCatchAll()))); + cxxCatchStmt(isCatchAll()))); EXPECT_TRUE(notMatches("void foo() try { throw; } catch(int) { }", - catchStmt(isCatchAll()))); + cxxCatchStmt(isCatchAll()))); EXPECT_TRUE(matches("void foo() try {} catch(int X) { }", varDecl(isExceptionVariable()))); EXPECT_TRUE(notMatches("void foo() try { int X; } catch (...) { }", @@ -3595,12 +3602,12 @@ TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) { new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class X { void f(); void g(); };", - recordDecl(decl().bind("x"), hasMethod(hasName("g"))), + cxxRecordDecl(decl().bind("x"), hasMethod(hasName("g"))), new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class X { X() : a(1), b(2) {} double a; int b; };", recordDecl(decl().bind("x"), - has(constructorDecl( + has(cxxConstructorDecl( hasAnyConstructorInitializer(forField(hasName("b")))))), new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( @@ -3624,12 +3631,12 @@ TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) { new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A{}; class B{}; class C : B, A {};", - recordDecl(decl().bind("x"), isDerivedFrom("::A")), + cxxRecordDecl(decl().bind("x"), isDerivedFrom("::A")), new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A{}; typedef A B; typedef A C; typedef A D;" "class E : A {};", - recordDecl(decl().bind("x"), isDerivedFrom("C")), + cxxRecordDecl(decl().bind("x"), isDerivedFrom("C")), new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A { class B { void f() {} }; };", @@ -3648,8 +3655,8 @@ TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) { new VerifyIdIsBoundTo("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A { A() : s(), i(42) {} const char *s; int i; };", - constructorDecl(hasName("::A::A"), decl().bind("x"), - forEachConstructorInitializer(forField(hasName("i")))), + cxxConstructorDecl(hasName("::A::A"), decl().bind("x"), + forEachConstructorInitializer(forField(hasName("i")))), new VerifyIdIsBoundTo("x", 1))); } @@ -3723,11 +3730,11 @@ TEST(IsTemplateInstantiation, MatchesImplicitClassTemplateInstantiation) { EXPECT_TRUE(matches( "template class X {}; class A {}; X x;", - recordDecl(hasName("::X"), isTemplateInstantiation()))); + cxxRecordDecl(hasName("::X"), isTemplateInstantiation()))); EXPECT_TRUE(matches( "template class X { T t; }; class A {}; X x;", - recordDecl(isTemplateInstantiation(), hasDescendant( + cxxRecordDecl(isTemplateInstantiation(), hasDescendant( fieldDecl(hasType(recordDecl(hasName("A")))))))); } @@ -3742,7 +3749,7 @@ TEST(IsTemplateInstantiation, MatchesExplicitClassTemplateInstantiation) { EXPECT_TRUE(matches( "template class X { T t; }; class A {};" "template class X;", - recordDecl(isTemplateInstantiation(), hasDescendant( + cxxRecordDecl(isTemplateInstantiation(), hasDescendant( fieldDecl(hasType(recordDecl(hasName("A")))))))); } @@ -3751,7 +3758,7 @@ TEST(IsTemplateInstantiation, EXPECT_TRUE(matches( "template class X {};" "template class X {}; class A {}; X x;", - recordDecl(hasName("::X"), isTemplateInstantiation()))); + cxxRecordDecl(hasName("::X"), isTemplateInstantiation()))); } TEST(IsTemplateInstantiation, @@ -3762,7 +3769,7 @@ TEST(IsTemplateInstantiation, " template class Y { U u; };" " Y y;" "};", - recordDecl(hasName("::X::Y"), isTemplateInstantiation()))); + cxxRecordDecl(hasName("::X::Y"), isTemplateInstantiation()))); } TEST(IsTemplateInstantiation, DoesNotMatchInstantiationsInsideOfInstantiation) { @@ -3775,31 +3782,31 @@ TEST(IsTemplateInstantiation, DoesNotMatchInstantiationsInsideOfInstantiation) { " template class Y { U u; };" " Y y;" "}; X x;", - recordDecl(hasName("::X::Y"), unless(isTemplateInstantiation())))); + cxxRecordDecl(hasName("::X::Y"), unless(isTemplateInstantiation())))); } TEST(IsTemplateInstantiation, DoesNotMatchExplicitClassTemplateSpecialization) { EXPECT_TRUE(notMatches( "template class X {}; class A {};" "template <> class X {}; X x;", - recordDecl(hasName("::X"), isTemplateInstantiation()))); + cxxRecordDecl(hasName("::X"), isTemplateInstantiation()))); } TEST(IsTemplateInstantiation, DoesNotMatchNonTemplate) { EXPECT_TRUE(notMatches( "class A {}; class Y { A a; };", - recordDecl(isTemplateInstantiation()))); + cxxRecordDecl(isTemplateInstantiation()))); } TEST(IsInstantiated, MatchesInstantiation) { EXPECT_TRUE( matches("template class A { T i; }; class Y { A a; };", - recordDecl(isInstantiated()))); + cxxRecordDecl(isInstantiated()))); } TEST(IsInstantiated, NotMatchesDefinition) { EXPECT_TRUE(notMatches("template class A { T i; };", - recordDecl(isInstantiated()))); + cxxRecordDecl(isInstantiated()))); } TEST(IsInTemplateInstantiation, MatchesInstantiationStmt) { @@ -3851,7 +3858,7 @@ TEST(IsExplicitTemplateSpecialization, DoesNotMatchPrimaryTemplate) { EXPECT_TRUE(notMatches( "template class X {};", - recordDecl(isExplicitTemplateSpecialization()))); + cxxRecordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(notMatches( "template void f(T t);", functionDecl(isExplicitTemplateSpecialization()))); @@ -3862,7 +3869,7 @@ TEST(IsExplicitTemplateSpecialization, EXPECT_TRUE(notMatches( "template class X {};" "template class X; extern template class X;", - recordDecl(isExplicitTemplateSpecialization()))); + cxxRecordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(notMatches( "template void f(T t) {}" "template void f(int t); extern template void f(long t);", @@ -3873,7 +3880,7 @@ TEST(IsExplicitTemplateSpecialization, DoesNotMatchImplicitTemplateInstantiations) { EXPECT_TRUE(notMatches( "template class X {}; X x;", - recordDecl(isExplicitTemplateSpecialization()))); + cxxRecordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(notMatches( "template void f(T t); void g() { f(10); }", functionDecl(isExplicitTemplateSpecialization()))); @@ -3884,7 +3891,7 @@ TEST(IsExplicitTemplateSpecialization, EXPECT_TRUE(matches( "template class X {};" "template<> class X {};", - recordDecl(isExplicitTemplateSpecialization()))); + cxxRecordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(matches( "template void f(T t) {}" "template<> void f(int t) {}", @@ -3966,7 +3973,7 @@ TEST(HasAncestor, MatchesInTemplateInstantiations) { TEST(HasAncestor, MatchesInImplicitCode) { EXPECT_TRUE(matches( "struct X {}; struct A { A() {} X x; };", - constructorDecl( + cxxConstructorDecl( hasAnyConstructorInitializer(withInitializer(expr( hasAncestor(recordDecl(hasName("A"))))))))); } @@ -3989,8 +3996,9 @@ TEST(HasAncestor, MatchesAllAncestors) { "void t() { C::f(); }", integerLiteral( equals(42), - allOf(hasAncestor(recordDecl(isTemplateInstantiation())), - hasAncestor(recordDecl(unless(isTemplateInstantiation()))))))); + allOf( + hasAncestor(cxxRecordDecl(isTemplateInstantiation())), + hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation()))))))); } TEST(HasParent, MatchesAllParents) { @@ -4000,23 +4008,23 @@ TEST(HasParent, MatchesAllParents) { integerLiteral( equals(42), hasParent(compoundStmt(hasParent(functionDecl( - hasParent(recordDecl(isTemplateInstantiation()))))))))); - EXPECT_TRUE(matches( - "template struct C { static void f() { 42; } };" - "void t() { C::f(); }", - integerLiteral( - equals(42), - hasParent(compoundStmt(hasParent(functionDecl( - hasParent(recordDecl(unless(isTemplateInstantiation())))))))))); + hasParent(cxxRecordDecl(isTemplateInstantiation()))))))))); + EXPECT_TRUE( + matches("template struct C { static void f() { 42; } };" + "void t() { C::f(); }", + integerLiteral( + equals(42), + hasParent(compoundStmt(hasParent(functionDecl(hasParent( + cxxRecordDecl(unless(isTemplateInstantiation())))))))))); EXPECT_TRUE(matches( "template struct C { static void f() { 42; } };" "void t() { C::f(); }", integerLiteral(equals(42), - hasParent(compoundStmt(allOf( - hasParent(functionDecl( - hasParent(recordDecl(isTemplateInstantiation())))), - hasParent(functionDecl(hasParent(recordDecl( - unless(isTemplateInstantiation()))))))))))); + hasParent(compoundStmt( + allOf(hasParent(functionDecl(hasParent( + cxxRecordDecl(isTemplateInstantiation())))), + hasParent(functionDecl(hasParent(cxxRecordDecl( + unless(isTemplateInstantiation()))))))))))); EXPECT_TRUE( notMatches("template struct C { static void f() {} };" "void t() { C::f(); }", @@ -4049,8 +4057,8 @@ TEST(TypeMatching, MatchesTypes) { } TEST(TypeMatching, MatchesVoid) { - EXPECT_TRUE( - matches("struct S { void func(); };", methodDecl(returns(voidType())))); + EXPECT_TRUE(matches("struct S { void func(); };", + cxxMethodDecl(returns(voidType())))); } TEST(TypeMatching, MatchesArrayTypes) { @@ -4813,12 +4821,12 @@ TEST(EqualsBoundNodeMatcher, UnlessDescendantsOfAncestorsMatch) { "void f(StringRef v) {" " v.data();" "}", - memberCallExpr( - callee(methodDecl(hasName("data"))), - on(declRefExpr(to(varDecl(hasType(recordDecl(hasName("StringRef")))) - .bind("var")))), - unless(hasAncestor(stmt(hasDescendant(memberCallExpr( - callee(methodDecl(anyOf(hasName("size"), hasName("length")))), + cxxMemberCallExpr( + callee(cxxMethodDecl(hasName("data"))), + on(declRefExpr(to( + varDecl(hasType(recordDecl(hasName("StringRef")))).bind("var")))), + unless(hasAncestor(stmt(hasDescendant(cxxMemberCallExpr( + callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), on(declRefExpr(to(varDecl(equalsBoundNode("var"))))))))))) .bind("data"), new VerifyIdIsBoundTo("data", 1))); @@ -4829,12 +4837,12 @@ TEST(EqualsBoundNodeMatcher, UnlessDescendantsOfAncestorsMatch) { " v.data();" " v.size();" "}", - memberCallExpr( - callee(methodDecl(hasName("data"))), - on(declRefExpr(to(varDecl(hasType(recordDecl(hasName("StringRef")))) - .bind("var")))), - unless(hasAncestor(stmt(hasDescendant(memberCallExpr( - callee(methodDecl(anyOf(hasName("size"), hasName("length")))), + cxxMemberCallExpr( + callee(cxxMethodDecl(hasName("data"))), + on(declRefExpr(to( + varDecl(hasType(recordDecl(hasName("StringRef")))).bind("var")))), + unless(hasAncestor(stmt(hasDescendant(cxxMemberCallExpr( + callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), on(declRefExpr(to(varDecl(equalsBoundNode("var"))))))))))) .bind("data"))); } diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp index 45b0910ab0a2..d96aa265cdb2 100644 --- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -301,12 +301,12 @@ TEST(ParserTest, CompletionNamedValues) { EXPECT_EQ("String nameX", Comps[0].MatcherDecl); // Can complete if there are names in the expression. - Code = "methodDecl(hasName(nameX), "; + Code = "cxxMethodDecl(hasName(nameX), "; Comps = Parser::completeExpression(Code, Code.size(), nullptr, &NamedValues); EXPECT_LT(0u, Comps.size()); // Can complete names and registry together. - Code = "methodDecl(hasP"; + Code = "cxxMethodDecl(hasP"; Comps = Parser::completeExpression(Code, Code.size(), nullptr, &NamedValues); ASSERT_EQ(3u, Comps.size()); EXPECT_EQ("aramA", Comps[0].TypedText); diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp index a6b0a1b41d6b..ca1dfefd538c 100644 --- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp @@ -129,7 +129,7 @@ TEST_F(RegistryTest, CanConstructNoArgs) { Matcher IsArrowValue = constructMatcher( "memberExpr", constructMatcher("isArrow")).getTypedMatcher(); Matcher BoolValue = - constructMatcher("boolLiteral").getTypedMatcher(); + constructMatcher("cxxBoolLiteral").getTypedMatcher(); const std::string ClassSnippet = "struct Foo { int x; };\n" "Foo *foo = new Foo;\n" @@ -195,7 +195,7 @@ TEST_F(RegistryTest, OverloadedMatchers) { "callExpr", constructMatcher( "callee", - constructMatcher("methodDecl", + constructMatcher("cxxMethodDecl", constructMatcher("hasName", StringRef("x"))))) .getTypedMatcher(); @@ -255,11 +255,11 @@ TEST_F(RegistryTest, PolymorphicMatchers) { EXPECT_FALSE(matches("void Foo(){};", RecordDecl)); Matcher ConstructExpr = constructMatcher( - "constructExpr", + "cxxConstructExpr", constructMatcher( "hasDeclaration", constructMatcher( - "methodDecl", + "cxxMethodDecl", constructMatcher( "ofClass", constructMatcher("hasName", StringRef("Foo")))))) .getTypedMatcher(); @@ -300,7 +300,7 @@ TEST_F(RegistryTest, TypeTraversal) { TEST_F(RegistryTest, CXXCtorInitializer) { Matcher CtorDecl = constructMatcher( - "constructorDecl", + "cxxConstructorDecl", constructMatcher( "hasAnyConstructorInitializer", constructMatcher("forField", @@ -416,9 +416,10 @@ TEST_F(RegistryTest, Errors) { "(Actual = String)", Error->toString()); Error.reset(new Diagnostics()); - EXPECT_TRUE(constructMatcher("recordDecl", constructMatcher("recordDecl"), - constructMatcher("parameterCountIs", 3), - Error.get()).isNull()); + EXPECT_TRUE( + constructMatcher("cxxRecordDecl", constructMatcher("cxxRecordDecl"), + constructMatcher("parameterCountIs", 3), Error.get()) + .isNull()); EXPECT_EQ("Incorrect type for arg 2. (Expected = Matcher) != " "(Actual = Matcher)", Error->toString()); @@ -432,7 +433,7 @@ TEST_F(RegistryTest, Errors) { Error->toString()); Error.reset(new Diagnostics()); EXPECT_TRUE(constructMatcher( - "recordDecl", + "cxxRecordDecl", constructMatcher("allOf", constructMatcher("isDerivedFrom", StringRef("FOO")), constructMatcher("isArrow")), diff --git a/clang/unittests/Tooling/RefactoringCallbacksTest.cpp b/clang/unittests/Tooling/RefactoringCallbacksTest.cpp index c2b331c70afc..ad8aa8f98feb 100644 --- a/clang/unittests/Tooling/RefactoringCallbacksTest.cpp +++ b/clang/unittests/Tooling/RefactoringCallbacksTest.cpp @@ -71,7 +71,7 @@ TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) { ReplaceStmtWithStmt Callback("always-false", "should-be"); expectRewritten(Code, Expected, id("always-false", conditionalOperator( - hasCondition(boolLiteral(equals(false))), + hasCondition(cxxBoolLiteral(equals(false))), hasFalseExpression(id("should-be", expr())))), Callback); } @@ -92,7 +92,7 @@ TEST(RefactoringCallbacksTest, RemovesEntireIfOnEmptyElse) { std::string Expected = "void f() { }"; ReplaceIfStmtWithItsBody Callback("id", false); expectRewritten(Code, Expected, - id("id", ifStmt(hasCondition(boolLiteral(equals(false))))), + id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false))))), Callback); }