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

Steve Naroff snaroff at apple.com
Sat Oct 4 17:06:12 PDT 2008


Author: snaroff
Date: Sat Oct  4 19:06:12 2008
New Revision: 57083

URL: http://llvm.org/viewvc/llvm-project?rev=57083&view=rev
Log:
Create a function, eliminating some redundancy between SynthesizeBlockInitExpr() and SynthesizeBlockLiterals().

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=57083&r1=57082&r2=57083&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteBlocks.cpp (original)
+++ cfe/trunk/Driver/RewriteBlocks.cpp Sat Oct  4 19:06:12 2008
@@ -110,6 +110,7 @@
   void SynthesizeBlockLiterals(SourceLocation FunLocStart,
                                  const char *FunName);
   
+  void CollectBlockDeclRefInfo(BlockExpr *Exp);
   void GetBlockCallExprs(Stmt *S);
   void GetBlockDeclRefExprs(Stmt *S);
   
@@ -392,14 +393,10 @@
   }
   S += " {\n";
   
-  bool haveByRefDecls = false;
-  
   // Create local declarations to avoid rewriting all closure decl ref exprs.
   // First, emit a declaration for all "by ref" decls.
   for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(), 
        E = BlockByRefDecls.end(); I != E; ++I) {
-    // Note: It is not possible to have "by ref" closure pointer decls.
-    haveByRefDecls = true;
     S += "  ";
     std::string Name = (*I)->getName();
     Context->getPointerType((*I)->getType()).getAsStringInternal(Name);
@@ -588,24 +585,8 @@
   // Insert closures that were part of the function.
   for (unsigned i = 0; i < Blocks.size(); i++) {
 
-    GetBlockDeclRefExprs(Blocks[i]);
-    if (BlockDeclRefs.size()) {
-      // Unique all "by copy" declarations.
-      for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
-        if (!BlockDeclRefs[i]->isByRef())
-          BlockByCopyDecls.insert(BlockDeclRefs[i]->getDecl());
-      // Unique all "by ref" declarations.
-      for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
-        if (BlockDeclRefs[i]->isByRef())
-          BlockByRefDecls.insert(BlockDeclRefs[i]->getDecl());
-   
-      // Find any imported blocks...they will need special attention.
-      for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
-        if (isBlockPointerType(BlockDeclRefs[i]->getType())) {
-          GetBlockCallExprs(Blocks[i]);
-          ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl());
-        }
-    }
+    CollectBlockDeclRefInfo(Blocks[i]);
+
     std::string Tag = "__" + std::string(FunName) + "_block_impl_" + utostr(i);
                       
     std::string CI = SynthesizeBlockImpl(Blocks[i], Tag, 
@@ -906,10 +887,7 @@
   return;
 }
 
-std::string RewriteBlocks::SynthesizeBlockInitExpr(BlockExpr *Exp, VarDecl *VD) {
-  Blocks.push_back(Exp);
-  bool haveByRefDecls = false;
-
+void RewriteBlocks::CollectBlockDeclRefInfo(BlockExpr *Exp) {  
   // Add initializers for any closure decl refs.
   GetBlockDeclRefExprs(Exp);
   if (BlockDeclRefs.size()) {
@@ -920,7 +898,6 @@
     // Unique all "by ref" declarations.
     for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
       if (BlockDeclRefs[i]->isByRef()) {
-        haveByRefDecls = true;
         BlockByRefDecls.insert(BlockDeclRefs[i]->getDecl());
       }
     // Find any imported blocks...they will need special attention.
@@ -930,6 +907,12 @@
         ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl());
       }
   }
+}
+
+std::string RewriteBlocks::SynthesizeBlockInitExpr(BlockExpr *Exp, VarDecl *VD) {
+  Blocks.push_back(Exp);
+
+  CollectBlockDeclRefInfo(Exp);
   std::string FuncName;
   
   if (CurFunctionDef)





More information about the cfe-commits mailing list