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

Fariborz Jahanian fjahanian at apple.com
Wed Dec 12 09:36:24 PST 2007


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).

>
> 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.

- Fariborz

>
>
> -Chris




More information about the cfe-commits mailing list