[cfe-commits] [PATCH] Make hasDeclaration work for enums
Daniel Jasper
djasper at google.com
Mon Dec 3 06:33:42 PST 2012
Hi klimek,
http://llvm-reviews.chandlerc.com/D158
Files:
include/clang/ASTMatchers/ASTMatchersInternal.h
unittests/ASTMatchers/ASTMatchersTest.cpp
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -380,6 +380,8 @@
/// FIXME: Add other ways to convert...
if (Node.isNull())
return false;
+ if (const EnumType *AsEnum = dyn_cast<EnumType>(Node.getTypePtr()))
+ return matchesDecl(AsEnum->getDecl(), Finder, Builder);
return matchesDecl(Node->getAsCXXRecordDecl(), Finder, Builder);
}
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -778,6 +778,12 @@
new VerifyIdIsBoundTo<Decl>("x", 2)));
}
+TEST(HasDeclaration, HasDeclarationOfEnumType) {
+ EXPECT_TRUE(matches("enum X {}; void y(X *x) { x; }",
+ expr(hasType(pointsTo(
+ qualType(hasDeclaration(enumDecl(hasName("X")))))))));
+}
+
TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) {
TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X")));
EXPECT_TRUE(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158.1.patch
Type: text/x-patch
Size: 1206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121203/6f8be191/attachment.bin>
More information about the cfe-commits
mailing list