From 7794cb85d394750db0631c02b7aa7837ae56764c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 2 Nov 2007 18:16:07 +0000 Subject: [PATCH] pretty-print @try/@catch/@finally from AST as the validation of AST. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43649 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/StmtPrinter.cpp | 34 +++++++++++++++++++++++++++++++--- Parse/ParseObjc.cpp | 5 +++-- include/clang/AST/Stmt.h | 10 ++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp index 0953891fdb..ad3091016c 100644 --- a/AST/StmtPrinter.cpp +++ b/AST/StmtPrinter.cpp @@ -322,11 +322,40 @@ void StmtPrinter::VisitAsmStmt(AsmStmt *Node) { } void StmtPrinter::VisitObjcAtTryStmt(ObjcAtTryStmt *Node) { - Indent() << "@try { /* todo */ }\n"; + Indent() << "@try"; + if (CompoundStmt *TS = dyn_cast(Node->getTryBody())) { + PrintRawCompoundStmt(TS); + OS << "\n"; + } + + for (ObjcAtCatchStmt *catchStmt = + static_cast(Node->getCatchStmts()); + catchStmt; + catchStmt = + static_cast(catchStmt->getNextCatchStmt())) { + Indent() << "@catch("; + if (catchStmt->getCatchParamStmt()) { + if (DeclStmt *DS = dyn_cast(catchStmt->getCatchParamStmt())) + PrintRawDecl(DS->getDecl()); + } + OS << ")"; + if (CompoundStmt *CS = dyn_cast(catchStmt->getCatchBody())) + { + PrintRawCompoundStmt(CS); + OS << "\n"; + } + } + + Indent() << "@finally"; + if (CompoundStmt *FS = dyn_cast( + static_cast( + Node->getFinallyStmt())->getFinallyBody())) { + PrintRawCompoundStmt(FS); + OS << "\n"; + } } void StmtPrinter::VisitObjcAtFinallyStmt(ObjcAtFinallyStmt *Node) { - Indent() << "@finally { /* todo */ } \n"; } void StmtPrinter::VisitObjcAtCatchStmt (ObjcAtCatchStmt *Node) { @@ -665,7 +694,6 @@ void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) { OS << "]"; } - //===----------------------------------------------------------------------===// // Stmt method implementations //===----------------------------------------------------------------------===// diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index bfc0a8c973..23d5f0e419 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1073,8 +1073,9 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { // FIXME: Is BlockContext right? Declarator DeclaratorInfo(DS, Declarator::BlockContext); ParseDeclarator(DeclaratorInfo); - StmtResult stmtResult = Actions.ActOnDeclarator(CurScope, - DeclaratorInfo, 0); + DeclTy * aBlockVarDecl = Actions.ActOnDeclarator(CurScope, + DeclaratorInfo, 0); + StmtResult stmtResult = Actions.ActOnDeclStmt(aBlockVarDecl); FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val; } else diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 262b5db8c3..760b0c5187 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -686,6 +686,10 @@ public: } } + Stmt *getCatchBody() const { return SubExprs[BODY]; } + Stmt *getNextCatchStmt() const { return NextAtCatchStmt; } + Stmt *getCatchParamStmt() const { return SubExprs[SELECTOR]; } + virtual SourceRange getSourceRange() const { return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd()); } @@ -711,6 +715,8 @@ class ObjcAtFinallyStmt : public Stmt { : Stmt(ObjcAtFinallyStmtClass), AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {} + Stmt *getFinallyBody () const { return AtFinallyStmt; } + virtual SourceRange getSourceRange() const { return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd()); } @@ -745,6 +751,10 @@ public: SubStmts[END_TRY] = NULL; } + Stmt *getTryBody() const { return SubStmts[TRY]; } + Stmt *getCatchStmts() const { return SubStmts[CATCH]; } + Stmt *getFinallyStmt() const { return SubStmts[FINALLY]; } + virtual SourceRange getSourceRange() const { return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd()); } -- 2.40.0