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 377b0479da90..38a0449f86e0 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 @@ class AbstractBuilder 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 @@ class AbstractBuilder std::initializer_list 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 851fb7148594..8a0b96483e4c 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir.h @@ -83,18 +83,44 @@ class Statement 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: