thakis created this revision. thakis added a reviewer: hans. thakis requested review of this revision.
And make it final while here. No behavior change. https://reviews.llvm.org/D112542 Files: clang/include/clang/AST/StmtObjC.h Index: clang/include/clang/AST/StmtObjC.h =================================================================== --- clang/include/clang/AST/StmtObjC.h +++ clang/include/clang/AST/StmtObjC.h @@ -162,8 +162,14 @@ }; /// Represents Objective-C's \@try ... \@catch ... \@finally statement. -class ObjCAtTryStmt : public Stmt { -private: +class ObjCAtTryStmt final + : public Stmt, + private llvm::TrailingObjects<ObjCAtTryStmt, Stmt *> { + friend TrailingObjects; + size_t numTrailingObjects(OverloadToken<Stmt *>) const { + return 1 + NumCatchStmts + HasFinally; + } + // The location of the @ in the \@try. SourceLocation AtTryLoc; @@ -178,10 +184,8 @@ /// The order of the statements in memory follows the order in the source, /// with the \@try body first, followed by the \@catch statements (if any) /// and, finally, the \@finally (if it exists). - Stmt **getStmts() { return reinterpret_cast<Stmt **> (this + 1); } - const Stmt* const *getStmts() const { - return reinterpret_cast<const Stmt * const*> (this + 1); - } + Stmt **getStmts() { return getTrailingObjects<Stmt *>(); } + Stmt *const *getStmts() const { return getTrailingObjects<Stmt *>(); } ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, @@ -257,8 +261,8 @@ } child_range children() { - return child_range(getStmts(), - getStmts() + 1 + NumCatchStmts + HasFinally); + return child_range( + getStmts(), getStmts() + numTrailingObjects(OverloadToken<Stmt *>())); } const_child_range children() const {
Index: clang/include/clang/AST/StmtObjC.h =================================================================== --- clang/include/clang/AST/StmtObjC.h +++ clang/include/clang/AST/StmtObjC.h @@ -162,8 +162,14 @@ }; /// Represents Objective-C's \@try ... \@catch ... \@finally statement. -class ObjCAtTryStmt : public Stmt { -private: +class ObjCAtTryStmt final + : public Stmt, + private llvm::TrailingObjects<ObjCAtTryStmt, Stmt *> { + friend TrailingObjects; + size_t numTrailingObjects(OverloadToken<Stmt *>) const { + return 1 + NumCatchStmts + HasFinally; + } + // The location of the @ in the \@try. SourceLocation AtTryLoc; @@ -178,10 +184,8 @@ /// The order of the statements in memory follows the order in the source, /// with the \@try body first, followed by the \@catch statements (if any) /// and, finally, the \@finally (if it exists). - Stmt **getStmts() { return reinterpret_cast<Stmt **> (this + 1); } - const Stmt* const *getStmts() const { - return reinterpret_cast<const Stmt * const*> (this + 1); - } + Stmt **getStmts() { return getTrailingObjects<Stmt *>(); } + Stmt *const *getStmts() const { return getTrailingObjects<Stmt *>(); } ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, @@ -257,8 +261,8 @@ } child_range children() { - return child_range(getStmts(), - getStmts() + 1 + NumCatchStmts + HasFinally); + return child_range( + getStmts(), getStmts() + numTrailingObjects(OverloadToken<Stmt *>())); } const_child_range children() const {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits