eval: add cache for type data member gathering & member lookup; eval_visualization: sketch out new hook organization which has single hook for both view rule expansion info, + expansion expr production, in a single combined path (the two often require the same information so it is maybe a good idea to combine them - if not, it will be easy to separate into two stages (expand + expr-child production), but basically just trying to get view rules out of 'block production', and more into just providing the information that actually varies per view rule

This commit is contained in:
Ryan Fleury
2024-09-25 09:34:23 -07:00
parent fcfd446c5e
commit c976154284
7 changed files with 277 additions and 34 deletions
+15 -14
View File
@@ -88,20 +88,20 @@
// For any view rules in this layer which also have graphical features, they
// are specified in both tables under the same name.
@table(coverage_check name name_lower string ih ex xp vb display_name docs schema description)
@table(coverage_check name name_lower string ih ex xr xe vb display_name docs schema description)
EV_ViewRuleTable:
{
{x Default default "default" - - - x "Default" - "" "" }
{x Array array "array" - - x - "Array" x "x:{expr}" "Specifies that a pointer points to N elements, rather than only 1." }
{x Slice slice "slice" - - x - "Slice" x "" "Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer." }
{x ByteSwap bswap "bswap" x - x - "Byte Swap" x "" "Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed." }
{x Cast cast "cast" - - x - "Cast" x "x:{type}" "Specifies that the expression to which the view rule is applied should be casted to the provided type." }
{x Only only "only" x - x - "Only" x "" "Specifies that only the provided member names should be shown in user-defined-type expansions." }
{x Omit omit "omit" x - x - "Omit" x "" "Specifies that the provided member names should not be shown in user-defined-type expansions." }
{x Bin bin "bin" x - - - "Display In Binary" x "" "Specifies that all numeric values should be shown in base 2 (binary)." }
{x Oct oct "oct" x - - - "Display In Octal" x "" "Specifies that all numeric values should be shown in base 8 (octal)." }
{x Dec dec "dec" x - - - "Display In Decimal" x "" "Specifies that all numeric values should be shown in base 10 (decimal)." }
{x Hex hex "hex" x - - - "Display In Hexadecimal" x "" "Specifies that all numeric values should be shown in base 16 (hexadecimal)." }
{x Default default "default" - - - x x "Default" - "" "" }
{x Array array "array" - - x - - "Array" x "x:{expr}" "Specifies that a pointer points to N elements, rather than only 1." }
{x Slice slice "slice" - - x - - "Slice" x "" "Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer." }
{x ByteSwap bswap "bswap" x - x - - "Byte Swap" x "" "Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed." }
{x Cast cast "cast" - - x - - "Cast" x "x:{type}" "Specifies that the expression to which the view rule is applied should be casted to the provided type." }
{x Only only "only" x - x - - "Only" x "" "Specifies that only the provided member names should be shown in user-defined-type expansions." }
{x Omit omit "omit" x - x - - "Omit" x "" "Specifies that the provided member names should not be shown in user-defined-type expansions." }
{x Bin bin "bin" x - - - - "Display In Binary" x "" "Specifies that all numeric values should be shown in base 2 (binary)." }
{x Oct oct "oct" x - - - - "Display In Octal" x "" "Specifies that all numeric values should be shown in base 8 (octal)." }
{x Dec dec "dec" x - - - - "Display In Decimal" x "" "Specifies that all numeric values should be shown in base 10 (decimal)." }
{x Hex hex "hex" x - - - - "Display In Hexadecimal" x "" "Specifies that all numeric values should be shown in base 16 (hexadecimal)." }
}
@enum EV_ViewRuleKind:
@@ -112,12 +112,13 @@ EV_ViewRuleTable:
@gen
{
@expand(EV_ViewRuleTable a) `$(a.xp == "x" -> "EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(" .. a.name_lower .. ");")`;
@expand(EV_ViewRuleTable a) `$(a.xr == "x" -> "EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(" .. a.name_lower .. ");")`;
@expand(EV_ViewRuleTable a) `$(a.xe == "x" -> "EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_DEF(" .. a.name_lower .. ");")`;
@expand(EV_ViewRuleTable a) `$(a.vb == "x" -> "EV_VIEW_RULE_BLOCK_PROD_FUNCTION_DEF(" .. a.name_lower .. ");")`;
}
@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.xp == "x" -> "EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME("..a.name_lower..")") $(a.xp != "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_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), }```;
}
@@ -99,6 +99,113 @@ ev_arch_from_eval_params(E_Eval eval, MD_Node *params)
////////////////////////////////
//~ rjf: default
EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_DEF(default)
{
EV_ExpandResult result = {0};
Temp scratch = scratch_begin(&arena, 1);
////////////////////////////
//- rjf: unpack expression type info
//
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(scratch.arena, expr);
E_TypeKey type_key = e_type_unwrap(irtree.type_key);
E_TypeKind type_kind = e_type_kind_from_key(type_key);
E_TypeKey direct_type_key = e_type_unwrap(e_type_direct_from_key(type_key));
E_TypeKind direct_type_kind = e_type_kind_from_key(direct_type_key);
////////////////////////////
//- rjf: structs/unions/classes -> expansions generate rows for all members
//
if((type_kind == E_TypeKind_Struct ||
type_kind == E_TypeKind_Union ||
type_kind == E_TypeKind_Class) ||
(e_type_kind_is_pointer_or_ref(type_kind) && (direct_type_kind == E_TypeKind_Struct ||
direct_type_kind == E_TypeKind_Union ||
direct_type_kind == E_TypeKind_Class)))
{
E_MemberArray members = e_type_data_members_from_key__cached(e_type_kind_is_pointer_or_ref(type_kind) ? direct_type_key : type_key);
result.total_semantic_row_count = result.total_visual_row_count = members.count;
result.row_exprs_count = dim_1u64(idx_range);
result.row_exprs = push_array(arena, E_Expr *, result.row_exprs_count);
for EachIndex(row_expr_idx, result.row_exprs_count)
{
result.row_exprs[row_expr_idx] = &e_expr_nil;
U64 member_idx = idx_range.min + row_expr_idx;
if(member_idx < members.count)
{
E_Member *member = &members.v[member_idx];
result.row_exprs[row_expr_idx] = e_expr_ref_member_access(arena, expr, member->name);
}
}
}
////////////////////////////
//- rjf: enums -> expansions generate rows for all members
//
else if(type_kind == E_TypeKind_Enum ||
(e_type_kind_is_pointer_or_ref(type_kind) && direct_type_kind == E_TypeKind_Enum))
{
E_Type *type = e_type_from_key(arena, e_type_kind_is_pointer_or_ref(type_kind) ? direct_type_key : type_key);
result.total_semantic_row_count = result.total_visual_row_count = type->count;
result.row_exprs_count = dim_1u64(idx_range);
result.row_exprs = push_array(arena, E_Expr *, result.row_exprs_count);
for EachIndex(row_expr_idx, result.row_exprs_count)
{
result.row_exprs[row_expr_idx] = &e_expr_nil;
U64 enumval_idx = idx_range.min + row_expr_idx;
if(enumval_idx < type->count)
{
E_EnumVal *enumval = &type->enum_vals[enumval_idx];
result.row_exprs[row_expr_idx] = e_expr_ref_member_access(arena, expr, enumval->name);
}
}
}
////////////////////////////
//- rjf: arrays -> expansions generate rows for all elements
//
else if(type_kind == E_TypeKind_Array ||
(e_type_kind_is_pointer_or_ref(type_kind) && direct_type_kind == E_TypeKind_Array))
{
B32 need_extra_deref = e_type_kind_is_pointer_or_ref(type_kind);
E_Expr *array_expr = need_extra_deref ? e_expr_ref_deref(arena, expr) : expr;
E_Type *type = e_type_from_key(arena, need_extra_deref ? direct_type_key : type_key);
result.total_semantic_row_count = result.total_visual_row_count = type->count;
result.row_exprs_count = dim_1u64(idx_range);
result.row_exprs = push_array(arena, E_Expr *, result.row_exprs_count);
for EachIndex(row_expr_idx, result.row_exprs_count)
{
result.row_exprs[row_expr_idx] = &e_expr_nil;
U64 element_idx = idx_range.min + row_expr_idx;
if(element_idx < type->count)
{
result.row_exprs[row_expr_idx] = e_expr_ref_array_index(arena, array_expr, element_idx);
}
}
}
////////////////////////////
//- rjf: pointer-to-pointer -> expansions generate dereference
//
else if(e_type_kind_is_pointer_or_ref(type_kind) && e_type_kind_is_pointer_or_ref(direct_type_kind))
{
result.total_semantic_row_count = result.total_visual_row_count = 1;
result.row_exprs_count = dim_1u64(idx_range);
result.row_exprs = push_array(arena, E_Expr *, result.row_exprs_count);
for EachIndex(row_expr_idx, result.row_exprs_count)
{
result.row_exprs[row_expr_idx] = &e_expr_nil;
if(idx_range.min + row_expr_idx < 1)
{
result.row_exprs[row_expr_idx] = e_expr_ref_deref(arena, expr);
}
}
}
scratch_end(scratch);
return result;
}
EV_VIEW_RULE_BLOCK_PROD_FUNCTION_DEF(default)
{
Temp scratch = scratch_begin(&arena, 1);
@@ -98,6 +98,18 @@ struct EV_ViewRuleList
U64 count;
};
////////////////////////////////
//~ rjf: Expansion Hook Output
typedef struct EV_ExpandResult EV_ExpandResult;
struct EV_ExpandResult
{
U64 total_semantic_row_count;
U64 total_visual_row_count;
U64 row_exprs_count;
E_Expr **row_exprs;
};
////////////////////////////////
//~ rjf: Blocks
@@ -157,21 +169,17 @@ struct EV_BlockList
U64 total_semantic_row_count;
};
typedef struct EV_BlockArray EV_BlockArray;
struct EV_BlockArray
{
EV_Block *v;
U64 count;
U64 total_visual_row_count;
U64 total_semantic_row_count;
};
////////////////////////////////
//~ rjf: View Rule Info Types
#define EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_SIG(name) E_Expr *name(Arena *arena, E_Expr *expr, MD_Node *params)
#define EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(name) ev_view_rule_expr_resolution__##name
#define EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(name) internal EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_SIG(EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(name))
#define EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_SIG(name) EV_ExpandResult name(Arena *arena, E_Expr *expr, MD_Node *params, Rng1U64 idx_range)
#define EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_NAME(name) ev_view_rule_expr_expand__##name
#define EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_DEF(name) internal EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_SIG(EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_NAME(name))
#define EV_VIEW_RULE_BLOCK_PROD_FUNCTION_SIG(name) void name(Arena *arena, \
EV_View *view, \
String8 filter, \
@@ -186,7 +194,9 @@ S32 depth, \
struct EV_BlockList *out)
#define EV_VIEW_RULE_BLOCK_PROD_FUNCTION_NAME(name) ev_view_rule_block_prod__##name
#define EV_VIEW_RULE_BLOCK_PROD_FUNCTION_DEF(name) internal EV_VIEW_RULE_BLOCK_PROD_FUNCTION_SIG(EV_VIEW_RULE_BLOCK_PROD_FUNCTION_NAME(name))
typedef EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_SIG(EV_ViewRuleExprResolutionHookFunctionType);
typedef EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_SIG(EV_ViewRuleExprExpandHookFunctionType);
typedef EV_VIEW_RULE_BLOCK_PROD_FUNCTION_SIG(EV_ViewRuleBlockProdHookFunctionType);
typedef U32 EV_ViewRuleInfoFlags; // NOTE(rjf): see @view_rule_info
@@ -202,6 +212,7 @@ struct EV_ViewRuleInfo
String8 string;
EV_ViewRuleInfoFlags flags;
EV_ViewRuleExprResolutionHookFunctionType *expr_resolution;
EV_ViewRuleExprExpandHookFunctionType *expr_expand;
EV_ViewRuleBlockProdHookFunctionType *block_prod;
};
@@ -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_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, },
{str8_lit_comp("slice"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(slice) , 0, },
{str8_lit_comp("bswap"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(bswap) , 0, },
{str8_lit_comp("cast"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(cast) , 0, },
{str8_lit_comp("only"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(only) , 0, },
{str8_lit_comp("omit"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(omit) , 0, },
{str8_lit_comp("bin"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, },
{str8_lit_comp("oct"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, },
{str8_lit_comp("dec"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, },
{str8_lit_comp("hex"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, },
{str8_lit_comp("default"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), 0, EV_VIEW_RULE_EXPR_EXPAND_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, },
{str8_lit_comp("slice"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(slice) , 0, 0, },
{str8_lit_comp("bswap"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(bswap) , 0, 0, },
{str8_lit_comp("cast"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(cast) , 0, 0, },
{str8_lit_comp("only"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(only) , 0, 0, },
{str8_lit_comp("omit"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(omit) , 0, 0, },
{str8_lit_comp("bin"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, },
{str8_lit_comp("oct"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, },
{str8_lit_comp("dec"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, },
{str8_lit_comp("hex"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), 0, 0, 0, },
};
C_LINKAGE_END
@@ -28,5 +28,6 @@ EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(bswap);
EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(cast);
EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(only);
EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(omit);
EV_VIEW_RULE_EXPR_EXPAND_FUNCTION_DEF(default);
EV_VIEW_RULE_BLOCK_PROD_FUNCTION_DEF(default);
#endif // EVAL_VISUALIZATION_META_H