[cfe-commits] r43948 - in /cfe/trunk: Sema/SemaDecl.cpp Sema/SemaType.cpp test/Sema/method-encoding-2.m

Chris Lattner clattner at apple.com
Wed Dec 12 17:00:16 PST 2007


On Dec 12, 2007, at 9:36 AM, Fariborz Jahanian wrote:

>
> On Dec 11, 2007, at 11:15 PM, Chris Lattner wrote:
>
>> On Nov 9, 2007, at 9:18 AM, Fariborz Jahanian wrote:
>>> Author: fjahanian
>>> Date: Fri Nov  9 11:18:29 2007
>>> New Revision: 43948
>>>
>>> Insert invisble arguments to method definition header.
>>
>> Hi Fariborz,
>>
>> The code for handling self etc evolved into:
>>
>> void Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
>> ...
>>  // Create Decl objects for each parameter, entrring them in the  
>> scope for
>>  // binding to their use.
>>  struct DeclaratorChunk::ParamInfo PI;
>>
>>  // Insert the invisible arguments, self and _cmd!
>>  PI.Ident = &Context.Idents.get("self");
>>  PI.IdentLoc = SourceLocation(); // synthesized vars have a null  
>> location.
>>  PI.InvalidType = false;
>>  if (MDecl->isInstance()) {
>>    QualType selfTy = Context.getObjcInterfaceType(MDecl- 
>> >getClassInterface());
>>    selfTy = Context.getPointerType(selfTy);
>>    PI.TypeInfo = selfTy.getAsOpaquePtr();
>>  } else
>>    PI.TypeInfo = Context.getObjcIdType().getAsOpaquePtr();
>>  CurMethodDecl->setSelfDecl(ActOnParamDeclarator(PI, FnBodyScope));
>>
>> similarly for _cmd.
>>
>> Questions:
>>
>> 1. Why are these turning into ParamVarDecls?  These are not  
>> parameters in the source language, they are magic variables.
>
> I agree that this is an implementation detail. This was a quick way  
> to support binding to the use of 'self' as variable which refers to  
> receiver of message in methods. Post-demo, we talked about  
> providing a special Decl node for the use of 'self' (which requires  
> more substantive changes).

Right.  Similiarly in C++ we have 'this'.  Maybe something like  
MagicVarDecl or something?

One other change that would be nice is to create these things lazily  
on the first time they are used.  That way, an ObjC method would only  
get a decl for self if explicitly referenced.  This is even more  
important for _cmd as it is almost never used.

>> 2. Why are you setting up a declarator chunk and passing stuff  
>> through ActOnParamDeclarator?  This code is in Sema already, so it  
>> seems like this layer of indirection is not needed.
>
> I don't remember this code; presumably done to enter the parameter  
> into scope. Maybe Steve has an explanation.

Ok, please investigate to see how hard it is to change when you have  
time,

Thanks!

-Chris



More information about the cfe-commits mailing list