]> granicus.if.org Git - clang/commitdiff
Fix two rewriter bugs with @catch.
authorSteve Naroff <snaroff@apple.com>
Fri, 1 Feb 2008 20:02:07 +0000 (20:02 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 1 Feb 2008 20:02:07 +0000 (20:02 +0000)
- Support @catch(...), rather than crash:-)
- Make sure all catch bodies get rewritten. This "fix" is really a workaround until the iterator for the "try" AST is fixed. Will fix this in a separate commit.

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

Driver/RewriteTest.cpp
test/Rewriter/rewrite-try-catch.m

index f01af9738e81b90f85c22e0dfa2e2cfd54d9f05a..52775a25b5f7df2ae3ce305ac2e62e06747f9c16 100644 (file)
@@ -1203,7 +1203,20 @@ Stmt *RewriteTest::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
     
     const char *lParenLoc = strchr(startBuf, '(');
 
-    if (DeclStmt *declStmt = dyn_cast<DeclStmt>(catchStmt)) {
+    if (!catchStmt) { // handle "..."
+      // Now rewrite the body...
+      lastCatchBody = catchList->getCatchBody();
+      SourceLocation rParenLoc = catchList->getRParenLoc();
+      SourceLocation bodyLoc = lastCatchBody->getLocStart();
+      const char *bodyBuf = SM->getCharacterData(bodyLoc);
+      const char *rParenBuf = SM->getCharacterData(rParenLoc);
+      assert((*rParenBuf == ')') && "bogus @catch paren location");
+      assert((*bodyBuf == '{') && "bogus @catch body location");
+      
+      buf += "1) { id _tmp = _caught;";
+      Rewrite.ReplaceText(startLoc, bodyBuf-startBuf+1, 
+                          buf.c_str(), buf.size());      
+    } else if (DeclStmt *declStmt = dyn_cast<DeclStmt>(catchStmt)) {
       QualType t = dyn_cast<ValueDecl>(declStmt->getDecl())->getType();
       if (t == Context->getObjCIdType()) {
         buf += "1) { ";
@@ -1236,6 +1249,10 @@ Stmt *RewriteTest::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
     } else if (!isa<NullStmt>(catchStmt)) {
       assert(false && "@catch rewrite bug");
     }
+    // make sure all the catch bodies get rewritten!
+    // FIXME: this call should be removed when the iterator for ObjCAtTryStmt
+    // is fixed. Currently, it only returns the first catch statement!
+    RewriteFunctionBodyOrGlobalInitializer(lastCatchBody);
     catchList = catchList->getNextCatchStmt();
   }
   // Complete the catch list...
index b8ba45ee64f6606d91cc05c01f18669d6d595c79..9cbc52b6c22ab07b2464f61fb6d6ca4f5a0a4a3f 100644 (file)
@@ -1,8 +1,13 @@
 // RUN: clang -rewrite-test %s | clang
 
-@interface foo @end
+@interface Foo @end
 @interface GARF @end
 
+void foo() {
+  @try  { TRY(); } 
+  @catch (...) { SPLATCH(); @throw; }
+}
+
 int main()
 {
 
@@ -10,7 +15,7 @@ int main()
    MYTRY();
 }
 
-@catch (foo* localException) {
+@catch (Foo* localException) {
    MYCATCH();
    @throw;
 }