]> granicus.if.org Git - clang/commitdiff
remove some more methods from objc decls, using the iterator
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 18:43:26 +0000 (18:43 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 18:43:26 +0000 (18:43 +0000)
interfaces more consistently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65138 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Driver/RewriteObjC.cpp
include/clang/AST/DeclObjC.h
lib/AST/ASTContext.cpp
lib/CodeGen/CGObjC.cpp
lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExprObjC.cpp
lib/Sema/SemaType.cpp

index f3bfc0b4345a3bfa60204023ba20f6ffcefbdb05..6ad48c4357fad2d34f2d11f9739f1bd19db72e13 100644 (file)
@@ -300,17 +300,17 @@ void DeclPrinter::PrintObjCMethodDecl(ObjCMethodDecl *OMD) {
   
   std::string name = OMD->getSelector().getAsString();
   std::string::size_type pos, lastPos = 0;
-  for (unsigned i = 0, e = OMD->getNumParams(); i != e; ++i) {
-    ParmVarDecl *PDecl = OMD->getParamDecl(i);
+  for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
+       E = OMD->param_end(); PI != E; ++PI) {
     // FIXME: selector is missing here!    
     pos = name.find_first_of(":", lastPos);
     Out << " " << name.substr(lastPos, pos - lastPos);
-    Out << ":(" << PDecl->getType().getAsString() << ")"
-        << PDecl->getNameAsString(); 
+    Out << ":(" << (*PI)->getType().getAsString() << ")"
+        << (*PI)->getNameAsString(); 
     lastPos = pos + 1;
   }
     
-  if (OMD->getNumParams() == 0)
+  if (OMD->param_begin() == OMD->param_end())
     Out << " " << name;
     
   if (OMD->isVariadic())
index f5659d6071e583e525cc66c8596134feb2e5d031..610e1c5106e3d19529e3f24e34772b2fe94205e1 100644 (file)
@@ -930,8 +930,9 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
   ResultStr += " _cmd";
   
   // Method arguments.
-  for (unsigned i = 0; i < OMD->getNumParams(); i++) {
-    ParmVarDecl *PDecl = OMD->getParamDecl(i);
+  for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
+       E = OMD->param_end(); PI != E; ++PI) {
+    ParmVarDecl *PDecl = *PI;
     ResultStr += ", ";
     if (PDecl->getType()->isObjCQualifiedIdType()) {
       ResultStr += "id ";
@@ -2253,8 +2254,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) {
   FunctionDecl *MsgSendFlavor = MsgSendFunctionDecl;
   // May need to use objc_msgSend_stret() as well.
   FunctionDecl *MsgSendStretFlavor = 0;
-  if (ObjCMethodDecl *mDecl = Exp->getMethodDecl()) {
-    QualType resultType = mDecl->getResultType();
+  if (ObjCMethodDecl *OMD = Exp->getMethodDecl()) {
+    QualType resultType = OMD->getResultType();
     if (resultType->isStructureType() || resultType->isUnionType())
       MsgSendStretFlavor = MsgSendStretFunctionDecl;
     else if (resultType->isRealFloatingType())
@@ -2473,12 +2474,13 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) {
   else
     ArgTypes.push_back(Context->getObjCIdType());
   ArgTypes.push_back(Context->getObjCSelType());
-  if (ObjCMethodDecl *mDecl = Exp->getMethodDecl()) {
+  if (ObjCMethodDecl *OMD = Exp->getMethodDecl()) {
     // Push any user argument types.
-    for (unsigned i = 0; i < mDecl->getNumParams(); i++) {
-      QualType t = mDecl->getParamDecl(i)->getType()->isObjCQualifiedIdType()
+    for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
+         E = OMD->param_end(); PI != E; ++PI) {
+      QualType t = (*PI)->getType()->isObjCQualifiedIdType()
                      ? Context->getObjCIdType() 
-                     : mDecl->getParamDecl(i)->getType();
+                     : (*PI)->getType();
       // Make sure we convert "t (^)(...)" to "t (*)(...)".
       if (isTopLevelBlockPointerType(t)) {
         const BlockPointerType *BPT = t->getAsBlockPointerType();
@@ -2486,8 +2488,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) {
       }
       ArgTypes.push_back(t);
     }
-    returnType = mDecl->getResultType()->isObjCQualifiedIdType()
-                   ? Context->getObjCIdType() : mDecl->getResultType();
+    returnType = OMD->getResultType()->isObjCQualifiedIdType()
+                   ? Context->getObjCIdType() : OMD->getResultType();
   } else {
     returnType = Context->getObjCIdType();
   }
@@ -3298,7 +3300,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
   // Set 'ivars' field for root class to 0. ObjC1 runtime does not use it.
   // 'info' field is initialized to CLS_META(2) for metaclass
   Result += ", 0,2, sizeof(struct _objc_class), 0";
-  if (IDecl->getNumClassMethods() > 0) {
+  if (IDecl->classmeth_begin() != IDecl->classmeth_end()) {
     Result += "\n\t, (struct _objc_method_list *)&_OBJC_CLASS_METHODS_";
     Result += IDecl->getNameAsString();
     Result += "\n"; 
@@ -3351,7 +3353,7 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
   }
   else
     Result += ",0";
-  if (IDecl->getNumInstanceMethods() > 0) {
+  if (IDecl->instmeth_begin() != IDecl->instmeth_end()) {
     Result += ", (struct _objc_method_list *)&_OBJC_INSTANCE_METHODS_";
     Result += CDecl->getNameAsString();
     Result += ", 0\n\t"; 
index 346514db505e705182a298e8d030360faeb99165..08f6ae9f9831158789489a0126856381a2ead42a 100644 (file)
@@ -198,11 +198,7 @@ public:
   typedef ObjCList<ParmVarDecl>::iterator param_iterator;
   param_iterator param_begin() const { return ParamInfo.begin(); }
   param_iterator param_end() const { return ParamInfo.end(); }
-  
-  unsigned getNumParams() const { return ParamInfo.size(); }
-  ParmVarDecl *getParamDecl(unsigned i) const {
-    return ParamInfo[i];
-  }  
+
   void setMethodParams(ParmVarDecl *const *NewParamInfo, unsigned NumParams) {
     ParamInfo.set(NewParamInfo, NumParams);
   }
@@ -814,10 +810,6 @@ public:
   ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
   ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
   
-  unsigned getNumPropertyImplementations() const
-  { return PropertyImplementations.size(); }
-  
-  
   typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator
     propimpl_iterator;
   propimpl_iterator propimpl_begin() const { 
@@ -959,12 +951,6 @@ public:
   
   void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
   
-  unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
-  unsigned getNumClassMethods() const { return ClassMethods.size(); }
-  
-  unsigned getNumPropertyImplementations() const 
-    { return PropertyImplementations.size(); }
-
   typedef llvm::SmallVector<ObjCMethodDecl*, 32>::const_iterator
        instmeth_iterator;
   instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); }
index b8c74e13965c4025111410c0f5be5fc150c7adb8..9ed62510894a9294089b064597a8c49d7b5ab36e 100644 (file)
@@ -1858,10 +1858,10 @@ void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
   // The first two arguments (self and _cmd) are pointers; account for
   // their size.
   int ParmOffset = 2 * PtrSize;
-  int NumOfParams = Decl->getNumParams();
-  for (int i = 0; i < NumOfParams; i++) {
-    QualType PType = Decl->getParamDecl(i)->getType();
-    int sz = getObjCEncodingTypeSize (PType);
+  for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
+       E = Decl->param_end(); PI != E; ++PI) {
+    QualType PType = (*PI)->getType();
+    int sz = getObjCEncodingTypeSize(PType);
     assert (sz > 0 && "getObjCEncodingForMethodDecl - Incomplete param type");
     ParmOffset += sz;
   }
@@ -1871,8 +1871,9 @@ void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
   
   // Argument types.
   ParmOffset = 2 * PtrSize;
-  for (int i = 0; i < NumOfParams; i++) {
-    ParmVarDecl *PVDecl = Decl->getParamDecl(i);
+  for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
+       E = Decl->param_end(); PI != E; ++PI) {
+    ParmVarDecl *PVDecl = *PI;
     QualType PType = PVDecl->getOriginalType(); 
     if (const ArrayType *AT =
           dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) 
index 9adcc358f86f8aac65b0ca495f25c43a9c9c46e8..dd0292ea4db0330f76f3676853865371d0528fa2 100644 (file)
@@ -115,10 +115,9 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
   Args.push_back(std::make_pair(OMD->getCmdDecl(),
                                 OMD->getCmdDecl()->getType()));
 
-  for (unsigned i = 0, e = OMD->getNumParams(); i != e; ++i) {
-    ParmVarDecl *IPD = OMD->getParamDecl(i);
-    Args.push_back(std::make_pair(IPD, IPD->getType()));
-  }
+  for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
+       E = OMD->param_end(); PI != E; ++PI)
+    Args.push_back(std::make_pair(*PI, (*PI)->getType()));
 
   StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocEnd());
 }
@@ -254,7 +253,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
     llvm::Value *SelfAsId = 
       Builder.CreateBitCast(LoadObjCSelf(), Types.ConvertType(IdTy));
     llvm::Value *Offset = EmitIvarOffset(IMP->getClassInterface(), Ivar);
-    llvm::Value *Arg = LocalDeclMap[OMD->getParamDecl(0)];
+    llvm::Value *Arg = LocalDeclMap[*OMD->param_begin()];
     llvm::Value *ArgAsId = 
       Builder.CreateBitCast(Builder.CreateLoad(Arg, "arg"),
                             Types.ConvertType(IdTy));
@@ -280,7 +279,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
     ValueDecl *Self = OMD->getSelfDecl();
     ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl();
     DeclRefExpr Base(Self, Self->getType(), Loc);
-    ParmVarDecl *ArgDecl = OMD->getParamDecl(0);
+    ParmVarDecl *ArgDecl = *OMD->param_begin();
     DeclRefExpr Arg(ArgDecl, ArgDecl->getType(), Loc);
     ObjCInterfaceDecl *OI = IMP->getClassInterface();
     ObjCIvarRefExpr IvarRef(Ivar, Ivar->getType(), Loc, &Base,
index 2ceea33d07d976c08605d1dff3a6ca98122a1d13..ce38edd7c5fe7306e1a72fdc0d31c4400395982a 100644 (file)
@@ -67,21 +67,16 @@ static bool hasFunctionProto(Decl *d) {
 /// arguments. It is an error to call this on a K&R function (use
 /// hasFunctionProto first).
 static unsigned getFunctionOrMethodNumArgs(Decl *d) {
-  if (const FunctionType *FnTy = getFunctionType(d)) {
-    const FunctionTypeProto *proto = cast<FunctionTypeProto>(FnTy);
-    return proto->getNumArgs();
-  } else {
-    return cast<ObjCMethodDecl>(d)->getNumParams();
-  }
+  if (const FunctionType *FnTy = getFunctionType(d))
+    return cast<FunctionTypeProto>(FnTy)->getNumArgs();
+  return cast<ObjCMethodDecl>(d)->param_size();
 }
 
 static QualType getFunctionOrMethodArgType(Decl *d, unsigned Idx) {
-  if (const FunctionType *FnTy = getFunctionType(d)) {
-    const FunctionTypeProto *proto = cast<FunctionTypeProto>(FnTy);
-    return proto->getArgType(Idx);
-  } else {
-    return cast<ObjCMethodDecl>(d)->getParamDecl(Idx)->getType();
-  }
+  if (const FunctionType *FnTy = getFunctionType(d))
+    return cast<FunctionTypeProto>(FnTy)->getArgType(Idx);
+  
+  return cast<ObjCMethodDecl>(d)->param_begin()[Idx]->getType();
 }
 
 static bool isFunctionOrMethodVariadic(Decl *d) {
index b8906377671ab0d0fae2f2917cc50c503940bdc8..65cd4b4e5485c463d77bb6f5d02ed3f9b2e03375 100644 (file)
@@ -46,11 +46,10 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
   PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
 
   // Introduce all of the other parameters into this scope.
-  for (unsigned i = 0, e = MDecl->getNumParams(); i != e; ++i) {
-    ParmVarDecl *PDecl = MDecl->getParamDecl(i);
-    if (PDecl->getIdentifier())
-      PushOnScopeChains(PDecl, FnBodyScope);
-  }
+  for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(),
+       E = MDecl->param_end(); PI != E; ++PI)
+    if ((*PI)->getIdentifier())
+      PushOnScopeChains(*PI, FnBodyScope);
 }
 
 Sema::DeclTy *Sema::
@@ -992,9 +991,15 @@ bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
     if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
       return false;
   }
-  for (unsigned i = 0, e = Method->getNumParams(); i != e; ++i) {
-    T1 = Context.getCanonicalType(Method->getParamDecl(i)->getType());
-    T2 = Context.getCanonicalType(PrevMethod->getParamDecl(i)->getType());
+  
+  ObjCMethodDecl::param_iterator ParamI = Method->param_begin(),
+       E = Method->param_end();
+  ObjCMethodDecl::param_iterator PrevI = PrevMethod->param_begin();
+  
+  for (; ParamI != E; ++ParamI, ++PrevI) {
+    assert(PrevI != PrevMethod->param_end() && "Param mismatch");
+    T1 = Context.getCanonicalType((*ParamI)->getType());
+    T2 = Context.getCanonicalType((*PrevI)->getType());
     if (T1 != T2) {
       // The result types are different.
       if (!matchBasedOnSizeAndAlignment)
@@ -1103,8 +1108,8 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
     if (Context.getCanonicalType(SetterMethod->getResultType()) 
         != Context.VoidTy)
       Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
-    if (SetterMethod->getNumParams() != 1 ||
-        (SetterMethod->getParamDecl(0)->getType() != property->getType())) {
+    if (SetterMethod->param_size() != 1 ||
+        ((*SetterMethod->param_begin())->getType() != property->getType())) {
       Diag(property->getLocation(), 
            diag::err_accessor_property_type_mismatch) 
         << property->getDeclName()
index 25b41c64decce46c3d1e8b886c5d009d46214cdb..19dc3821c763ce167955ef676222db4f9c109e1b 100644 (file)
@@ -154,7 +154,7 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
     Expr *argExpr = Args[i];
     assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
     
-    QualType lhsType = Method->getParamDecl(i)->getType();
+    QualType lhsType = Method->param_begin()[i]->getType();
     QualType rhsType = argExpr->getType();
 
     // If necessary, apply function/array conversion. C99 6.7.5.3p[7,8]. 
index 02ba807758bc3741ec35241db81351ed7744cafe..252cd2d533cee1c63a89d120ae322565837cf30f 100644 (file)
@@ -662,7 +662,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip) {
 /// ObjCGetTypeForMethodDefinition - Builds the type for a method definition
 /// declarator
 QualType Sema::ObjCGetTypeForMethodDefinition(DeclTy *D) {
-  ObjCMethodDecl *MDecl = dyn_cast<ObjCMethodDecl>(static_cast<Decl *>(D));
+  ObjCMethodDecl *MDecl = cast<ObjCMethodDecl>(static_cast<Decl *>(D));
   QualType T = MDecl->getResultType();
   llvm::SmallVector<QualType, 16> ArgTys;
   
@@ -671,14 +671,13 @@ QualType Sema::ObjCGetTypeForMethodDefinition(DeclTy *D) {
     QualType selfTy = Context.getObjCInterfaceType(MDecl->getClassInterface());
     selfTy = Context.getPointerType(selfTy);
     ArgTys.push_back(selfTy);
-  }
-  else
+  } else
     ArgTys.push_back(Context.getObjCIdType());
   ArgTys.push_back(Context.getObjCSelType());
       
-  for (int i = 0, e = MDecl->getNumParams(); i != e; ++i) {
-    ParmVarDecl *PDecl = MDecl->getParamDecl(i);
-    QualType ArgTy = PDecl->getType();
+  for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(),
+       E = MDecl->param_end(); PI != E; ++PI) {
+    QualType ArgTy = (*PI)->getType();
     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