diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-02-12 14:57:11 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-02-13 10:08:03 +0000 |
commit | ca514784717ef9c8418968a60ed4641af78c7d7b (patch) | |
tree | 75434335e1d147047d086441a01323c229bbb601 /gcc/rust/backend | |
parent | 3ae8d55860cbe95f80d5e5c76ca71883dbde0e10 (diff) | |
download | gcc-ca514784717ef9c8418968a60ed4641af78c7d7b.zip gcc-ca514784717ef9c8418968a60ed4641af78c7d7b.tar.gz gcc-ca514784717ef9c8418968a60ed4641af78c7d7b.tar.bz2 |
Add ReferenceType with BorrowExpr and DereferenceExpr
This also adds in the mising InferenceType _ which was mostly implemented
before as part of Data Structures 1.
We create GENERIC REFERENCE_TYPES for these this is the building block
to finish work on mutability rules and pointers.
Fixes: #196
Addresses: #169 #170
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 7 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 31 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-tyty.h | 2 |
3 files changed, 40 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 3955a5b..b50e103 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -445,6 +445,13 @@ public: translated = compiled_type; } + void visit (TyTy::ReferenceType &type) override + { + Btype *base_compiled_type + = TyTyResolveCompile::compile (ctx, type.get_base ()); + translated = ctx->get_backend ()->reference_type (base_compiled_type); + } + private: TyTyResolveCompile (Context *ctx) : ctx (ctx) {} diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index c63479c..842804d 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -816,6 +816,37 @@ public: ctx->add_statement (goto_label); } + void visit (HIR::BorrowExpr &expr) + { + Bexpression *main_expr + = CompileExpr::Compile (expr.get_expr ().get (), ctx); + + translated + = ctx->get_backend ()->address_expression (main_expr, expr.get_locus ()); + } + + void visit (HIR::DereferenceExpr &expr) + { + Bexpression *main_expr + = CompileExpr::Compile (expr.get_expr ().get (), ctx); + + 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 TupleExpr"); + return; + } + + Btype *expected_type = TyTyResolveCompile::compile (ctx, tyty); + bool known_valid = true; + translated + = ctx->get_backend ()->indirect_expression (expected_type, main_expr, + known_valid, + expr.get_locus ()); + } + private: CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {} diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index f591696..eb8a961 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -56,6 +56,8 @@ public: void visit (TyTy::ArrayType &) override { gcc_unreachable (); } + void visit (TyTy::ReferenceType &) override { gcc_unreachable (); } + void visit (TyTy::UnitType &) override { translated = backend->void_type (); } void visit (TyTy::FnType &type) override |