From 1b868928ea1bd04185a4a8abf968f0a7436426bd Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Thu, 7 May 2026 17:01:21 -0700 Subject: [PATCH] infer path style from top node --- src/radbin/radbin.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/radbin/radbin.c b/src/radbin/radbin.c index 380f46a7..ce798280 100644 --- a/src/radbin/radbin.c +++ b/src/radbin/radbin.c @@ -1229,13 +1229,46 @@ rb_thread_entry_point(void *p) RDI_SourceFile *null_inline_src_file = rdi_element_from_name_idx(rdi, SourceFiles, 0); if(inline_src_file && inline_src_file != null_inline_src_file) { - String8 path = str8_from_rdi_path_node_idx(scratch.arena, rdi, PathStyle_SystemAbsolute, src_file->file_path_node_idx); + // TODO: remove 'path_style' from the str8_from_rdi_path_node_idx and detect + // path style based on the top node "?:" -> windows, "/" -> unix + String8 top_part = {0}; + for(RDI_FilePathNode *fpn = rdi_element_from_name_idx(rdi, FilePathNodes, src_file->file_path_node_idx); + fpn != rdi_element_from_name_idx(rdi, FilePathNodes, 0); + fpn = rdi_element_from_name_idx(rdi, FilePathNodes, fpn->parent_path_node)) + { + if(fpn->parent_path_node == 0) + { + top_part.str = rdi_string_from_idx(rdi, fpn->name_string_idx, &top_part.size); + } + } + PathStyle path_style = PathStyle_SystemAbsolute; + if (str8_match_wildcard(top_part, str8_lit("?:"), 0)) { path_style = PathStyle_WindowsAbsolute; } + else if(str8_match(top_part, str8_lit("/"), 0)) { path_style = PathStyle_UnixAbsolute; } + + String8 path = str8_from_rdi_path_node_idx(scratch.arena, rdi, path_style, src_file->file_path_node_idx); str8_list_pushf(arena, &output_blobs, "[inlined] %S %S:%u\n", inline_name, path, inline_line.line_num); } } } } - String8 path = str8_from_rdi_path_node_idx(scratch.arena, rdi, PathStyle_SystemAbsolute, src_file->file_path_node_idx); + + // TODO: remove 'path_style' from the str8_from_rdi_path_node_idx and detect + // path style based on the top node [c:|d:] -> windows, / -> unix + String8 top_part = {0}; + for(RDI_FilePathNode *fpn = rdi_element_from_name_idx(rdi, FilePathNodes, src_file->file_path_node_idx); + fpn != rdi_element_from_name_idx(rdi, FilePathNodes, 0); + fpn = rdi_element_from_name_idx(rdi, FilePathNodes, fpn->parent_path_node)) + { + if(fpn->parent_path_node == 0) + { + top_part.str = rdi_string_from_idx(rdi, fpn->name_string_idx, &top_part.size); + } + } + PathStyle path_style = PathStyle_SystemAbsolute; + if (str8_match_wildcard(top_part, str8_lit("?:"), 0)) { path_style = PathStyle_WindowsAbsolute; } + else if(str8_match(top_part, str8_lit("/"), 0)) { path_style = PathStyle_UnixAbsolute; } + + String8 path = str8_from_rdi_path_node_idx(scratch.arena, rdi, path_style, src_file->file_path_node_idx); str8_list_pushf(arena, &output_blobs, "%S:%u\n", path, line.line_num); scratch_end(scratch); }