[cfe-dev] Help - Matchers for ObjC AST nodes?

Manuel Klimek klimek at google.com
Wed Nov 5 00:24:58 PST 2014


On Wed Nov 05 2014 at 1:29:36 AM Dean Sutherland <dfsuther at yahoo-inc.com>
wrote:

> 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 :)


>
> Suggestions or guidance would be most welcome.
>
>
> Dean
> dfsuther at yahoo-inc.com
>
> -----------------------
> `-ExprWithCleanups 0x7fb8af3f4210 <line:927:13, col:72> 'void'
> `-ObjCMessageExpr 0x7fb8af3f41c8 <col:13, col:72> 'void'
> selector=loadHTMLString:baseURL:
> |-PseudoObjectExpr 0x7fb8af3f4188 <col:14, col:34> 'UIWebView *'
> | |-ObjCPropertyRefExpr 0x7fb8af3f4110 <col:14, col:34> '<pseudo-object
> type>' lvalue objcproperty Kind=PropertyRef Property="webview"
> Messaging=Getter
> | | `-OpaqueValueExpr 0x7fb8af3f40f0 <col:14, col:19> 'HRBookendedWebView
> *'
> | |   `-PseudoObjectExpr 0x7fb8af3f17c8 <col:14, col:19>
> 'HRBookendedWebView *'
> | |     |-ObjCPropertyRefExpr 0x7fb8af3f1750 <col:14, col:19>
> '<pseudo-object type>' lvalue objcproperty Kind=PropertyRef
> Property="articleWebView" Messaging=Getter
> | |     | `-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> | |     |   `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> | |     |     `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> | |     |-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> | |     | `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> | |     |   `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> | |     `-ImplicitCastExpr 0x7fb8af3f17b0 <col:19> 'HRBookendedWebView *'
> <ARCReclaimReturnedObject>
> | |       `-ObjCMessageExpr 0x7fb8af3f1780 <col:19> 'HRBookendedWebView *'
> selector=articleWebView
> | |         `-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> | |           `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> | |             `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> | |-OpaqueValueExpr 0x7fb8af3f40f0 <col:14, col:19> 'HRBookendedWebView *'
> | | `-PseudoObjectExpr 0x7fb8af3f17c8 <col:14, col:19> 'HRBookendedWebView
> *'
> | |   |-ObjCPropertyRefExpr 0x7fb8af3f1750 <col:14, col:19>
> '<pseudo-object type>' lvalue objcproperty Kind=PropertyRef
> Property="articleWebView" Messaging=Getter
> | |   | `-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> | |   |   `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> | |   |     `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> | |   |-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> | |   | `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> | |   |   `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> | |   `-ImplicitCastExpr 0x7fb8af3f17b0 <col:19> 'HRBookendedWebView *'
> <ARCReclaimReturnedObject>
> | |     `-ObjCMessageExpr 0x7fb8af3f1780 <col:19> 'HRBookendedWebView *'
> selector=articleWebView
> | |       `-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> | |         `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> | |           `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> | `-ImplicitCastExpr 0x7fb8af3f4170 <col:34> 'UIWebView *'
> <ARCReclaimReturnedObject>
> |   `-ObjCMessageExpr 0x7fb8af3f4140 <col:34> 'UIWebView *'
> selector=webview
> |     `-OpaqueValueExpr 0x7fb8af3f40f0 <col:14, col:19>
> 'HRBookendedWebView *'
> |       `-PseudoObjectExpr 0x7fb8af3f17c8 <col:14, col:19>
> 'HRBookendedWebView *'
> |         |-ObjCPropertyRefExpr 0x7fb8af3f1750 <col:14, col:19>
> '<pseudo-object type>' lvalue objcproperty Kind=PropertyRef
> Property="articleWebView" Messaging=Getter
> |         | `-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> |         |   `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> |         |     `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> |         |-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> |         | `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> |         |   `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> |         `-ImplicitCastExpr 0x7fb8af3f17b0 <col:19> 'HRBookendedWebView
> *' <ARCReclaimReturnedObject>
> |           `-ObjCMessageExpr 0x7fb8af3f1780 <col:19> 'HRBookendedWebView
> *' selector=articleWebView
> |             `-OpaqueValueExpr 0x7fb8af3f1730 <col:14>
> 'HRiPadArticleViewController *'
> |               `-ImplicitCastExpr 0x7fb8af3f16e8 <col:14>
> 'HRiPadArticleViewController *' <LValueToRValue>
> |                 `-DeclRefExpr 0x7fb8af3f16c0 <col:14>
> 'HRiPadArticleViewController *const __strong' lvalue ImplicitParam
> 0x7fb8af3f0dd0 'self' 'HRiPadArticleViewController *const __strong'
> |-ObjCStringLiteral 0x7fb8af3f4058 <col:57, col:58> 'NSString *'
> | `-StringLiteral 0x7fb8af3f4030 <col:58> 'char [1]' lvalue ""
> `-ImplicitCastExpr 0x7fb8af3f41b0 </Applications/Xcode.app/
> Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/
> iPhoneSimulator8.1.sdk/usr/include/sys/_types.h:52:23, col:33> 'NSURL *'
> <NullToPointer>
> `-ParenExpr 0x7fb8af3f40d0 <col:23, col:33> 'void *'
> `-CStyleCastExpr 0x7fb8af3f40a8 <col:24, col:32> 'void *' <NullToPointer>
> `-IntegerLiteral 0x7fb8af3f4078 <col:32> 'int' 0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141105/9316db4a/attachment.html>


More information about the cfe-dev mailing list