From 161a9c5afaafb4d527b7efba9675a8b2cbbe32e0 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 2 Nov 2007 00:18:53 +0000 Subject: [PATCH] AST for @finally statement. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43629 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseObjc.cpp | 12 +++++++++--- Sema/Sema.h | 3 +++ Sema/SemaStmt.cpp | 6 ++++++ include/clang/Parse/Action.h | 5 +++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index f65e250fae..5d691a63ae 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1055,9 +1055,10 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { return true; } StmtResult CatchStmts; + StmtResult FinallyStmt; StmtResult TryBody = ParseCompoundStatementBody(); while (Tok.is(tok::at)) { - SourceLocation AtCatchLoc = ConsumeToken(); + SourceLocation AtCatchFinallyLoc = ConsumeToken(); if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_catch) { StmtTy *FirstPart = 0; ConsumeToken(); // consume catch @@ -1080,12 +1081,13 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { StmtResult CatchBody = ParseCompoundStatementBody(); if (CatchBody.isInvalid) CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); - CatchStmts = Actions.ActOnObjcAtCatchStmt(AtCatchLoc, RParenLoc, + CatchStmts = Actions.ActOnObjcAtCatchStmt(AtCatchFinallyLoc, RParenLoc, FirstPart, CatchBody.Val, CatchStmts.Val); ExitScope(); } else { - Diag(AtCatchLoc, diag::err_expected_lparen_after, "@catch clause"); + Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after, + "@catch clause"); return true; } catch_or_finally_seen = true; @@ -1093,6 +1095,10 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { else if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_finally) { ConsumeToken(); // consume finally StmtResult FinallyBody = ParseCompoundStatementBody(); + if (FinallyBody.isInvalid) + FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); + FinallyStmt = Actions.ActOnObjcAtFinallyStmt(AtCatchFinallyLoc, + FinallyBody.Val); catch_or_finally_seen = true; break; } diff --git a/Sema/Sema.h b/Sema/Sema.h index 83d8260931..cdb6c1f630 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -343,6 +343,9 @@ public: SourceLocation RParen, StmtTy *Parm, StmtTy *Body, StmtTy *CatchList); + virtual StmtResult ActOnObjcAtFinallyStmt(SourceLocation AtLoc, + StmtTy *Body); + //===--------------------------------------------------------------------===// // Expression Parsing Callbacks: SemaExpr.cpp. diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index 252a2422c8..3bd6955a2f 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -659,3 +659,9 @@ Sema::ActOnObjcAtCatchStmt(SourceLocation AtLoc, return CatchList ? CatchList : CS; } +Action::StmtResult +Sema::ActOnObjcAtFinallyStmt(SourceLocation AtLoc, StmtTy *Body) { + ObjcAtFinallyStmt *FS = new ObjcAtFinallyStmt(AtLoc, + static_cast(Body)); + return FS; +} diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 1859df43e1..b900c5833f 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -295,6 +295,11 @@ public: return 0; } + virtual StmtResult ActOnObjcAtFinallyStmt(SourceLocation AtLoc, + StmtTy *Body) { + return 0; + } + //===--------------------------------------------------------------------===// // Expression Parsing Callbacks. //===--------------------------------------------------------------------===// -- 2.40.0