[cfe-commits] r43802 - in /cfe/trunk: AST/Stmt.cpp AST/StmtPrinter.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaStmt.cpp include/clang/AST/Stmt.h include/clang/AST/StmtNodes.def include/clang/Parse/Action.h include/clang/Parse/Parser.h

Fariborz Jahanian fjahanian at apple.com
Tue Nov 6 18:00:49 PST 2007


Author: fjahanian
Date: Tue Nov  6 20:00:49 2007
New Revision: 43802

URL: http://llvm.org/viewvc/llvm-project?rev=43802&view=rev
Log:
AST for objective-c's @throw statement and its pretty-printing.

Modified:
    cfe/trunk/AST/Stmt.cpp
    cfe/trunk/AST/StmtPrinter.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/AST/StmtNodes.def
    cfe/trunk/include/clang/Parse/Action.h
    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=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/trunk/AST/Stmt.cpp Tue Nov  6 20:00:49 2007
@@ -209,3 +209,11 @@
   return &SubStmts[0]+END_TRY; 
 }
 
+// ObjcAtThrowStmt
+Stmt::child_iterator ObjcAtThrowStmt::child_begin() {
+  return &Throw;
+}
+
+Stmt::child_iterator ObjcAtThrowStmt::child_end() {
+  return &Throw+1;
+}

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Tue Nov  6 20:00:49 2007
@@ -361,6 +361,15 @@
   Indent() << "@catch (...) { /* todo */ } \n";
 }
 
+void StmtPrinter::VisitObjcAtThrowStmt (ObjcAtThrowStmt *Node) {
+  Indent() << "@throw";
+  if (Node->getThrowExpr()) {
+    OS << " ";
+    PrintExpr(Node->getThrowExpr());
+  }
+  OS << ";\n";
+}
+
 //===----------------------------------------------------------------------===//
 //  Expr printing methods.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Tue Nov  6 20:00:49 2007
@@ -1052,16 +1052,18 @@
 ///  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:

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Nov  6 20:00:49 2007
@@ -350,6 +350,9 @@
                                         StmtTy *Try, 
                                         StmtTy *Catch, StmtTy *Finally);
   
+  virtual StmtResult ActOnObjcAtThrowStmt(SourceLocation AtLoc, 
+                                          StmtTy *Throw);
+  
   //===--------------------------------------------------------------------===//
   // Expression Parsing Callbacks: SemaExpr.cpp.
 

Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Tue Nov  6 20:00:49 2007
@@ -675,6 +675,11 @@
   return TS;
 }
 
+Action::StmtResult
+Sema::ActOnObjcAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw) {
+  ObjcAtThrowStmt *TS = new ObjcAtThrowStmt(AtLoc, static_cast<Stmt*>(Throw));
+  return TS;
+}
 
 
 

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Nov  6 20:00:49 2007
@@ -800,6 +800,33 @@
     
 };
 
+/// 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

Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Tue Nov  6 20:00:49 2007
@@ -48,8 +48,9 @@
 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.

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Nov  6 20:00:49 2007
@@ -305,6 +305,12 @@
                                         StmtTy *Catch, StmtTy *Finally) {
     return 0;
   }
+  
+  virtual StmtResult ActOnObjcAtThrowStmt(SourceLocation AtLoc, 
+                                          StmtTy *Throw) {
+    return 0;
+  }
+  
   //===--------------------------------------------------------------------===//
   // Expression Parsing Callbacks.
   //===--------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=43802&r1=43801&r2=43802&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Nov  6 20:00:49 2007
@@ -275,7 +275,6 @@
   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 @@
   StmtResult ParseReturnStatement();
   StmtResult ParseAsmStatement();
   StmtResult ParseObjCTryStmt(SourceLocation atLoc);
+  StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
   void ParseAsmOperandsOpt();
 
   //===--------------------------------------------------------------------===//





More information about the cfe-commits mailing list