[cfe-dev] Objective-C tidy up
David Chisnall
csdavec at swansea.ac.uk
Wed Jun 4 04:30:23 PDT 2008
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;
}
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.
Occurrences of self / _cmd in an Objective-C program refer to some
variable defined in some way in some scope, with an implicit
declaration if the scope happens to be a method. This means that,
unless you want to complicate parsing a lot, self and _cmd want to be
some kind of decl refs, when encountered in the source code (this was
originally done with super, where it was a decl ref with an implicit
cast, but I had to change it because super really does require special
handling). By the way, it is not uncommon to use self and _cmd
symbols in Objective-C programs when you write method-like functions
that you want to call directly, without going via the dynamic dispatch
mechanism (the equivalent of C++ non-virtual member functions).
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.
Steve - I don't intend to make any requirements on the calling
convention. For the Étoilé runtime, _cmd is a field of a structure
passed as the second argument, not the second argument. As long as
CodeGen can get the argument from somewhere and create %self.addr and
%_cmd.addr in the function preamble, it won't be a problem (currently
I do this in the runtime-agnostic part. I plan on moving this into
the CGObjCRuntime class, so that all of the traditional runtimes can
do it this way, but the Étoilé runtime and potentially COLA or a
future Apple runtime can do it a different way).
David
More information about the cfe-dev
mailing list