[cfe-commits] r44006 - in /cfe/trunk/Sema: Sema.h SemaDecl.cpp SemaType.cpp

Steve Naroff snaroff at apple.com
Sun Nov 11 19:44:46 PST 2007


Author: snaroff
Date: Sun Nov 11 21:44:46 2007
New Revision: 44006

URL: http://llvm.org/viewvc/llvm-project?rev=44006&view=rev
Log:

Remove Sema::ObjcBuildMethodParameter().
Modify Sema::ParseParamDeclarator() to work for both ActOnStartOfFunctionDef() and ObjcActOnStartOfMethodDef().


Modified:
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaType.cpp

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Sun Nov 11 21:44:46 2007
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_AST_SEMA_H
 
 #include "clang/Parse/Action.h"
+#include "clang/Parse/DeclSpec.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -39,7 +40,6 @@
   class FunctionDecl;
   class QualType;
   struct LangOptions;
-  struct DeclaratorChunk;
   class Token;
   class IntegerLiteral;
   class ArrayType;
@@ -231,10 +231,8 @@
   void AddTopLevelDecl(Decl *current, Decl *last);
 
   /// More parsing and symbol table subroutines...
-  ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
-                                    Scope *FnBodyScope);
-  ParmVarDecl *ObjcBuildMethodParameter(ParmVarDecl *param, Scope *FnBodyScope);
-  
+  ParmVarDecl *ParseParamDeclarator(struct DeclaratorChunk::ParamInfo &PI, 
+                                    Scope *FnBodyScope);  
   ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, 
                                SourceLocation IdLoc, Scope *S);
   ScopedDecl *LookupInterfaceDecl(IdentifierInfo *II);

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Sun Nov 11 21:44:46 2007
@@ -840,10 +840,8 @@
 
 // Called from Sema::ParseStartOfFunctionDef().
 ParmVarDecl *
-Sema::ParseParamDeclarator(DeclaratorChunk &FTI, unsigned ArgNo,
-                           Scope *FnScope) {
-  const DeclaratorChunk::ParamInfo &PI = FTI.Fun.ArgInfo[ArgNo];
-
+Sema::ParseParamDeclarator(struct DeclaratorChunk::ParamInfo &PI, Scope *FnScope) 
+{
   IdentifierInfo *II = PI.Ident;
   // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
   // Can this happen for params?  We already checked that they don't conflict
@@ -894,57 +892,6 @@
   return New;
 }
 
-// Called from Sema::ObjcParseStartOfMethodDef().
-ParmVarDecl *
-Sema::ObjcBuildMethodParameter(ParmVarDecl *PI, Scope *FnScope) {
-  
-  IdentifierInfo *II = PI->getIdentifier();
-  
-  // FIXME: Handle storage class (auto, register). No declarator?
-  // TODO: Chain to previous parameter with the prevdeclarator chain?
-  
-  // Perform the default function/array conversion (C99 6.7.5.3p[7,8]).
-  // Doing the promotion here has a win and a loss. The win is the type for
-  // both Decl's and DeclRefExpr's will match (a convenient invariant for the
-  // code generator). The loss is the orginal type isn't preserved. For example:
-  //
-  // void func(int parmvardecl[5]) { // convert "int [5]" to "int *"
-  //    int blockvardecl[5];
-  //    sizeof(parmvardecl);  // size == 4
-  //    sizeof(blockvardecl); // size == 20
-  // }
-  //
-  // For expressions, all implicit conversions are captured using the
-  // ImplicitCastExpr AST node (we have no such mechanism for Decl's).
-  //
-  // FIXME: If a source translation tool needs to see the original type, then
-  // we need to consider storing both types (in ParmVarDecl)...
-  // 
-  QualType parmDeclType = PI->getType();
-  if (const ArrayType *AT = parmDeclType->getAsArrayType())
-    parmDeclType = Context.getPointerType(AT->getElementType());
-  else if (parmDeclType->isFunctionType())
-    parmDeclType = Context.getPointerType(parmDeclType);
-  
-  ParmVarDecl *New = new ParmVarDecl(PI->getLocation(), II, parmDeclType, 
-                                     VarDecl::None, 0);
-  // FIXME: need to check for invalid type.
-  /**
-  if (PI.InvalidType)
-    New->setInvalidDecl();
-   */
-  
-  // If this has an identifier, add it to the scope stack.
-  if (II) {
-    New->setNext(II->getFETokenInfo<ScopedDecl>());
-    II->setFETokenInfo(New);
-    FnScope->AddDecl(New);
-  }
-  
-  return New;
-}
-
-
 Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
   assert(CurFunctionDecl == 0 && "Function parsing confused");
   assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
@@ -987,8 +934,10 @@
       FTI.ArgInfo[0].TypeInfo == Context.VoidTy.getAsOpaquePtr()) {
     // empty arg list, don't push any params.
   } else {
-    for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
-      Params.push_back(ParseParamDeclarator(D.getTypeObject(0), i,FnBodyScope));
+    for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
+      Params.push_back(ParseParamDeclarator(D.getTypeObject(0).Fun.ArgInfo[i],
+                                            FnBodyScope));
+    }
   }
   
   FD->setParams(&Params[0], Params.size());
@@ -1047,30 +996,32 @@
   
   // Create Decl objects for each parameter, adding them to the FunctionDecl.
   llvm::SmallVector<ParmVarDecl*, 16> Params;
-  ParmVarDecl *PDecl;
+  struct DeclaratorChunk::ParamInfo PI;
+
+  PI.Ident = &Context.Idents.get("self");
+  PI.IdentLoc = SourceLocation(/*FIXME*/);
+  
   // Insert the invisible arguments!
   if (MDecl->isInstance()) {
     QualType selfTy = Context.getObjcInterfaceType(MDecl->getClassInterface());
     selfTy = Context.getPointerType(selfTy);
-    PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), 
-                            &Context.Idents.get("self"),
-                            selfTy,
-                            VarDecl::None, 0);
-  }
-  else
-    PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), 
-                            &Context.Idents.get("self"),
-                            Context.getObjcIdType(), VarDecl::None, 0);
-  Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope));
-  PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), 
-                          &Context.Idents.get("_cmd"),
-                          Context.getObjcSelType(), VarDecl::None, 0);
-  Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope));
+    PI.TypeInfo = selfTy.getAsOpaquePtr();
+  } else
+    PI.TypeInfo = Context.getObjcIdType().getAsOpaquePtr();
+    
+  Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
+  
+  PI.Ident = &Context.Idents.get("_cmd");
+  PI.IdentLoc = SourceLocation(/*FIXME*/);
+  PI.TypeInfo = Context.getObjcSelType().getAsOpaquePtr();
+  Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
   
-    
   for (int i = 0; i <  MDecl->getNumParams(); i++) {
-    PDecl = MDecl->getParamDecl(i);
-    Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope));
+    ParmVarDecl *PDecl = MDecl->getParamDecl(i);
+    PI.Ident = PDecl->getIdentifier();
+    PI.IdentLoc = PDecl->getLocation();
+    PI.TypeInfo = PDecl->getType().getAsOpaquePtr();
+    Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
   }
 
   FD->setParams(&Params[0], Params.size());

Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=44006&r1=44005&r2=44006&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Sun Nov 11 21:44:46 2007
@@ -348,7 +348,7 @@
     assert(!ArgTy.isNull() && "Couldn't parse type?");
     // Perform the default function/array conversion (C99 6.7.5.3p[7,8]).
     // This matches the conversion that is done in 
-    // Sema::ObjcBuildMethodParameter(). 
+    // Sema::ParseParamDeclarator(). 
     if (const ArrayType *AT = ArgTy->getAsArrayType())
       ArgTy = Context.getPointerType(AT->getElementType());
     else if (ArgTy->isFunctionType())





More information about the cfe-commits mailing list