aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/RewriteModernObjC.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-03-15 23:50:33 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-03-15 23:50:33 +0000
commit220419acf26033d794edef802cbb916a4d2896b4 (patch)
tree47158226c749d9b64b88d84232476cbfd2f52b92 /lib/Rewrite/RewriteModernObjC.cpp
parenta43ef3e0511dc48d98d61598163c9deddc09cb9c (diff)
modern objective-c translation: writing @try/@catch/@finally
statements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/RewriteModernObjC.cpp')
-rw-r--r--lib/Rewrite/RewriteModernObjC.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp
index 74745204a4..1081b9df90 100644
--- a/lib/Rewrite/RewriteModernObjC.cpp
+++ b/lib/Rewrite/RewriteModernObjC.cpp
@@ -1836,11 +1836,15 @@ void RewriteModernObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf)
Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
ObjCAtFinallyStmt *finalStmt = S->getFinallyStmt();
- // bool noCatch = S->getNumCatchStmts() == 0;
+ bool noCatch = S->getNumCatchStmts() == 0;
std::string buf;
if (finalStmt) {
- buf = "{ id volatile _rethrow = 0;\n";
+ if (noCatch)
+ buf = "{ id volatile _rethrow = 0;\n";
+ else {
+ buf = "{ id volatile _rethrow = 0;\ntry {\n";
+ }
}
// Get the start location and compute the semi location.
SourceLocation startLoc = S->getLocStart();
@@ -1853,24 +1857,6 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
// @try -> try
ReplaceText(startLoc, 1, "");
- if (finalStmt) {
- buf.clear();
- buf = "catch (id e) {_rethrow = e;}\n";
- SourceLocation startFinalLoc = finalStmt->getLocStart();
- ReplaceText(startFinalLoc, 8, buf);
- Stmt *body = finalStmt->getFinallyBody();
- SourceLocation startFinalBodyLoc = body->getLocStart();
- buf.clear();
- buf = "{ struct _FIN { _FIN(id reth) : rethrow(reth) {}\n";
- buf += "\t~_FIN() { if (rethrow) objc_exception_throw(rethrow); }\n";
- buf += "\tid rethrow;\n";
- buf += "\t} _fin_force_rethow(_rethrow);";
- ReplaceText(startFinalBodyLoc, 1, buf);
-
- SourceLocation endFinalBodyLoc = body->getLocEnd();
- ReplaceText(endFinalBodyLoc, 1, "}\n}");
- }
-
for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
ObjCAtCatchStmt *Catch = S->getCatchStmt(I);
VarDecl *catchDecl = Catch->getCatchParamDecl();
@@ -1914,6 +1900,28 @@ Stmt *RewriteModernObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) {
ReplaceText(startLoc, 1, "");
}
+ if (finalStmt) {
+ buf.clear();
+ if (noCatch)
+ buf = "catch (id e) {_rethrow = e;}\n";
+ else
+ buf = "}\ncatch (id e) {_rethrow = e;}\n";
+
+ SourceLocation startFinalLoc = finalStmt->getLocStart();
+ ReplaceText(startFinalLoc, 8, buf);
+ Stmt *body = finalStmt->getFinallyBody();
+ SourceLocation startFinalBodyLoc = body->getLocStart();
+ buf.clear();
+ buf = "{ struct _FIN { _FIN(id reth) : rethrow(reth) {}\n";
+ buf += "\t~_FIN() { if (rethrow) objc_exception_throw(rethrow); }\n";
+ buf += "\tid rethrow;\n";
+ buf += "\t} _fin_force_rethow(_rethrow);";
+ ReplaceText(startFinalBodyLoc, 1, buf);
+
+ SourceLocation endFinalBodyLoc = body->getLocEnd();
+ ReplaceText(endFinalBodyLoc, 1, "}\n}");
+ }
+
return 0;
}