From fabb3894d5fe5c2ca87917fd08b2f0813553532d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Mon, 8 Mar 2021 21:13:02 +0100 Subject: WIP for #252 Removed TyTy::UnitType and TyTy::TypeKind::UNIT. Replaced by TyTy::TupleType with an empty list of fields. Added default empty vector for fields in ctor for TyTy::TypeType. --- gcc/rust/backend/rust-compile-context.h | 11 ++++++----- gcc/rust/backend/rust-compile-expr.h | 8 ++++---- gcc/rust/backend/rust-compile-stmt.h | 2 +- gcc/rust/backend/rust-compile-tyty.h | 10 +++++++--- 4 files changed, 18 insertions(+), 13 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 6f45e57..6347464 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -351,11 +351,6 @@ public: ctx->get_mappings ()->lookup_location (type.get_ref ())); } - void visit (TyTy::UnitType &) override - { - translated = ctx->get_backend ()->void_type (); - } - void visit (TyTy::ADTType &type) override { if (ctx->lookup_compiled_types (type.get_ty_ref (), &translated, &type)) @@ -389,6 +384,12 @@ public: void visit (TyTy::TupleType &type) override { + if (type.num_fields () == 0) + { + translated = ctx->get_backend ()->void_type (); + return; + } + bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &translated); if (ok) return; diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index f4353cd..d0c752c 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -368,7 +368,7 @@ public: } Bvariable *tmp = NULL; - bool needs_temp = if_type->get_kind () != TyTy::TypeKind::UNIT; + bool needs_temp = !if_type->is_unit (); if (needs_temp) { fncontext fnctx = ctx->peek_fn (); @@ -405,7 +405,7 @@ public: } Bvariable *tmp = NULL; - bool needs_temp = if_type->get_kind () != TyTy::TypeKind::UNIT; + bool needs_temp = !if_type->is_unit (); if (needs_temp) { fncontext fnctx = ctx->peek_fn (); @@ -441,7 +441,7 @@ public: } Bvariable *tmp = NULL; - bool needs_temp = block_tyty->get_kind () != TyTy::TypeKind::UNIT; + bool needs_temp = !block_tyty->is_unit (); if (needs_temp) { fncontext fnctx = ctx->peek_fn (); @@ -541,7 +541,7 @@ public: fncontext fnctx = ctx->peek_fn (); Bvariable *tmp = NULL; - bool needs_temp = block_tyty->get_kind () != TyTy::TypeKind::UNIT; + bool needs_temp = !block_tyty->is_unit (); if (needs_temp) { Bblock *enclosing_scope = ctx->peek_enclosing_scope (); diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h index 3c2916d..a777df6 100644 --- a/gcc/rust/backend/rust-compile-stmt.h +++ b/gcc/rust/backend/rust-compile-stmt.h @@ -81,7 +81,7 @@ public: return; auto fnctx = ctx->peek_fn (); - if (ty->get_kind () == TyTy::TypeKind::UNIT) + if (ty->is_unit ()) { Bstatement *expr_stmt = ctx->get_backend ()->expression_statement (fnctx.fndecl, init); diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index 774fd2e..44d9416 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -50,7 +50,13 @@ public: void visit (TyTy::ADTType &) override { gcc_unreachable (); } - void visit (TyTy::TupleType &) override { gcc_unreachable (); } + void visit (TyTy::TupleType &type) override + { + if (type.num_fields () == 0) + translated = backend->void_type (); + else + gcc_unreachable (); + } void visit (TyTy::ArrayType &) override { gcc_unreachable (); } @@ -60,8 +66,6 @@ public: void visit (TyTy::FnPtr &type) override { gcc_unreachable (); } - void visit (TyTy::UnitType &) override { translated = backend->void_type (); } - void visit (TyTy::FnType &type) override { Backend::Btyped_identifier receiver; -- cgit v1.1