From: Kushal Pal <kushalpal...@gmail.com>

gcc/rust/ChangeLog:

        * checks/errors/borrowck/rust-bir-builder-internal.h:
        Use `make_*` functions to create BIR::Statements.
        * checks/errors/borrowck/rust-bir.h: Make a complete constructor
        and introduce `make_*` functions to create various
        BIR::Statements.

Signed-off-by: Kushal Pal <kushalpal...@gmail.com>
---
 .../borrowck/rust-bir-builder-internal.h      | 28 +++++------
 gcc/rust/checks/errors/borrowck/rust-bir.h    | 48 ++++++++++++++-----
 2 files changed, 51 insertions(+), 25 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h 
b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
index 34726cf4840..74be02b90f6 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
@@ -239,7 +239,8 @@ protected:
 protected: // Helpers to add BIR statements
   void push_assignment (PlaceId lhs, AbstractExpr *rhs, location_t location)
   {
-    ctx.get_current_bb ().statements.emplace_back (lhs, rhs, location);
+    ctx.get_current_bb ().statements.push_back (
+      Statement::make_assignment (lhs, rhs, location));
     translated = lhs;
   }
 
@@ -266,47 +267,46 @@ protected: // Helpers to add BIR statements
                    std::initializer_list<BasicBlockId> destinations = {})
   {
     auto copy = move_place (switch_val, location);
-    ctx.get_current_bb ().statements.emplace_back (Statement::Kind::SWITCH,
-                                                  copy);
+    ctx.get_current_bb ().statements.push_back (Statement::make_switch (copy));
     ctx.get_current_bb ().successors.insert (
       ctx.get_current_bb ().successors.end (), destinations);
   }
 
   void push_goto (BasicBlockId bb)
   {
-    ctx.get_current_bb ().statements.emplace_back (Statement::Kind::GOTO);
+    ctx.get_current_bb ().statements.push_back (Statement::make_goto ());
     if (bb != INVALID_BB) // INVALID_BB means the goto will be resolved later.
       ctx.get_current_bb ().successors.push_back (bb);
   }
 
   void push_storage_live (PlaceId place)
   {
-    ctx.get_current_bb ().statements.emplace_back (
-      Statement::Kind::STORAGE_LIVE, place);
+    ctx.get_current_bb ().statements.push_back (
+      Statement::make_storage_live (place));
   }
 
   void push_storage_dead (PlaceId place)
   {
-    ctx.get_current_bb ().statements.emplace_back (
-      Statement::Kind::STORAGE_DEAD, place);
+    ctx.get_current_bb ().statements.push_back (
+      Statement::make_storage_dead (place));
   }
 
   void push_user_type_ascription (PlaceId place, TyTy::BaseType *ty)
   {
-    ctx.get_current_bb ().statements.emplace_back (
-      Statement::Kind::USER_TYPE_ASCRIPTION, place, ty);
+    ctx.get_current_bb ().statements.push_back (
+      Statement::make_user_type_ascription (place, ty));
   }
 
   void push_fake_read (PlaceId place)
   {
-    ctx.get_current_bb ().statements.emplace_back (Statement::Kind::FAKE_READ,
-                                                  place);
+    ctx.get_current_bb ().statements.push_back (
+      Statement::make_fake_read (place));
   }
 
   void push_return (location_t location)
   {
-    ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN,
-                                                  INVALID_PLACE, location);
+    ctx.get_current_bb ().statements.push_back (
+      Statement::make_return (location));
   }
 
   PlaceId borrow_place (PlaceId place_id, TyTy::BaseType *ty,
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h 
b/gcc/rust/checks/errors/borrowck/rust-bir.h
index 74c53a68a02..583d1ebd58f 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -83,18 +83,44 @@ private:
   location_t location;
 
 public:
-  Statement (PlaceId lhs, AbstractExpr *rhs, location_t location)
-    : kind (Kind::ASSIGNMENT), place (lhs), expr (rhs), location (location)
-  {}
-
-  explicit Statement (Kind kind, PlaceId place = INVALID_PLACE,
-                     location_t location = UNKNOWN_LOCATION)
-    : kind (kind), place (place), location (location)
-  {}
+  static Statement make_assignment (PlaceId place, AbstractExpr *rhs,
+                                   location_t location)
+  {
+    return Statement (Kind::ASSIGNMENT, place, rhs, nullptr, location);
+  }
+  static Statement make_switch (PlaceId place)
+  {
+    return Statement (Kind::SWITCH, place);
+  }
+  static Statement make_return (location_t location)
+  {
+    return Statement (Kind::RETURN, INVALID_PLACE, nullptr, nullptr, location);
+  }
+  static Statement make_goto () { return Statement (Kind::GOTO); }
+  static Statement make_storage_dead (PlaceId place)
+  {
+    return Statement (Kind::STORAGE_DEAD, place);
+  }
+  static Statement make_storage_live (PlaceId place)
+  {
+    return Statement (Kind::STORAGE_LIVE, place);
+  }
+  static Statement make_user_type_ascription (PlaceId place,
+                                             TyTy::BaseType *type)
+  {
+    return Statement (Kind::USER_TYPE_ASCRIPTION, place, nullptr, type);
+  }
+  static Statement make_fake_read (PlaceId place)
+  {
+    return Statement (Kind::FAKE_READ, place);
+  }
 
-  explicit Statement (Kind kind, PlaceId place, TyTy::BaseType *type,
-                     location_t location = UNKNOWN_LOCATION)
-    : kind (kind), place (place), type (type), location (location)
+private:
+  // compelete constructor, used by make_* functions
+  Statement (Kind kind, PlaceId place = INVALID_PLACE,
+            AbstractExpr *rhs = nullptr, TyTy::BaseType *type = nullptr,
+            location_t location = UNKNOWN_LOCATION)
+    : kind (kind), place (place), expr (rhs), type (type), location (location)
   {}
 
 public:
-- 
2.45.2

Reply via email to