[cfe-commits] r55356 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp

Daniel Dunbar daniel at zuster.org
Mon Aug 25 23:07:48 PDT 2008


Author: ddunbar
Date: Tue Aug 26 01:07:48 2008
New Revision: 55356

URL: http://llvm.org/viewvc/llvm-project?rev=55356&view=rev
Log:
Move implicit Obj-C param creation into ObjCMethodDecl.
 - Add ObjCMethodDecl::createImplicitParams.
 - Remove ObjCMethodDecl::set{Self,Cmd}Decl
 - Remove Sema::CreateImplicitParameter

No (intended) functionality change.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=55356&r1=55355&r2=55356&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Aug 26 01:07:48 2008
@@ -131,8 +131,12 @@
   // The following are only used for method definitions, null otherwise.
   // FIXME: space savings opportunity, consider a sub-class.
   Stmt *Body;
-  // Decls for implicit parameters
+
+  /// SelfDecl - Decl for the implicit self parameter. This is lazily
+  /// constructed by createImplicitParams.
   ImplicitParamDecl *SelfDecl;
+  /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
+  /// constructed by createImplicitParams.
   ImplicitParamDecl *CmdDecl;
   
   ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
@@ -207,10 +211,14 @@
   }  
   void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
 
+  /// createImplicitParams - Used to lazily create the self and cmd
+  /// implict parameters. This must be called prior to using getSelfDecl()
+  /// or getCmdDecl(). The call is ignored if the implicit paramters
+  /// have already been created.
+  void createImplicitParams(ASTContext &Context);
+
   ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
-  void setSelfDecl(ImplicitParamDecl *decl) { SelfDecl = decl; }
   ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
-  void setCmdDecl(ImplicitParamDecl *decl) { CmdDecl = decl; }
   
   bool isInstance() const { return IsInstance; }
   bool isVariadic() const { return IsVariadic; }

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=55356&r1=55355&r2=55356&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Aug 26 01:07:48 2008
@@ -299,8 +299,6 @@
   
   /// Helpers for dealing with function parameters
   bool CheckParmsForFunctionDef(FunctionDecl *FD);
-  ImplicitParamDecl *CreateImplicitParameter(Scope *S, IdentifierInfo *Id, 
-                                       SourceLocation IdLoc, QualType Type);
   void CheckCXXDefaultArguments(FunctionDecl *FD);
   void CheckExtraCXXDefaultArguments(Declarator &D);
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=55356&r1=55355&r2=55356&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Aug 26 01:07:48 2008
@@ -493,21 +493,6 @@
   return HasInvalidParm;
 }
 
-/// CreateImplicitParameter - Creates an implicit function parameter
-/// in the scope S and with the given type. This routine is used, for
-/// example, to create the implicit "self" parameter in an Objective-C
-/// method.
-ImplicitParamDecl *
-Sema::CreateImplicitParameter(Scope *S, IdentifierInfo *Id, 
-                              SourceLocation IdLoc, QualType Type) {
-  ImplicitParamDecl *New = ImplicitParamDecl::Create(Context, CurContext,
-      IdLoc, Id, Type, 0);
-  if (Id)
-    PushOnScopeChains(New, S);
-
-  return New;
-}
-
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed.
 Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=55356&r1=55355&r2=55356&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Aug 26 01:07:48 2008
@@ -40,28 +40,12 @@
 
   // 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.
-  QualType selfTy;
-  if (MDecl->isInstance()) {
-    selfTy = Context.getObjCIdType();
-    if (ObjCInterfaceDecl *OID = MDecl->getClassInterface()) {
-      // There may be no interface context due to error in declaration of the 
-      // interface (which has been reported). Recover gracefully
-      selfTy = Context.getObjCInterfaceType(OID);
-      selfTy = Context.getPointerType(selfTy);
-    }
-  } else // we have a factory method.
-    selfTy = Context.getObjCClassType();
-  getCurMethodDecl()->setSelfDecl(CreateImplicitParameter(FnBodyScope,
-        PI.Ident, PI.IdentLoc, selfTy));
-  
-  PI.Ident = &Context.Idents.get("_cmd");
-  getCurMethodDecl()->setCmdDecl(CreateImplicitParameter(FnBodyScope,
-        PI.Ident, PI.IdentLoc, Context.getObjCSelType()));
+  MDecl->createImplicitParams(Context);
+  
+  PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
+  PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
 
   // Introduce all of the other parameters into this scope.
   for (unsigned i = 0, e = MDecl->getNumParams(); i != e; ++i) {





More information about the cfe-commits mailing list