aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-02-27 13:43:37 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:32:57 +0100
commitc29a3bc945c2d018f75974c12c29aaf99a978984 (patch)
tree70446069f91938748c7dc014416ec26937d86ae9 /gcc/rust/backend
parentd3a3e52addbe07fed81209a29fe653d840dc67d2 (diff)
downloadgcc-c29a3bc945c2d018f75974c12c29aaf99a978984.zip
gcc-c29a3bc945c2d018f75974c12c29aaf99a978984.tar.gz
gcc-c29a3bc945c2d018f75974c12c29aaf99a978984.tar.bz2
gccrs: Refactor HIR to reduce the amount of raw pointers
Attempt to use references and smart pointers whenever possible. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): Remove usage of get function to retrieve a raw pointer. * backend/rust-compile-base.h: Change API usage from raw pointer to a reference. * backend/rust-compile-block.cc (CompileBlock::compile): Likewise. (CompileBlock::visit): Likewise. (CompileConditionalBlocks::visit): Likewise. * backend/rust-compile-block.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::Compile): Likewise. (CompileExpr::visit): Likewise. (check_match_scrutinee): Likewise. (CompileExpr::array_value_expr): Likewise. (CompileExpr::array_copied_expr): Likewise. (CompileExpr::generate_closure_function): Likewise. (CompileExpr::generate_possible_fn_trait_call): Likewise. * backend/rust-compile-expr.h: Likewise. * backend/rust-compile-fnparam.cc (CompileFnParam::compile): Likewise. (CompileFnParam::visit): Likewise. * backend/rust-compile-fnparam.h: Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-intrinsic.cc (compile_fn_params): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Likewise. (compile_range_pattern_bound): Likewise. (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-compile-pattern.h: Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. (HIRCompileBase::query_compile): Likewise. * backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise. * backend/rust-compile-struct-field-expr.cc (CompileStructExprField::Compile): Likewise. (CompileStructExprField::visit): Likewise. * backend/rust-compile-struct-field-expr.h: Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-compile.cc: Likewise. * backend/rust-mangle-v0.cc (v0_inherent_or_trait_impl_path): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-bir-builder.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_type_privacy): Likewise. (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise. * checks/lints/rust-lint-marklive.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir.h: Likewise. * typecheck/rust-autoderef.cc: Likewise. * typecheck/rust-hir-dot-operator.cc (MethodResolver::select): Likewise. * typecheck/rust-hir-inherent-impl-overlap.h: Likewise. * typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_item_candidate): Likewise. (PathProbeImplTrait::process_trait_impl_items_for_candidates): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise. (TraitItemReference::resolve_item): Likewise. * typecheck/rust-hir-type-check-base.cc: Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::Resolve): Likewise. (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-enumitem.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::Resolve): Likewise. (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::Resolve): Likewise. (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::visit): Likewise. (TypeCheckImplItemWithTrait::visit): Likewise. * typecheck/rust-hir-type-check-implitem.h: Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. (TypeCheckItem::resolve_impl_item): Likewise. (TypeCheckItem::resolve_impl_block_substitutions): Likewise. (TypeCheckItem::resolve_impl_block_self): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve): Likewise. (TypeCheckPattern::visit): Likewise. (ClosureParamInfer::Resolve): Likewise. (ClosureParamInfer::visit): Likewise. * typecheck/rust-hir-type-check-pattern.h: Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::Resolve): Likewise. (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-hir-type-check-struct-field.h: Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr): Likewise. (TypeCheckStructExpr::Resolve): Likewise. (TypeCheckStructExpr::resolve): Likewise. (TypeCheckStructExpr::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckResolveGenericArguments::resolve): Likewise. (TypeCheckType::Resolve): Likewise. (TypeCheckType::visit): Likewise. (TypeCheckType::resolve_root_path): Likewise. (TypeResolveGenericParam::Resolve): Likewise. (TypeResolveGenericParam::visit): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check-type.h: Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-hir-type-check.h: Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise. (TypeCheckBase::get_predicate_from_bound): Likewise. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. (TypeCheckMethodCallExpr::go): Likewise. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-subst.cc: Likewise. * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Likewise. (VariantDef::VariantDef): Remove copy constructor. (VariantDef::operator=): Change to move operator. (VariantDef::get_discriminant): Replace return type to a reference instead of a reference to a unique pointer. (VariantDef::clone): Change to references. (VariantDef::monomorphized_clone): Likewise. (FnType::as_string): Likewise. (FnType::clone): Likewise. * typecheck/rust-tyty.h: Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_impl_block): Likewise. * backend/rust-compile-asm.cc: Use a reference instead of the raw pointer value. * checks/errors/borrowck/rust-bir-builder-pattern.cc: Use references. * checks/errors/rust-hir-pattern-analysis.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-asm.cc4
-rw-r--r--gcc/rust/backend/rust-compile-base.cc35
-rw-r--r--gcc/rust/backend/rust-compile-base.h2
-rw-r--r--gcc/rust/backend/rust-compile-block.cc27
-rw-r--r--gcc/rust/backend/rust-compile-block.h4
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc208
-rw-r--r--gcc/rust/backend/rust-compile-expr.h6
-rw-r--r--gcc/rust/backend/rust-compile-fnparam.cc14
-rw-r--r--gcc/rust/backend/rust-compile-fnparam.h4
-rw-r--r--gcc/rust/backend/rust-compile-implitem.cc4
-rw-r--r--gcc/rust/backend/rust-compile-intrinsic.cc2
-rw-r--r--gcc/rust/backend/rust-compile-item.cc9
-rw-r--r--gcc/rust/backend/rust-compile-pattern.cc77
-rw-r--r--gcc/rust/backend/rust-compile-pattern.h8
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc4
-rw-r--r--gcc/rust/backend/rust-compile-stmt.cc12
-rw-r--r--gcc/rust/backend/rust-compile-struct-field-expr.cc16
-rw-r--r--gcc/rust/backend/rust-compile-struct-field-expr.h2
-rw-r--r--gcc/rust/backend/rust-compile-type.cc2
-rw-r--r--gcc/rust/backend/rust-compile-var-decl.h4
-rw-r--r--gcc/rust/backend/rust-compile.cc10
-rw-r--r--gcc/rust/backend/rust-mangle-v0.cc4
22 files changed, 219 insertions, 239 deletions
diff --git a/gcc/rust/backend/rust-compile-asm.cc b/gcc/rust/backend/rust-compile-asm.cc
index be553a3..22498bc 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -85,7 +85,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
{
auto out = output.get_out ();
- tree out_tree = CompileExpr::Compile (out.expr.get (), this->ctx);
+ tree out_tree = CompileExpr::Compile (*out.expr, this->ctx);
// expects a tree list
// TODO: This assumes that the output is a register
std::string expr_name = "=r";
@@ -112,7 +112,7 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
{
auto in = input.get_in ();
- tree in_tree = CompileExpr::Compile (in.expr.get (), this->ctx);
+ tree in_tree = CompileExpr::Compile (*in.expr, this->ctx);
// expects a tree list
// TODO: This assumes that the input is a register
std::string expr_name = "r";
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 8166c3a..598f2e2 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -582,8 +582,9 @@ HIRCompileBase::compile_function_body (tree fndecl,
if (function_body.has_expr ())
{
- location_t locus = function_body.get_final_expr ()->get_locus ();
- tree return_value = CompileExpr::Compile (function_body.expr.get (), ctx);
+ location_t locus = function_body.get_final_expr ().get_locus ();
+ tree return_value
+ = CompileExpr::Compile (function_body.get_final_expr (), ctx);
// we can only return this if non unit value return type
if (!fn_return_ty->is_unit ())
@@ -709,18 +710,18 @@ HIRCompileBase::compile_function (
size_t i = is_method ? 1 : 0;
for (auto &referenced_param : function_params)
{
- auto tyty_param = fntype->param_at (i++);
+ auto &tyty_param = fntype->param_at (i++);
auto param_tyty = tyty_param.second;
auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty);
location_t param_locus = referenced_param.get_locus ();
Bvariable *compiled_param_var
- = CompileFnParam::compile (ctx, fndecl, &referenced_param,
+ = CompileFnParam::compile (ctx, fndecl, referenced_param,
compiled_param_type, param_locus);
param_vars.push_back (compiled_param_var);
- const HIR::Pattern &param_pattern = *referenced_param.get_param_name ();
+ const HIR::Pattern &param_pattern = referenced_param.get_param_name ();
ctx->insert_var_decl (param_pattern.get_mappings ().get_hirid (),
compiled_param_var);
}
@@ -768,14 +769,14 @@ HIRCompileBase::compile_function (
tree
HIRCompileBase::compile_constant_item (
TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path,
- HIR::Expr *const_value_expr, location_t locus)
+ HIR::Expr &const_value_expr, location_t locus)
{
const std::string &ident = canonical_path.get ();
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
tree const_type = build_qualified_type (type, TYPE_QUAL_CONST);
bool is_block_expr
- = const_value_expr->get_expression_type () == HIR::Expr::ExprType::Block;
+ = const_value_expr.get_expression_type () == HIR::Expr::ExprType::Block;
// in order to compile a block expr we want to reuse as much existing
// machineary that we already have. This means the best approach is to
@@ -789,14 +790,14 @@ HIRCompileBase::compile_constant_item (
TREE_READONLY (fndecl) = 1;
tree enclosing_scope = NULL_TREE;
- location_t start_location = const_value_expr->get_locus ();
- location_t end_location = const_value_expr->get_locus ();
+ location_t start_location = const_value_expr.get_locus ();
+ location_t end_location = const_value_expr.get_locus ();
if (is_block_expr)
{
- HIR::BlockExpr *function_body
- = static_cast<HIR::BlockExpr *> (const_value_expr);
- start_location = function_body->get_locus ();
- end_location = function_body->get_end_locus ();
+ HIR::BlockExpr &function_body
+ = static_cast<HIR::BlockExpr &> (const_value_expr);
+ start_location = function_body.get_locus ();
+ end_location = function_body.get_end_locus ();
}
tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/,
@@ -814,9 +815,9 @@ HIRCompileBase::compile_constant_item (
if (is_block_expr)
{
- HIR::BlockExpr *function_body
- = static_cast<HIR::BlockExpr *> (const_value_expr);
- compile_function_body (fndecl, *function_body, resolved_type);
+ HIR::BlockExpr &function_body
+ = static_cast<HIR::BlockExpr &> (const_value_expr);
+ compile_function_body (fndecl, function_body, resolved_type);
}
else
{
@@ -824,7 +825,7 @@ HIRCompileBase::compile_constant_item (
tree return_expr
= Backend::return_statement (fndecl, value,
- const_value_expr->get_locus ());
+ const_value_expr.get_locus ());
ctx->add_statement (return_expr);
}
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index eeb3ff0..5fb1d83 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -92,7 +92,7 @@ protected:
tree compile_constant_item (TyTy::BaseType *resolved_type,
const Resolver::CanonicalPath &canonical_path,
- HIR::Expr *const_value_expr, location_t locus);
+ HIR::Expr &const_value_expr, location_t locus);
tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param,
std::vector<HIR::FunctionParam> &function_params,
diff --git a/gcc/rust/backend/rust-compile-block.cc b/gcc/rust/backend/rust-compile-block.cc
index eb8af2a..f844a27 100644
--- a/gcc/rust/backend/rust-compile-block.cc
+++ b/gcc/rust/backend/rust-compile-block.cc
@@ -28,10 +28,10 @@ CompileBlock::CompileBlock (Context *ctx, Bvariable *result)
{}
tree
-CompileBlock::compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result)
+CompileBlock::compile (HIR::BlockExpr &expr, Context *ctx, Bvariable *result)
{
CompileBlock compiler (ctx, result);
- compiler.visit (*expr);
+ compiler.visit (expr);
return compiler.translated;
}
@@ -60,10 +60,10 @@ CompileBlock::visit (HIR::BlockExpr &expr)
if (expr.has_expr ())
{
- tree compiled_expr = CompileExpr::Compile (expr.expr.get (), ctx);
+ tree compiled_expr = CompileExpr::Compile (expr.get_final_expr (), ctx);
if (result != nullptr)
{
- location_t locus = expr.get_final_expr ()->get_locus ();
+ location_t locus = expr.get_final_expr ().get_locus ();
tree result_reference = Backend::var_expression (result, locus);
tree assignment
@@ -93,10 +93,8 @@ CompileConditionalBlocks::visit (HIR::IfExpr &expr)
{
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
- tree condition_expr
- = CompileExpr::Compile (expr.get_if_condition ().get (), ctx);
- tree then_block
- = CompileBlock::compile (expr.get_if_block ().get (), ctx, result);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
translated = Backend::if_statement (fndecl, condition_expr, then_block, NULL,
expr.get_locus ());
@@ -107,23 +105,20 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
{
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
- tree condition_expr
- = CompileExpr::Compile (expr.get_if_condition ().get (), ctx);
- tree then_block
- = CompileBlock::compile (expr.get_if_block ().get (), ctx, result);
+ tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
// else block
std::vector<Bvariable *> locals;
- location_t start_location = expr.get_else_block ()->get_locus ();
- location_t end_location = expr.get_else_block ()->get_locus (); // FIXME
+ location_t start_location = expr.get_else_block ().get_locus ();
+ location_t end_location = expr.get_else_block ().get_locus (); // FIXME
tree enclosing_scope = ctx->peek_enclosing_scope ();
tree else_block = Backend::block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (else_block);
tree else_stmt_decl
- = CompileExprWithBlock::compile (expr.get_else_block ().get (), ctx,
- result);
+ = CompileExprWithBlock::compile (&expr.get_else_block (), ctx, result);
ctx->add_statement (else_stmt_decl);
diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h
index 6616882..37e3980 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -28,7 +28,7 @@ namespace Compile {
class CompileBlock : private HIRCompileBase
{
public:
- static tree compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result);
+ static tree compile (HIR::BlockExpr &expr, Context *ctx, Bvariable *result);
protected:
void visit (HIR::BlockExpr &expr);
@@ -134,7 +134,7 @@ public:
void visit (HIR::BlockExpr &expr) override
{
- translated = CompileBlock::compile (&expr, ctx, result);
+ translated = CompileBlock::compile (expr, ctx, result);
}
// Empty visit for unused Expression HIR nodes.
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 7251cc8..c46bda9 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -40,24 +40,24 @@ CompileExpr::CompileExpr (Context *ctx)
{}
tree
-CompileExpr::Compile (HIR::Expr *expr, Context *ctx)
+CompileExpr::Compile (HIR::Expr &expr, Context *ctx)
{
CompileExpr compiler (ctx);
- expr->accept_vis (compiler);
+ expr.accept_vis (compiler);
return compiler.translated;
}
void
CompileExpr::visit (HIR::TupleIndexExpr &expr)
{
- HIR::Expr *tuple_expr = expr.get_tuple_expr ().get ();
+ HIR::Expr &tuple_expr = expr.get_tuple_expr ();
TupleIndex index = expr.get_tuple_index ();
tree receiver_ref = CompileExpr::Compile (tuple_expr, ctx);
TyTy::BaseType *tuple_expr_ty = nullptr;
bool ok
- = ctx->get_tyctx ()->lookup_type (tuple_expr->get_mappings ().get_hirid (),
+ = ctx->get_tyctx ()->lookup_type (tuple_expr.get_mappings ().get_hirid (),
&tuple_expr_ty);
rust_assert (ok);
@@ -97,7 +97,7 @@ CompileExpr::visit (HIR::TupleExpr &expr)
std::vector<tree> vals;
for (auto &elem : expr.get_tuple_elems ())
{
- auto e = CompileExpr::Compile (elem.get (), ctx);
+ auto e = CompileExpr::Compile (*elem, ctx);
vals.push_back (e);
}
@@ -111,7 +111,7 @@ CompileExpr::visit (HIR::ReturnExpr &expr)
auto fncontext = ctx->peek_fn ();
tree return_value = expr.has_return_expr ()
- ? CompileExpr::Compile (expr.return_expr.get (), ctx)
+ ? CompileExpr::Compile (expr.get_expr (), ctx)
: unit_expression (expr.get_locus ());
if (expr.has_return_expr ())
@@ -141,8 +141,8 @@ void
CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
@@ -153,8 +153,7 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
auto lang_item_type
= LangItem::OperatorToLangItem (expr.get_expr_type ());
translated = resolve_operator_overload (lang_item_type, expr, lhs, rhs,
- expr.get_lhs ().get (),
- expr.get_rhs ().get ());
+ expr.get_lhs (), expr.get_rhs ());
return;
}
@@ -185,8 +184,8 @@ void
CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
@@ -198,8 +197,7 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
expr.get_expr_type ());
auto compound_assignment
= resolve_operator_overload (lang_item_type, expr, lhs, rhs,
- expr.get_lhs ().get (),
- expr.get_rhs ().get ());
+ expr.get_lhs (), expr.get_rhs ());
ctx->add_statement (compound_assignment);
return;
@@ -236,18 +234,18 @@ CompileExpr::visit (HIR::NegationExpr &expr)
{
auto op = expr.get_expr_type ();
- const auto literal_expr = expr.get_expr ().get ();
+ auto &literal_expr = expr.get_expr ();
// If it's a negated integer/float literal, we can return early
if (op == NegationOperator::NEGATE
- && literal_expr->get_expression_type () == HIR::Expr::ExprType::Lit)
+ && literal_expr.get_expression_type () == HIR::Expr::ExprType::Lit)
{
- auto new_literal_expr = static_cast<HIR::LiteralExpr *> (literal_expr);
- auto lit_type = new_literal_expr->get_lit_type ();
+ auto &new_literal_expr = static_cast<HIR::LiteralExpr &> (literal_expr);
+ auto lit_type = new_literal_expr.get_lit_type ();
if (lit_type == HIR::Literal::LitType::INT
|| lit_type == HIR::Literal::LitType::FLOAT)
{
- new_literal_expr->set_negative ();
+ new_literal_expr.set_negative ();
translated = CompileExpr::Compile (literal_expr, ctx);
return;
}
@@ -265,7 +263,7 @@ CompileExpr::visit (HIR::NegationExpr &expr)
auto lang_item_type = LangItem::NegationOperatorToLangItem (op);
translated
= resolve_operator_overload (lang_item_type, expr, negated_expr,
- nullptr, expr.get_expr ().get (), nullptr);
+ nullptr, expr.get_expr (), tl::nullopt);
return;
}
@@ -276,8 +274,8 @@ void
CompileExpr::visit (HIR::ComparisonExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
auto location = expr.get_locus ();
translated = Backend::comparison_expression (op, lhs, rhs, location);
@@ -287,8 +285,8 @@ void
CompileExpr::visit (HIR::LazyBooleanExpr &expr)
{
auto op = expr.get_expr_type ();
- auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
auto location = expr.get_locus ();
translated = Backend::lazy_boolean_expression (op, lhs, rhs, location);
@@ -307,14 +305,14 @@ CompileExpr::visit (HIR::TypeCastExpr &expr)
TyTy::BaseType *casted_tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_casted_expr ()->get_mappings ().get_hirid (), &casted_tyty))
+ expr.get_casted_expr ().get_mappings ().get_hirid (), &casted_tyty))
{
translated = error_mark_node;
return;
}
auto type_to_cast_to = TyTyResolveCompile::compile (ctx, type_to_cast_to_ty);
- auto casted_expr = CompileExpr::Compile (expr.get_casted_expr ().get (), ctx);
+ auto casted_expr = CompileExpr::Compile (expr.get_casted_expr (), ctx);
std::vector<Resolver::Adjustment> *adjustments = nullptr;
bool ok = ctx->get_tyctx ()->lookup_cast_autoderef_mappings (
@@ -405,7 +403,7 @@ CompileExpr::visit (HIR::BlockExpr &expr)
&ret_var_stmt);
ctx->add_statement (ret_var_stmt);
- auto block_stmt = CompileBlock::compile (&expr, ctx, tmp);
+ auto block_stmt = CompileBlock::compile (expr, ctx, tmp);
rust_assert (TREE_CODE (block_stmt) == BIND_EXPR);
ctx->add_statement (block_stmt);
@@ -415,7 +413,7 @@ CompileExpr::visit (HIR::BlockExpr &expr)
void
CompileExpr::visit (HIR::UnsafeBlockExpr &expr)
{
- expr.get_block_expr ()->accept_vis (*this);
+ expr.get_block_expr ().accept_vis (*this);
}
void
@@ -487,7 +485,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
auto lvalue_locus
= ctx->get_mappings ().lookup_location (expected->get_ty_ref ());
auto rvalue_locus = argument->get_locus ();
- auto rvalue = CompileStructExprField::Compile (argument.get (), ctx);
+ auto rvalue = CompileStructExprField::Compile (*argument, ctx);
TyTy::BaseType *actual = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
@@ -519,7 +517,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
auto lvalue_locus
= ctx->get_mappings ().lookup_location (expected->get_ty_ref ());
auto rvalue_locus = argument->get_locus ();
- auto rvalue = CompileStructExprField::Compile (argument.get (), ctx);
+ auto rvalue = CompileStructExprField::Compile (*argument, ctx);
TyTy::BaseType *actual = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
@@ -544,7 +542,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
std::vector<tree> ctor_arguments;
if (adt->is_enum ())
{
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
tree folded_discrim_expr = fold_expr (discrim_expr_node);
tree qualifier = folded_discrim_expr;
@@ -563,21 +561,21 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
void
CompileExpr::visit (HIR::GroupedExpr &expr)
{
- translated = CompileExpr::Compile (expr.get_expr_in_parens ().get (), ctx);
+ translated = CompileExpr::Compile (expr.get_expr_in_parens (), ctx);
}
void
CompileExpr::visit (HIR::FieldAccessExpr &expr)
{
- HIR::Expr *receiver_expr = expr.get_receiver_expr ().get ();
+ HIR::Expr &receiver_expr = expr.get_receiver_expr ();
tree receiver_ref = CompileExpr::Compile (receiver_expr, ctx);
// resolve the receiver back to ADT type
TyTy::BaseType *receiver = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver))
+ expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver))
{
- rust_error_at (expr.get_receiver_expr ()->get_locus (),
+ rust_error_at (expr.get_receiver_expr ().get_locus (),
"unresolved type for receiver");
return;
}
@@ -672,7 +670,7 @@ CompileExpr::visit (HIR::LoopExpr &expr)
ctx->push_loop_begin_label (loop_begin_label);
tree code_block
- = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
+ = CompileBlock::compile (expr.get_loop_block (), ctx, nullptr);
tree loop_expr = Backend::loop_expression (code_block, expr.get_locus ());
ctx->add_statement (loop_expr);
@@ -699,8 +697,8 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
}
std::vector<Bvariable *> locals;
- location_t start_location = expr.get_loop_block ()->get_locus ();
- location_t end_location = expr.get_loop_block ()->get_locus (); // FIXME
+ location_t start_location = expr.get_loop_block ().get_locus ();
+ location_t end_location = expr.get_loop_block ().get_locus (); // FIXME
tree enclosing_scope = ctx->peek_enclosing_scope ();
tree loop_block = Backend::block (fnctx.fndecl, enclosing_scope, locals,
@@ -713,15 +711,14 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
- tree condition
- = CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
+ tree condition = CompileExpr::Compile (expr.get_predicate_expr (), ctx);
tree exit_condition = fold_build1_loc (expr.get_locus (), TRUTH_NOT_EXPR,
boolean_type_node, condition);
tree exit_expr = Backend::exit_expression (exit_condition, expr.get_locus ());
ctx->add_statement (exit_expr);
tree code_block_stmt
- = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
+ = CompileBlock::compile (expr.get_loop_block (), ctx, nullptr);
rust_assert (TREE_CODE (code_block_stmt) == BIND_EXPR);
ctx->add_statement (code_block_stmt);
@@ -737,12 +734,12 @@ CompileExpr::visit (HIR::BreakExpr &expr)
{
if (expr.has_break_expr ())
{
- tree compiled_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree compiled_expr = CompileExpr::Compile (expr.get_expr (), ctx);
Bvariable *loop_result_holder = ctx->peek_loop_context ();
tree result_reference
= Backend::var_expression (loop_result_holder,
- expr.get_expr ()->get_locus ());
+ expr.get_expr ().get_locus ());
tree assignment
= Backend::assignment_statement (result_reference, compiled_expr,
@@ -865,7 +862,7 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
void
CompileExpr::visit (HIR::BorrowExpr &expr)
{
- tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree main_expr = CompileExpr::Compile (expr.get_expr (), ctx);
if (RS_DST_FLAG_P (TREE_TYPE (main_expr)))
{
translated = main_expr;
@@ -892,7 +889,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr)
return;
}
- tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx);
+ tree main_expr = CompileExpr::Compile (expr.get_expr (), ctx);
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
@@ -903,7 +900,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr)
auto lang_item_type = LangItem::Kind::DEREF;
tree operator_overload_call
= resolve_operator_overload (lang_item_type, expr, main_expr, nullptr,
- expr.get_expr ().get (), nullptr);
+ expr.get_expr (), tl::nullopt);
// rust deref always returns a reference from this overload then we can
// actually do the indirection
@@ -963,8 +960,8 @@ CompileExpr::visit (HIR::LiteralExpr &expr)
void
CompileExpr::visit (HIR::AssignmentExpr &expr)
{
- auto lvalue = CompileExpr::Compile (expr.get_lhs ().get (), ctx);
- auto rvalue = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
+ auto lvalue = CompileExpr::Compile (expr.get_lhs (), ctx);
+ auto rvalue = CompileExpr::Compile (expr.get_rhs (), ctx);
// assignments are coercion sites so lets convert the rvalue if necessary
TyTy::BaseType *expected = nullptr;
@@ -972,16 +969,16 @@ CompileExpr::visit (HIR::AssignmentExpr &expr)
bool ok;
ok = ctx->get_tyctx ()->lookup_type (
- expr.get_lhs ()->get_mappings ().get_hirid (), &expected);
+ expr.get_lhs ().get_mappings ().get_hirid (), &expected);
rust_assert (ok);
ok = ctx->get_tyctx ()->lookup_type (
- expr.get_rhs ()->get_mappings ().get_hirid (), &actual);
+ expr.get_rhs ().get_mappings ().get_hirid (), &actual);
rust_assert (ok);
rvalue = coercion_site (expr.get_mappings ().get_hirid (), rvalue, actual,
- expected, expr.get_lhs ()->get_locus (),
- expr.get_rhs ()->get_locus ());
+ expected, expr.get_lhs ().get_locus (),
+ expr.get_rhs ().get_locus ());
// rust_debug_loc (expr.get_locus (), "XXXXXX assignment");
// debug_tree (rvalue);
@@ -1002,7 +999,7 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
{
TyTy::BaseType *scrutinee_expr_tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_scrutinee_expr ()->get_mappings ().get_hirid (),
+ expr.get_scrutinee_expr ().get_mappings ().get_hirid (),
&scrutinee_expr_tyty))
{
return TyTy::TypeKind::ERROR;
@@ -1080,7 +1077,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
// lets compile the scrutinee expression
tree match_scrutinee_rval
- = CompileExpr::Compile (expr.get_scrutinee_expr ().get (), ctx);
+ = CompileExpr::Compile (expr.get_scrutinee_expr (), ctx);
Bvariable *match_scrutinee_tmp_var
= Backend::temporary_variable (fnctx.fndecl, enclosing_scope,
@@ -1090,7 +1087,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
ctx->add_statement (ret_var_stmt);
tree match_scrutinee_expr = match_scrutinee_tmp_var->get_tree (
- expr.get_scrutinee_expr ()->get_locus ());
+ expr.get_scrutinee_expr ().get_locus ());
tree assignment
= Backend::assignment_statement (match_scrutinee_expr, match_scrutinee_rval,
@@ -1123,14 +1120,13 @@ CompileExpr::visit (HIR::MatchExpr &expr)
ctx->push_block (arm_body_block);
// setup the bindings for the block
- CompilePatternBindings::Compile (kase_pattern.get (),
- match_scrutinee_expr, ctx);
+ CompilePatternBindings::Compile (*kase_pattern, match_scrutinee_expr,
+ ctx);
// compile the expr and setup the assignment if required when tmp !=
// NULL
location_t arm_locus = kase_arm.get_locus ();
- tree kase_expr_tree
- = CompileExpr::Compile (kase.get_expr ().get (), ctx);
+ tree kase_expr_tree = CompileExpr::Compile (kase.get_expr (), ctx);
tree result_reference = Backend::var_expression (tmp, arm_locus);
tree assignment
= Backend::assignment_statement (result_reference, kase_expr_tree,
@@ -1145,7 +1141,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
ctx->pop_block ();
tree check_expr
- = CompilePatternCheckExpr::Compile (kase_pattern.get (),
+ = CompilePatternCheckExpr::Compile (*kase_pattern,
match_scrutinee_expr, ctx);
tree check_stmt
@@ -1167,7 +1163,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
{
TyTy::BaseType *tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- expr.get_fnexpr ()->get_mappings ().get_hirid (), &tyty))
+ expr.get_fnexpr ().get_mappings ().get_hirid (), &tyty))
{
rust_error_at (expr.get_locus (), "unknown type");
return;
@@ -1193,7 +1189,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
{
HirId variant_id;
bool ok = ctx->get_tyctx ()->lookup_variant_definition (
- expr.get_fnexpr ()->get_mappings ().get_hirid (), &variant_id);
+ expr.get_fnexpr ().get_mappings ().get_hirid (), &variant_id);
rust_assert (ok);
ok = adt->lookup_variant_by_id (variant_id, &variant,
@@ -1207,7 +1203,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
// assignments are coercion sites so lets convert the rvalue if
// necessary
@@ -1236,7 +1232,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
std::vector<tree> ctor_arguments;
if (adt->is_enum ())
{
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
tree folded_discrim_expr = fold_expr (discrim_expr_node);
tree qualifier = folded_discrim_expr;
@@ -1270,13 +1266,13 @@ CompileExpr::visit (HIR::CallExpr &expr)
}
const TyTy::FnType *fn = static_cast<const TyTy::FnType *> (base);
- auto param = fn->param_at (index);
+ auto &param = fn->param_at (index);
*result = param.second;
return true;
};
- auto fn_address = CompileExpr::Compile (expr.get_fnexpr ().get (), ctx);
+ auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx);
// is this a closure call?
bool possible_trait_call
@@ -1303,7 +1299,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
if (is_variadic && i >= required_num_args)
{
@@ -1343,7 +1339,7 @@ void
CompileExpr::visit (HIR::MethodCallExpr &expr)
{
// method receiver
- tree self = CompileExpr::Compile (expr.get_receiver ().get (), ctx);
+ tree self = CompileExpr::Compile (expr.get_receiver (), ctx);
// lookup the expected function type
TyTy::BaseType *lookup_fntype = nullptr;
@@ -1383,7 +1379,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// lookup the autoderef mappings
HirId autoderef_mappings_id
- = expr.get_receiver ()->get_mappings ().get_hirid ();
+ = expr.get_receiver ().get_mappings ().get_hirid ();
std::vector<Resolver::Adjustment> *adjustments = nullptr;
ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id,
&adjustments);
@@ -1391,7 +1387,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// apply adjustments for the fn call
self = resolve_adjustements (*adjustments, self,
- expr.get_receiver ()->get_locus ());
+ expr.get_receiver ().get_locus ());
std::vector<tree> args;
args.push_back (self); // adjusted self
@@ -1400,7 +1396,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
for (size_t i = 0; i < expr.get_arguments ().size (); i++)
{
auto &argument = expr.get_arguments ().at (i);
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
// assignments are coercion sites so lets convert the rvalue if
// necessary, offset from the already adjusted implicit self
@@ -1482,8 +1478,8 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
tree
CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
HIR::OperatorExprMeta expr, tree lhs,
- tree rhs, HIR::Expr *lhs_expr,
- HIR::Expr *rhs_expr)
+ tree rhs, HIR::Expr &lhs_expr,
+ tl::optional<HIR::Expr &> rhs_expr)
{
TyTy::FnType *fntype;
bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
@@ -1514,7 +1510,7 @@ CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type,
rust_assert (ok);
// apply adjustments for the fn call
- tree self = resolve_adjustements (*adjustments, lhs, lhs_expr->get_locus ());
+ tree self = resolve_adjustements (*adjustments, lhs, lhs_expr.get_locus ());
std::vector<tree> args;
args.push_back (self); // adjusted self
@@ -1829,7 +1825,7 @@ CompileExpr::visit (HIR::ArrayExpr &expr)
const TyTy::ArrayType &array_tyty
= static_cast<const TyTy::ArrayType &> (*tyty);
- HIR::ArrayElems &elements = *expr.get_internal_elements ();
+ HIR::ArrayElems &elements = expr.get_internal_elements ();
switch (elements.get_array_expr_type ())
{
case HIR::ArrayElems::ArrayExprType::VALUES: {
@@ -1858,7 +1854,7 @@ CompileExpr::array_value_expr (location_t expr_locus,
size_t i = 0;
for (auto &elem : elems.get_values ())
{
- tree translated_expr = CompileExpr::Compile (elem.get (), ctx);
+ tree translated_expr = CompileExpr::Compile (*elem, ctx);
constructor.push_back (translated_expr);
indexes.push_back (i++);
}
@@ -1885,8 +1881,7 @@ CompileExpr::array_copied_expr (location_t expr_locus,
}
ctx->push_const_context ();
- tree capacity_expr
- = CompileExpr::Compile (elems.get_num_copies_expr ().get (), ctx);
+ tree capacity_expr = CompileExpr::Compile (elems.get_num_copies_expr (), ctx);
ctx->pop_const_context ();
if (!TREE_CONSTANT (capacity_expr))
@@ -1896,8 +1891,7 @@ CompileExpr::array_copied_expr (location_t expr_locus,
}
// get the compiled value
- tree translated_expr
- = CompileExpr::Compile (elems.get_elem_to_copy ().get (), ctx);
+ tree translated_expr = CompileExpr::Compile (elems.get_elem_to_copy (), ctx);
tree max_domain = TYPE_MAX_VALUE (domain);
tree min_domain = TYPE_MIN_VALUE (domain);
@@ -2102,8 +2096,8 @@ HIRCompileBase::resolve_unsized_dyn_adjustment (
void
CompileExpr::visit (HIR::RangeFromToExpr &expr)
{
- tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
- tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
+ tree from = CompileExpr::Compile (expr.get_from_expr (), ctx);
+ tree to = CompileExpr::Compile (expr.get_to_expr (), ctx);
if (from == error_mark_node || to == error_mark_node)
{
translated = error_mark_node;
@@ -2125,7 +2119,7 @@ CompileExpr::visit (HIR::RangeFromToExpr &expr)
void
CompileExpr::visit (HIR::RangeFromExpr &expr)
{
- tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
+ tree from = CompileExpr::Compile (expr.get_from_expr (), ctx);
if (from == error_mark_node)
{
translated = error_mark_node;
@@ -2147,7 +2141,7 @@ CompileExpr::visit (HIR::RangeFromExpr &expr)
void
CompileExpr::visit (HIR::RangeToExpr &expr)
{
- tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
+ tree to = CompileExpr::Compile (expr.get_to_expr (), ctx);
if (to == error_mark_node)
{
translated = error_mark_node;
@@ -2182,8 +2176,8 @@ CompileExpr::visit (HIR::RangeFullExpr &expr)
void
CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
{
- tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
- tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
+ tree from = CompileExpr::Compile (expr.get_from_expr (), ctx);
+ tree to = CompileExpr::Compile (expr.get_to_expr (), ctx);
if (from == error_mark_node || to == error_mark_node)
{
translated = error_mark_node;
@@ -2205,9 +2199,8 @@ CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
void
CompileExpr::visit (HIR::ArrayIndexExpr &expr)
{
- tree array_reference
- = CompileExpr::Compile (expr.get_array_expr ().get (), ctx);
- tree index = CompileExpr::Compile (expr.get_index_expr ().get (), ctx);
+ tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx);
+ tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
// this might be an core::ops::index lang item situation
TyTy::FnType *fntype;
@@ -2218,8 +2211,8 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr)
auto lang_item_type = LangItem::Kind::INDEX;
tree operator_overload_call
= resolve_operator_overload (lang_item_type, expr, array_reference,
- index, expr.get_array_expr ().get (),
- expr.get_index_expr ().get ());
+ index, expr.get_array_expr (),
+ expr.get_index_expr ());
tree actual_type = TREE_TYPE (operator_overload_call);
bool can_indirect = TYPE_PTR_P (actual_type) || TYPE_REF_P (actual_type);
@@ -2241,7 +2234,7 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr)
// indirection if required
TyTy::BaseType *array_expr_ty = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- expr.get_array_expr ()->get_mappings ().get_hirid (), &array_expr_ty);
+ expr.get_array_expr ().get_mappings ().get_hirid (), &array_expr_ty);
rust_assert (ok);
// do we need to add an indirect reference
@@ -2392,7 +2385,7 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
= Backend::struct_field_expression (args_param_expr, i,
closure_param.get_locus ());
- CompilePatternBindings::Compile (closure_param.get_pattern ().get (),
+ CompilePatternBindings::Compile (closure_param.get_pattern (),
compiled_param_var, ctx);
i++;
}
@@ -2404,13 +2397,13 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
}
// lookup locals
- HIR::Expr *function_body = expr.get_expr ().get ();
+ HIR::Expr &function_body = expr.get_expr ();
bool is_block_expr
- = function_body->get_expression_type () == HIR::Expr::ExprType::Block;
+ = function_body.get_expression_type () == HIR::Expr::ExprType::Block;
if (is_block_expr)
{
- auto body_mappings = function_body->get_mappings ();
+ auto body_mappings = function_body.get_mappings ();
if (flag_name_resolution_2_0)
{
auto nr_ctx
@@ -2431,13 +2424,13 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
}
tree enclosing_scope = NULL_TREE;
- location_t start_location = function_body->get_locus ();
- location_t end_location = function_body->get_locus ();
+ location_t start_location = function_body.get_locus ();
+ location_t end_location = function_body.get_locus ();
if (is_block_expr)
{
- HIR::BlockExpr *body = static_cast<HIR::BlockExpr *> (function_body);
- start_location = body->get_locus ();
- end_location = body->get_end_locus ();
+ auto &body = static_cast<HIR::BlockExpr &> (function_body);
+ start_location = body.get_locus ();
+ end_location = body.get_end_locus ();
}
tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/,
@@ -2462,15 +2455,14 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
if (is_block_expr)
{
- HIR::BlockExpr *body = static_cast<HIR::BlockExpr *> (function_body);
- compile_function_body (fndecl, *body, tyret);
+ auto &body = static_cast<HIR::BlockExpr &> (function_body);
+ compile_function_body (fndecl, body, tyret);
}
else
{
tree value = CompileExpr::Compile (function_body, ctx);
tree return_expr
- = Backend::return_statement (fndecl, value,
- function_body->get_locus ());
+ = Backend::return_statement (fndecl, value, function_body.get_locus ());
ctx->add_statement (return_expr);
}
@@ -2557,8 +2549,8 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
}
// need to apply any autoderef's to the self argument
- HIR::Expr *fnexpr = expr.get_fnexpr ().get ();
- HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid ();
+ HIR::Expr &fnexpr = expr.get_fnexpr ();
+ HirId autoderef_mappings_id = fnexpr.get_mappings ().get_hirid ();
std::vector<Resolver::Adjustment> *adjustments = nullptr;
bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id,
&adjustments);
@@ -2571,7 +2563,7 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
std::vector<tree> tuple_arg_vals;
for (auto &argument : expr.get_arguments ())
{
- auto rvalue = CompileExpr::Compile (argument.get (), ctx);
+ auto rvalue = CompileExpr::Compile (*argument, ctx);
tuple_arg_vals.push_back (rvalue);
}
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 2312375..0178a93 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -28,7 +28,7 @@ namespace Compile {
class CompileExpr : private HIRCompileBase, protected HIR::HIRExpressionVisitor
{
public:
- static tree Compile (HIR::Expr *expr, Context *ctx);
+ static tree Compile (HIR::Expr &expr, Context *ctx);
void visit (HIR::TupleIndexExpr &expr) override;
void visit (HIR::TupleExpr &expr) override;
@@ -98,8 +98,8 @@ protected:
tree resolve_operator_overload (LangItem::Kind lang_item_type,
HIR::OperatorExprMeta expr, tree lhs,
- tree rhs, HIR::Expr *lhs_expr,
- HIR::Expr *rhs_expr);
+ tree rhs, HIR::Expr &lhs_expr,
+ tl::optional<HIR::Expr &> rhs_expr);
tree compile_bool_literal (const HIR::LiteralExpr &expr,
const TyTy::BaseType *tyty);
diff --git a/gcc/rust/backend/rust-compile-fnparam.cc b/gcc/rust/backend/rust-compile-fnparam.cc
index af24ca0..c00092d 100644
--- a/gcc/rust/backend/rust-compile-fnparam.cc
+++ b/gcc/rust/backend/rust-compile-fnparam.cc
@@ -31,20 +31,20 @@ CompileFnParam::CompileFnParam (Context *ctx, tree fndecl, tree decl_type,
{}
Bvariable *
-CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam *param,
+CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam &param,
tree decl_type, location_t locus)
{
CompileFnParam compiler (ctx, fndecl, decl_type, locus);
- param->get_param_name ()->accept_vis (compiler);
+ param.get_param_name ().accept_vis (compiler);
return compiler.compiled_param;
}
Bvariable *
-CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern *param,
+CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern &param,
tree decl_type, location_t locus)
{
CompileFnParam compiler (ctx, fndecl, decl_type, locus);
- param->accept_vis (compiler);
+ param.accept_vis (compiler);
return compiler.compiled_param;
}
@@ -72,21 +72,21 @@ void
CompileFnParam::visit (HIR::StructPattern &pattern)
{
tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx);
+ CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
}
void
CompileFnParam::visit (HIR::TupleStructPattern &pattern)
{
tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx);
+ CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
}
void
CompileFnParam::visit (HIR::ReferencePattern &pattern)
{
tree tmp_param_var = create_tmp_param_var (decl_type);
- CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx);
+ CompilePatternBindings::Compile (pattern, tmp_param_var, ctx);
}
Bvariable *
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h
index 09a3e69..82a705f 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -29,9 +29,9 @@ class CompileFnParam : private HIRCompileBase, protected HIR::HIRPatternVisitor
{
public:
static Bvariable *compile (Context *ctx, tree fndecl,
- HIR::FunctionParam *param, tree decl_type,
+ HIR::FunctionParam &param, tree decl_type,
location_t locus);
- static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern *param,
+ static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern &param,
tree decl_type, location_t locus);
void visit (HIR::IdentifierPattern &pattern) override;
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 98337c8f..352685e 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -44,7 +44,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
rust_assert (canonical_path);
- HIR::Expr *const_value_expr = constant.get_expr ().get ();
+ HIR::Expr &const_value_expr = constant.get_expr ();
tree const_expr
= compile_constant_item (resolved_type, *canonical_path, const_value_expr,
constant.get_locus ());
@@ -114,7 +114,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
function.get_self (), function.get_function_params (),
function.get_qualifiers (), vis,
func.get_outer_attrs (), func.get_locus (),
- func.get_block_expr ().get (), *canonical_path, fntype);
+ &func.get_block_expr (), *canonical_path, fntype);
reference = address_expression (fndecl, ref_locus);
}
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index de3bb6e..bf595e4 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -321,7 +321,7 @@ compile_fn_params (Context *ctx, TyTy::FnType *fntype, tree fndecl,
location_t param_locus = referenced_param->get_locus ();
Bvariable *compiled_param_var
- = CompileFnParam::compile (ctx, fndecl, referenced_param,
+ = CompileFnParam::compile (ctx, fndecl, *referenced_param,
compiled_param_type, param_locus);
compiled_param_variables->push_back (compiled_param_var);
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index 0878716..dd37e39 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -60,7 +60,7 @@ CompileItem::visit (HIR::StaticItem &var)
rust_assert (canonical_path.has_value ());
- HIR::Expr *const_value_expr = var.get_expr ().get ();
+ HIR::Expr &const_value_expr = var.get_expr ();
ctx->push_const_context ();
tree value = compile_constant_item (resolved_type, *canonical_path,
const_value_expr, var.get_locus ());
@@ -120,7 +120,7 @@ CompileItem::visit (HIR::ConstantItem &constant)
.value ();
}
- HIR::Expr *const_value_expr = constant.get_expr ().get ();
+ HIR::Expr &const_value_expr = constant.get_expr ();
ctx->push_const_context ();
tree const_expr
= compile_constant_item (resolved_type, canonical_path, const_value_expr,
@@ -222,8 +222,7 @@ CompileItem::visit (HIR::Function &function)
function.get_function_params (),
function.get_qualifiers (), function.get_visibility (),
function.get_outer_attrs (), function.get_locus (),
- function.get_definition ().get (), canonical_path,
- fntype);
+ &function.get_definition (), canonical_path, fntype);
reference = address_expression (fndecl, ref_locus);
if (function.get_qualifiers ().is_const ())
@@ -235,7 +234,7 @@ CompileItem::visit (HIR::ImplBlock &impl_block)
{
TyTy::BaseType *self_lookup = nullptr;
if (!ctx->get_tyctx ()->lookup_type (
- impl_block.get_type ()->get_mappings ().get_hirid (), &self_lookup))
+ impl_block.get_type ().get_mappings ().get_hirid (), &self_lookup))
{
rust_error_at (impl_block.get_locus (), "failed to resolve type of impl");
return;
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index ffa1fa7..d6161bd 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -67,7 +67,7 @@ CompilePatternCheckExpr::visit (HIR::PathInExpression &pattern)
// must be enum
match_scrutinee_expr = scrutinee_expr_qualifier_expr;
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
check_expr
@@ -80,10 +80,9 @@ void
CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
{
// Compile the literal
- HIR::LiteralExpr *litexpr
- = new HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (),
- pattern.get_locus (),
- std::vector<AST::Attribute> ());
+ auto litexpr = Rust::make_unique<HIR::LiteralExpr> (
+ HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (),
+ pattern.get_locus (), std::vector<AST::Attribute> ()));
// Note: Floating point literals are currently accepted but will likely be
// forbidden in LiteralPatterns in a future version of Rust.
@@ -95,7 +94,7 @@ CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
rust_sorry_at (pattern.get_locus (), "floating-point literal in pattern");
}
- tree lit = CompileExpr::Compile (litexpr, ctx);
+ tree lit = CompileExpr::Compile (*litexpr, ctx);
check_expr = Backend::comparison_expression (ComparisonOperator::EQUAL,
match_scrutinee_expr, lit,
@@ -103,19 +102,17 @@ CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern)
}
static tree
-compile_range_pattern_bound (HIR::RangePatternBound *bound,
+compile_range_pattern_bound (HIR::RangePatternBound &bound,
Analysis::NodeMapping mappings, location_t locus,
Context *ctx)
{
tree result = NULL_TREE;
- switch (bound->get_bound_type ())
+ switch (bound.get_bound_type ())
{
case HIR::RangePatternBound::RangePatternBoundType::LITERAL: {
- HIR::RangePatternBoundLiteral &ref
- = *static_cast<HIR::RangePatternBoundLiteral *> (bound);
+ auto &ref = static_cast<HIR::RangePatternBoundLiteral &> (bound);
- HIR::LiteralExpr *litexpr
- = new HIR::LiteralExpr (mappings, ref.get_literal (), locus,
+ HIR::LiteralExpr litexpr (mappings, ref.get_literal (), locus,
std::vector<AST::Attribute> ());
result = CompileExpr::Compile (litexpr, ctx);
@@ -123,8 +120,7 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound,
break;
case HIR::RangePatternBound::RangePatternBoundType::PATH: {
- HIR::RangePatternBoundPath &ref
- = *static_cast<HIR::RangePatternBoundPath *> (bound);
+ auto &ref = static_cast<HIR::RangePatternBoundPath &> (bound);
result = ResolvePathRef::Compile (ref.get_path (), ctx);
@@ -134,8 +130,7 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound,
break;
case HIR::RangePatternBound::RangePatternBoundType::QUALPATH: {
- HIR::RangePatternBoundQualPath &ref
- = *static_cast<HIR::RangePatternBoundQualPath *> (bound);
+ auto &ref = static_cast<HIR::RangePatternBoundQualPath &> (bound);
result = ResolvePathRef::Compile (ref.get_qualified_path (), ctx);
@@ -150,10 +145,10 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound,
void
CompilePatternCheckExpr::visit (HIR::RangePattern &pattern)
{
- tree upper = compile_range_pattern_bound (pattern.get_upper_bound ().get (),
+ tree upper = compile_range_pattern_bound (pattern.get_upper_bound (),
pattern.get_mappings (),
pattern.get_locus (), ctx);
- tree lower = compile_range_pattern_bound (pattern.get_lower_bound ().get (),
+ tree lower = compile_range_pattern_bound (pattern.get_lower_bound (),
pattern.get_mappings (),
pattern.get_locus (), ctx);
@@ -175,7 +170,7 @@ CompilePatternCheckExpr::visit (HIR::ReferencePattern &pattern)
{
match_scrutinee_expr
= indirect_expression (match_scrutinee_expr, pattern.get_locus ());
- pattern.get_referenced_pattern ()->accept_vis (*this);
+ pattern.get_referenced_pattern ().accept_vis (*this);
}
void
@@ -183,14 +178,13 @@ CompilePatternCheckExpr::visit (HIR::AltPattern &pattern)
{
auto &alts = pattern.get_alts ();
- check_expr = CompilePatternCheckExpr::Compile (alts.at (0).get (),
+ check_expr = CompilePatternCheckExpr::Compile (*alts.at (0),
match_scrutinee_expr, ctx);
auto end = alts.end ();
for (auto i = alts.begin () + 1; i != end; i++)
{
tree next_expr
- = CompilePatternCheckExpr::Compile (i->get (), match_scrutinee_expr,
- ctx);
+ = CompilePatternCheckExpr::Compile (**i, match_scrutinee_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_OR, check_expr, next_expr,
(*i)->get_locus ());
@@ -229,7 +223,7 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
// // would be DECL_QUALIFIER i think. For now this will just access the
// // first record field and its respective qualifier because it will
// // always be set because this is all a big special union
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
// find discriminant field of scrutinee
@@ -282,11 +276,11 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern)
ident.get_locus ());
tree check_expr_sub
- = CompilePatternCheckExpr::Compile (ident.get_pattern ().get (),
+ = CompilePatternCheckExpr::Compile (ident.get_pattern (),
field_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
- check_expr_sub, ident.get_pattern ()->get_locus ());
+ check_expr_sub, ident.get_pattern ().get_locus ());
}
break;
@@ -328,7 +322,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
rust_assert (ok);
// find expected discriminant
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
// find discriminant field of scrutinee
@@ -357,8 +351,8 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
tuple_field_index = 0;
}
- std::unique_ptr<HIR::TupleStructItems> &items = pattern.get_items ();
- switch (items->get_item_type ())
+ HIR::TupleStructItems &items = pattern.get_items ();
+ switch (items.get_item_type ())
{
case HIR::TupleStructItems::RANGED: {
// TODO
@@ -368,7 +362,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
case HIR::TupleStructItems::MULTIPLE: {
HIR::TupleStructItemsNoRange &items_no_range
- = static_cast<HIR::TupleStructItemsNoRange &> (*items.get ());
+ = static_cast<HIR::TupleStructItemsNoRange &> (items);
rust_assert (items_no_range.get_patterns ().size ()
== variant->num_fields ());
@@ -381,8 +375,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern)
pattern->get_locus ());
tree check_expr_sub
- = CompilePatternCheckExpr::Compile (pattern.get (), field_expr,
- ctx);
+ = CompilePatternCheckExpr::Compile (*pattern, field_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
check_expr_sub, pattern->get_locus ());
@@ -397,7 +390,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
{
check_expr = boolean_true_node;
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::RANGED: {
// TODO
@@ -407,7 +400,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
case HIR::TuplePatternItems::MULTIPLE: {
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
size_t tuple_field_index = 0;
for (auto &pat : items.get_patterns ())
@@ -418,7 +411,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern)
pat->get_locus ());
tree check_expr_sub
- = CompilePatternCheckExpr::Compile (pat.get (), field_expr, ctx);
+ = CompilePatternCheckExpr::Compile (*pat, field_expr, ctx);
check_expr = Backend::arithmetic_or_logical_expression (
ArithmeticOrLogicalOperator::BITWISE_AND, check_expr,
check_expr_sub, pat->get_locus ());
@@ -459,8 +452,8 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
rust_assert (variant->get_variant_type ()
== TyTy::VariantDef::VariantType::TUPLE);
- std::unique_ptr<HIR::TupleStructItems> &items = pattern.get_items ();
- switch (items->get_item_type ())
+ HIR::TupleStructItems &items = pattern.get_items ();
+ switch (items.get_item_type ())
{
case HIR::TupleStructItems::RANGED: {
// TODO
@@ -470,7 +463,7 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
case HIR::TupleStructItems::MULTIPLE: {
HIR::TupleStructItemsNoRange &items_no_range
- = static_cast<HIR::TupleStructItemsNoRange &> (*items.get ());
+ = static_cast<HIR::TupleStructItemsNoRange &> (items);
rust_assert (items_no_range.get_patterns ().size ()
== variant->num_fields ());
@@ -609,8 +602,8 @@ CompilePatternBindings::visit (HIR::ReferencePattern &pattern)
tree derefed
= indirect_expression (match_scrutinee_expr, pattern.get_locus ());
- CompilePatternBindings::Compile (pattern.get_referenced_pattern ().get (),
- derefed, ctx);
+ CompilePatternBindings::Compile (pattern.get_referenced_pattern (), derefed,
+ ctx);
}
void
@@ -670,12 +663,12 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
tree access_expr = Backend::var_expression (tmp_var, pattern.get_locus ());
ctx->add_statement (init_stmt);
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::ItemType::RANGED: {
size_t tuple_idx = 0;
auto &items
- = static_cast<HIR::TuplePatternItemsRanged &> (*pattern.get_items ());
+ = static_cast<HIR::TuplePatternItemsRanged &> (pattern.get_items ());
auto &items_lower = items.get_lower_patterns ();
auto &items_upper = items.get_upper_patterns ();
@@ -719,7 +712,7 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
case HIR::TuplePatternItems::ItemType::MULTIPLE: {
size_t tuple_idx = 0;
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
for (auto &sub : items.get_patterns ())
{
diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h
index 521ed0d..0b785c6 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -26,11 +26,11 @@ class CompilePatternCheckExpr : public HIRCompileBase,
public HIR::HIRPatternVisitor
{
public:
- static tree Compile (HIR::Pattern *pattern, tree match_scrutinee_expr,
+ static tree Compile (HIR::Pattern &pattern, tree match_scrutinee_expr,
Context *ctx)
{
CompilePatternCheckExpr compiler (ctx, match_scrutinee_expr);
- pattern->accept_vis (compiler);
+ pattern.accept_vis (compiler);
rust_assert (compiler.check_expr);
return compiler.check_expr;
}
@@ -71,11 +71,11 @@ class CompilePatternBindings : public HIRCompileBase,
public HIR::HIRPatternVisitor
{
public:
- static void Compile (HIR::Pattern *pattern, tree match_scrutinee_expr,
+ static void Compile (HIR::Pattern &pattern, tree match_scrutinee_expr,
Context *ctx)
{
CompilePatternBindings compiler (ctx, match_scrutinee_expr);
- pattern->accept_vis (compiler);
+ pattern.accept_vis (compiler);
}
void visit (HIR::StructPattern &pattern) override;
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 7c9b303..31ebbf1 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -81,7 +81,7 @@ ResolvePathRef::attempt_constructor_expression_lookup (
tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt);
// make the ctor for the union
- HIR::Expr *discrim_expr = variant->get_discriminant ();
+ HIR::Expr &discrim_expr = variant->get_discriminant ();
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx);
tree folded_discrim_expr = fold_expr (discrim_expr_node);
tree qualifier = folded_discrim_expr;
@@ -301,7 +301,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
TyTy::BaseType *self = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- impl->get_type ()->get_mappings ().get_hirid (), &self);
+ impl->get_type ().get_mappings ().get_hirid (), &self);
rust_assert (ok);
if (!lookup->has_substitutions_defined ())
diff --git a/gcc/rust/backend/rust-compile-stmt.cc b/gcc/rust/backend/rust-compile-stmt.cc
index d8b27ff..a4b5a98 100644
--- a/gcc/rust/backend/rust-compile-stmt.cc
+++ b/gcc/rust/backend/rust-compile-stmt.cc
@@ -40,13 +40,13 @@ CompileStmt::Compile (HIR::Stmt *stmt, Context *ctx)
void
CompileStmt::visit (HIR::ExprStmt &stmt)
{
- translated = CompileExpr::Compile (stmt.get_expr ().get (), ctx);
+ translated = CompileExpr::Compile (stmt.get_expr (), ctx);
}
void
CompileStmt::visit (HIR::LetStmt &stmt)
{
- HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
+ HIR::Pattern &stmt_pattern = stmt.get_pattern ();
HirId stmt_id = stmt_pattern.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
@@ -68,7 +68,7 @@ CompileStmt::visit (HIR::LetStmt &stmt)
if (!stmt.has_init_expr ())
return;
- tree init = CompileExpr::Compile (stmt.get_init_expr ().get (), ctx);
+ tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx);
// FIXME use error_mark_node, check that CompileExpr returns error_mark_node
// on failure and make this an assertion
if (init == nullptr)
@@ -76,11 +76,11 @@ CompileStmt::visit (HIR::LetStmt &stmt)
TyTy::BaseType *actual = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual);
+ stmt.get_init_expr ().get_mappings ().get_hirid (), &actual);
rust_assert (ok);
- location_t lvalue_locus = stmt.get_pattern ()->get_locus ();
- location_t rvalue_locus = stmt.get_init_expr ()->get_locus ();
+ location_t lvalue_locus = stmt.get_pattern ().get_locus ();
+ location_t rvalue_locus = stmt.get_init_expr ().get_locus ();
TyTy::BaseType *expected = ty;
init = coercion_site (stmt.get_mappings ().get_hirid (), init, actual,
expected, lvalue_locus, rvalue_locus);
diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.cc b/gcc/rust/backend/rust-compile-struct-field-expr.cc
index 4a3b26c..0ac25e7 100644
--- a/gcc/rust/backend/rust-compile-struct-field-expr.cc
+++ b/gcc/rust/backend/rust-compile-struct-field-expr.cc
@@ -27,22 +27,22 @@ CompileStructExprField::CompileStructExprField (Context *ctx)
{}
tree
-CompileStructExprField::Compile (HIR::StructExprField *field, Context *ctx)
+CompileStructExprField::Compile (HIR::StructExprField &field, Context *ctx)
{
CompileStructExprField compiler (ctx);
- switch (field->get_kind ())
+ switch (field.get_kind ())
{
case HIR::StructExprField::StructExprFieldKind::IDENTIFIER:
- compiler.visit (static_cast<HIR::StructExprFieldIdentifier &> (*field));
+ compiler.visit (static_cast<HIR::StructExprFieldIdentifier &> (field));
break;
case HIR::StructExprField::StructExprFieldKind::IDENTIFIER_VALUE:
compiler.visit (
- static_cast<HIR::StructExprFieldIdentifierValue &> (*field));
+ static_cast<HIR::StructExprFieldIdentifierValue &> (field));
break;
case HIR::StructExprField::StructExprFieldKind::INDEX_VALUE:
- compiler.visit (static_cast<HIR::StructExprFieldIndexValue &> (*field));
+ compiler.visit (static_cast<HIR::StructExprFieldIndexValue &> (field));
break;
}
return compiler.translated;
@@ -51,13 +51,13 @@ CompileStructExprField::Compile (HIR::StructExprField *field, Context *ctx)
void
CompileStructExprField::visit (HIR::StructExprFieldIdentifierValue &field)
{
- translated = CompileExpr::Compile (field.get_value ().get (), ctx);
+ translated = CompileExpr::Compile (field.get_value (), ctx);
}
void
CompileStructExprField::visit (HIR::StructExprFieldIndexValue &field)
{
- translated = CompileExpr::Compile (field.get_value ().get (), ctx);
+ translated = CompileExpr::Compile (field.get_value (), ctx);
}
void
@@ -74,7 +74,7 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field)
HIR::GenericArgs::create_empty ());
HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
{});
- translated = CompileExpr::Compile (&expr, ctx);
+ translated = CompileExpr::Compile (expr, ctx);
}
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.h b/gcc/rust/backend/rust-compile-struct-field-expr.h
index f1d7055..055019c 100644
--- a/gcc/rust/backend/rust-compile-struct-field-expr.h
+++ b/gcc/rust/backend/rust-compile-struct-field-expr.h
@@ -27,7 +27,7 @@ namespace Compile {
class CompileStructExprField : private HIRCompileBase
{
public:
- static tree Compile (HIR::StructExprField *field, Context *ctx);
+ static tree Compile (HIR::StructExprField &field, Context *ctx);
protected:
void visit (HIR::StructExprFieldIdentifierValue &field);
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index b546a05..c53b359 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -428,7 +428,7 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type)
= TyTyResolveCompile::compile (ctx, type.get_element_type ());
ctx->push_const_context ();
- tree capacity_expr = CompileExpr::Compile (&type.get_capacity_expr (), ctx);
+ tree capacity_expr = CompileExpr::Compile (type.get_capacity_expr (), ctx);
ctx->pop_const_context ();
tree folded_capacity_expr = fold_expr (capacity_expr);
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index 6b6af77..4c46a7b 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -68,12 +68,12 @@ public:
void visit (HIR::TuplePattern &pattern) override
{
- switch (pattern.get_items ()->get_item_type ())
+ switch (pattern.get_items ().get_item_type ())
{
case HIR::TuplePatternItems::ItemType::MULTIPLE: {
rust_assert (TREE_CODE (translated_type) == RECORD_TYPE);
auto &items = static_cast<HIR::TuplePatternItemsMultiple &> (
- *pattern.get_items ());
+ pattern.get_items ());
size_t offs = 0;
for (auto &sub : items.get_patterns ())
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 7e0a9b6..7b00066 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -259,17 +259,17 @@ HIRCompileBase::compute_address_for_trait_item (
HIR::ImplBlock *impl_block = item.second;
rust_assert (impl_block != nullptr);
- // Lookup type for potentially associated impl.
- std::unique_ptr<HIR::Type> &self_type_path = impl_block->get_type ();
-
// Checks for empty impl blocks, triggered by Sized trait.
- if (self_type_path == nullptr)
+ if (!impl_block->has_type ())
continue;
+ // Lookup type for potentially associated impl.
+ HIR::Type &self_type_path = impl_block->get_type ();
+
// Convert HIR::Type to TyTy::BaseType
TyTy::BaseType *self = nullptr;
bool ok = ctx->get_tyctx ()->lookup_type (
- self_type_path->get_mappings ().get_hirid (), &self);
+ self_type_path.get_mappings ().get_hirid (), &self);
rust_assert (ok);
diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc
index d604dcf..67d7e4d 100644
--- a/gcc/rust/backend/rust-mangle-v0.cc
+++ b/gcc/rust/backend/rust-mangle-v0.cc
@@ -328,7 +328,7 @@ v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx,
// lookup impl type
TyTy::BaseType *impl_ty = nullptr;
ok = ctx->get_tyctx ()->lookup_type (
- impl_block->get_type ()->get_mappings ().get_hirid (), &impl_ty);
+ impl_block->get_type ().get_mappings ().get_hirid (), &impl_ty);
rust_assert (ok);
// FIXME: dummy value for now
@@ -342,7 +342,7 @@ v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx,
TyTy::BaseType *trait_ty = nullptr;
ok = ctx->get_tyctx ()->lookup_type (
- impl_block->get_trait_ref ()->get_mappings ().get_hirid (), &trait_ty);
+ impl_block->get_trait_ref ().get_mappings ().get_hirid (), &trait_ty);
rust_assert (ok);
v0path.trait_type = v0_type_prefix (ctx, trait_ty);