[cfe-commits] r104614 - /cfe/trunk/lib/Frontend/RewriteObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Tue May 25 10:12:53 PDT 2010


Author: fjahanian
Date: Tue May 25 12:12:52 2010
New Revision: 104614

URL: http://llvm.org/viewvc/llvm-project?rev=104614&view=rev
Log:
Refactoring of block-pointer type rewrite.


Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=104614&r1=104613&r2=104614&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Tue May 25 12:12:52 2010
@@ -404,6 +404,18 @@
       return isa<BlockPointerType>(T);
     }
 
+    /// convertBlockPointerToFunctionPointer - Converts a block-pointer type
+    /// to a function pointer type and upon success, returns true; false
+    /// otherwise.
+    bool convertBlockPointerToFunctionPointer(QualType &T) {
+      if (isTopLevelBlockPointerType(T)) {
+        const BlockPointerType *BPT = T->getAs<BlockPointerType>();
+        T = Context->getPointerType(BPT->getPointeeType());
+        return true;
+      }
+      return false;
+    }
+    
     // FIXME: This predicate seems like it would be useful to add to ASTContext.
     bool isObjCType(QualType T) {
       if (!LangOpts.ObjC1 && !LangOpts.ObjC2)
@@ -1111,12 +1123,11 @@
       ResultStr += PDecl->getNameAsString();
     } else {
       std::string Name = PDecl->getNameAsString();
-      if (isTopLevelBlockPointerType(PDecl->getType())) {
-        // Make sure we convert "t (^)(...)" to "t (*)(...)".
-        const BlockPointerType *BPT = PDecl->getType()->getAs<BlockPointerType>();
-        Context->getPointerType(BPT->getPointeeType()).getAsStringInternal(Name,
-                                                        Context->PrintingPolicy);
-      } else
+      QualType QT = PDecl->getType();
+      // Make sure we convert "t (^)(...)" to "t (*)(...)".
+      if (convertBlockPointerToFunctionPointer(QT))
+        QT.getAsStringInternal(Name, Context->PrintingPolicy);
+      else
         PDecl->getType().getAsStringInternal(Name, Context->PrintingPolicy);
       ResultStr += Name;
     }
@@ -2947,10 +2958,7 @@
                                 ? Context->getObjCIdType()
                                 : ICE->getType();
       // Make sure we convert "type (^)(...)" to "type (*)(...)".
-      if (isTopLevelBlockPointerType(type)) {
-        const BlockPointerType *BPT = type->getAs<BlockPointerType>();
-        type = Context->getPointerType(BPT->getPointeeType());
-      }
+      (void)convertBlockPointerToFunctionPointer(type);
       userExpr = NoTypeInfoCStyleCastExpr(Context, type, CastExpr::CK_Unknown,
                                           userExpr);
     }
@@ -2988,18 +2996,12 @@
                      ? Context->getObjCIdType()
                      : (*PI)->getType();
       // Make sure we convert "t (^)(...)" to "t (*)(...)".
-      if (isTopLevelBlockPointerType(t)) {
-        const BlockPointerType *BPT = t->getAs<BlockPointerType>();
-        t = Context->getPointerType(BPT->getPointeeType());
-      }
+      (void)convertBlockPointerToFunctionPointer(t);
       ArgTypes.push_back(t);
     }
     returnType = OMD->getResultType()->isObjCQualifiedIdType()
                    ? Context->getObjCIdType() : OMD->getResultType();
-    if (isTopLevelBlockPointerType(returnType)) {
-      const BlockPointerType *BPT = returnType->getAs<BlockPointerType>();
-      returnType = Context->getPointerType(BPT->getPointeeType());
-    }
+    (void)convertBlockPointerToFunctionPointer(returnType);
   } else {
     returnType = Context->getObjCIdType();
   }
@@ -4120,11 +4122,8 @@
       if (AI != BD->param_begin()) S += ", ";
       ParamStr = (*AI)->getNameAsString();
       QualType QT = (*AI)->getType();
-      if (isTopLevelBlockPointerType(QT)) {
-        const BlockPointerType *BPT = QT->getAs<BlockPointerType>();
-        Context->getPointerType(BPT->getPointeeType()).
-        getAsStringInternal(ParamStr, Context->PrintingPolicy);
-      }
+      if (convertBlockPointerToFunctionPointer(QT))
+        QT.getAsStringInternal(ParamStr, Context->PrintingPolicy);
       else
         QT.getAsStringInternal(ParamStr, Context->PrintingPolicy);      
       S += ParamStr;
@@ -4556,24 +4555,16 @@
   // FTP will be null for closures that don't take arguments.
   // Generate a funky cast.
   llvm::SmallVector<QualType, 8> ArgTypes;
-  bool HasBlockType = false;
   QualType Res = FT->getResultType();
-  if (isTopLevelBlockPointerType(Res)) {
-    const BlockPointerType *BPT = Res->getAs<BlockPointerType>();
-    Res = Context->getPointerType(BPT->getPointeeType());
-    HasBlockType = true;
-  }
+  bool HasBlockType = convertBlockPointerToFunctionPointer(Res);
   
   if (FTP) {
     for (FunctionProtoType::arg_type_iterator I = FTP->arg_type_begin(),
          E = FTP->arg_type_end(); I && (I != E); ++I) {
       QualType t = *I;
       // Make sure we convert "t (^)(...)" to "t (*)(...)".
-      if (isTopLevelBlockPointerType(t)) {
-        const BlockPointerType *BPT = t->getAs<BlockPointerType>();
-        t = Context->getPointerType(BPT->getPointeeType());
+      if (convertBlockPointerToFunctionPointer(t))
         HasBlockType = true;
-      }
       ArgTypes.push_back(t);
     }
   }
@@ -4644,10 +4635,7 @@
          E = FTP->arg_type_end(); I && (I != E); ++I) {
       QualType t = *I;
       // Make sure we convert "t (^)(...)" to "t (*)(...)".
-      if (isTopLevelBlockPointerType(t)) {
-        const BlockPointerType *BPT = t->getAs<BlockPointerType>();
-        t = Context->getPointerType(BPT->getPointeeType());
-      }
+      (void)convertBlockPointerToFunctionPointer(t);
       ArgTypes.push_back(t);
     }
   }





More information about the cfe-commits mailing list