From: Steve Naroff Date: Sun, 26 Apr 2009 18:52:16 +0000 (+0000) Subject: Add PCH read/write support for ObjC statements. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1eb5540760dc79502e32d4fe9c28217476ea14b9;p=clang Add PCH read/write support for ObjC statements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70143 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/StmtObjC.h b/include/clang/AST/StmtObjC.h index b9ac8fd045..fa335bb1c2 100644 --- a/include/clang/AST/StmtObjC.h +++ b/include/clang/AST/StmtObjC.h @@ -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(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(SubExprs[NEXT_CATCH]); } ObjCAtCatchStmt *getNextCatchStmt() { return static_cast(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(SubStmts[CATCH]); } ObjCAtCatchStmt *getCatchStmts() { return dyn_cast_or_null(SubStmts[CATCH]); } + void setCatchStmts(Stmt *S) { SubStmts[CATCH] = S; } + const ObjCAtFinallyStmt *getFinallyStmt() const { return dyn_cast_or_null(SubStmts[FINALLY]); } ObjCAtFinallyStmt *getFinallyStmt() { return dyn_cast_or_null(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(SubStmts[SYNC_BODY]); @@ -211,6 +248,7 @@ public: CompoundStmt *getSynchBody() { return reinterpret_cast(SubStmts[SYNC_BODY]); } + void setSynchBody(Stmt *S) { SubStmts[SYNC_BODY] = S; } const Expr *getSynchExpr() const { return reinterpret_cast(SubStmts[SYNC_EXPR]); @@ -218,6 +256,7 @@ public: Expr *getSynchExpr() { return reinterpret_cast(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(Throw); } Expr *getThrowExpr() { return reinterpret_cast(Throw); } + void setThrowExpr(Stmt *S) { Throw = S; } + + SourceLocation getThrowLoc() { return AtThrowLoc; } + void setThrowLoc(SourceLocation Loc) { AtThrowLoc = Loc; } virtual SourceRange getSourceRange() const { if (Throw) diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index c57752b997..650da2857b 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -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 diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index 0407ed8996..c2d50ce9fc 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -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(StmtStack[StmtStack.size() - 3])); + S->setCollection(cast_or_null(StmtStack[StmtStack.size() - 2])); + S->setBody(cast_or_null(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(StmtStack[StmtStack.size() - 2])); + S->setNextCatchStmt(cast_or_null(StmtStack[StmtStack.size() - 1])); + S->setCatchParamDecl(cast_or_null(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(StmtStack[StmtStack.size() - 3])); + S->setCatchStmts(cast_or_null(StmtStack[StmtStack.size() - 2])); + S->setFinallyStmt(cast_or_null(StmtStack[StmtStack.size() - 1])); + S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + return 3; +} + +unsigned PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { + VisitStmt(S); + S->setSynchExpr(cast_or_null(StmtStack[StmtStack.size() - 2])); + S->setSynchBody(cast_or_null(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. diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index d40b106539..5037a09193 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -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