From 9af2ae0ff91535da104db0d3828d863770439fad Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 16 Feb 2021 15:40:28 +0000 Subject: Support Generic arguments to Structs This removes StructFieldType from the TyTy base as it is not a type that can be unified against. It adds in a substition mapper implementation which will likely change over time when this this support is extended over to Functions and TupleStructs. Note generic argument binding is not supported as part of this yet. Fixes #235 --- gcc/rust/backend/rust-compile-expr.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'gcc/rust/backend/rust-compile-expr.h') diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 00625df..95a6744 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -539,8 +539,16 @@ public: void visit (HIR::StructExprStructFields &struct_expr) { - Btype *type - = ResolvePathType::Compile (&struct_expr.get_struct_name (), ctx); + TyTy::BaseType *tyty = nullptr; + if (!ctx->get_tyctx ()->lookup_type ( + struct_expr.get_mappings ().get_hirid (), &tyty)) + { + rust_error_at (struct_expr.get_locus (), "unknown type"); + return; + } + + Btype *type = TyTyResolveCompile::compile (ctx, tyty); + rust_assert (type != nullptr); // this assumes all fields are in order from type resolution and if a base // struct was specified those fields are filed via accesors @@ -573,8 +581,8 @@ public: return; } rust_assert (receiver->get_kind () == TyTy::TypeKind::ADT); + TyTy::ADTType *adt = static_cast (receiver); - TyTy::ADTType *adt = (TyTy::ADTType *) receiver; size_t index = 0; adt->get_field (expr.get_field_name (), &index); -- cgit v1.1