aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2007-11-02 18:16:07 +0000
committerFariborz Jahanian <fjahanian@apple.com>2007-11-02 18:16:07 +0000
commit7794cb85d394750db0631c02b7aa7837ae56764c (patch)
tree250c4b78e87c359c41584750dc3455bc9fc5d28c
parent0497331350e9f7838c03eca5f2782a53160f7423 (diff)
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
-rw-r--r--AST/StmtPrinter.cpp34
-rw-r--r--Parse/ParseObjc.cpp5
-rw-r--r--include/clang/AST/Stmt.h10
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<CompoundStmt>(Node->getTryBody())) {
+ PrintRawCompoundStmt(TS);
+ OS << "\n";
+ }
+
+ for (ObjcAtCatchStmt *catchStmt =
+ static_cast<ObjcAtCatchStmt *>(Node->getCatchStmts());
+ catchStmt;
+ catchStmt =
+ static_cast<ObjcAtCatchStmt *>(catchStmt->getNextCatchStmt())) {
+ Indent() << "@catch(";
+ if (catchStmt->getCatchParamStmt()) {
+ if (DeclStmt *DS = dyn_cast<DeclStmt>(catchStmt->getCatchParamStmt()))
+ PrintRawDecl(DS->getDecl());
+ }
+ OS << ")";
+ if (CompoundStmt *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody()))
+ {
+ PrintRawCompoundStmt(CS);
+ OS << "\n";
+ }
+ }
+
+ Indent() << "@finally";
+ if (CompoundStmt *FS = dyn_cast<CompoundStmt>(
+ static_cast<ObjcAtFinallyStmt *>(
+ 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());
}