[PATCH] D112542: [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 26 08:05:25 PDT 2021


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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112542.382327.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211026/72f094f9/attachment.bin>


More information about the cfe-commits mailing list