This is an archive of the discontinued LLVM Phabricator instance.

[PATCH] AST traversal from types to decls
ClosedPublic

Authored by aaron.ballman on Sep 9 2015, 9:21 AM.

Details

Reviewers
klimek
Summary

The AST matching code that traverses from types to decls misses a lot of possible conversions. This patch adds all of the conversions I could find. However, not all of the type->decl conversions can be used from the AST matchers yet. For instance, we do not have matcher support for ObjCInterfaceDecl. I've added a test case for the one conversion we currently support. I feel it's reasonable to have reduced test coverage for the other types at this point compared to the difficulty of tracking down why simple matchers were failing.

This now allows us to write a matcher like:

varDecl(hasType(namedDecl(hasName("Foo"))))

that matches code like:

typedef int Foo;
Foo f; // matches f

Previously, the hasType(namedDecl()) matcher would only properly match if the type queried was a TagType. Now it can support any type which is traversable to a decl.

Diff Detail

Event Timeline

aaron.ballman retitled this revision from to [PATCH] AST traversal from types to decls.
aaron.ballman updated this object.
aaron.ballman added a reviewer: klimek.
aaron.ballman added a subscriber: cfe-commits.

After speaking with Manuel on IRC about the testability, we decided the best approach would be to add the AST matcher functionality required to actually test out the changes to HasDeclarationMatcher::matchesSpecialized(). I've updated the patch accordingly. Specifically, this new patch:

  • Fixed HasDeclarationMatcher to properly convert all types into decls where possible
  • Added objcObjectPointerType()
  • Updated documentation for pointerType() to call out that it does not match ObjCObjectPointerType types
  • Added objcInterfaceDecl()
  • Changed pointsTo() to handle ObjCObjectPointerType as well as PointerType
  • Added templateTypeParmType()
  • Added injectedClassNameType()
  • Added unresolvedUsingTypenameDecl()
  • Added tests and documentation for everything

While this may seem like a lot of unrelated changes, they all relate back to fixing HasDeclarationMatcher.

klimek accepted this revision.Sep 10 2015, 11:53 PM
klimek edited edge metadata.

LG. This is great, thanks!

This revision is now accepted and ready to land.Sep 10 2015, 11:53 PM
aaron.ballman closed this revision.Sep 11 2015, 4:53 AM

Thanks! I've commit in r247404.