Matcher that finds all variables/fields of polymorphic type


I want to create a tool that identifies all class declarations that inherit a certain class, and I managed to do that by using this matcher:


I also managed to find all variable and fields of the same type, but I got stuck when I tried to find all variables and fields of a type that inherits the respective class, I imagined something like:

Finder->addMatcher(fieldDecl(isSameOrDerivedFrom(cxxRecordDecl(hasAnyName(superClassNames)))).bind("fieldDecl"), this);

Can this be done directly from a matcher?

Got it, it’s like this:

Finder->addMatcher(varDecl(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(superClassNames))))).bind(“var”), this);