diff options
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index ccff51a..b823d29 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -99,6 +99,8 @@ public: void visit (HIR::CallExpr &expr); + void visit (HIR::MethodCallExpr &expr); + void visit (HIR::IdentifierExpr &expr) { // need to look up the reference for this identifier @@ -409,27 +411,71 @@ public: void visit (HIR::IfExpr &expr) { - auto stmt = CompileConditionalBlocks::compile (&expr, ctx); + auto stmt = CompileConditionalBlocks::compile (&expr, ctx, nullptr); ctx->add_statement (stmt); } void visit (HIR::IfExprConseqElse &expr) { - auto stmt = CompileConditionalBlocks::compile (&expr, ctx); + // this can be a return expression + TyTy::TyBase *if_type = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &if_type)) + { + rust_error_at (expr.get_locus (), + "failed to lookup type of IfExprConseqElse"); + return; + } + + fncontext fnctx = ctx->peek_fn (); + Bblock *enclosing_scope = ctx->peek_enclosing_scope (); + Btype *block_type = TyTyResolveCompile::compile (ctx, if_type); + + bool is_address_taken = false; + Bstatement *ret_var_stmt = nullptr; + Bvariable *tmp = ctx->get_backend ()->temporary_variable ( + fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken, + expr.get_locus (), &ret_var_stmt); + ctx->add_statement (ret_var_stmt); + + auto stmt = CompileConditionalBlocks::compile (&expr, ctx, tmp); ctx->add_statement (stmt); + + translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ()); } void visit (HIR::IfExprConseqIf &expr) { - auto stmt = CompileConditionalBlocks::compile (&expr, ctx); + auto stmt = CompileConditionalBlocks::compile (&expr, ctx, nullptr); ctx->add_statement (stmt); } void visit (HIR::BlockExpr &expr) { - auto code_block = CompileBlock::compile (&expr, ctx); + TyTy::TyBase *block_tyty = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &block_tyty)) + { + rust_error_at (expr.get_locus (), "failed to lookup type of BlockExpr"); + return; + } + + fncontext fnctx = ctx->peek_fn (); + Bblock *enclosing_scope = ctx->peek_enclosing_scope (); + Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty); + + bool is_address_taken = false; + Bstatement *ret_var_stmt = nullptr; + Bvariable *tmp = ctx->get_backend ()->temporary_variable ( + fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken, + expr.get_locus (), &ret_var_stmt); + ctx->add_statement (ret_var_stmt); + + auto code_block = CompileBlock::compile (&expr, ctx, tmp); auto block_stmt = ctx->get_backend ()->block_statement (code_block); ctx->add_statement (block_stmt); + + translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ()); } void visit (HIR::StructExprStructFields &struct_expr) |