[cfe-commits] r43623 - in /cfe/trunk: AST/Stmt.cpp AST/StmtPrinter.cpp Parse/ParseObjc.cpp include/clang/AST/Stmt.h include/clang/AST/StmtNodes.def include/clang/Parse/Parser.h
Fariborz Jahanian
fjahanian at apple.com
Thu Nov 1 14:12:44 PDT 2007
Author: fjahanian
Date: Thu Nov 1 16:12:44 2007
New Revision: 43623
URL: http://llvm.org/viewvc/llvm-project?rev=43623&view=rev
Log:
Bunch of class declarations for objective-c's @try-catch statement.
Modified:
cfe/trunk/AST/Stmt.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/AST/StmtNodes.def
cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Stmt.cpp?rev=43623&r1=43622&r2=43623&view=diff
==============================================================================
--- cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/trunk/AST/Stmt.cpp Thu Nov 1 16:12:44 2007
@@ -193,3 +193,15 @@
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; }
+
+// ObjcAtFinallyStmt
+Stmt::child_iterator ObjcAtFinallyStmt::child_begin() { return &AtFinallyStmt; }
+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; }
+
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=43623&r1=43622&r2=43623&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Thu Nov 1 16:12:44 2007
@@ -321,6 +321,18 @@
Indent() << "asm (/*todo*/);\n";
}
+void StmtPrinter::VisitObjcAtTryStmt(ObjcAtTryStmt *Node) {
+ Indent() << "@try { /* todo */ }\n";
+}
+
+void StmtPrinter::VisitObjcAtFinallyStmt(ObjcAtFinallyStmt *Node) {
+ Indent() << "@finally { /* todo */ } \n";
+}
+
+void StmtPrinter::VisitObjcAtCatchStmt (ObjcAtCatchStmt *Node) {
+ Indent() << "@catch (...) { /* todo */ } \n";
+}
+
//===----------------------------------------------------------------------===//
// Expr printing methods.
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43623&r1=43622&r2=43623&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Thu Nov 1 16:12:44 2007
@@ -1046,12 +1046,12 @@
/// parameter-declaration
/// '...' [OBJC2]
///
-Parser::DeclTy *Parser::ParseObjCTryStmt(SourceLocation atLoc) {
+Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
bool catch_or_finally_seen = false;
ConsumeToken(); // consume try
if (Tok.isNot(tok::l_brace)) {
Diag (Tok, diag::err_expected_lbrace);
- return 0;
+ return true;
}
StmtResult TryBody = ParseCompoundStatementBody();
while (Tok.is(tok::at)) {
@@ -1071,11 +1071,11 @@
else
ConsumeToken(); // consume '...'
ConsumeParen();
- StmtResult CatchMody = ParseCompoundStatementBody();
+ StmtResult CatchBody = ParseCompoundStatementBody();
}
else {
Diag(catchLoc, diag::err_expected_lparen_after, "@catch clause");
- return 0;
+ return true;
}
catch_or_finally_seen = true;
}
@@ -1088,7 +1088,7 @@
}
if (!catch_or_finally_seen)
Diag(atLoc, diag::err_missing_catch_finally);
- return 0;
+ return true;
}
/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=43623&r1=43622&r2=43623&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu Nov 1 16:12:44 2007
@@ -657,7 +657,95 @@
virtual child_iterator child_begin();
virtual child_iterator child_end();
};
-
+
+/// ObjcAtCatchStmt - This represents objective-c's @catch statement.
+class ObjcAtCatchStmt : public Stmt {
+private:
+ // Points to next @catch statement, or null
+ ObjcAtCatchStmt *NextAtCatchStmt;
+ ScopedDecl *AtCatchDeclarator;
+ Stmt *AtCatchStmt;
+
+ 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) {}
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(AtCatchLoc, AtCatchStmt->getLocEnd());
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjcAtCatchStmtClass;
+ }
+ static bool classof(const ObjcAtCatchStmt *) { return true; }
+
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+
+};
+
+/// ObjcAtFinallyStmt - This represent objective-c's @finally Statement
+class ObjcAtFinallyStmt : public Stmt {
+ private:
+ Stmt *AtFinallyStmt;
+ SourceLocation AtFinallyLoc;
+
+ public:
+ ObjcAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt)
+ : Stmt(ObjcAtFinallyStmtClass),
+ AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {}
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd());
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjcAtFinallyStmtClass;
+ }
+ static bool classof(const ObjcAtFinallyStmt *) { return true; }
+
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+
+};
+
+/// ObjcAtTryStmt - This represent objective-c's over-all
+/// @try ... @catch ... @finally statement.
+class ObjcAtTryStmt : public Stmt {
+private:
+ enum { TRY, CATCH, FINALLY, END_TRY };
+ Stmt* SubStmts[END_TRY];
+
+ SourceLocation AtTryLoc;
+
+public:
+ ObjcAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
+ ObjcAtCatchStmt *atCatchStmt,
+ ObjcAtFinallyStmt *atFinallyStmt)
+ : Stmt(ObjcAtTryStmtClass), AtTryLoc(atTryLoc) {
+ SubStmts[TRY] = atTryStmt;
+ SubStmts[CATCH] = atCatchStmt;
+ SubStmts[FINALLY] = atFinallyStmt;
+ SubStmts[END_TRY] = NULL;
+ }
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd());
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjcAtTryStmtClass;
+ }
+ static bool classof(const ObjcAtTryStmt *) { return true; }
+
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+
+};
} // end namespace clang
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=43623&r1=43622&r2=43623&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Thu Nov 1 16:12:44 2007
@@ -43,7 +43,13 @@
// GNU Stmt Extensions
STMT(18, AsmStmt , Stmt)
-LAST_STMT(17)
+
+// Obj-C statements
+STMT(19, ObjcAtTryStmt , Stmt)
+STMT(20, ObjcAtCatchStmt , Stmt)
+STMT(21, ObjcAtFinallyStmt , Stmt)
+
+LAST_STMT(21)
FIRST_EXPR(31)
// Expressions.
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=43623&r1=43622&r2=43623&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Nov 1 16:12:44 2007
@@ -275,7 +275,6 @@
DeclTy *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
DeclTy *ParseObjCPropertySynthesize(SourceLocation atLoc);
DeclTy *ParseObjCPropertyDynamic(SourceLocation atLoc);
- DeclTy *ParseObjCTryStmt(SourceLocation atLoc);
DeclTy *ParseObjCThrowStmt(SourceLocation atLoc);
IdentifierInfo *ParseObjCSelector(SourceLocation &MethodLocation);
@@ -389,6 +388,7 @@
StmtResult ParseBreakStatement();
StmtResult ParseReturnStatement();
StmtResult ParseAsmStatement();
+ StmtResult ParseObjCTryStmt(SourceLocation atLoc);
void ParseAsmOperandsOpt();
//===--------------------------------------------------------------------===//
More information about the cfe-commits
mailing list