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
diff --git a/clang/unittests/AST/ASTContextParentMapTest.cpp b/clang/unittests/AST/ASTContextParentMapTest.cpp
index 0dcb175..94e9735 100644
--- a/clang/unittests/AST/ASTContextParentMapTest.cpp
+++ b/clang/unittests/AST/ASTContextParentMapTest.cpp
@@ -27,8 +27,9 @@
TEST(GetParents, ReturnsParentForDecl) {
MatchVerifier<Decl> 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 @@
EXPECT_TRUE(DeclVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> c; c.f(); }",
- methodDecl(hasName("f"),
- hasParent(recordDecl(isTemplateInstantiation())))));
+ cxxMethodDecl(hasName("f"),
+ hasParent(cxxRecordDecl(isTemplateInstantiation())))));
EXPECT_TRUE(DeclVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> c; c.f(); }",
- methodDecl(hasName("f"),
- hasParent(recordDecl(unless(isTemplateInstantiation()))))));
+ cxxMethodDecl(hasName("f"),
+ hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))))));
EXPECT_FALSE(DeclVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> 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 @@
EXPECT_TRUE(TemplateVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> 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 d8cb977..d06fbfe 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -471,7 +471,7 @@
"struct A {"
" A();"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A()"));
}
@@ -480,7 +480,7 @@
"struct A {"
" A(int a);"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A(int a)"));
}
@@ -489,7 +489,7 @@
"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 @@
"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 @@
"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 @@
"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 @@
"struct A {"
" constexpr A();"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"constexpr A()"));
}
@@ -534,7 +534,7 @@
"struct A {"
" A() = default;"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A() = default"));
}
@@ -543,7 +543,7 @@
"struct A {"
" A() = delete;"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A() = delete"));
}
@@ -553,7 +553,7 @@
"struct A {"
" A(const A &a);"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A<T...>(const A<T...> &a)"));
// WRONG; Should be: "A(const A<T...> &a);"
}
@@ -564,7 +564,7 @@
"struct A : public T... {"
" A(T&&... ts) : T(ts)... {}"
"};",
- constructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A<T...>(T &&...ts) : T(ts)..."));
// WRONG; Should be: "A(T &&...ts) : T(ts)... {}"
}
@@ -574,7 +574,7 @@
"struct A {"
" ~A();"
"};",
- destructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
"~A()"));
}
@@ -583,7 +583,7 @@
"struct A {"
" virtual ~A();"
"};",
- destructorDecl(ofClass(hasName("A"))).bind("id"),
+ cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
"virtual ~A()"));
}
@@ -592,7 +592,7 @@
"struct A {"
" operator int();"
"};",
- methodDecl(ofClass(hasName("A"))).bind("id"),
+ cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
"operator int()"));
}
@@ -601,7 +601,7 @@
"struct A {"
" operator bool();"
"};",
- methodDecl(ofClass(hasName("A"))).bind("id"),
+ cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
"operator bool()"));
}
@@ -611,7 +611,7 @@
"struct A {"
" operator Z();"
"};",
- methodDecl(ofClass(hasName("A"))).bind("id"),
+ cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
"operator Z()"));
}
@@ -621,7 +621,7 @@
"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 @@
"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 @@
"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 @@
"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 @@
"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 @@
ASSERT_TRUE(PrintedDeclCXX98Matches(
Code,
- methodDecl(ofClass(hasName("Z"))).bind("id"),
+ cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Expected));
}
}
@@ -714,7 +714,7 @@
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 b0a8f85..4c77def 100644
--- a/clang/unittests/AST/SourceLocationTest.cpp
+++ b/clang/unittests/AST/SourceLocationTest.cpp
@@ -92,13 +92,13 @@
TEST(CXXNewExpr, ArrayRange) {
RangeVerifier<CXXNewExpr> 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<CXXNewExpr> 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(CXXNewExpr, TypeParenRange) {
RangeVerifier<CXXNewExpr> 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<TypeLoc> {
@@ -252,7 +252,7 @@
"int foo() {\n"
" return int{};\n"
"}",
- functionalCastExpr(), Lang_CXX11));
+ cxxFunctionalCastExpr(), Lang_CXX11));
}
TEST(CXXConstructExpr, SourceRange) {
@@ -262,7 +262,7 @@
"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 @@
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 @@
"U foo() {\n"
" return U{};\n"
"}",
- unresolvedConstructExpr(), Args, Lang_CXX11));
+ cxxUnresolvedConstructExpr(), Args, Lang_CXX11));
}
TEST(UsingDecl, SourceRange) {
@@ -434,11 +434,11 @@
LocationVerifier<FriendDecl> ConstructorVerifier;
ConstructorVerifier.expectLocation(6, 11);
EXPECT_TRUE(ConstructorVerifier.match(
- Code, friendDecl(has(constructorDecl(ofClass(hasName("B")))))));
+ Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B")))))));
LocationVerifier<FriendDecl> 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 @@
RangeVerifier<FriendDecl> 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<FriendDecl> 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 @@
" friend void operator+<>(S<T> src);\n"
"};\n"
"void test(S<double> s) { +s; }",
- friendDecl(hasParent(recordDecl(isTemplateInstantiation())))));
+ friendDecl(hasParent(cxxRecordDecl(isTemplateInstantiation())))));
}
TEST(ObjCMessageExpr, CXXConstructExprRange) {
@@ -539,7 +539,7 @@
"+ (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 b1fd2c1..bc7fd54 100644
--- a/clang/unittests/AST/StmtPrinterTest.cpp
+++ b/clang/unittests/AST/StmtPrinterTest.cpp
@@ -196,7 +196,7 @@
"void foo(A a, A b) {"
" bar(a & b);"
"}",
- memberCallExpr(anything()).bind("id"),
+ cxxMemberCallExpr(anything()).bind("id"),
"a & b"));
}
@@ -210,7 +210,7 @@
"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 *()
}