Fixing a bug where hasType(decl()) would fail to match on C code involving structs or unions.

llvm-svn: 246860
This commit is contained in:
Aaron Ballman 2015-09-04 18:34:48 +00:00
parent 23a4df27ab
commit c129c69105
3 changed files with 12 additions and 5 deletions

View File

@ -668,16 +668,14 @@ private:
return matchesDecl(Node.getDecl(), Finder, Builder);
}
/// \brief Extracts the CXXRecordDecl or EnumDecl of a QualType and returns
/// whether the inner matcher matches on it.
/// \brief Extracts the TagDecl of a QualType and returns whether the inner
/// matcher matches on it.
bool matchesSpecialized(const QualType &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
/// 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);
return matchesDecl(Node->getAsTagDecl(), Finder, Builder);
}
/// \brief Gets the TemplateDecl from a TemplateSpecializationType

View File

@ -919,6 +919,9 @@ TEST(TypeMatcher, MatchesClassType) {
EXPECT_TRUE(
matches("class A { public: A *a; class B {}; };", TypeAHasClassB));
EXPECT_TRUE(matchesC("struct S {}; void f(void) { struct S s; }",
varDecl(hasType(namedDecl(hasName("S"))))));
}
TEST(Matcher, BindMatchedNodes) {

View File

@ -119,6 +119,12 @@ testing::AssertionResult matchesObjC(const std::string &Code,
"", FileContentMappings(), "input.m");
}
template <typename T>
testing::AssertionResult matchesC(const std::string &Code, const T &AMatcher) {
return matchesConditionally(Code, AMatcher, true, "", FileContentMappings(),
"input.c");
}
template <typename T>
testing::AssertionResult notMatchesObjC(const std::string &Code,
const T &AMatcher) {