aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-11-02 13:54:14 +0000
committerGitHub <noreply@github.com>2021-11-02 13:54:14 +0000
commit5f0df4812c37fc428b5508e019e9fb7f8a7b77b1 (patch)
tree2a2bef1a866b93287a48990c09a4243d0ab41c0f /gcc/rust/backend/rust-compile-expr.h
parent09af9b16b436606fa8ced0aa6cc111555bdc3da7 (diff)
parentfc5f8d746362a42adc52e538dec248bd2992a794 (diff)
downloadgcc-5f0df4812c37fc428b5508e019e9fb7f8a7b77b1.zip
gcc-5f0df4812c37fc428b5508e019e9fb7f8a7b77b1.tar.gz
gcc-5f0df4812c37fc428b5508e019e9fb7f8a7b77b1.tar.bz2
Merge #781
781: Add missing typechecking for enums r=philberty a=philberty This PR splits up the Algebraic data type into one which can support many variants which is what an enum is. It then changes the type checking for construction of ADT's to use the VariantDef structures as required. This does not fully implement but does allow us to have most of the type checking in place to start code-generation work. This combines work from Mark Wielaard (https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=enum-type) and Philip Addresses #79 Co-authored-by: Mark Wielaard <mark@klomp.org> Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 0512373..f43db50 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -698,7 +698,13 @@ public:
if (receiver->get_kind () == TyTy::TypeKind::ADT)
{
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (receiver);
- adt->get_field (expr.get_field_name (), &field_index);
+ rust_assert (!adt->is_enum ());
+ rust_assert (adt->number_of_variants () == 1);
+
+ TyTy::VariantDef *variant = adt->get_variants ().at (0);
+ bool ok = variant->lookup_field (expr.get_field_name (), nullptr,
+ &field_index);
+ rust_assert (ok);
}
else if (receiver->get_kind () == TyTy::TypeKind::REF)
{
@@ -707,9 +713,15 @@ public:
rust_assert (b->get_kind () == TyTy::TypeKind::ADT);
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (b);
- adt->get_field (expr.get_field_name (), &field_index);
- Btype *adt_tyty = TyTyResolveCompile::compile (ctx, adt);
+ rust_assert (!adt->is_enum ());
+ rust_assert (adt->number_of_variants () == 1);
+ TyTy::VariantDef *variant = adt->get_variants ().at (0);
+ bool ok = variant->lookup_field (expr.get_field_name (), nullptr,
+ &field_index);
+ rust_assert (ok);
+
+ Btype *adt_tyty = TyTyResolveCompile::compile (ctx, adt);
Bexpression *indirect
= ctx->get_backend ()->indirect_expression (adt_tyty, receiver_ref,
true, expr.get_locus ());