diff options
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 854fe5e..6ea97ee 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -169,6 +169,48 @@ public: ctx->add_statement (assignment); } + void visit (HIR::ArrayIndexExpr &expr) + { + Bexpression *array = CompileExpr::Compile (expr.get_array_expr (), ctx); + Bexpression *index = CompileExpr::Compile (expr.get_index_expr (), ctx); + translated + = ctx->get_backend ()->array_index_expression (array, index, + expr.get_locus ()); + } + + void visit (HIR::ArrayExpr &expr) + { + TyTy::TyBase *tyty = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &tyty)) + { + rust_fatal_error (expr.get_locus (), + "did not resolve type for this array expr"); + return; + } + + Btype *array_type = TyTyResolveCompile::compile (ctx, tyty); + + expr.get_internal_elements ()->accept_vis (*this); + std::vector<unsigned long> indexes; + for (size_t i = 0; i < constructor.size (); i++) + indexes.push_back (i); + + translated + = ctx->get_backend ()->array_constructor_expression (array_type, indexes, + constructor, + expr.get_locus ()); + } + + void visit (HIR::ArrayElemsValues &elems) + { + elems.iterate ([&] (HIR::Expr *e) mutable -> bool { + Bexpression *translated_expr = CompileExpr::Compile (e, ctx); + constructor.push_back (translated_expr); + return true; + }); + } + void visit (HIR::ArithmeticOrLogicalExpr &expr) { Operator op; @@ -303,6 +345,7 @@ private: CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {} Bexpression *translated; + std::vector<Bexpression *> constructor; }; } // namespace Compile |