mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-14 16:12:24 -07:00
clean up & fixup pass over type pattern matching, allow closed {}s, ()s, []s, <>s in wildcards
This commit is contained in:
+84
-28
@@ -449,12 +449,28 @@ e_auto_hook_map_insert_new_(Arena *arena, E_AutoHookMap *map, E_AutoHookParams *
|
||||
String8List pattern_parts = {0};
|
||||
if(e_type_key_match(e_type_key_zero(), type_key))
|
||||
{
|
||||
U8 pattern_split = '?';
|
||||
pattern_parts = str8_split(arena, params->type_pattern, &pattern_split, 1, StringSplitFlag_KeepEmpties);
|
||||
U64 start_string_off = 0;
|
||||
for(U64 off = 0; off <= params->type_pattern.size; off += 1)
|
||||
{
|
||||
U8 byte = (off < params->type_pattern.size ? params->type_pattern.str[off] : 0);
|
||||
if(byte == 0 || byte == '?')
|
||||
{
|
||||
String8 new_part = str8_substr(params->type_pattern, r1u64(start_string_off, off));
|
||||
if(new_part.size != 0)
|
||||
{
|
||||
str8_list_push(arena, &pattern_parts, new_part);
|
||||
}
|
||||
start_string_off = off+1;
|
||||
}
|
||||
if(byte == '?')
|
||||
{
|
||||
str8_list_push(arena, &pattern_parts, str8_zero());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: if the type key is nonzero, *or* we have type patterns, then insert
|
||||
// into map accordingle
|
||||
// into map accordingly
|
||||
if(!e_type_key_match(e_type_key_zero(), type_key) ||
|
||||
pattern_parts.node_count != 0)
|
||||
{
|
||||
@@ -1048,7 +1064,9 @@ e_auto_hook_exprs_from_type_key(Arena *arena, E_TypeKey type_key)
|
||||
E_AutoHookMap *map = e_ir_ctx->auto_hook_map;
|
||||
String8 type_string = str8_skip_chop_whitespace(e_type_string_from_key(scratch.arena, type_key));
|
||||
|
||||
////////////////////////////
|
||||
//- rjf: gather exact-type-key-matches from the map
|
||||
//
|
||||
if(map != 0 && map->slots_count != 0)
|
||||
{
|
||||
U64 hash = e_hash_from_string(5381, type_string);
|
||||
@@ -1063,48 +1081,86 @@ e_auto_hook_exprs_from_type_key(Arena *arena, E_TypeKey type_key)
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
//- rjf: gather fuzzy matches from all patterns in the map
|
||||
//
|
||||
if(map != 0 && map->first_pattern != 0)
|
||||
{
|
||||
for(E_AutoHookNode *auto_hook_node = map->first_pattern;
|
||||
auto_hook_node != 0;
|
||||
auto_hook_node = auto_hook_node->pattern_order_next)
|
||||
{
|
||||
////////////////////////
|
||||
//- rjf: determine if this pattern fits this type's string
|
||||
//
|
||||
B32 fits_this_type_string = 1;
|
||||
U64 scan_pos = 0;
|
||||
for(String8Node *n = auto_hook_node->type_pattern_parts.first; n != 0; n = n->next)
|
||||
{
|
||||
if(n->string.size == 0)
|
||||
U64 scan_pos = 0;
|
||||
for(String8Node *n = auto_hook_node->type_pattern_parts.first; n != 0 && fits_this_type_string; n = n->next)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
U64 pattern_part_pos = type_string.size;
|
||||
for(U64 p = scan_pos; p < type_string.size;)
|
||||
{
|
||||
p = str8_find_needle(type_string, p, n->string, 0);
|
||||
if(p < type_string.size)
|
||||
String8 pattern_string = n->string;
|
||||
|
||||
//- rjf: skip whitespace
|
||||
for(;scan_pos < type_string.size;)
|
||||
{
|
||||
pattern_part_pos = p;
|
||||
p += n->string.size;
|
||||
if(char_is_space(type_string.str[scan_pos]))
|
||||
{
|
||||
scan_pos += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: no pattern string -> wildcard. skip wildcard portion
|
||||
if(pattern_string.size == 0)
|
||||
{
|
||||
String8 terminator_pattern_string = n->next ? n->next->string : str8_zero();
|
||||
U64 brace_nest_depth = 0;
|
||||
U64 paren_nest_depth = 0;
|
||||
U64 angle_nest_depth = 0;
|
||||
U64 brack_nest_depth = 0;
|
||||
for(;scan_pos < type_string.size; scan_pos += 1)
|
||||
{
|
||||
if(0){}
|
||||
else if(type_string.str[scan_pos] == '{') { brace_nest_depth += 1; }
|
||||
else if(type_string.str[scan_pos] == '(') { paren_nest_depth += 1; }
|
||||
else if(type_string.str[scan_pos] == '<') { angle_nest_depth += 1; }
|
||||
else if(type_string.str[scan_pos] == '[') { brack_nest_depth += 1; }
|
||||
else if(type_string.str[scan_pos] == '}' && brace_nest_depth > 0) { brace_nest_depth -= 1; }
|
||||
else if(type_string.str[scan_pos] == ')' && paren_nest_depth > 0) { paren_nest_depth -= 1; }
|
||||
else if(type_string.str[scan_pos] == '>' && angle_nest_depth > 0) { angle_nest_depth -= 1; }
|
||||
else if(type_string.str[scan_pos] == ']' && brack_nest_depth > 0) { brack_nest_depth -= 1; }
|
||||
else if(str8_match(terminator_pattern_string, str8_skip(type_string, scan_pos), StringMatchFlag_RightSideSloppy))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: pattern string -> find next occurrence.
|
||||
else if(pattern_string.size != 0)
|
||||
{
|
||||
if(!str8_match(str8_substr(type_string, r1u64(scan_pos, scan_pos+pattern_string.size)), pattern_string, 0))
|
||||
{
|
||||
fits_this_type_string = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scan_pos += pattern_string.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pattern_part_pos > scan_pos && n == auto_hook_node->type_pattern_parts.first)
|
||||
if(fits_this_type_string && scan_pos < type_string.size)
|
||||
{
|
||||
fits_this_type_string = 0;
|
||||
break;
|
||||
}
|
||||
if(pattern_part_pos >= type_string.size)
|
||||
{
|
||||
fits_this_type_string = 0;
|
||||
break;
|
||||
}
|
||||
scan_pos = pattern_part_pos + n->string.size;
|
||||
if(n->next == 0 && scan_pos < type_string.size)
|
||||
{
|
||||
fits_this_type_string = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
//- rjf: push expression if this type fits
|
||||
//
|
||||
if(fits_this_type_string)
|
||||
{
|
||||
E_Expr *expr = e_parse_from_string(auto_hook_node->expr_string).expr;
|
||||
|
||||
@@ -167,6 +167,14 @@ struct TemplatedDynamicArray
|
||||
};
|
||||
raddbg_type_view(TemplatedDynamicArray<?>, rows($, count, array(v, count)));
|
||||
|
||||
template<typename T>
|
||||
struct OpaqueTemplatedDynamicArray
|
||||
{
|
||||
void *v;
|
||||
int count;
|
||||
};
|
||||
raddbg_type_view(OpaqueTemplatedDynamicArray<?>, rows($, count, array(v, count)));
|
||||
|
||||
struct Struct_With_Embedded_Arrays
|
||||
{
|
||||
int x;
|
||||
@@ -445,6 +453,8 @@ type_coverage_eval_tests(void)
|
||||
{dynamic.pairs, dynamic.count},
|
||||
};
|
||||
|
||||
OpaqueTemplatedDynamicArray<Pair> otd = {dynamic.pairs, dynamic.count};
|
||||
|
||||
raddbg_pin(columns(sequence(6), fixed.pairs[$], memory_[$]));
|
||||
raddbg_pin(basics);
|
||||
raddbg_pin(fixed);
|
||||
|
||||
Reference in New Issue
Block a user