From: Ted Kremenek Date: Fri, 1 Feb 2008 21:28:59 +0000 (+0000) Subject: For ObjCAtCatchStmt, removed field 'NextAtCatchStmt' (which referenced the next ... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff981021554a4965943ca2d19019cea811614602;p=clang For ObjCAtCatchStmt, removed field 'NextAtCatchStmt' (which referenced the next @catch) and put the the next ObjcAtCatchStmt* as part of SubExprs. This fixes a bug with iterating over the children of ObjcAtCatch, where the next @catch was not properly being iterated over as a child. Altered serialization of ObjCAtCatchStmt to reflect this new layout of its subexpressions, and fixed an ownership issue with the next @catch not being serialized as an owned pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46647 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp index fd72481fee..249794db59 100644 --- a/AST/Stmt.cpp +++ b/AST/Stmt.cpp @@ -152,13 +152,14 @@ ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc, SubExprs[SELECTOR] = catchVarStmtDecl; SubExprs[BODY] = atCatchStmt; if (!atCatchList) - NextAtCatchStmt = NULL; + SubExprs[NEXT_CATCH] = NULL; else { - ObjCAtCatchStmt *AtCatchList = - static_cast(atCatchList); - while (AtCatchList->NextAtCatchStmt) - AtCatchList = AtCatchList->NextAtCatchStmt; - AtCatchList->NextAtCatchStmt = this; + ObjCAtCatchStmt *AtCatchList = static_cast(atCatchList); + + while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt()) + AtCatchList = NextCatch; + + AtCatchList->SubExprs[NEXT_CATCH] = this; } AtCatchLoc = atCatchLoc; RParenLoc = rparenloc; diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp index 227f365e1c..9a03a5320f 100644 --- a/AST/StmtSerialization.cpp +++ b/AST/StmtSerialization.cpp @@ -859,8 +859,7 @@ WhileStmt* WhileStmt::CreateImpl(Deserializer& D) { void ObjCAtCatchStmt::EmitImpl(Serializer& S) const { S.Emit(AtCatchLoc); S.Emit(RParenLoc); - S.EmitPtr(NextAtCatchStmt); - S.BatchEmitOwnedPtrs((unsigned) END_EXPR,&SubExprs[0]); + S.BatchEmitOwnedPtrs((unsigned) END_EXPR, &SubExprs[0]); } ObjCAtCatchStmt* ObjCAtCatchStmt::CreateImpl(Deserializer& D) { @@ -868,8 +867,6 @@ ObjCAtCatchStmt* ObjCAtCatchStmt::CreateImpl(Deserializer& D) { SourceLocation RParenLoc = SourceLocation::ReadVal(D); ObjCAtCatchStmt* stmt = new ObjCAtCatchStmt(AtCatchLoc,RParenLoc); - - D.ReadPtr(stmt->NextAtCatchStmt); // Allows backpatching. D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubExprs[0]); return stmt; diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 0018c54473..751d995079 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -817,9 +817,7 @@ public: /// ObjCAtCatchStmt - This represents objective-c's @catch statement. class ObjCAtCatchStmt : public Stmt { private: - // Points to next @catch statement, or null - ObjCAtCatchStmt *NextAtCatchStmt; - enum { SELECTOR, BODY, END_EXPR }; + enum { SELECTOR, BODY, NEXT_CATCH, END_EXPR }; Stmt *SubExprs[END_EXPR]; SourceLocation AtCatchLoc, RParenLoc; @@ -833,8 +831,14 @@ public: const Stmt *getCatchBody() const { return SubExprs[BODY]; } Stmt *getCatchBody() { return SubExprs[BODY]; } - const ObjCAtCatchStmt *getNextCatchStmt() const { return NextAtCatchStmt; } - ObjCAtCatchStmt *getNextCatchStmt() { return NextAtCatchStmt; } + + const ObjCAtCatchStmt *getNextCatchStmt() const { + return static_cast(SubExprs[NEXT_CATCH]); + } + ObjCAtCatchStmt *getNextCatchStmt() { + return static_cast(SubExprs[NEXT_CATCH]); + } + const Stmt *getCatchParamStmt() const { return SubExprs[SELECTOR]; } Stmt *getCatchParamStmt() { return SubExprs[SELECTOR]; }