diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2007-11-01 23:59:59 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2007-11-01 23:59:59 +0000 |
commit | 3b1191d7eaf2f4984564e01ab84b6713a9d80e70 (patch) | |
tree | ac1f65d26eb2833d68dfc7f63fcb0586cbf945fb | |
parent | beb7713c6102687f7e49e27b8228e84a69d8f6c6 (diff) |
AST build for @catch clause (this is work in progress).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43628 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | AST/Stmt.cpp | 10 | ||||
-rw-r--r-- | Parse/ParseObjc.cpp | 27 | ||||
-rw-r--r-- | Sema/Sema.h | 4 | ||||
-rw-r--r-- | Sema/SemaStmt.cpp | 11 | ||||
-rw-r--r-- | include/clang/AST/Stmt.h | 28 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 7 |
6 files changed, 68 insertions, 19 deletions
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp index 1738f9573b..8e1abda582 100644 --- a/AST/Stmt.cpp +++ b/AST/Stmt.cpp @@ -194,8 +194,10 @@ Stmt::child_iterator AsmStmt::child_begin() { return child_iterator(); } Stmt::child_iterator AsmStmt::child_end() { return child_iterator(); } // ObjcAtCatchStmt -Stmt::child_iterator ObjcAtCatchStmt::child_begin() { return &AtCatchStmt; } -Stmt::child_iterator ObjcAtCatchStmt::child_end() { return &AtCatchStmt+1; } +Stmt::child_iterator ObjcAtCatchStmt::child_begin() { return &SubExprs[0]; } +Stmt::child_iterator ObjcAtCatchStmt::child_end() { + return &SubExprs[0]+END_EXPR; +} // ObjcAtFinallyStmt Stmt::child_iterator ObjcAtFinallyStmt::child_begin() { return &AtFinallyStmt; } @@ -203,5 +205,7 @@ Stmt::child_iterator ObjcAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } // ObjcAtTryStmt Stmt::child_iterator ObjcAtTryStmt::child_begin() { return &SubStmts[0]; } -Stmt::child_iterator ObjcAtTryStmt::child_end() { return &SubStmts[0]+1; } +Stmt::child_iterator ObjcAtTryStmt::child_end() { + return &SubStmts[0]+END_TRY; +} diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 765422a985..f65e250fae 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -13,6 +13,7 @@ #include "clang/Parse/Parser.h" #include "clang/Parse/DeclSpec.h" +#include "clang/Parse/Scope.h" #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/SmallVector.h" using namespace clang; @@ -1053,28 +1054,38 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { Diag (Tok, diag::err_expected_lbrace); return true; } + StmtResult CatchStmts; StmtResult TryBody = ParseCompoundStatementBody(); while (Tok.is(tok::at)) { - ConsumeToken(); + SourceLocation AtCatchLoc = ConsumeToken(); if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_catch) { - SourceLocation catchLoc = ConsumeToken(); // consume catch + StmtTy *FirstPart = 0; + ConsumeToken(); // consume catch if (Tok.is(tok::l_paren)) { ConsumeParen(); + EnterScope(Scope::DeclScope); if (Tok.isNot(tok::ellipsis)) { DeclSpec DS; ParseDeclarationSpecifiers(DS); - // Parse the parameter-declaration. - // FIXME: BlockContext may not be the right context! - Declarator ParmDecl(DS, Declarator::BlockContext); - ParseDeclarator(ParmDecl); + // FIXME: Is BlockContext right? + Declarator DeclaratorInfo(DS, Declarator::BlockContext); + ParseDeclarator(DeclaratorInfo); + StmtResult stmtResult = Actions.ActOnDeclarator(CurScope, + DeclaratorInfo, 0); + FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val; } else ConsumeToken(); // consume '...' - ConsumeParen(); + SourceLocation RParenLoc = ConsumeParen(); StmtResult CatchBody = ParseCompoundStatementBody(); + if (CatchBody.isInvalid) + CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); + CatchStmts = Actions.ActOnObjcAtCatchStmt(AtCatchLoc, RParenLoc, + FirstPart, CatchBody.Val, CatchStmts.Val); + ExitScope(); } else { - Diag(catchLoc, diag::err_expected_lparen_after, "@catch clause"); + Diag(AtCatchLoc, diag::err_expected_lparen_after, "@catch clause"); return true; } catch_or_finally_seen = true; diff --git a/Sema/Sema.h b/Sema/Sema.h index 0df8644178..83d8260931 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -339,6 +339,10 @@ public: virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, SourceLocation RParenLoc); + virtual StmtResult ActOnObjcAtCatchStmt(SourceLocation AtLoc, + SourceLocation RParen, StmtTy *Parm, + StmtTy *Body, StmtTy *CatchList); + //===--------------------------------------------------------------------===// // Expression Parsing Callbacks: SemaExpr.cpp. diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index 31dc236709..252a2422c8 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -648,3 +648,14 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, SourceLocation RParenLoc) { return new AsmStmt(AsmLoc, RParenLoc); } + +Action::StmtResult +Sema::ActOnObjcAtCatchStmt(SourceLocation AtLoc, + SourceLocation RParen, StmtTy *Parm, + StmtTy *Body, StmtTy *CatchList) { + ObjcAtCatchStmt *CS = new ObjcAtCatchStmt(AtLoc, RParen, + static_cast<Stmt*>(Parm), static_cast<Stmt*>(Body), + static_cast<Stmt*>(CatchList)); + return CatchList ? CatchList : CS; +} + diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 580b3d6dbd..2f2a14c010 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -663,19 +663,31 @@ class ObjcAtCatchStmt : public Stmt { private: // Points to next @catch statement, or null ObjcAtCatchStmt *NextAtCatchStmt; - ScopedDecl *AtCatchDeclarator; - Stmt *AtCatchStmt; - + enum { SELECTOR, BODY, END_EXPR }; + Stmt *SubExprs[END_EXPR]; SourceLocation AtCatchLoc, RParenLoc; + public: ObjcAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc, - ScopedDecl *atCatchDeclarator, Stmt *atCatchStmt) - : Stmt(ObjcAtCatchStmtClass), NextAtCatchStmt(0), - AtCatchDeclarator(atCatchDeclarator), AtCatchStmt(atCatchStmt), - AtCatchLoc(atCatchLoc), RParenLoc(rparenloc) {} + Stmt *catchVarStmtDecl, Stmt *atCatchStmt, Stmt *atCatchList) + : Stmt(ObjcAtCatchStmtClass), + AtCatchLoc(atCatchLoc), RParenLoc(rparenloc) { + SubExprs[SELECTOR] = catchVarStmtDecl; + SubExprs[BODY] = atCatchStmt; + SubExprs[END_EXPR] = NULL; + if (!atCatchList) + NextAtCatchStmt = NULL; + else { + ObjcAtCatchStmt *AtCatchList = + static_cast<ObjcAtCatchStmt*>(atCatchList); + while (AtCatchList->NextAtCatchStmt) + AtCatchList = AtCatchList->NextAtCatchStmt; + AtCatchList->NextAtCatchStmt = this; + } + } virtual SourceRange getSourceRange() const { - return SourceRange(AtCatchLoc, AtCatchStmt->getLocEnd()); + return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd()); } static bool classof(const Stmt *T) { diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 0be53afda8..1859df43e1 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -288,6 +288,13 @@ public: return 0; } + // Objective-c statements + virtual StmtResult ActOnObjcAtCatchStmt(SourceLocation AtLoc, + SourceLocation RParen, StmtTy *Parm, + StmtTy *Body, StmtTy *CatchList) { + return 0; + } + //===--------------------------------------------------------------------===// // Expression Parsing Callbacks. //===--------------------------------------------------------------------===// |