[cfe-commits] r95796 - in /cfe/trunk: lib/Frontend/RewriteObjC.cpp test/Rewriter/rewrite-unique-block-api.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Feb 10 12:18:26 PST 2010
Author: fjahanian
Date: Wed Feb 10 14:18:25 2010
New Revision: 95796
URL: http://llvm.org/viewvc/llvm-project?rev=95796&view=rev
Log:
Patch to rewrite blocks into unique api names.
Fixes radar 7630551
Added:
cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm
Modified:
cfe/trunk/lib/Frontend/RewriteObjC.cpp
Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=95796&r1=95795&r2=95796&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Wed Feb 10 14:18:25 2010
@@ -4158,16 +4158,23 @@
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 @@
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);
Added: cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm?rev=95796&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-unique-block-api.mm Wed Feb 10 14:18:25 2010
@@ -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));
+
+ at interface a
+- (void)processStuff;
+ at end
+
+ at implementation a
+- (void)processStuff {
+ f(^(char x) { });
+}
+ at end
+
+ at interface b
+- (void)processStuff;
+ at end
+
+ at implementation b
+- (void)processStuff {
+ f(^(char x) { });
+}
+ at 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
More information about the cfe-commits
mailing list