From f48d8431c0b0940136a9756a34cf1fdb833bbf40 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 19 Jan 2024 18:29:11 -0800 Subject: [PATCH] allow implicit namespacification of identifier mapping path in eval parser, based on namespace of the procedure (if any) that the instruction pointer is currently within --- src/eval/eval_parser.c | 47 ++++++++++++++++++++++++++++++ src/scratch/i_hate_c_plus_plus.cpp | 13 +++++++++ 2 files changed, 60 insertions(+) diff --git a/src/eval/eval_parser.c b/src/eval/eval_parser.c index 05769ad7..364e61d4 100644 --- a/src/eval/eval_parser.c +++ b/src/eval/eval_parser.c @@ -789,6 +789,35 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 TG_Key type_key = zero_struct; String8 local_lookup_string = token_string; + //- rjf: form namespaceify fallback + String8 namespaceified_token_string = token_string; + if(ctx->rdbg->procedures != 0 && ctx->rdbg->scopes != 0 && ctx->rdbg->scope_vmap != 0) + { + U64 scope_idx = raddbg_vmap_idx_from_voff(ctx->rdbg->scope_vmap, ctx->rdbg->scope_vmap_count, ctx->ip_voff); + RADDBG_Scope *scope = &ctx->rdbg->scopes[scope_idx]; + U64 proc_idx = scope->proc_idx; + RADDBG_Procedure *procedure = &ctx->rdbg->procedures[proc_idx]; + U64 name_size = 0; + U8 *name_ptr = raddbg_string_from_idx(ctx->rdbg, procedure->name_string_idx, &name_size); + String8 name = str8(name_ptr, name_size); + U64 past_scope_resolution_pos = 0; + for(;;) + { + U64 past_next_dbl_colon_pos = str8_find_needle(name, past_scope_resolution_pos, str8_lit("::"), 0)+2; + U64 past_next_dot_pos = str8_find_needle(name, past_scope_resolution_pos, str8_lit("."), 0)+1; + U64 past_next_scope_resolution_pos = Min(past_next_dbl_colon_pos, past_next_dot_pos); + if(past_next_scope_resolution_pos < name.size) + { + past_scope_resolution_pos = past_next_scope_resolution_pos; + } + else + { + break; + } + } + namespaceified_token_string = push_str8f(scratch.arena, "%S%S", str8_prefix(name, past_scope_resolution_pos), token_string); + } + //- rjf: try members if(mapped_identifier == 0) { @@ -888,6 +917,12 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 RADDBG_NameMapNode *node = raddbg_name_map_lookup(ctx->rdbg, &parsed_name_map, token_string.str, token_string.size); U32 matches_count = 0; U32 *matches = raddbg_matches_from_map_node(ctx->rdbg, node, &matches_count); + if(matches_count == 0) + { + node = raddbg_name_map_lookup(ctx->rdbg, &parsed_name_map, namespaceified_token_string.str, namespaceified_token_string.size); + matches_count = 0; + matches = raddbg_matches_from_map_node(ctx->rdbg, node, &matches_count); + } if(matches_count != 0) { U32 match_idx = matches[0]; @@ -918,6 +953,12 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 RADDBG_NameMapNode *node = raddbg_name_map_lookup(ctx->rdbg, &parsed_name_map, token_string.str, token_string.size); U32 matches_count = 0; U32 *matches = raddbg_matches_from_map_node(ctx->rdbg, node, &matches_count); + if(matches_count == 0) + { + node = raddbg_name_map_lookup(ctx->rdbg, &parsed_name_map, namespaceified_token_string.str, namespaceified_token_string.size); + matches_count = 0; + matches = raddbg_matches_from_map_node(ctx->rdbg, node, &matches_count); + } if(matches_count != 0) { U32 match_idx = matches[0]; @@ -948,6 +989,12 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 RADDBG_NameMapNode *node = raddbg_name_map_lookup(ctx->rdbg, &parsed_name_map, token_string.str, token_string.size); U32 matches_count = 0; U32 *matches = raddbg_matches_from_map_node(ctx->rdbg, node, &matches_count); + if(matches_count == 0) + { + node = raddbg_name_map_lookup(ctx->rdbg, &parsed_name_map, namespaceified_token_string.str, namespaceified_token_string.size); + matches_count = 0; + matches = raddbg_matches_from_map_node(ctx->rdbg, node, &matches_count); + } if(matches_count != 0) { U32 match_idx = matches[0]; diff --git a/src/scratch/i_hate_c_plus_plus.cpp b/src/scratch/i_hate_c_plus_plus.cpp index af81d532..ac4e9f96 100644 --- a/src/scratch/i_hate_c_plus_plus.cpp +++ b/src/scratch/i_hate_c_plus_plus.cpp @@ -1,7 +1,20 @@ #include +namespace SomeWeirdNamespace +{ + int X = 0; + int Y = 0; + void Foo(void) + { + X = 123; + Y = 456; + int x = 0; + } +} + int main() { std::fstream temp; + SomeWeirdNamespace::Foo(); return 0; }