From 08652e8b0a6369893281708cfa65665970b120da Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 27 Aug 2024 11:46:54 -0700 Subject: [PATCH] cast view rule --- src/df/core/df_core.c | 12 ++++++++++++ src/df/core/df_core.h | 1 + src/df/core/df_core.mdesk | 1 + src/df/core/generated/df_core.meta.c | 3 ++- src/df/core/generated/df_core.meta.h | 2 ++ src/df/gfx/df_view_rules.c | 10 ++++++++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index f798d56f..21254b49 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -5250,6 +5250,18 @@ df_value_from_params(MD_Node *params) return value_eval.value; } +internal E_TypeKey +df_type_key_from_params(MD_Node *params) +{ + Temp scratch = scratch_begin(0, 0); + String8 expr = md_string_from_children(scratch.arena, params); + E_TokenArray tokens = e_token_array_from_text(scratch.arena, expr); + E_Parse parse = e_parse_type_from_text_tokens(scratch.arena, expr, &tokens); + E_TypeKey type_key = e_type_from_expr(parse.expr); + scratch_end(scratch); + return type_key; +} + internal E_Value df_value_from_params_key(MD_Node *params, String8 key) { diff --git a/src/df/core/df_core.h b/src/df/core/df_core.h index 327e6fba..ffbd7ee4 100644 --- a/src/df/core/df_core.h +++ b/src/df/core/df_core.h @@ -1630,6 +1630,7 @@ internal B32 df_viz_row_is_editable(DF_EvalVizRow *row); //- rjf: eval / view rule params tree info extraction internal U64 df_base_offset_from_eval(E_Eval eval); internal E_Value df_value_from_params(MD_Node *params); +internal E_TypeKey df_type_key_from_params(MD_Node *params); internal E_Value df_value_from_params_key(MD_Node *params, String8 key); internal Rng1U64 df_range_from_eval_params(E_Eval eval, MD_Node *params); internal TXT_LangKind df_lang_kind_from_eval_params(E_Eval eval, MD_Node *params); diff --git a/src/df/core/df_core.mdesk b/src/df/core/df_core.mdesk index e0c1ea34..ebfa3793 100644 --- a/src/df/core/df_core.mdesk +++ b/src/df/core/df_core.mdesk @@ -525,6 +525,7 @@ DF_CoreViewRuleTable: {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." } {List list "list" - - - x "List" x "x:{member}" "Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list." } {ByteSwap bswap "bswap" x - x - "Byte Swap" x "" "Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed." } + {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." } {BaseDec base_dec "dec" x - - - "Decimal Base (Base 10)" x "" "Specifies that all integral evaluations should appear in base-10 form." } {BaseBin base_bin "bin" x - - - "Binary Base (Base 2)" x "" "Specifies that all integral evaluations should appear in base-2 form." } {BaseOct base_oct "oct" x - - - "Octal Base (Base 8)" x "" "Specifies that all integral evaluations should appear in base-8 form." } diff --git a/src/df/core/generated/df_core.meta.c b/src/df/core/generated/df_core.meta.c index f97bd709..c6138360 100644 --- a/src/df/core/generated/df_core.meta.c +++ b/src/df/core/generated/df_core.meta.c @@ -481,13 +481,14 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[221] = { str8_lit_comp("log_marker"), str8_lit_comp("Logs a marker in the application log, to denote specific points in time within the log."), str8_lit_comp(""), str8_lit_comp("Log Marker"), (DF_CmdSpecFlag_ListInUI*1)|(DF_CmdSpecFlag_ListInIPCDocs*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, }; -DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[19] = +DF_CoreViewRuleSpecInfo df_g_core_view_rule_spec_info_table[20] = { {str8_lit_comp("default"), str8_lit_comp("Default"), str8_lit_comp(""), str8_lit_comp(""), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(default) , }, {str8_lit_comp("array"), str8_lit_comp("Array"), str8_lit_comp("x:{expr}"), str8_lit_comp("Specifies that a pointer points to N elements, rather than only 1."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(array) , 0, }, {str8_lit_comp("slice"), str8_lit_comp("Slice"), str8_lit_comp(""), str8_lit_comp("Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(slice) , 0, }, {str8_lit_comp("list"), str8_lit_comp("List"), str8_lit_comp("x:{member}"), str8_lit_comp("Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*1), 0, DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_NAME(list) , }, {str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(bswap) , 0, }, +{str8_lit_comp("cast"), str8_lit_comp("Cast"), str8_lit_comp("x:{type}"), str8_lit_comp("Specifies that the expression to which the view rule is applied should be casted to the provided type."), (DF_CoreViewRuleSpecInfoFlag_Inherited*0)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*1)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(cast) , 0, }, {str8_lit_comp("dec"), str8_lit_comp("Decimal Base (Base 10)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-10 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, }, {str8_lit_comp("bin"), str8_lit_comp("Binary Base (Base 2)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-2 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, }, {str8_lit_comp("oct"), str8_lit_comp("Octal Base (Base 8)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-8 form."), (DF_CoreViewRuleSpecInfoFlag_Inherited*1)|(DF_CoreViewRuleSpecInfoFlag_Expandable*0)|(DF_CoreViewRuleSpecInfoFlag_ExprResolution*0)|(DF_CoreViewRuleSpecInfoFlag_VizBlockProd*0), 0, 0, }, diff --git a/src/df/core/generated/df_core.meta.h b/src/df/core/generated/df_core.meta.h index 754e0dc9..462eaa5c 100644 --- a/src/df/core/generated/df_core.meta.h +++ b/src/df/core/generated/df_core.meta.h @@ -355,6 +355,7 @@ DF_CoreViewRuleKind_Array, DF_CoreViewRuleKind_Slice, DF_CoreViewRuleKind_List, DF_CoreViewRuleKind_ByteSwap, +DF_CoreViewRuleKind_Cast, DF_CoreViewRuleKind_BaseDec, DF_CoreViewRuleKind_BaseBin, DF_CoreViewRuleKind_BaseOct, @@ -433,6 +434,7 @@ U64 inline_depth; DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(array); DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(slice); DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(bswap); +DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(cast); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(default); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(list); DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(only); diff --git a/src/df/gfx/df_view_rules.c b/src/df/gfx/df_view_rules.c index 7f1399a0..0eec1740 100644 --- a/src/df/gfx/df_view_rules.c +++ b/src/df/gfx/df_view_rules.c @@ -281,6 +281,16 @@ DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(bswap) return expr; } +//////////////////////////////// +//~ rjf: "cast" + +DF_CORE_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_DEF(cast) +{ + E_TypeKey type_key = df_type_key_from_params(params); + expr = e_expr_ref_cast(arena, type_key, expr); + return expr; +} + //////////////////////////////// //~ rjf: "dec"