[cfe-dev] Parsing objective-c message expressions

Ted Kremenek kremenek at apple.com
Tue Jul 29 09:34:11 PDT 2008


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