]> granicus.if.org Git - clang/commitdiff
Patch to rewrite blocks into unique api names.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 10 Feb 2010 20:18:25 +0000 (20:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 10 Feb 2010 20:18:25 +0000 (20:18 +0000)
Fixes radar 7630551

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95796 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/RewriteObjC.cpp
test/Rewriter/rewrite-unique-block-api.mm [new file with mode: 0644]

index 3ee266a110fc11a025fb981bf3def31e9d99f0b1..50a281fbccadf0551820831738d1d72df084a31c 100644 (file)
@@ -4158,16 +4158,23 @@ void RewriteObjC::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) {
   SynthesizeBlockLiterals(FunLocStart, FuncName);
 }
 
+static void BuildUniqueMethodName(std::string &Name,
+                                  ObjCMethodDecl *MD) {
+  ObjCInterfaceDecl *IFace = MD->getClassInterface();
+  Name = IFace->getNameAsCString();
+  Name += "__" + MD->getSelector().getAsString();
+  // Convert colons to underscores.
+  std::string::size_type loc = 0;
+  while ((loc = Name.find(":", loc)) != std::string::npos)
+    Name.replace(loc, 1, "_");
+}
+
 void RewriteObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) {
   //fprintf(stderr,"In InsertBlockLiteralsWitinMethod\n");
   //SourceLocation FunLocStart = MD->getLocStart();
   SourceLocation FunLocStart = MD->getLocStart();
-  std::string FuncName = MD->getSelector().getAsString();
-  // Convert colons to underscores.
-  std::string::size_type loc = 0;
-  while ((loc = FuncName.find(":", loc)) != std::string::npos)
-    FuncName.replace(loc, 1, "_");
-
+  std::string FuncName;
+  BuildUniqueMethodName(FuncName, MD);
   SynthesizeBlockLiterals(FunLocStart, FuncName.c_str());
 }
 
@@ -4779,13 +4786,9 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp) {
 
   if (CurFunctionDef)
     FuncName = CurFunctionDef->getNameAsString();
-  else if (CurMethodDef) {
-    FuncName = CurMethodDef->getSelector().getAsString();
-    // Convert colons to underscores.
-    std::string::size_type loc = 0;
-    while ((loc = FuncName.find(":", loc)) != std::string::npos)
-      FuncName.replace(loc, 1, "_");
-  } else if (GlobalVarDecl)
+  else if (CurMethodDef)
+    BuildUniqueMethodName(FuncName, CurMethodDef);
+  else if (GlobalVarDecl)
     FuncName = std::string(GlobalVarDecl->getNameAsString());
 
   std::string BlockNumber = utostr(Blocks.size()-1);
diff --git a/test/Rewriter/rewrite-unique-block-api.mm b/test/Rewriter/rewrite-unique-block-api.mm
new file mode 100644 (file)
index 0000000..780a3f0
--- /dev/null
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7630551
+
+void f(void (^b)(char c));
+
+@interface a
+- (void)processStuff;
+@end
+
+@implementation a
+- (void)processStuff {
+    f(^(char x) { });
+}
+@end
+
+@interface b
+- (void)processStuff;
+@end
+
+@implementation b
+- (void)processStuff {
+    f(^(char x) { });
+}
+@end
+
+// CHECK-LP: struct __a__processStuff_block_impl_0
+// CHECK-LP: static void __a__processStuff_block_func_0
+
+// CHECK-LP: struct __b__processStuff_block_impl_0
+// CHECK-LP: static void __b__processStuff_block_func_0