aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2007-11-07 02:00:49 +0000
committerFariborz Jahanian <fjahanian@apple.com>2007-11-07 02:00:49 +0000
commit39f8f159c488a900e5958d5aab3e467af9ec8a2b (patch)
tree5bcfdd83309810aa705ba6afa9f362336f1c260d
parent159e3300f938ae05c0bf249508714e621cc89de5 (diff)
AST for objective-c's @throw statement and its pretty-printing.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43802 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/Stmt.cpp8
-rw-r--r--AST/StmtPrinter.cpp9
-rw-r--r--Parse/ParseObjc.cpp10
-rw-r--r--Sema/Sema.h3
-rw-r--r--Sema/SemaStmt.cpp5
-rw-r--r--include/clang/AST/Stmt.h27
-rw-r--r--include/clang/AST/StmtNodes.def3
-rw-r--r--include/clang/Parse/Action.h6
-rw-r--r--include/clang/Parse/Parser.h2
9 files changed, 67 insertions, 6 deletions
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index 8e1abda582..28681c6a0a 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -209,3 +209,11 @@ Stmt::child_iterator ObjcAtTryStmt::child_end() {
return &SubStmts[0]+END_TRY;
}
+// ObjcAtThrowStmt
+Stmt::child_iterator ObjcAtThrowStmt::child_begin() {
+ return &Throw;
+}
+
+Stmt::child_iterator ObjcAtThrowStmt::child_end() {
+ return &Throw+1;
+}
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index d42a16640f..7fa553d810 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -361,6 +361,15 @@ void StmtPrinter::VisitObjcAtCatchStmt (ObjcAtCatchStmt *Node) {
Indent() << "@catch (...) { /* todo */ } \n";
}
+void StmtPrinter::VisitObjcAtThrowStmt (ObjcAtThrowStmt *Node) {
+ Indent() << "@throw";
+ if (Node->getThrowExpr()) {
+ OS << " ";
+ PrintExpr(Node->getThrowExpr());
+ }
+ OS << ";\n";
+}
+
//===----------------------------------------------------------------------===//
// Expr printing methods.
//===----------------------------------------------------------------------===//
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index 4290fc5044..a149b8611f 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -1052,16 +1052,18 @@ Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
/// objc-throw-statement:
/// throw expression[opt];
///
-Parser::DeclTy *Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
+Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
+ ExprResult Res;
ConsumeToken(); // consume throw
if (Tok.isNot(tok::semi)) {
- ExprResult Res = ParseExpression();
+ Res = ParseExpression();
if (Res.isInvalid) {
SkipUntil(tok::semi);
- return 0;
+ return true;
}
}
- return 0;
+ ConsumeToken(); // consume ';'
+ return Actions.ActOnObjcAtThrowStmt(atLoc, Res.Val);
}
/// objc-try-catch-statement:
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 01ac1e4a14..2781b16745 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -350,6 +350,9 @@ public:
StmtTy *Try,
StmtTy *Catch, StmtTy *Finally);
+ virtual StmtResult ActOnObjcAtThrowStmt(SourceLocation AtLoc,
+ StmtTy *Throw);
+
//===--------------------------------------------------------------------===//
// Expression Parsing Callbacks: SemaExpr.cpp.
diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp
index b495bb828d..65acf0bb14 100644
--- a/Sema/SemaStmt.cpp
+++ b/Sema/SemaStmt.cpp
@@ -675,6 +675,11 @@ Sema::ActOnObjcAtTryStmt(SourceLocation AtLoc,
return TS;
}
+Action::StmtResult
+Sema::ActOnObjcAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw) {
+ ObjcAtThrowStmt *TS = new ObjcAtThrowStmt(AtLoc, static_cast<Stmt*>(Throw));
+ return TS;
+}
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 67cf0c0891..d1a7415e59 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -800,6 +800,33 @@ public:
};
+/// ObjcAtThrowStmt - This represents objective-c's @throw statement.
+class ObjcAtThrowStmt : public Stmt {
+private:
+ Stmt *Throw;
+ SourceLocation AtThrowLoc;
+
+public:
+ ObjcAtThrowStmt(SourceLocation atThrowLoc, Stmt *throwExpr)
+ : Stmt(ObjcAtThrowStmtClass), Throw(throwExpr) {
+ AtThrowLoc = atThrowLoc;
+ }
+
+ Expr *const getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); }
+
+ virtual SourceRange getSourceRange() const {
+ return SourceRange(AtThrowLoc, Throw->getLocEnd());
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjcAtThrowStmtClass;
+ }
+ static bool classof(const ObjcAtThrowStmt *) { return true; }
+
+ virtual child_iterator child_begin();
+ virtual child_iterator child_end();
+};
+
} // end namespace clang
#endif
diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def
index b94e6c3db2..db87975823 100644
--- a/include/clang/AST/StmtNodes.def
+++ b/include/clang/AST/StmtNodes.def
@@ -48,8 +48,9 @@ STMT(18, AsmStmt , Stmt)
STMT(19, ObjcAtTryStmt , Stmt)
STMT(20, ObjcAtCatchStmt , Stmt)
STMT(21, ObjcAtFinallyStmt , Stmt)
+STMT(22, ObjcAtThrowStmt , Stmt)
-LAST_STMT(21)
+LAST_STMT(22)
FIRST_EXPR(31)
// Expressions.
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 41c60f4e5d..acdd27e1b7 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -305,6 +305,12 @@ public:
StmtTy *Catch, StmtTy *Finally) {
return 0;
}
+
+ virtual StmtResult ActOnObjcAtThrowStmt(SourceLocation AtLoc,
+ StmtTy *Throw) {
+ return 0;
+ }
+
//===--------------------------------------------------------------------===//
// Expression Parsing Callbacks.
//===--------------------------------------------------------------------===//
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 1bdf2e743e..b7476a77b6 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -275,7 +275,6 @@ private:
DeclTy *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
DeclTy *ParseObjCPropertySynthesize(SourceLocation atLoc);
DeclTy *ParseObjCPropertyDynamic(SourceLocation atLoc);
- DeclTy *ParseObjCThrowStmt(SourceLocation atLoc);
IdentifierInfo *ParseObjCSelector(SourceLocation &MethodLocation);
// Definitions for Objective-c context sensitive keywords recognition.
@@ -389,6 +388,7 @@ private:
StmtResult ParseReturnStatement();
StmtResult ParseAsmStatement();
StmtResult ParseObjCTryStmt(SourceLocation atLoc);
+ StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
void ParseAsmOperandsOpt();
//===--------------------------------------------------------------------===//