[cfe-dev] Objective-C tidy up
clattner at apple.com
Wed Jun 4 10:11:29 PDT 2008
On Jun 4, 2008, at 4:30 AM, David Chisnall wrote:
> On 3 Jun 2008, at 18:27, Chris Lattner wrote:
>> I fail to see the point. "this" in C++ has the exact same behavior
>> and should also be modeled with PredefinedExpr.
> There is one important difference with this. In C++, this is a
> keyword, so the following is an invalid C++ program:
> int main(void)
> int this = 0;
> return this;
> In contrast, the following is a valid Objective-C program:
> int main(void)
> int self = 0;
> return self;
Ahhh, excellent point. Okay, you successfully convinced me that these
should be decls, otherwise they can't participate in name lookup.
> Any function in Objective-C can use self and _cmd as identifier
> names. Any occurrence of the 'this' token in a C++ program refers
> to an instance of an object with a type defined by the context.
Does 'super' in ObjC work the same way?
> So, the question is not what should occurrences of the self and _cmd
> tokens be turned into (although that might be a separate question),
> it's what the entries in the decl map should be populated with. As
> far as my code goes, this can be pretty much any sort of decl. It
> needs to have a type associated with it for Sema to be able to be
> able to do type checking (for self, this is a pointer to an instance
> of the current class, e.g. NSObject*, for _cmd it is SEL). For
> CodeGen, it needs to have a name.
Gotcha. What do you think of a new subclass of ValueDecl?
It would be really nice to lazily allocate these objects when they are
first used. This would allow us to avoid allocating the _cmd decl for
almost every ObjC method, and avoid 'self' on many of them.
Thanks for being patient with me David!
More information about the cfe-dev