aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-02-24 11:59:16 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-02-24 11:59:19 +0000
commita6dd242845303f44f38035189fd9360c7f572dfc (patch)
tree112a5102be29f9d4df0162592ff0d63f591177ee /gcc/rust/backend
parent7d4845bc958712b3a437ad636d64fc241610fbc0 (diff)
downloadgcc-a6dd242845303f44f38035189fd9360c7f572dfc.zip
gcc-a6dd242845303f44f38035189fd9360c7f572dfc.tar.gz
gcc-a6dd242845303f44f38035189fd9360c7f572dfc.tar.bz2
Refactor ArrayIndexExpr code into implementation cc file
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc31
-rw-r--r--gcc/rust/backend/rust-compile-expr.h31
2 files changed, 32 insertions, 30 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index e2d1138..6849471 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1484,5 +1484,36 @@ CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
expr.get_locus ());
}
+void
+CompileExpr::visit (HIR::ArrayIndexExpr &expr)
+{
+ tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx);
+ tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
+
+ // lets check if the array is a reference type then we can add an
+ // 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);
+ rust_assert (ok);
+
+ // do we need to add an indirect reference
+ if (array_expr_ty->get_kind () == TyTy::TypeKind::REF)
+ {
+ TyTy::ReferenceType *r
+ = static_cast<TyTy::ReferenceType *> (array_expr_ty);
+ TyTy::BaseType *tuple_type = r->get_base ();
+ tree array_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
+
+ array_reference
+ = ctx->get_backend ()->indirect_expression (array_tyty, array_reference,
+ true, expr.get_locus ());
+ }
+
+ translated
+ = ctx->get_backend ()->array_index_expression (array_reference, index,
+ expr.get_locus ());
+}
+
} // namespace Compile
} // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 096b705..7fd708c 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -201,36 +201,7 @@ public:
void visit (HIR::CompoundAssignmentExpr &expr) override;
- void visit (HIR::ArrayIndexExpr &expr) override
- {
- tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx);
- tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
-
- // lets check if the array is a reference type then we can add an
- // 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);
- rust_assert (ok);
-
- // do we need to add an indirect reference
- if (array_expr_ty->get_kind () == TyTy::TypeKind::REF)
- {
- TyTy::ReferenceType *r
- = static_cast<TyTy::ReferenceType *> (array_expr_ty);
- TyTy::BaseType *tuple_type = r->get_base ();
- tree array_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
-
- array_reference
- = ctx->get_backend ()->indirect_expression (array_tyty,
- array_reference, true,
- expr.get_locus ());
- }
-
- translated
- = ctx->get_backend ()->array_index_expression (array_reference, index,
- expr.get_locus ());
- }
+ void visit (HIR::ArrayIndexExpr &expr) override;
void visit (HIR::ArrayExpr &expr) override;