wildcard instance identifier resolution in type views; ?{arg1, arg2, arg3} in type view pattern -> use arg1, arg2, or arg3 in expression

This commit is contained in:
Ryan Fleury
2025-05-28 15:41:48 -07:00
parent 1d72de8c4a
commit f116d88b08
6 changed files with 62 additions and 3 deletions
+25 -1
View File
@@ -463,13 +463,31 @@ e_auto_hook_map_insert_new_(Arena *arena, E_AutoHookMap *map, E_AutoHookParams *
p->string = new_part;
pattern.count += 1;
}
start_string_off = off+1;
}
if(byte == '?')
{
E_PatternPart *p = push_array(arena, E_PatternPart, 1);
SLLQueuePush(pattern.first_part, pattern.last_part, p);
pattern.count += 1;
if(off+1 < params->type_pattern.size && params->type_pattern.str[off+1] == '{')
{
off += 2;
String8 wildcard_inst_names_string = str8_skip(params->type_pattern, off);
wildcard_inst_names_string = str8_prefix(wildcard_inst_names_string, str8_find_needle(wildcard_inst_names_string, 0, str8_lit("}"), 0));
if(wildcard_inst_names_string.size != 0)
{
Temp scratch = scratch_begin(&arena, 1);
U8 wildcard_inst_name_split_char = ',';
String8List wildcard_inst_names = str8_split(scratch.arena, wildcard_inst_names_string, &wildcard_inst_name_split_char, 1, 0);
for(String8Node *n = wildcard_inst_names.first; n != 0; n = n->next)
{
str8_list_push(arena, &p->wildcard_inst_names, str8_skip_chop_whitespace(n->string));
}
scratch_end(scratch);
off += wildcard_inst_names_string.size;
}
}
start_string_off = off+1;
}
}
}
@@ -1131,6 +1149,7 @@ e_push_auto_hook_matches_from_type_key(Arena *arena, E_TypeKey type_key)
U64 angle_nest_depth = 0;
U64 brack_nest_depth = 0;
U64 start_inst_off = scan_pos;
String8Node *wildcard_inst_name_node = part->wildcard_inst_names.first;
for(B32 done = 0; !done && scan_pos < type_string.size; scan_pos += 1)
{
if(0){}
@@ -1156,7 +1175,12 @@ e_push_auto_hook_matches_from_type_key(Arena *arena, E_TypeKey type_key)
start_inst_off = scan_pos+1;
E_AutoHookWildcardInst *inst = push_array(arena, E_AutoHookWildcardInst, 1);
SLLQueuePush(first_wildcard_inst, last_wildcard_inst, inst);
inst->name = wildcard_inst_name_node ? wildcard_inst_name_node->string : str8_zero();
inst->inst_expr = e_parse_from_string(wildcard_inst_string).expr;
if(wildcard_inst_name_node)
{
wildcard_inst_name_node = wildcard_inst_name_node->next;
}
}
if(done)
{
+3
View File
@@ -683,6 +683,7 @@ typedef struct E_AutoHookWildcardInst E_AutoHookWildcardInst;
struct E_AutoHookWildcardInst
{
E_AutoHookWildcardInst *next;
String8 name;
E_Expr *inst_expr;
};
@@ -1082,6 +1083,8 @@ struct E_Cache
//- rjf: [ir] ir gen options
B32 disallow_autohooks;
B32 disallow_chained_fastpaths;
E_AutoHookWildcardInst *first_wildcard_inst;
E_AutoHookWildcardInst *last_wildcard_inst;
//- rjf: [ir] ir caches
E_UsedExprMap *used_expr_map;
+29
View File
@@ -607,6 +607,8 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I
{
Task *next;
E_Expr *expr;
E_AutoHookWildcardInst *first_wildcard_inst;
E_AutoHookWildcardInst *last_wildcard_inst;
E_IRTreeAndType *overridden;
};
Task start_task = {0, root_expr, 0};
@@ -620,6 +622,12 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I
//- rjf: poison the expression we are about to use, so we don't recursively use it
e_expr_poison(expr);
//- rjf: push stack elements
E_AutoHookWildcardInst *first_wildcard_inst_restore = e_cache->first_wildcard_inst;
E_AutoHookWildcardInst *last_wildcard_inst_restore = e_cache->last_wildcard_inst;
if(t->first_wildcard_inst) { e_cache->first_wildcard_inst = t->first_wildcard_inst; }
if(t->last_wildcard_inst) { e_cache->last_wildcard_inst = t->last_wildcard_inst; }
//- rjf: do expr -> irtree generation for this expression
if(expr->kind == E_ExprKind_Ref)
{
@@ -1614,6 +1622,21 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I
{
default:{}break;
//- rjf: try to map name as a wildcard instance
case E_IdentifierResolutionPath_WildcardInst:
if(!generated && qualifier.size == 0 && !string_mapped && e_cache->first_wildcard_inst != 0)
{
for(E_AutoHookWildcardInst *inst = e_cache->first_wildcard_inst; inst != 0; inst = inst->next)
{
if(str8_match(inst->name, string, 0))
{
generated = 1;
result = e_push_irtree_and_type_from_expr(arena, parent, &e_default_identifier_resolution_rule, disallow_autohooks, 1, inst->inst_expr);
break;
}
}
}break;
//- rjf: try to map name as parent expression signifier ('$')
case E_IdentifierResolutionPath_ParentExpr:
if(qualifier.size == 0 && !string_mapped && str8_match(string, str8_lit("$"), 0) && parent != 0 && (parent->root != &e_irnode_nil || parent->msgs.first != 0))
@@ -2369,6 +2392,10 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I
result.auto_hook = 1;
}
//- rjf: restore stack elements
e_cache->first_wildcard_inst = first_wildcard_inst_restore;
e_cache->last_wildcard_inst = last_wildcard_inst_restore;
//- rjf: find any auto hooks according to this generation's type
if(!disallow_autohooks && result.mode != E_Mode_Null)
{
@@ -2381,6 +2408,8 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I
Task *task = push_array(scratch.arena, Task, 1);
SLLQueuePush(first_task, last_task, task);
task->expr = match->expr;
task->first_wildcard_inst = match->first_wildcard_inst;
task->last_wildcard_inst = match->last_wildcard_inst;
task->overridden = push_array(scratch.arena, E_IRTreeAndType, 1);
task->overridden[0] = result;
goto end_autohook_find;
+3
View File
@@ -9,6 +9,7 @@
typedef enum E_IdentifierResolutionPath
{
E_IdentifierResolutionPath_WildcardInst,
E_IdentifierResolutionPath_ParentExpr,
E_IdentifierResolutionPath_ParentExprMember,
E_IdentifierResolutionPath_ImplicitThisMember,
@@ -81,6 +82,7 @@ struct E_IRState
E_IdentifierResolutionPath e_default_identifier_resolution_paths[] =
{
E_IdentifierResolutionPath_WildcardInst,
E_IdentifierResolutionPath_ParentExpr,
E_IdentifierResolutionPath_ParentExprMember,
E_IdentifierResolutionPath_ImplicitThisMember,
@@ -103,6 +105,7 @@ E_IdentifierResolutionRule e_default_identifier_resolution_rule =
E_IdentifierResolutionPath e_callable_identifier_resolution_paths[] =
{
E_IdentifierResolutionPath_Macros,
E_IdentifierResolutionPath_WildcardInst,
E_IdentifierResolutionPath_ParentExpr,
E_IdentifierResolutionPath_ParentExprMember,
E_IdentifierResolutionPath_ImplicitThisMember,
+1 -1
View File
@@ -2536,7 +2536,7 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(array)
{
E_Type *type = e_type_from_key(eval.irtree.type_key);
U64 count = 1;
if(type->args != 0 && type->count > 0) E_ParentKey(eval.parent_key)
if(type->args != 0 && type->count > 0) E_ParentKey(e_key_match(e_key_zero(), eval.parent_key) ? eval.key : eval.parent_key)
{
E_Key count_key = e_key_from_expr(type->args[0]);
E_Value count_value = e_value_from_key(count_key);
+1 -1
View File
@@ -173,7 +173,7 @@ struct OpaqueTemplatedDynamicArray
void *v;
int count;
};
raddbg_type_view(OpaqueTemplatedDynamicArray<?>, rows($, count, array(v, count)));
raddbg_type_view(OpaqueTemplatedDynamicArray<?{type}>, array(cast(type *)v, count));
struct Struct_With_Embedded_Arrays
{