From 01800942a9ea585b8ad41501465f74ff66863499 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Mon, 26 Jun 2023 15:47:56 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Declare vars individually when parsing struct declarations. A struct declaration with variables is now absorbed into the 'declaration' rule, like any other variable declaration. A struct declaration without variables is now reduced to the 'struct_declaration_without_vars' rule. They both are reduced to a 'declaration_statement' in the end. --- libs/vkd3d-shader/hlsl.y | 75 +++++++++--------------- tests/hlsl/initializer-multi.shader_test | 8 +-- 2 files changed, 31 insertions(+), 52 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 629e0777..80ba8e11 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4554,11 +4554,10 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type shift_expr %type statement %type statement_list -%type struct_declaration +%type struct_declaration_without_vars %type type_specs %type unary_expr %type variables_def -%type variables_def_optional %type variables_def_typed %token VAR_IDENTIFIER @@ -4691,47 +4690,19 @@ preproc_directive: } } -struct_declaration: - var_modifiers struct_spec variables_def_optional ';' +struct_declaration_without_vars: + var_modifiers struct_spec ';' { - struct parse_variable_def *v, *v_next; - struct hlsl_type *type; - unsigned int modifiers = $1; + if (!$2->name) + hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, + "Anonymous struct type must declare a variable."); - if (!$3) - { - if (!$2->name) - hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, - "Anonymous struct type must declare a variable."); - if (modifiers) - hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, - "Modifiers are not allowed on struct type declarations."); - } + if ($1) + hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, + "Modifiers are not allowed on struct type declarations."); - if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) + if (!($$ = make_empty_list(ctx))) YYABORT; - - check_invalid_in_out_modifiers(ctx, modifiers, &@1); - - if ($3) - { - LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $3, struct parse_variable_def, entry) - { - v->basic_type = type; - v->modifiers = modifiers; - v->modifiers_loc = @1; - - declare_var(ctx, v); - } - - if (!($$ = initialize_vars(ctx, $3))) - YYABORT; - } - else - { - if (!($$ = make_empty_list(ctx))) - YYABORT; - } } struct_spec: @@ -5511,7 +5482,7 @@ type: declaration_statement: declaration - | struct_declaration + | struct_declaration_without_vars | typedef { if (!($$ = make_empty_list(ctx))) @@ -5579,13 +5550,6 @@ declaration: YYABORT; } -variables_def_optional: - %empty - { - $$ = NULL; - } - | variables_def - variables_def: variable_def { @@ -5668,7 +5632,22 @@ variable_def: } variable_def_typed: - var_modifiers type variable_def + var_modifiers struct_spec variable_def + { + unsigned int modifiers = $1; + struct hlsl_type *type; + + if (!(type = apply_type_modifiers(ctx, $2, &modifiers, true, &@1))) + YYABORT; + + check_invalid_in_out_modifiers(ctx, modifiers, &@1); + + $$ = $3; + $$->basic_type = type; + $$->modifiers = modifiers; + $$->modifiers_loc = @1; + } + | var_modifiers type variable_def { unsigned int modifiers = $1; struct hlsl_type *type; diff --git a/tests/hlsl/initializer-multi.shader_test b/tests/hlsl/initializer-multi.shader_test index 73dd9f2f..8f8a31e2 100644 --- a/tests/hlsl/initializer-multi.shader_test +++ b/tests/hlsl/initializer-multi.shader_test @@ -20,7 +20,7 @@ float4 main() : sv_target } -[pixel shader todo] +[pixel shader] float4 main() : sv_target { struct apple { @@ -32,11 +32,11 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (7.2, 8.0, 7.2, 8.0) -[pixel shader todo] +[pixel shader] float4 main() : sv_target { struct apple { @@ -48,5 +48,5 @@ float4 main() : sv_target } [test] -todo draw quad +draw quad probe all rgba (5.2, 9.0, 5.2, 9.0)