diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-08-02 09:13:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 09:13:20 +0000 |
commit | b56c6fdfaad9ca1681714d288d1282cf08554462 (patch) | |
tree | d815a7d24660b24da5fcf7d05b5f2b3e8de99ae1 /gcc/rust/resolve/rust-ast-resolve-stmt.h | |
parent | 06a65591eb09fbec25e4ee38c1cf751b416af5bf (diff) | |
parent | 389fd74a3f3e9422a965263b6961b51295c55976 (diff) | |
download | gcc-b56c6fdfaad9ca1681714d288d1282cf08554462.zip gcc-b56c6fdfaad9ca1681714d288d1282cf08554462.tar.gz gcc-b56c6fdfaad9ca1681714d288d1282cf08554462.tar.bz2 |
Merge #601
601: union support for hir type checking and gcc backend r=dkm a=dkm
From Mark Wielaard : https://gcc.gnu.org/pipermail/gcc-rust/2021-August/000107.html
>
> 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).
Fixes #157
Co-authored-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'gcc/rust/resolve/rust-ast-resolve-stmt.h')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 210a9fc..b604432 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -131,6 +131,38 @@ public: resolver->get_type_scope ().pop (); } + void visit (AST::Union &union_decl) override + { + auto path = CanonicalPath::new_seg (union_decl.get_node_id (), + union_decl.get_identifier ()); + resolver->get_type_scope ().insert ( + path, union_decl.get_node_id (), union_decl.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { + RichLocation r (union_decl.get_locus ()); + r.add_range (locus); + rust_error_at (r, "redefined multiple times"); + }); + + NodeId scope_node_id = union_decl.get_node_id (); + resolver->get_type_scope ().push (scope_node_id); + + if (union_decl.has_generics ()) + { + for (auto &generic : union_decl.get_generic_params ()) + { + ResolveGenericParam::go (generic.get (), union_decl.get_node_id ()); + } + } + + union_decl.iterate ([&] (AST::StructField &field) mutable -> bool { + ResolveType::go (field.get_field_type ().get (), + union_decl.get_node_id ()); + return true; + }); + + resolver->get_type_scope ().pop (); + } + void visit (AST::Function &function) override { auto path = ResolveFunctionItemToCanonicalPath::resolve (function); |