[cfe-commits] r150406 - /cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Mon Feb 13 10:57:49 PST 2012


Author: fjahanian
Date: Mon Feb 13 12:57:49 2012
New Revision: 150406

URL: http://llvm.org/viewvc/llvm-project?rev=150406&view=rev
Log:
objective-c translator: more rewriting of ivar types
into a c-type which closely matches the objective-c type.


Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=150406&r1=150405&r2=150406&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Mon Feb 13 12:57:49 2012
@@ -428,6 +428,8 @@
       return false;
     }
     
+    bool convertObjCTypeToCStyleType(QualType &T);
+    
     bool needToScanForQualifiers(QualType T);
     QualType getSuperStructType();
     QualType getConstantStringStructType();
@@ -3177,8 +3179,8 @@
     std::string Name = IvarDecl->getNameAsString();
 
     Result += "\t";
-    convertToUnqualifiedObjCType(Type);
-    convertBlockPointerToFunctionPointer(Type);
+    convertObjCTypeToCStyleType(Type);
+    
     Type.getAsStringInternal(Name, Context->getPrintingPolicy());
     Result += Name;
     if (IvarDecl->isBitField()) {
@@ -3697,6 +3699,27 @@
   return;
 }
 
+/// convertObjCTypeToCStyleType - This routine converts such objc types
+/// as qualified objects, and blocks to their closest c/c++ types that
+/// it can. It returns true if input type was modified.
+bool RewriteModernObjC::convertObjCTypeToCStyleType(QualType &T) {
+  QualType oldT = T;
+  convertBlockPointerToFunctionPointer(T);
+  if (T->isFunctionPointerType()) {
+    QualType PointeeTy;
+    if (const PointerType* PT = T->getAs<PointerType>()) {
+      PointeeTy = PT->getPointeeType();
+      if (const FunctionType *FT = PointeeTy->getAs<FunctionType>()) {
+        T = convertFunctionTypeOfBlocks(FT);
+        T = Context->getPointerType(T);
+      }
+    }
+  }
+  
+  convertToUnqualifiedObjCType(T);
+  return T != oldT;
+}
+
 /// convertFunctionTypeOfBlocks - This routine converts a function type
 /// whose result type may be a block pointer or whose argument type(s)
 /// might be block pointers to an equivalent function type replacing
@@ -3707,22 +3730,20 @@
   // Generate a funky cast.
   SmallVector<QualType, 8> ArgTypes;
   QualType Res = FT->getResultType();
-  bool HasBlockType = convertBlockPointerToFunctionPointer(Res);
+  bool modified = convertObjCTypeToCStyleType(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 (convertBlockPointerToFunctionPointer(t))
-        HasBlockType = true;
+      if (convertObjCTypeToCStyleType(t))
+        modified = true;
       ArgTypes.push_back(t);
     }
   }
   QualType FuncType;
-  // FIXME. Does this work if block takes no argument but has a return type
-  // which is of block type?
-  if (HasBlockType)
+  if (modified)
     FuncType = getSimpleFunctionType(Res, &ArgTypes[0], ArgTypes.size());
   else FuncType = QualType(FT, 0);
   return FuncType;





More information about the cfe-commits mailing list