diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2021-02-07 12:40:19 +0800 |
---|---|---|
committer | SimplyTheOther <simplytheother@gmail.com> | 2021-02-07 12:40:19 +0800 |
commit | 94be91d6159101caa7c560b188bd6c02d8d86d17 (patch) | |
tree | b3c32de54db1a850079f79d3dfb4c4000dec9d90 /gcc/rust/backend/rust-compile-expr.h | |
parent | 27eef5b7a065e8ea05ac575c4b364bb5dbc44e46 (diff) | |
parent | db7134353447921136a321b8fd78cea78f2c344e (diff) | |
download | gcc-94be91d6159101caa7c560b188bd6c02d8d86d17.zip gcc-94be91d6159101caa7c560b188bd6c02d8d86d17.tar.gz gcc-94be91d6159101caa7c560b188bd6c02d8d86d17.tar.bz2 |
Merge branch 'master' of https://github.com/redbrain/gccrs
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) |