[cfe-dev] Parsing objective-c message expressions
Ted Kremenek
kremenek at apple.com
Sat Aug 2 10:32:14 PDT 2008
Hi Rajesh,
Please see my answer to this question in the following thread:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-August/002416.html
Ted
On Aug 1, 2008, at 9:09 AM, Rajesh Karmani wrote:
> Hi,
> Is there a way to find the parent expression given an expression?
> Say I have an instance of ObjCMessageExpr and
> want to find out if it's part of a declaration (DeclStmt) or an
> statement by itself. Is there any facility to do that?
>
>
> Thanks.
>
> rajesh
>
>
> Ted Kremenek wrote:
>>
>> On Jul 29, 2008, at 8:11 AM, Rajesh Karmani wrote:
>>
>>
>>> Hi,
>>> I have just started looking at Clang and found it to be a great
>>> tool.
>>> I also came across the RewriteObjc module and wanted to play around
>>> with
>>> how the Objective-C messages are "rewritten".
>>>
>>> I have not been able to figure out how an assignment statement like:
>>>
>>> c = [obj execute];
>>>
>>> is parsed in Clang (what functions are called?). I would like to
>>> rewrite
>>> such statements differently from
>>>
>>> [obj execute];
>>>
>>> where nothing is being returned. Could someone please guide me which
>>> parts of code should I be looking at?
>>>
>> Hi Rajesh,
>>
>> In general, an excellent way to figure out the structure of the ASTs
>> is to use the --ast-dump option:
>>
>> clang --ast-dump myfile.m
>>
>> For example:
>>
>> void f(NSObject *m) {
>> NSObject* c = [m execute];
>> }
>>
>> becomes:
>>
>> void f(NSObject *m)
>> (CompoundStmt 0x2372060 <<stdin>:3:21, line:5:1>
>> (DeclStmt 0x2371ff0 <line:4:3>
>> 0x2371fa0 "NSObject *c =
>> (ImplicitCastExpr 0x236c030 <col:17, col:27> 'NSObject *'
>> (ObjCMessageExpr 0x2372010 <col:17, col:27> 'id':'struct
>> objc_object *' selector=execute
>> (DeclRefExpr 0x2371fd0 <col:18> 'NSObject *' ParmVar='m'
>> 0x23712b0)))")
>>
>> Note that assignments and variable declarations are different.
>> Assignments are represented using BinaryOperator, while variable
>> declarations are represented using DeclStmt.
>>
>> Ted
>>
More information about the cfe-dev
mailing list