[cfe-commits] r43628 - in /cfe/trunk: AST/Stmt.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaStmt.cpp include/clang/AST/Stmt.h include/clang/Parse/Action.h
Fariborz Jahanian
fjahanian at apple.com
Thu Nov 1 17:00:01 PDT 2007
Author: fjahanian
Date: Thu Nov 1 18:59:59 2007
New Revision: 43628
URL: http://llvm.org/viewvc/llvm-project?rev=43628&view=rev
Log:
AST build for @catch clause (this is work in progress).
Modified:
cfe/trunk/AST/Stmt.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaStmt.cpp
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Parse/Action.h
Modified: cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Stmt.cpp?rev=43628&r1=43627&r2=43628&view=diff
==============================================================================
--- cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/trunk/AST/Stmt.cpp Thu Nov 1 18:59:59 2007
@@ -194,8 +194,10 @@
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 @@
// 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;
+}
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43628&r1=43627&r2=43628&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Thu Nov 1 18:59:59 2007
@@ -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 @@
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;
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=43628&r1=43627&r2=43628&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Nov 1 18:59:59 2007
@@ -339,6 +339,10 @@
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.
Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=43628&r1=43627&r2=43628&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Thu Nov 1 18:59:59 2007
@@ -648,3 +648,14 @@
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;
+}
+
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=43628&r1=43627&r2=43628&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu Nov 1 18:59:59 2007
@@ -663,19 +663,31 @@
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) {
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=43628&r1=43627&r2=43628&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Nov 1 18:59:59 2007
@@ -288,6 +288,13 @@
return 0;
}
+ // Objective-c statements
+ virtual StmtResult ActOnObjcAtCatchStmt(SourceLocation AtLoc,
+ SourceLocation RParen, StmtTy *Parm,
+ StmtTy *Body, StmtTy *CatchList) {
+ return 0;
+ }
+
//===--------------------------------------------------------------------===//
// Expression Parsing Callbacks.
//===--------------------------------------------------------------------===//
More information about the cfe-commits
mailing list