[llvm-branch-commits] [cfe-branch] r119235 - in /cfe/branches/Apple/whitney: lib/Rewrite/RewriteObjC.cpp test/Rewriter/rewrite-block-pointer.mm

Daniel Dunbar daniel at zuster.org
Mon Nov 15 13:45:07 PST 2010


Author: ddunbar
Date: Mon Nov 15 15:45:07 2010
New Revision: 119235

URL: http://llvm.org/viewvc/llvm-project?rev=119235&view=rev
Log:
Merge r118205:
--
Author: Fariborz Jahanian <fjahanian at apple.com>
Date:   Wed Nov 3 23:29:24 2010 +0000

    Patch to rewrite objc qualified types which occur in
    block pointer type arguments. Partial fix for
    // rdar: //8608902

Modified:
    cfe/branches/Apple/whitney/lib/Rewrite/RewriteObjC.cpp
    cfe/branches/Apple/whitney/test/Rewriter/rewrite-block-pointer.mm

Modified: cfe/branches/Apple/whitney/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Rewrite/RewriteObjC.cpp?rev=119235&r1=119234&r2=119235&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Rewrite/RewriteObjC.cpp Mon Nov 15 15:45:07 2010
@@ -423,6 +423,7 @@
       return false;
     }
     bool PointerTypeTakesAnyBlockArguments(QualType QT);
+    bool PointerTypeTakesAnyObjCQualifiedType(QualType QT);
     void GetExtentOfArgList(const char *Name, const char *&LParen,
                             const char *&RParen);
     void RewriteCastExpr(CStyleCastExpr *CE);
@@ -4888,6 +4889,26 @@
   return false;
 }
 
+bool RewriteObjC::PointerTypeTakesAnyObjCQualifiedType(QualType QT) {
+  const FunctionProtoType *FTP;
+  const PointerType *PT = QT->getAs<PointerType>();
+  if (PT) {
+    FTP = PT->getPointeeType()->getAs<FunctionProtoType>();
+  } else {
+    const BlockPointerType *BPT = QT->getAs<BlockPointerType>();
+    assert(BPT && "BlockPointerTypeTakeAnyBlockArguments(): not a block pointer type");
+    FTP = BPT->getPointeeType()->getAs<FunctionProtoType>();
+  }
+  if (FTP) {
+    for (FunctionProtoType::arg_type_iterator I = FTP->arg_type_begin(),
+         E = FTP->arg_type_end(); I != E; ++I)
+      if ((*I)->isObjCQualifiedIdType() ||
+          (*I)->isObjCQualifiedInterfaceType())
+        return true;
+  }
+  return false;
+}
+
 void RewriteObjC::GetExtentOfArgList(const char *Name, const char *&LParen,
                                      const char *&RParen) {
   const char *argPtr = strchr(Name, '(');
@@ -4931,28 +4952,57 @@
   // scan backward (from the decl location) for the end of the previous decl.
   while (*startBuf != '^' && *startBuf != ';' && startBuf != MainFileStart)
     startBuf--;
-
+  SourceLocation Start = DeclLoc.getFileLocWithOffset(startBuf-endBuf);
+  std::string buf;
+  unsigned OrigLength=0;
   // *startBuf != '^' if we are dealing with a pointer to function that
   // may take block argument types (which will be handled below).
   if (*startBuf == '^') {
     // Replace the '^' with '*', computing a negative offset.
-    DeclLoc = DeclLoc.getFileLocWithOffset(startBuf-endBuf);
-    ReplaceText(DeclLoc, 1, "*");
+    buf = '*';
+    startBuf++;
+    OrigLength++;
   }
-  if (PointerTypeTakesAnyBlockArguments(DeclT)) {
+  while (*startBuf != ')') {
+    buf += *startBuf;
+    startBuf++;
+    OrigLength++;
+  }
+  buf += ')';
+  OrigLength++;
+  
+  if (PointerTypeTakesAnyBlockArguments(DeclT) ||
+      PointerTypeTakesAnyObjCQualifiedType(DeclT)) {
     // Replace the '^' with '*' for arguments.
+    // Replace id<P> with id/*<>*/
     DeclLoc = ND->getLocation();
     startBuf = SM->getCharacterData(DeclLoc);
     const char *argListBegin, *argListEnd;
     GetExtentOfArgList(startBuf, argListBegin, argListEnd);
     while (argListBegin < argListEnd) {
-      if (*argListBegin == '^') {
-        SourceLocation CaretLoc = DeclLoc.getFileLocWithOffset(argListBegin-startBuf);
-        ReplaceText(CaretLoc, 1, "*");
+      if (*argListBegin == '^')
+        buf += '*';
+      else if (*argListBegin ==  '<') {
+        buf += "/*"; 
+        buf += *argListBegin++;
+        OrigLength++;;
+        while (*argListBegin != '>') {
+          buf += *argListBegin++;
+          OrigLength++;
+        }
+        buf += *argListBegin;
+        buf += "*/";
       }
+      else
+        buf += *argListBegin;
       argListBegin++;
+      OrigLength++;
     }
+    buf += ')';
+    OrigLength++;
   }
+  ReplaceText(Start, OrigLength, buf);
+  
   return;
 }
 

Modified: cfe/branches/Apple/whitney/test/Rewriter/rewrite-block-pointer.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Rewriter/rewrite-block-pointer.mm?rev=119235&r1=119234&r2=119235&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Rewriter/rewrite-block-pointer.mm (original)
+++ cfe/branches/Apple/whitney/test/Rewriter/rewrite-block-pointer.mm Mon Nov 15 15:45:07 2010
@@ -58,3 +58,23 @@
 
 @end
 
+// rdar: //8608902
+ at protocol CoreDAVAccountInfoProvider;
+ at protocol CodeProvider;
+typedef void (^BDVDiscoveryCompletionHandler)(int success, id<CoreDAVAccountInfoProvider> discoveredInfo);
+typedef void (^BDVDiscoveryCompletion)(id<CodeProvider> codeInfo, int success, id<CoreDAVAccountInfoProvider> discoveredInfo);
+typedef void (^BDVDiscovery)(int success);
+typedef void (^BDVDisc)(id<CoreDAVAccountInfoProvider> discoveredInfo, id<CodeProvider> codeInfo, 
+                        int success, id<CoreDAVAccountInfoProvider, CodeProvider> Info);
+typedef void (^BLOCK)(id, id<CoreDAVAccountInfoProvider>, id<CodeProvider> codeInfo);
+typedef void (^EMPTY_BLOCK)();
+typedef void (^  BDVDiscoveryCompletion1  )(id<CodeProvider> codeInfo, int success, id<CoreDAVAccountInfoProvider> discoveredInfo);
+
+void (^BL)(void(^arg1)(), int i1, void(^arg)(int));
+
+typedef void (^iscoveryCompletionHandler)(void(^arg1)(), id<CoreDAVAccountInfoProvider> discoveredInfo);
+
+typedef void (^DVDisc)(id<CoreDAVAccountInfoProvider> discoveredInfo, id<CodeProvider> codeInfo,
+			void(^arg1)(), int i1, void(^arg)(id<CoreDAVAccountInfoProvider>),
+                        int success, id<CoreDAVAccountInfoProvider, CodeProvider> Info);
+





More information about the llvm-branch-commits mailing list