From 83650a5fe033ec05948c935a6d05d6770dafe40f Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 15 Aug 2025 10:56:42 -0700 Subject: [PATCH] support `unsigned` -> `unsigned int`; support `as`-style casts in expressions; pack `int` alias in pdb-produced rdis --- src/eval/eval_ir.c | 2 +- src/eval/eval_parse.c | 53 +++++++++++++++++++++++++++++++-- src/raddbg/raddbg_main.c | 1 + src/rdi_from_pdb/rdi_from_pdb.c | 1 + 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/eval/eval_ir.c b/src/eval/eval_ir.c index e9efeb63..3e34a22a 100644 --- a/src/eval/eval_ir.c +++ b/src/eval/eval_ir.c @@ -2222,7 +2222,7 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I { E_IRTreeAndType direct_irtree = e_push_irtree_and_type_from_expr(arena, parent, &e_default_identifier_resolution_rule, disallow_autohooks, 1, expr->first); result = direct_irtree; - E_TypeKey direct_type_key = result.type_key; + E_TypeKey direct_type_key = e_type_key_unwrap(result.type_key, E_TypeUnwrapFlag_AllDecorative); E_TypeKind direct_type_kind = e_type_kind_from_key(direct_type_key); if(e_type_kind_is_signed(direct_type_kind)) { diff --git a/src/eval/eval_parse.c b/src/eval/eval_parse.c index bf244b4b..7e87d294 100644 --- a/src/eval/eval_parse.c +++ b/src/eval/eval_parse.c @@ -859,10 +859,19 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, token.range, "Missing `)`."); } + // rjf: require type + if(type_parse.expr == &e_expr_nil) + { + e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, token.range, "Expected type in `cast(...)`."); + } + // rjf: fill prefix unary info - prefix_unary_kind = E_ExprKind_Cast; - prefix_unary_precedence = 2; - prefix_unary_cast_expr = type_parse.expr; + else + { + prefix_unary_kind = E_ExprKind_Cast; + prefix_unary_precedence = 2; + prefix_unary_cast_expr = type_parse.expr; + } end_cast_parse:; } @@ -1303,6 +1312,33 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t } } + // rjf: "as" style casts + if(token.kind == E_TokenKind_Identifier && + str8_match(token_string, str8_lit("as"), 0)) + { + it += 1; + + // rjf: parse type expression + E_Parse type_parse = e_push_parse_from_string_tokens__prec(arena, text, e_token_array_make_first_opl(it, it_opl), e_max_precedence, 1); + e_msg_list_concat_in_place(&result.msgs, &type_parse.msgs); + it = type_parse.last_token; + + // rjf: require type + if(type_parse.expr == &e_expr_nil) + { + e_msgf(arena, &result.msgs, E_MsgKind_MalformedInput, token.range, "Expected type following `as`."); + } + + // rjf: build cast expr + else + { + E_Expr *rhs = atom; + atom = e_push_expr(arena, E_ExprKind_Cast, token.range); + e_expr_push_child(atom, type_parse.expr); + e_expr_push_child(atom, rhs); + } + } + // rjf: quit if this doesn't look like any patterns of postfix unary we know if(!is_postfix_unary) { @@ -1310,6 +1346,17 @@ e_push_parse_from_string_tokens__prec(Arena *arena, String8 text, E_TokenArray t } } + //////////////////////////// + //- rjf: no atom, just single `unsigned` prefix unary? -> unsigned int type expr + // + if(atom == &e_expr_nil && + first_prefix_unary != 0 && + first_prefix_unary->kind == E_ExprKind_Unsigned) + { + atom = e_push_expr(arena, E_ExprKind_LeafIdentifier, first_prefix_unary->cast_type_expr->range); + atom->string = str8_lit("int"); + } + //////////////////////////// //- rjf: upgrade `atom` w/ previously parsed prefix unaries // diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index 9795474f..4b7b30ed 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -6,6 +6,7 @@ // //- urgent fixes // [ ] hardware breakpoints regression (global eval in ctrl) +// [ ] native filesystem dialog, resizing raddbg window -> crash! // //- memory view // [ ] have smaller visible range than entire memory diff --git a/src/rdi_from_pdb/rdi_from_pdb.c b/src/rdi_from_pdb/rdi_from_pdb.c index 09ab8fb2..95b57049 100644 --- a/src/rdi_from_pdb/rdi_from_pdb.c +++ b/src/rdi_from_pdb/rdi_from_pdb.c @@ -3781,6 +3781,7 @@ p2r_convert(Arena *arena, ASYNC_Root *async_root, P2R_ConvertParams *in) { "__uint8" , RDI_TypeKind_U8 , CV_BasicType_UINT8 }, { "__int16" , RDI_TypeKind_S16 , CV_BasicType_INT16 }, { "__uint16" , RDI_TypeKind_U16 , CV_BasicType_UINT16 }, + { "int" , RDI_TypeKind_S32 , CV_BasicType_INT32 }, { "int32" , RDI_TypeKind_S32 , CV_BasicType_INT32 }, { "uint32" , RDI_TypeKind_U32 , CV_BasicType_UINT32 }, { "__int64" , RDI_TypeKind_S64 , CV_BasicType_INT64 },