aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.cc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2022-05-10 11:52:44 -0700
committerDavid Faust <david.faust@oracle.com>2022-05-11 09:29:55 -0700
commit5aa411c537289f5695b63de12b973415b2d830d6 (patch)
tree66278e6fc22996db0395061b10308d91329c1edf /gcc/rust/backend/rust-compile-expr.cc
parent502c8a859750064103bb71f4d559cef7b1c1b8af (diff)
downloadgcc-5aa411c537289f5695b63de12b973415b2d830d6.zip
gcc-5aa411c537289f5695b63de12b973415b2d830d6.tar.gz
gcc-5aa411c537289f5695b63de12b973415b2d830d6.tar.bz2
Allow match on primitive types
This patch enables compiling match expressions for other primitive types, like int and char. However, we cannot currently compile matches on floats; CASE_LABEL_EXPR doesn't support floating-point types.
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 1cf4e3d..0fd1e3a 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -212,7 +212,8 @@ CompileExpr::visit (HIR::MatchExpr &expr)
}
TyTy::TypeKind scrutinee_kind = scrutinee_expr_tyty->get_kind ();
- rust_assert (scrutinee_kind == TyTy::TypeKind::BOOL
+ rust_assert ((TyTy::is_primitive_type_kind (scrutinee_kind)
+ && scrutinee_kind != TyTy::TypeKind::NEVER)
|| scrutinee_kind == TyTy::TypeKind::ADT);
if (scrutinee_kind == TyTy::TypeKind::ADT)
@@ -223,6 +224,13 @@ CompileExpr::visit (HIR::MatchExpr &expr)
rust_assert (adt->is_enum ());
rust_assert (adt->number_of_variants () > 0);
}
+ else if (scrutinee_kind == TyTy::TypeKind::FLOAT)
+ {
+ // FIXME: CASE_LABEL_EXPR does not support floating point types.
+ // Find another way to compile these.
+ sorry_at (expr.get_locus ().gcc_location (),
+ "match on floating-point types is not yet supported");
+ }
TyTy::BaseType *expr_tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
@@ -253,7 +261,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
= CompileExpr::Compile (expr.get_scrutinee_expr ().get (), ctx);
tree match_scrutinee_expr_qualifier_expr;
- if (scrutinee_kind == TyTy::TypeKind::BOOL)
+ if (TyTy::is_primitive_type_kind (scrutinee_kind))
{
match_scrutinee_expr_qualifier_expr = match_scrutinee_expr;
}
@@ -274,7 +282,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
else
{
// FIXME: match on other types of expressions not yet implemented.
- gcc_assert (0);
+ gcc_unreachable ();
}
// setup the end label so the cases can exit properly