]> granicus.if.org Git - clang/commitdiff
Add PCH read/write support for ObjC statements.
authorSteve Naroff <snaroff@apple.com>
Sun, 26 Apr 2009 18:52:16 +0000 (18:52 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 26 Apr 2009 18:52:16 +0000 (18:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70143 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/StmtObjC.h
include/clang/Frontend/PCHBitCodes.h
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp

index b9ac8fd0450e0b5ecf5547d217d170d2605a321b..fa335bb1c225da4863df42240e86c08e37bb83a0 100644 (file)
@@ -29,6 +29,8 @@ class ObjCForCollectionStmt : public Stmt {
 public:
   ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, Stmt *Body, 
                         SourceLocation FCL, SourceLocation RPL);
+  explicit ObjCForCollectionStmt(EmptyShell Empty) : 
+    Stmt(ObjCForCollectionStmtClass, Empty) { }
   
   Stmt *getElement() { return SubExprs[ELEM]; }
   Expr *getCollection() { 
@@ -42,7 +44,16 @@ public:
   }
   const Stmt *getBody() const { return SubExprs[BODY]; }
   
+  void setElement(Stmt *S) { SubExprs[ELEM] = S; }
+  void setCollection(Expr *E) { 
+    SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(E);
+  }
+  void setBody(Stmt *S) { SubExprs[BODY] = S; }
+  
+  SourceLocation getForLoc() const { return ForLoc; }
+  void setForLoc(SourceLocation Loc) { ForLoc = Loc; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
   
   virtual SourceRange getSourceRange() const { 
     return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 
@@ -73,26 +84,34 @@ public:
   ObjCAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc,
                   ParmVarDecl *catchVarDecl, 
                   Stmt *atCatchStmt, Stmt *atCatchList);
+
+  explicit ObjCAtCatchStmt(EmptyShell Empty) : 
+    Stmt(ObjCAtCatchStmtClass, Empty) { }
   
   const Stmt *getCatchBody() const { return SubExprs[BODY]; }
   Stmt *getCatchBody() { return SubExprs[BODY]; }
-
+  void setCatchBody(Stmt *S) { SubExprs[BODY] = S; }
+  
   const ObjCAtCatchStmt *getNextCatchStmt() const {
     return static_cast<const ObjCAtCatchStmt*>(SubExprs[NEXT_CATCH]);
   }
   ObjCAtCatchStmt *getNextCatchStmt() { 
     return static_cast<ObjCAtCatchStmt*>(SubExprs[NEXT_CATCH]);
   }
-
+  void setNextCatchStmt(Stmt *S) { SubExprs[NEXT_CATCH] = S; }
+  
   const ParmVarDecl *getCatchParamDecl() const { 
     return ExceptionDecl; 
   }
   ParmVarDecl *getCatchParamDecl() { 
     return ExceptionDecl; 
   }
+  void setCatchParamDecl(ParmVarDecl *D) { ExceptionDecl = D; }
   
   SourceLocation getAtCatchLoc() const { return AtCatchLoc; }
+  void setAtCatchLoc(SourceLocation Loc) { AtCatchLoc = Loc; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
   
   virtual SourceRange getSourceRange() const { 
     return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd()); 
@@ -117,15 +136,20 @@ public:
   ObjCAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt)
   : Stmt(ObjCAtFinallyStmtClass), 
     AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {}
+
+  explicit ObjCAtFinallyStmt(EmptyShell Empty) : 
+    Stmt(ObjCAtFinallyStmtClass, Empty) { }
   
   const Stmt *getFinallyBody() const { return AtFinallyStmt; }
   Stmt *getFinallyBody() { return AtFinallyStmt; }
-
+  void setFinallyBody(Stmt *S) { AtFinallyStmt = S; }
+  
   virtual SourceRange getSourceRange() const { 
     return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd()); 
   }
   
   SourceLocation getAtFinallyLoc() const { return AtFinallyLoc; }
+  void setAtFinallyLoc(SourceLocation Loc) { AtFinallyLoc = Loc; }
   
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == ObjCAtFinallyStmtClass;
@@ -154,22 +178,32 @@ public:
       SubStmts[FINALLY] = atFinallyStmt;
       AtTryLoc = atTryLoc;
     }
+  explicit ObjCAtTryStmt(EmptyShell Empty) : 
+    Stmt(ObjCAtTryStmtClass, Empty) { }
     
   SourceLocation getAtTryLoc() const { return AtTryLoc; }
+  void setAtTryLoc(SourceLocation Loc) { AtTryLoc = Loc; }
+  
   const Stmt *getTryBody() const { return SubStmts[TRY]; }
   Stmt *getTryBody() { return SubStmts[TRY]; }
+  void setTryBody(Stmt *S) { SubStmts[TRY] = S; }
+  
   const ObjCAtCatchStmt *getCatchStmts() const { 
     return dyn_cast_or_null<ObjCAtCatchStmt>(SubStmts[CATCH]); 
   }
   ObjCAtCatchStmt *getCatchStmts() { 
     return dyn_cast_or_null<ObjCAtCatchStmt>(SubStmts[CATCH]); 
   }
+  void setCatchStmts(Stmt *S) { SubStmts[CATCH] = S; }
+  
   const ObjCAtFinallyStmt *getFinallyStmt() const { 
     return dyn_cast_or_null<ObjCAtFinallyStmt>(SubStmts[FINALLY]); 
   }
   ObjCAtFinallyStmt *getFinallyStmt() { 
     return dyn_cast_or_null<ObjCAtFinallyStmt>(SubStmts[FINALLY]); 
   }
+  void setFinallyStmt(Stmt *S) { SubStmts[FINALLY] = S; }
+
   virtual SourceRange getSourceRange() const { 
     return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd()); 
   }
@@ -202,8 +236,11 @@ public:
     SubStmts[SYNC_BODY] = synchBody;
     AtSynchronizedLoc = atSynchronizedLoc;
   }
+  explicit ObjCAtSynchronizedStmt(EmptyShell Empty) : 
+    Stmt(ObjCAtSynchronizedStmtClass, Empty) { }
   
   SourceLocation getAtSynchronizedLoc() const { return AtSynchronizedLoc; }
+  void setAtSynchronizedLoc(SourceLocation Loc) { AtSynchronizedLoc = Loc; }
   
   const CompoundStmt *getSynchBody() const {
     return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]);
@@ -211,6 +248,7 @@ public:
   CompoundStmt *getSynchBody() { 
     return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]); 
   }
+  void setSynchBody(Stmt *S) { SubStmts[SYNC_BODY] = S; }
   
   const Expr *getSynchExpr() const { 
     return reinterpret_cast<Expr*>(SubStmts[SYNC_EXPR]); 
@@ -218,6 +256,7 @@ public:
   Expr *getSynchExpr() { 
     return reinterpret_cast<Expr*>(SubStmts[SYNC_EXPR]); 
   }
+  void setSynchExpr(Stmt *S) { SubStmts[SYNC_EXPR] = S; }
   
   virtual SourceRange getSourceRange() const { 
     return SourceRange(AtSynchronizedLoc, getSynchBody()->getLocEnd()); 
@@ -241,9 +280,15 @@ public:
   : Stmt(ObjCAtThrowStmtClass), Throw(throwExpr) {
     AtThrowLoc = atThrowLoc;
   }
+  explicit ObjCAtThrowStmt(EmptyShell Empty) : 
+    Stmt(ObjCAtThrowStmtClass, Empty) { }
   
   const Expr *getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); }
   Expr *getThrowExpr() { return reinterpret_cast<Expr*>(Throw); }
+  void setThrowExpr(Stmt *S) { Throw = S; }
+  
+  SourceLocation getThrowLoc() { return AtThrowLoc; }
+  void setThrowLoc(SourceLocation Loc) { AtThrowLoc = Loc; }
   
   virtual SourceRange getSourceRange() const {
     if (Throw)
index c57752b9976b0859a51afd7bc509b81e389c75d6..650da2857b570ae159087a0c2ad6a8cf97a5541e 100644 (file)
@@ -570,7 +570,20 @@ namespace clang {
       /// \brief An ObjCMessageExpr record.
       EXPR_OBJC_MESSAGE_EXPR,
       /// \brief An ObjCSuperExpr record.
-      EXPR_OBJC_SUPER_EXPR
+      EXPR_OBJC_SUPER_EXPR,
+
+      /// \brief An ObjCForCollectionStmt record.      
+      STMT_OBJC_FOR_COLLECTION,
+      /// \brief An ObjCAtCatchStmt record.      
+      STMT_OBJC_CATCH,
+      /// \brief An ObjCAtFinallyStmt record.      
+      STMT_OBJC_FINALLY,
+      /// \brief An ObjCAtTryStmt record.      
+      STMT_OBJC_AT_TRY,
+      /// \brief An ObjCAtSynchronizedStmt record.      
+      STMT_OBJC_AT_SYNCHRONIZED,
+      /// \brief An ObjCAtThrowStmt record.      
+      STMT_OBJC_AT_THROW
     };
 
     /// \brief The kinds of designators that can occur in a
index 0407ed899684b7906d0d43d8712241f9ab8fcb33..c2d50ce9fc3fb8c0bc73f9d8629b244139ceade6 100644 (file)
@@ -502,6 +502,13 @@ namespace {
     unsigned VisitObjCKVCRefExpr(ObjCKVCRefExpr *E);
     unsigned VisitObjCMessageExpr(ObjCMessageExpr *E);
     unsigned VisitObjCSuperExpr(ObjCSuperExpr *E);
+    
+    unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
+    unsigned VisitObjCCatchStmt(ObjCAtCatchStmt *);
+    unsigned VisitObjCFinallyStmt(ObjCAtFinallyStmt *);
+    unsigned VisitObjCAtTryStmt(ObjCAtTryStmt *);
+    unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
+    unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
   };
 }
 
@@ -1140,6 +1147,57 @@ unsigned PCHStmtReader::VisitObjCSuperExpr(ObjCSuperExpr *E) {
   return 0;
 }
 
+unsigned PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
+  VisitStmt(S);
+  S->setElement(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3]));
+  S->setCollection(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
+  S->setBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+  S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 3;
+}
+
+unsigned PCHStmtReader::VisitObjCCatchStmt(ObjCAtCatchStmt *S) {
+  VisitStmt(S);
+  S->setCatchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2]));
+  S->setNextCatchStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+  S->setCatchParamDecl(cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
+  S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 2;
+}
+
+unsigned PCHStmtReader::VisitObjCFinallyStmt(ObjCAtFinallyStmt *S) {
+  VisitStmt(S);
+  S->setFinallyBody(StmtStack.back());
+  S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 1;
+}
+
+unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
+  VisitStmt(S);
+  S->setTryBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 3]));
+  S->setCatchStmts(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2]));
+  S->setFinallyStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+  S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 3;
+}
+
+unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
+  VisitStmt(S);
+  S->setSynchExpr(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 2]));
+  S->setSynchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
+  S->setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 2;
+}
+
+unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
+  VisitStmt(S);
+  S->setThrowExpr(StmtStack.back());
+  S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 1;
+}
+
 //===----------------------------------------------------------------------===//
 // PCH reader implementation
 //===----------------------------------------------------------------------===//
@@ -3371,6 +3429,24 @@ Stmt *PCHReader::ReadStmt() {
     case pch::EXPR_OBJC_SUPER_EXPR:
       S = new (Context) ObjCSuperExpr(Empty);
       break;
+    case pch::STMT_OBJC_FOR_COLLECTION:
+      S = new (Context) ObjCForCollectionStmt(Empty);
+      break;
+    case pch::STMT_OBJC_CATCH:
+      S = new (Context) ObjCAtCatchStmt(Empty);
+      break;
+    case pch::STMT_OBJC_FINALLY:
+      S = new (Context) ObjCAtFinallyStmt(Empty);
+      break;
+    case pch::STMT_OBJC_AT_TRY:
+      S = new (Context) ObjCAtTryStmt(Empty);
+      break;
+    case pch::STMT_OBJC_AT_SYNCHRONIZED:
+      S = new (Context) ObjCAtSynchronizedStmt(Empty);
+      break;
+    case pch::STMT_OBJC_AT_THROW:
+      S = new (Context) ObjCAtThrowStmt(Empty);
+      break;
     }
 
     // We hit a STMT_STOP, so we're done with this expression.
index d40b1065392bdef8db1bb146dbd33fcaa0347a0f..5037a091931a3402b592ac591d2e69b1a4f0d5ca 100644 (file)
@@ -667,7 +667,7 @@ namespace {
     void VisitBlockExpr(BlockExpr *E);
     void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
       
-    // Objective-C
+    // Objective-C Expressions
     void VisitObjCStringLiteral(ObjCStringLiteral *E);
     void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
     void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
@@ -677,6 +677,14 @@ namespace {
     void VisitObjCKVCRefExpr(ObjCKVCRefExpr *E);
     void VisitObjCMessageExpr(ObjCMessageExpr *E);
     void VisitObjCSuperExpr(ObjCSuperExpr *E);
+    
+    // Objective-C Statements    
+    void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
+    void VisitObjCCatchStmt(ObjCAtCatchStmt *);
+    void VisitObjCFinallyStmt(ObjCAtFinallyStmt *);
+    void VisitObjCAtTryStmt(ObjCAtTryStmt *);
+    void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
+    void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
   };
 }
 
@@ -1259,6 +1267,51 @@ void PCHStmtWriter::VisitObjCSuperExpr(ObjCSuperExpr *E) {
   Code = pch::EXPR_OBJC_SUPER_EXPR;
 }
 
+void PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
+  VisitStmt(S);
+  Writer.WriteSubStmt(S->getElement());
+  Writer.WriteSubStmt(S->getCollection());
+  Writer.WriteSubStmt(S->getBody());
+  Writer.AddSourceLocation(S->getForLoc(), Record);
+  Writer.AddSourceLocation(S->getRParenLoc(), Record);
+  Code = pch::STMT_OBJC_FOR_COLLECTION;
+}
+
+void PCHStmtWriter::VisitObjCCatchStmt(ObjCAtCatchStmt *S) {
+  Writer.WriteSubStmt(S->getCatchBody());
+  Writer.WriteSubStmt(S->getNextCatchStmt());
+  Writer.AddDeclRef(S->getCatchParamDecl(), Record);
+  Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
+  Writer.AddSourceLocation(S->getRParenLoc(), Record);
+  Code = pch::STMT_OBJC_CATCH;
+}
+
+void PCHStmtWriter::VisitObjCFinallyStmt(ObjCAtFinallyStmt *S) {
+  Writer.WriteSubStmt(S->getFinallyBody());
+  Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
+  Code = pch::STMT_OBJC_FINALLY;
+}
+
+void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
+  Writer.WriteSubStmt(S->getTryBody());
+  Writer.WriteSubStmt(S->getCatchStmts());
+  Writer.WriteSubStmt(S->getFinallyStmt());
+  Writer.AddSourceLocation(S->getAtTryLoc(), Record);
+  Code = pch::STMT_OBJC_AT_TRY;
+}
+
+void PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
+  Writer.WriteSubStmt(S->getSynchExpr());
+  Writer.WriteSubStmt(S->getSynchBody());
+  Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
+  Code = pch::STMT_OBJC_AT_SYNCHRONIZED;
+}
+
+void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
+  Writer.WriteSubStmt(S->getThrowExpr());
+  Writer.AddSourceLocation(S->getThrowLoc(), Record);
+  Code = pch::STMT_OBJC_AT_THROW;
+}
 
 //===----------------------------------------------------------------------===//
 // PCHWriter Implementation