extend eval visualization view rule hooks to support view-rule-defined (id <-> number) mapping; used for id-based state keys, but an immediate-mode ordering (e.g. sorted/filtered debug info tables); can be used in the future for sorted types/arrays/etc., while preserving expansion/view rule state. also, pull out the block tree -> list(block*range) walk, since it is going to be useful in multiple places

This commit is contained in:
Ryan Fleury
2024-09-25 16:32:43 -07:00
parent f2ecb3d898
commit df2bc62563
4 changed files with 141 additions and 14 deletions
@@ -121,5 +121,5 @@ EV_ViewRuleTable:
@data(EV_ViewRuleInfo) @c_file ev_builtin_view_rule_info_table:
{
@expand(EV_ViewRuleTable a)
```{str8_lit_comp("$(a.string)"), (EV_ViewRuleInfoFlag_Inherited*$(a.ih == "x"))|(EV_ViewRuleInfoFlag_Expandable*$(a.ex == "x")), $(a.xr == "x" -> "EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME("..a.name_lower..")") $(a.xr != "x" -> 0), $(a.xe == "x" -> "EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME("..a.name_lower..")") $(a.xe != "x" -> 0), $(a.xe == "x" -> "EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME("..a.name_lower..")") $(a.xe != "x" -> 0), $(a.vb == "x" -> "EV_VIEW_RULE_BLOCK_PROD_FUNCTION_NAME("..a.name_lower..")") $(a.vb != "x" -> 0), }```;
```{str8_lit_comp("$(a.string)"), (EV_ViewRuleInfoFlag_Inherited*$(a.ih == "x"))|(EV_ViewRuleInfoFlag_Expandable*$(a.ex == "x")), $(a.xr == "x" -> "EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME("..a.name_lower..")") $(a.xr != "x" -> 0), $(a.xe == "x" -> "EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME("..a.name_lower..")") $(a.xe != "x" -> 0), $(a.xe == "x" -> "EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME("..a.name_lower..")") $(a.xe != "x" -> 0), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), $(a.vb == "x" -> "EV_VIEW_RULE_BLOCK_PROD_FUNCTION_NAME("..a.name_lower..")") $(a.vb != "x" -> 0), }```;
}
@@ -472,6 +472,19 @@ ev_view_rule_list_copy(Arena *arena, EV_ViewRuleList *src)
return dst;
}
////////////////////////////////
//~ rjf: View Rule Expansion ID Spaces
EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_DEF(identity)
{
return num;
}
EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_DEF(identity)
{
return id;
}
////////////////////////////////
//~ rjf: View Rule Expression Resolution
@@ -576,7 +589,8 @@ ev2_block_tree_from_expr(Arena *arena, EV_View *view, String8 filter, String8 st
{
for(EV_ExpandNode *child = expand_node->first; child != 0; child = child->next)
{
U64 split_relative_idx = child->key.child_num - 1; // TODO(rjf): key -> index
U64 split_num = expand_view_rule_info->expr_expand_num_from_id(child->key.child_num, expand_info.user_data);
U64 split_relative_idx = split_num - 1;
EV_ExpandRangeInfo child_expand = expand_view_rule_info->expr_expand_range_info(arena, view, filter, t->expr, expand_params, r1u64(split_relative_idx, split_relative_idx+1), expand_info.user_data);
if(child_expand.row_exprs_count > 0)
{
@@ -669,6 +683,73 @@ ev2_depth_from_block(EV2_Block *block)
return depth;
}
internal EV2_BlockRangeList
ev2_block_range_list_from_tree(Arena *arena, EV2_BlockTree *block_tree)
{
EV2_BlockRangeList list = {0};
{
Temp scratch = scratch_begin(&arena, 1);
typedef struct BlockTask BlockTask;
struct BlockTask
{
BlockTask *next;
EV2_Block *block;
EV2_Block *next_child;
Rng1U64 block_relative_range;
};
BlockTask start_task = {0, block_tree->root, block_tree->root->first, r1u64(0, block_tree->root->visual_row_count)};
for(BlockTask *t = &start_task; t != 0; t = t->next)
{
// rjf: get block-relative range, truncated by split position of next child
Rng1U64 block_relative_range = t->block_relative_range;
if(t->next_child != &ev2_nil_block)
{
block_relative_range.max = t->next_child->split_relative_idx+1;
}
U64 block_num_visual_rows = dim_1u64(block_relative_range);
// rjf: generate range node
if(block_num_visual_rows != 0)
{
EV2_BlockRangeNode *n = push_array(arena, EV2_BlockRangeNode, 1);
n->v.block = t->block;
n->v.range = block_relative_range;
SLLQueuePush(list.first, list.last, n);
list.count += 1;
}
// rjf: generate task for child, + for post-child parts of this block
if(t->next_child != &ev2_nil_block)
{
// rjf: generate task for child - do *before* remainder (descend block tree depth first)
BlockTask *child_task = push_array(scratch.arena, BlockTask, 1);
child_task->next = t->next;
t->next = child_task;
child_task->block = t->next_child;
child_task->next_child = t->next_child->first;
child_task->block_relative_range = r1u64(0, t->next_child->visual_row_count);
// rjf: generate task for post-child rows, if any, after children
Rng1U64 remainder_range = r1u64(t->next_child->split_relative_idx+1, t->block_relative_range.max);
if(remainder_range.max > remainder_range.min)
{
BlockTask *remainder_task = push_array(scratch.arena, BlockTask, 1);
remainder_task->next = child_task->next;
child_task->next = remainder_task;
remainder_task->block = t->block;
remainder_task->next_child = t->next_child->next;
remainder_task->block_relative_range = remainder_range;
}
}
}
scratch_end(scratch);
}
return list;
}
////////////////////////////////
//~ rjf: Row Building (v2)
internal EV2_WindowedRowList
ev2_windowed_row_list_from_block_tree(Arena *arena, EV_View *view, String8 filter, EV2_BlockTree *block_tree, Rng1U64 visible_range)
{
@@ -749,7 +830,8 @@ ev2_windowed_row_list_from_block_tree(Arena *arena, EV_View *view, String8 filte
for EachIndex(idx, expand_range_info.row_exprs_count)
{
U64 row_visual_size = expand_range_info.row_exprs_num_visual_rows[idx];
U64 child_id = block_relative_range.min + idx + 1; // TODO(rjf): index -> key
U64 child_num = block_relative_range.min + idx + 1;
U64 child_id = t->block->expand_view_rule_info->expr_expand_id_from_num(child_num, t->block->expand_view_rule_info_user_data);
EV2_Row *row = push_array(arena, EV2_Row, 1);
SLLQueuePush(rows.first, rows.last, row);
rows.count += 1;
@@ -189,6 +189,14 @@ struct EV_ExpandRangeInfo
#define EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(name) ev_view_rule_expr_expand_range_info__##name
#define EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_DEF(name) internal EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_SIG(EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(name))
#define EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_SIG(name) U64 name(U64 num, void *user_data)
#define EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(name) ev_view_rule_expr_expand_id_from_num_##name
#define EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_DEF(name) internal EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_SIG(EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(name))
#define EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_SIG(name) U64 name(U64 id, void *user_data)
#define EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(name) ev_view_rule_expr_expand_num_from_id_##name
#define EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_DEF(name) internal EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_SIG(EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(name))
#define EV_VIEW_RULE_BLOCK_PROD_FUNCTION_SIG(name) void name(Arena *arena, \
EV_View *view, \
String8 filter, \
@@ -207,6 +215,8 @@ struct EV_BlockList *out)
typedef EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_SIG(EV_ViewRuleExprResolutionHookFunctionType);
typedef EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_SIG(EV_ViewRuleExprExpandInfoHookFunctionType);
typedef EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_SIG(EV_ViewRuleExprExpandRangeInfoHookFunctionType);
typedef EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_SIG(EV_ViewRuleExprExpandIDFromNumHookFunctionType);
typedef EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_SIG(EV_ViewRuleExprExpandNumFromIDHookFunctionType);
typedef EV_VIEW_RULE_BLOCK_PROD_FUNCTION_SIG(EV_ViewRuleBlockProdHookFunctionType);
typedef U32 EV_ViewRuleInfoFlags; // NOTE(rjf): see @view_rule_info
@@ -224,6 +234,8 @@ struct EV_ViewRuleInfo
EV_ViewRuleExprResolutionHookFunctionType *expr_resolution;
EV_ViewRuleExprExpandInfoHookFunctionType *expr_expand_info;
EV_ViewRuleExprExpandRangeInfoHookFunctionType *expr_expand_range_info;
EV_ViewRuleExprExpandIDFromNumHookFunctionType *expr_expand_id_from_num;
EV_ViewRuleExprExpandIDFromNumHookFunctionType *expr_expand_num_from_id;
EV_ViewRuleBlockProdHookFunctionType *block_prod;
};
@@ -288,6 +300,28 @@ struct EV2_BlockTree
U64 total_visual_row_count;
};
typedef struct EV2_BlockRange EV2_BlockRange;
struct EV2_BlockRange
{
EV2_Block *block;
Rng1U64 range;
};
typedef struct EV2_BlockRangeNode EV2_BlockRangeNode;
struct EV2_BlockRangeNode
{
EV2_BlockRangeNode *next;
EV2_BlockRange v;
};
typedef struct EV2_BlockRangeList EV2_BlockRangeList;
struct EV2_BlockRangeList
{
EV2_BlockRangeNode *first;
EV2_BlockRangeNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Rows (v2)
@@ -461,6 +495,12 @@ internal EV_ViewRuleList *ev_view_rule_list_from_string(Arena *arena, String8 st
internal EV_ViewRuleList *ev_view_rule_list_from_inheritance(Arena *arena, EV_ViewRuleList *src);
internal EV_ViewRuleList *ev_view_rule_list_copy(Arena *arena, EV_ViewRuleList *src);
////////////////////////////////
//~ rjf: View Rule Expansion ID Spaces
EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_DEF(identity);
EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_DEF(identity);
////////////////////////////////
//~ rjf: View Rule Expression Resolution
@@ -472,6 +512,11 @@ internal E_Expr *ev_expr_from_expr_view_rules(Arena *arena, E_Expr *expr, EV_Vie
internal EV2_BlockTree ev2_block_tree_from_expr(Arena *arena, EV_View *view, String8 filter, String8 string, E_Expr *expr, EV_ViewRuleList *view_rules);
internal EV2_BlockTree ev2_block_tree_from_string(Arena *arena, EV_View *view, String8 filter, String8 string, EV_ViewRuleList *view_rules);
internal U64 ev2_depth_from_block(EV2_Block *block);
internal EV2_BlockRangeList ev2_block_range_list_from_tree(Arena *arena, EV2_BlockTree *block_tree);
////////////////////////////////
//~ rjf: Row Building (v2)
internal EV2_WindowedRowList ev2_windowed_row_list_from_block_tree(Arena *arena, EV_View *view, String8 filter, EV2_BlockTree *block_tree, Rng1U64 visible_range);
internal String8 ev2_expr_string_from_row(Arena *arena, EV2_Row *row, EV_StringFlags flags);
internal B32 ev2_row_is_expandable(EV2_Row *row);
@@ -6,17 +6,17 @@
C_LINKAGE_BEGIN
EV_ViewRuleInfo ev_builtin_view_rule_info_table[11] =
{
{str8_lit_comp("default"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), 0, EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_BLOCK_PROD_FUNCTION_NAME(default) , },
{str8_lit_comp("array"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(array) , 0, 0, 0, },
{str8_lit_comp("slice"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(slice) , 0, 0, 0, },
{str8_lit_comp("bswap"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(bswap) , 0, 0, 0, },
{str8_lit_comp("cast"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(cast) , 0, 0, 0, },
{str8_lit_comp("only"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(only) , 0, 0, 0, },
{str8_lit_comp("omit"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(omit) , 0, 0, 0, },
{str8_lit_comp("bin"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, 0, },
{str8_lit_comp("oct"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, 0, },
{str8_lit_comp("dec"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, 0, },
{str8_lit_comp("hex"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, 0, },
{str8_lit_comp("default"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), 0, EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), EV_VIEW_RULE_BLOCK_PROD_FUNCTION_NAME(default) , },
{str8_lit_comp("array"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(array) , 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("slice"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(slice) , 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("bswap"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(bswap) , 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("cast"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(cast) , 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("only"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(only) , 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("omit"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(omit) , 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("bin"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("oct"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("dec"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
{str8_lit_comp("hex"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity), 0, },
};
C_LINKAGE_END