From 1c2855a31473ccdfa5aa4456c71131a0e66db9fc Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 25 Jul 2025 15:17:39 -0700 Subject: [PATCH] unwrap decorative type operators on casts when building ops for casting, to allow for graceful enum casting; gracefully skip struct/enum symbol name prefixes --- src/eval/eval_ir.c | 8 +++++--- src/eval/eval_parse.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/eval/eval_ir.c b/src/eval/eval_ir.c index 7082c615..f6775432 100644 --- a/src/eval/eval_ir.c +++ b/src/eval/eval_ir.c @@ -841,6 +841,8 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I e_msg_list_concat_in_place(&result.msgs, &cast_irtree.msgs); E_TypeKey cast_type = cast_irtree.type_key; E_TypeKind cast_type_kind = e_type_kind_from_key(cast_type); + E_TypeKey cast_type_unwrapped = e_type_key_unwrap(cast_irtree.type_key, E_TypeUnwrapFlag_AllDecorative); + E_TypeKind cast_type_unwrapped_kind = e_type_kind_from_key(cast_type_unwrapped); U64 cast_type_byte_size = e_type_byte_size_from_key(cast_type); E_IRTreeAndType casted_tree = e_push_irtree_and_type_from_expr(arena, parent, &e_default_identifier_resolution_rule, disallow_autohooks, 1, casted_expr); e_msg_list_concat_in_place(&result.msgs, &casted_tree.msgs); @@ -848,7 +850,7 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I E_TypeKind casted_type_kind = e_type_kind_from_key(casted_type); U64 casted_type_byte_size = e_type_byte_size_from_key(casted_type); U8 in_group = e_type_group_from_kind(casted_type_kind); - U8 out_group = e_type_group_from_kind(cast_type_kind); + U8 out_group = e_type_group_from_kind(cast_type_unwrapped_kind); RDI_EvalConversionKind conversion_rule = rdi_eval_conversion_kind_from_typegroups(in_group, out_group); // rjf: bad conditions? -> error if applicable, exit @@ -880,11 +882,11 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I { new_tree = e_irtree_convert_lo(arena, in_tree, out_group, in_group); } - if(cast_type_byte_size < casted_type_byte_size && e_type_kind_is_integer(cast_type_kind)) + if(cast_type_byte_size < casted_type_byte_size && e_type_kind_is_integer(cast_type_unwrapped_kind)) { new_tree = e_irtree_trunc(arena, in_tree, cast_type); } - if(e_type_kind_is_signed(cast_type_kind) && e_type_kind_is_integer(casted_type_kind) && !e_type_kind_is_signed(casted_type_kind)) + if(e_type_kind_is_signed(cast_type_unwrapped_kind) && e_type_kind_is_integer(casted_type_kind) && !e_type_kind_is_signed(casted_type_kind)) { new_tree = e_irtree_trunc(arena, in_tree, cast_type); } diff --git a/src/eval/eval_parse.c b/src/eval/eval_parse.c index 664ec814..bf244b4b 100644 --- a/src/eval/eval_parse.c +++ b/src/eval/eval_parse.c @@ -1001,6 +1001,21 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t { E_Token token = e_token_at_it(it, &tokens); String8 token_string = str8_substr(text, token.range); + + // rjf: skip no-op prefix keywords + if(token.kind == E_TokenKind_Identifier && + (str8_match(token_string, str8_lit("struct"), 0) || + str8_match(token_string, str8_lit("union"), 0) || + str8_match(token_string, str8_lit("enum"), 0) || + str8_match(token_string, str8_lit("class"), 0) || + str8_match(token_string, str8_lit("typename"), 0))) + { + it += 1; + token = e_token_at_it(it, &tokens); + token_string = str8_substr(text, token.range); + } + + // rjf: build identifier atom if(token.kind == E_TokenKind_Identifier) { String8 identifier_string = token_string;