Help - Matchers for ObjC AST nodes?

I'd like to write a matcher that would find the following ObjectiveC snippet:

[self.externalWebView loadHTMLString:@"" baseURL:nil];

(A dump of the AST for this code snippet is appended at the end of this message.)

If matchers for ObjC AST nodes existed, the matcher I want might look something like this:

objcMessageExpr(hasSelector("loadHTMLString:baseURL:"),
hasArgument(1, ignoringParenImpCasts(integerLiteral(equals(0)))));

How do I go about writing the matchers I need, such as objcMessageExpr
and hasSelector? I took a whack at the writing objcMessageExpr and
promptly got lost in failed template instantiation errors.

Suggestions or guidance would be most welcome.

Dean
dfsuther@yahoo-inc.com

Take a look at the AST matcher guide: http://clang.llvm.org/docs/LibASTMatchers.html

In the source tree, check out clang/include/clang/ASTMatchers/ASTMatchersMacros.h for the macros used for writing matchers, and clang/include/clang/ASTMatchers/ASTMatchers.h to look at how existing matchers are implemented.

I’d like to write a matcher that would find the following ObjectiveC snippet:

[self.externalWebView loadHTMLString:@"" baseURL:nil];

(A dump of the AST for this code snippet is appended at the end of this message.)

If matchers for ObjC AST nodes existed, the matcher I want might look something like this:

objcMessageExpr(hasSelector(“loadHTMLString:baseURL:”),
hasArgument(1, ignoringParenImpCasts(integerLiteral(equals(0)))));

How do I go about writing the matchers I need, such as objcMessageExpr
and hasSelector? I took a whack at the writing objcMessageExpr and
promptly got lost in failed template instantiation errors.

If you have a more concrete example of what you tried it would be easier to help :slight_smile:

I’d already read the matcher guide, as well as reading through the suggested .h files. Sadly, I completely missed seeing that the various .cc files that implement the matchers lacked imports of the *ObjC.h files from the AST. Adding those imports has made my compilation errors evaporate. I’m back to making progress!

Dean