This is an archive of the discontinued LLVM Phabricator instance.

ASTMatchers: Add support for Objective-C
Needs ReviewPublic

Authored by ddkilzer on Aug 25 2014, 3:58 PM.

Details

Summary

After implementing D5042 using ASTMatchers for part of the work, I realized how much easier my life would have been had ASTMatchers been available for Objective-C, so I started implementing them.

Here are the commits landed so far:

ASTMatchers: Add support for objCMessageExpr()
ASTMatchers: Add support for hasSelector() within objCMessageExpr()
ASTMatchers: Add support for is{,Super}{Instance,Class}Receiver() with objCMessageExpr()

Diff Detail

Event Timeline

ddkilzer updated this revision to Diff 12922.Aug 25 2014, 3:58 PM
ddkilzer retitled this revision from to ASTMatchers: Add support for Objective-C.
ddkilzer updated this object.
ddkilzer edited the test plan for this revision. (Show Details)
ddkilzer added reviewers: jordan_rose, krememek.
ddkilzer added a subscriber: Unknown Object (MLST).
ddkilzer updated this object.Aug 25 2014, 3:59 PM

Phabricator (arcanist) squashed my local commits when uploading the patch, but this is a good first cut to get feedback about direction. (If I should be using a mailing list instead, please let me know.)

Apart from the code layout (and that I have no idea about Obj-C) looks good.
Please also don't forget to update the docs:
$ cd docs/tools
$ python dump_ast_matchers.py

include/clang/ASTMatchers/ASTMatchers.h
3713–3714

I'd prefer grouping this with the other node matchers on top of the file.

unittests/ASTMatchers/ASTMatchersTest.cpp
4456

I assume we'll have more obj-c stuff coming, and this already compiles pretty slow, so I'd prefer to split out an ASTMatchersObjCTest.cpp/.h unless you see specific reasons not to do that.

jordan_rose added inline comments.Aug 26 2014, 9:07 AM
include/clang/ASTMatchers/ASTMatchers.h
3726–3731

Rather than using getAsString, consider using a stack-based SmallString, and then print the selector to it using an llvm::raw_svector_ostream. You can do the comparison by wrapping both strings with StringRef. That should save heap traffic during matching.

unittests/ASTMatchers/ASTMatchersTest.h
175

I think it's okay to leave out GC and just test plain MRR and ARC. Also, since I don't think we can use enum classes yet, please prefix these enum values.