Skip to content

Commit

Permalink
Use more smart pointers in HIR member functions
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* checks/lints/rust-lint-marklive.h:
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit):
	* hir/rust-hir-dump.cc (Dump::visit):
	* hir/tree/rust-hir-expr.h (RUST_HIR_EXPR_H):
	(class ArrayElemsValues):
	(class TupleExpr):
	(struct StructBase):
	(class StructExprStructFields):
	(class CallExpr):
	(class MethodCallExpr):
	(class WhileLetLoopExpr):
	(class IfLetExpr):
	* hir/tree/rust-hir-path.h:
	* hir/tree/rust-hir-type.h:
	* hir/tree/rust-hir.cc (TypePath::to_trait_bound):
	(StructExprStructFields::as_string):
	* hir/tree/rust-hir.h:
	* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
	* typecheck/rust-tyty-bounds.cc:

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Oct 15, 2024
1 parent 1964fcc commit 322881b
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 114 deletions.
4 changes: 2 additions & 2 deletions gcc/rust/checks/lints/rust-lint-marklive.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class MarkLive : public MarkLiveBase
stct.get_struct_name ().accept_vis (*this);
if (stct.has_struct_base ())
{
stct.struct_base->base_struct->accept_vis (*this);
stct.get_struct_base ().get_base ().accept_vis (*this);
}
}

Expand All @@ -258,7 +258,7 @@ class MarkLive : public MarkLiveBase

void visit (HIR::StructExprStructBase &stct) override
{
stct.get_struct_base ()->base_struct->accept_vis (*this);
stct.get_struct_base ().get_base ().accept_vis (*this);
}

void visit (HIR::Module &module) override
Expand Down
19 changes: 11 additions & 8 deletions gcc/rust/hir/rust-ast-lower-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.

#include "rust-ast-lower-expr.h"
#include "optional.h"
#include "rust-ast-lower-base.h"
#include "rust-ast-lower-block.h"
#include "rust-ast-lower-struct-field-expr.h"
Expand Down Expand Up @@ -77,7 +78,7 @@ ASTLoweringExpr::visit (AST::TupleIndexExpr &expr)
void
ASTLoweringExpr::visit (AST::TupleExpr &expr)
{
std::vector<std::unique_ptr<HIR::Expr> > tuple_elements;
std::vector<std::unique_ptr<HIR::Expr>> tuple_elements;
for (auto &e : expr.get_tuple_elems ())
{
HIR::Expr *t = ASTLoweringExpr::translate (*e);
Expand Down Expand Up @@ -174,7 +175,7 @@ ASTLoweringExpr::visit (AST::CallExpr &expr)
HIR::Expr *func = ASTLoweringExpr::translate (expr.get_function_expr ());

auto const &in_params = expr.get_params ();
std::vector<std::unique_ptr<HIR::Expr> > params;
std::vector<std::unique_ptr<HIR::Expr>> params;
for (auto &param : in_params)
{
auto trans = ASTLoweringExpr::translate (*param);
Expand All @@ -200,7 +201,7 @@ ASTLoweringExpr::visit (AST::MethodCallExpr &expr)
HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ());

auto const &in_params = expr.get_params ();
std::vector<std::unique_ptr<HIR::Expr> > params;
std::vector<std::unique_ptr<HIR::Expr>> params;
for (auto &param : in_params)
{
auto trans = ASTLoweringExpr::translate (*param);
Expand Down Expand Up @@ -290,7 +291,7 @@ ASTLoweringExpr::visit (AST::ArrayIndexExpr &expr)
void
ASTLoweringExpr::visit (AST::ArrayElemsValues &elems)
{
std::vector<std::unique_ptr<HIR::Expr> > elements;
std::vector<std::unique_ptr<HIR::Expr>> elements;
for (auto &elem : elems.get_values ())
{
HIR::Expr *translated_elem = ASTLoweringExpr::translate (*elem);
Expand Down Expand Up @@ -511,16 +512,17 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)
HIR::PathInExpression copied_path (*path);
delete path;

HIR::StructBase *base = nullptr;
tl::optional<std::unique_ptr<HIR::StructBase>> base = tl::nullopt;
if (struct_expr.has_struct_base ())
{
HIR::Expr *translated_base = ASTLoweringExpr::translate (
struct_expr.get_struct_base ().get_base_struct ());
base = new HIR::StructBase (std::unique_ptr<HIR::Expr> (translated_base));
base = tl::optional (Rust::make_unique<StructBase> (
std::unique_ptr<HIR::Expr> (translated_base)));
}

auto const &in_fields = struct_expr.get_fields ();
std::vector<std::unique_ptr<HIR::StructExprField> > fields;
std::vector<std::unique_ptr<HIR::StructExprField>> fields;
for (auto &field : in_fields)
{
HIR::StructExprField *translated
Expand All @@ -535,7 +537,8 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)

translated
= new HIR::StructExprStructFields (mapping, copied_path, std::move (fields),
struct_expr.get_locus (), base,
struct_expr.get_locus (),
std::move (base),
struct_expr.get_inner_attrs (),
struct_expr.get_outer_attrs ());
}
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/hir/rust-hir-dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ Dump::visit (StructExprStructFields &e)
if (!e.has_struct_base ())
put_field ("struct_base", "none");
else
put_field ("struct_base", e.get_struct_base ()->as_string ());
put_field ("struct_base", e.get_struct_base ().as_string ());

end ("StructExprStructFields");
}
Expand All @@ -1193,7 +1193,7 @@ Dump::visit (StructExprStructBase &e)
begin ("StructExprStructBase");
do_structexprstruct (e);

put_field ("struct_base", e.get_struct_base ()->as_string ());
put_field ("struct_base", e.get_struct_base ().as_string ());

end ("StructExprStructBase");
}
Expand Down
Loading

0 comments on commit 322881b

Please sign in to comment.