From 389fd74a3f3e9422a965263b6961b51295c55976 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 1 Aug 2021 12:57:33 +0200 Subject: union support for hir type checking and gcc backend Treat a union as a Struct variant like a tuple struct. Add an iterator and get_identifier functions to the AST Union class. Same for the HIR Union class, plus a get_generics_params method. Add a new ADTKind enum and adt_kind field to the ADTType to select the underlying abstract data type (struct struct, tuple struct or union, with enum as possible future variant). An union constructor can have only one field. Add an union_index field to StructExprStruct which is set during type checking in the TypeCheckStructExpr HIR StructExprStructFields visitor. For the Gcc_backend class rename fill_in_struct to fill_in_fields and use it from a new union_type method. Handle union_index in constructor_expression (so only one field is initialized). --- gcc/rust/rust-backend.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gcc/rust/rust-backend.h') diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h index be23fd3..4635796 100644 --- a/gcc/rust/rust-backend.h +++ b/gcc/rust/rust-backend.h @@ -178,6 +178,9 @@ public: // Get a struct type. virtual Btype *struct_type (const std::vector &fields) = 0; + // Get a union type. + virtual Btype *union_type (const std::vector &fields) = 0; + // Get an array type. virtual Btype *array_type (Btype *element_type, Bexpression *length) = 0; @@ -424,7 +427,7 @@ public: // corresponding fields in BTYPE. virtual Bexpression * constructor_expression (Btype *btype, const std::vector &vals, - Location) + int, Location) = 0; // Return an expression that constructs an array of BTYPE with INDEXES and -- cgit v1.1