From 7d4845bc958712b3a437ad636d64fc241610fbc0 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 24 Feb 2022 11:49:51 +0000 Subject: Add code generation for range expressions --- gcc/rust/backend/rust-compile-expr.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gcc/rust/backend/rust-compile-expr.h') diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 2fee3be..096b705 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -803,6 +803,16 @@ public: void visit (HIR::MatchExpr &expr) override; + void visit (HIR::RangeFromToExpr &expr) override; + + void visit (HIR::RangeFromExpr &expr) override; + + void visit (HIR::RangeToExpr &expr) override; + + void visit (HIR::RangeFullExpr &expr) override; + + void visit (HIR::RangeFromToInclExpr &expr) override; + protected: tree compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn, TyTy::BaseType *receiver, -- cgit v1.1 From a6dd242845303f44f38035189fd9360c7f572dfc Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 24 Feb 2022 11:59:16 +0000 Subject: Refactor ArrayIndexExpr code into implementation cc file --- gcc/rust/backend/rust-compile-expr.h | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) (limited to 'gcc/rust/backend/rust-compile-expr.h') 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 (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; -- cgit v1.1 From d8351d9168f92c997858fdb25942c05dc832f330 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 24 Feb 2022 16:22:29 +0000 Subject: Decouple the HIR::OperatorExpr from resolving operator overloads This means we can reuse the same code for operations that are not HIR::OperatorExpr's such as ArrayIndexExpr which can resolve to core::ops::index lang items. --- gcc/rust/backend/rust-compile-expr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/rust/backend/rust-compile-expr.h') diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 7fd708c..f2b4df8 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -799,7 +799,7 @@ protected: tree resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type, - HIR::OperatorExpr &expr, tree lhs, tree rhs, + HIR::OperatorExprMeta expr, tree lhs, tree rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_expr); tree compile_bool_literal (const HIR::LiteralExpr &expr, -- cgit v1.1