[cfe-dev] Objective-C tidy up

David Chisnall csdavec at swansea.ac.uk
Tue Jun 3 10:23:30 PDT 2008


On 3 Jun 2008, at 17:49, Chris Lattner wrote:

>
> On Jun 3, 2008, at 4:39 AM, David Chisnall wrote:
>
>>
>> On 3 Jun 2008, at 07:33, Chris Lattner wrote:
>>
>>> Why should self and _cmd be ParmVarDecls?  Shouldn't they be
>>> PredefinedExprs?
>>
>> That's what I did to start with, but PredefinedExprs need special
>> handling in codegen, while ParmVarDecls are automatically turned
>> into loads of %var.addr.  Since they are parameters, and since it
>> simplifies the rest of the implementation, it seemed like a
>> ParmVarDecl would be the right thing to choose.
>
> ParmVarDecl is an artifact of common implementations, not the way the
> language works.  They are not parameters, as they obviously don't have
> location info etc.

They are artefacts of both all existing implementations (GNU, Apple,  
and POC) and the language philosophy ('no magic'), and is something  
relied on by a lot of existing code.  You can promote them to explicit  
parameters by requesting a pointer to the function implementing the  
method (something supported by both Brad Cox's original design and  
implementation, and by OpenStep) and calling this as a C function.   
The fact that they have no source location is merely syntactic sugar -  
they are real parameters and Objective-C programmers expect to be able  
to treat them as such.  Treating them as something special seems like  
an unnecessary layer of abstraction which reflects neither how they  
are used nor how they are implemented.

This is in contrast to super, which is an alias for self with  
different semantics (i.e. sending a message to super sends a message  
where the destination class is resolved at compile time, not at  
runtime).

>>> +++ include/clang/AST/DeclObjC.h	(working copy)
>>> @@ -91,7 +91,8 @@
>>> // The following are only used for method definitions, null
>>> otherwise.
>>> // FIXME: space savings opportunity, consider a sub-class.
>>> Stmt *Body;
>>> -  ParmVarDecl *SelfDecl;
>>> +  // Decls for implicit parameters
>>> +  llvm::SmallVector<ParmVarDecl *, 2> ImplicitParamInfo;
>>>
>>> If there are always exactly two of these, just use:
>>>
>>> ParmVarDecl *ImplicitParamInfo[2];
>>
>> There will be three for the √Čtoil√© runtime.  Someone expressed
>> interest in porting Objective-C to the COLA runtime from the
>> Viewpoints Research Institute as well, and this would have somewhere
>> between one and four depending on how they did it.
>
> Please use a fixed size array.  That is cheaper than a smallvector<4>.

I've made this change, and included the updated diff.

David

-------------- next part --------------
A non-text attachment was scrubbed...
Name: objc.diff
Type: application/octet-stream
Size: 18657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080603/099acbab/attachment.obj>
-------------- next part --------------



More information about the cfe-dev mailing list