[cfe-commits] r152931 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-modern-throw.m

Fariborz Jahanian fjahanian at apple.com
Fri Mar 16 09:52:06 PDT 2012


Author: fjahanian
Date: Fri Mar 16 11:52:06 2012
New Revision: 152931

URL: http://llvm.org/viewvc/llvm-project?rev=152931&view=rev
Log:
modern objective-c translator: writing @throw statement.


Added:
    cfe/trunk/test/Rewriter/rewrite-modern-throw.m
Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=152931&r1=152930&r2=152931&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Fri Mar 16 11:52:06 2012
@@ -1939,8 +1939,8 @@
   /* void objc_exception_throw(id) __attribute__((noreturn)); */
   if (S->getThrowExpr())
     buf = "objc_exception_throw(";
-  else // add an implicit argument
-    buf = "objc_exception_throw(_caught";
+  else
+    buf = "throw";
 
   // handle "@  throw" correctly.
   const char *wBuf = strchr(startBuf, 'w');
@@ -1950,7 +1950,8 @@
   const char *semiBuf = strchr(startBuf, ';');
   assert((*semiBuf == ';') && "@throw: can't find ';'");
   SourceLocation semiLoc = startLoc.getLocWithOffset(semiBuf-startBuf);
-  ReplaceText(semiLoc, 1, ");");
+  if (S->getThrowExpr())
+    ReplaceText(semiLoc, 1, ");");
   return 0;
 }
 

Added: cfe/trunk/test/Rewriter/rewrite-modern-throw.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-throw.m?rev=152931&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-throw.m (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-throw.m Fri Mar 16 11:52:06 2012
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions  -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+
+void *sel_registerName(const char *);
+
+ at interface Foo @end
+void TRY();
+void SPLATCH();
+void MYTRY();
+void MYCATCH();
+
+void foo() {
+  @try  { TRY(); } 
+  @catch (...) { SPLATCH(); @throw; }
+}
+
+int main()
+{
+
+  @try  {
+     MYTRY();
+  }
+
+  @catch (Foo* localException) {
+     MYCATCH();
+     @throw localException;
+  }
+  
+  // no catch clause
+  @try { } 
+  @finally { }
+}
+
+
+ at interface INST
+{
+  INST* throw_val;
+}
+
+- (id) ThrowThis;
+
+- (void) MainMeth;
+
+ at end
+
+
+ at implementation INST
+- (id) ThrowThis { return 0; }
+
+- (void) MainMeth {
+  @try  {
+     MYTRY();
+  }
+  @catch (Foo* localException) {
+     MYCATCH();
+     @throw [self ThrowThis];
+  }
+  @catch (...) {
+    @throw [throw_val ThrowThis];
+  }
+}
+ at end





More information about the cfe-commits mailing list