[PATCH] ASTMatchers: Add support for Objective-C
Jordan Rose
jordan_rose at apple.com
Tue Aug 26 09:07:33 PDT 2014
================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:3726-3731
@@ +3725,8 @@
+/// matches '[NSArray alloc]'
+AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, ExpectedSelector) {
+ assert(!ExpectedSelector.empty());
+ const std::string ActualSelectorString = Node.getSelector().getAsString();
+ const StringRef ActualSelector = ActualSelectorString;
+ return ExpectedSelector == ActualSelector;
+}
+
----------------
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.
================
Comment at: unittests/ASTMatchers/ASTMatchersTest.h:175
@@ -174,1 +174,3 @@
+enum ObjCMemoryManagement { MRR, MRR_GC, GCOnly, ARC };
+typedef enum ObjCMemoryManagement ObjCMemoryManagement;
----------------
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.
http://reviews.llvm.org/D5056
More information about the cfe-commits
mailing list