[cfe-commits] r57350 - /cfe/trunk/Driver/RewriteBlocks.cpp

Steve Naroff snaroff at apple.com
Fri Oct 10 08:33:35 PDT 2008


Author: snaroff
Date: Fri Oct 10 10:33:34 2008
New Revision: 57350

URL: http://llvm.org/viewvc/llvm-project?rev=57350&view=rev
Log:
Fix/simplify RewriteBlocks::RewriteBlockPointerFunctionArgs().

This completes the fix for <rdar://problem/6272905> clang block rewriter: parameter to function not imported into block?.

Modified:
    cfe/trunk/Driver/RewriteBlocks.cpp

Modified: cfe/trunk/Driver/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteBlocks.cpp?rev=57350&r1=57349&r2=57350&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteBlocks.cpp (original)
+++ cfe/trunk/Driver/RewriteBlocks.cpp Fri Oct 10 10:33:34 2008
@@ -740,7 +740,7 @@
 
 void RewriteBlocks::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) {
   SourceLocation DeclLoc = FD->getLocation();
-  unsigned parenCount = 0, nArgs = 0;
+  unsigned parenCount = 0;
   
   // We have 1 or more arguments that have closure pointers.
   const char *startBuf = SM->getCharacterData(DeclLoc);
@@ -750,63 +750,23 @@
   
   parenCount++;
   // advance the location to startArgList.
-  DeclLoc = DeclLoc.getFileLocWithOffset(startArgList-startBuf+1);
+  DeclLoc = DeclLoc.getFileLocWithOffset(startArgList-startBuf);
   assert((DeclLoc.isValid()) && "Invalid DeclLoc");
   
-  const char *topLevelCommaCursor = 0;
   const char *argPtr = startArgList;
-  bool scannedBlockDecl = false;
-  std::string Tag = "struct __block_impl *";
   
   while (*argPtr++ && parenCount) {
     switch (*argPtr) {
       case '^': 
-        scannedBlockDecl = true; 
+        // Replace the '^' with '*'.
+        DeclLoc = DeclLoc.getFileLocWithOffset(argPtr-startArgList);
+        ReplaceText(DeclLoc, 1, "*", 1);
         break;
       case '(': 
         parenCount++; 
         break;
       case ')': 
         parenCount--;
-        if (parenCount == 0) {
-          if (scannedBlockDecl) {
-            // If we are rewriting a definition, don't forget the arg name.
-            if (FD->getBody())
-              Tag += FD->getParamDecl(nArgs)->getName();
-            // The last argument is a closure pointer decl, rewrite it!
-            if (topLevelCommaCursor)
-              ReplaceText(DeclLoc, argPtr-topLevelCommaCursor-2, Tag.c_str(), Tag.size());
-            else
-              ReplaceText(DeclLoc, argPtr-startArgList-1, Tag.c_str(), Tag.size());
-            scannedBlockDecl = false; // reset.
-          }
-          nArgs++;
-        }
-        break;
-      case ',':
-        if (parenCount == 1) {
-          // Make sure the function takes more than one argument.
-          assert((FD->getNumParams() > 1) && "Rewriter fuzzy parser confused");
-          if (scannedBlockDecl) {
-            // If we are rewriting a definition, don't forget the arg name.
-            if (FD->getBody())
-              Tag += FD->getParamDecl(nArgs)->getName();
-            // The current argument is a closure pointer decl, rewrite it!
-            if (topLevelCommaCursor)
-              ReplaceText(DeclLoc, argPtr-topLevelCommaCursor-1, Tag.c_str(), Tag.size());
-            else
-              ReplaceText(DeclLoc, argPtr-startArgList-1, Tag.c_str(), Tag.size());
-            scannedBlockDecl = false;
-          }
-          nArgs++;
-          // advance the location to topLevelCommaCursor.
-          if (topLevelCommaCursor)
-            DeclLoc = DeclLoc.getFileLocWithOffset(argPtr-topLevelCommaCursor);
-          else
-            DeclLoc = DeclLoc.getFileLocWithOffset(argPtr-startArgList+1);
-          topLevelCommaCursor = argPtr;
-          assert((DeclLoc.isValid()) && "Invalid DeclLoc");
-        }
         break;
     }
   }





More information about the cfe-commits mailing list