diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 9d1cce68..2dfb9f58 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -5930,6 +5930,8 @@ static bool state_block_add_entry(struct hlsl_state_block *state_block, struct h %type if_body +%type array + %type var_modifiers %type any_identifier @@ -7385,52 +7387,43 @@ variable_def_typed: $$->modifiers_loc = @1; } +array: + '[' ']' + { + $$ = HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT; + } + | '[' expr ']' + { + $$ = evaluate_static_expression_as_uint(ctx, $2, &@2); + + if (!$$) + { + hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, + "Array size is not a positive integer constant."); + YYABORT; + } + + if ($$ > 65536) + { + hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, + "Array size %u is not between 1 and 65536.", $$); + YYABORT; + } + + destroy_block($2); + } + arrays: %empty { $$.sizes = NULL; $$.count = 0; } - | '[' expr ']' arrays - { - uint32_t *new_array; - unsigned int size; - - size = evaluate_static_expression_as_uint(ctx, $2, &@2); - - destroy_block($2); - - $$ = $4; - - if (!size) - { - hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, - "Array size is not a positive integer constant."); - vkd3d_free($$.sizes); - YYABORT; - } - - if (size > 65536) - { - hlsl_error(ctx, &@2, VKD3D_SHADER_ERROR_HLSL_INVALID_SIZE, - "Array size %u is not between 1 and 65536.", size); - vkd3d_free($$.sizes); - YYABORT; - } - - if (!(new_array = hlsl_realloc(ctx, $$.sizes, ($$.count + 1) * sizeof(*new_array)))) - { - vkd3d_free($$.sizes); - YYABORT; - } - $$.sizes = new_array; - $$.sizes[$$.count++] = size; - } - | '[' ']' arrays + | array arrays { uint32_t *new_array; - $$ = $3; + $$ = $2; if (!(new_array = hlsl_realloc(ctx, $$.sizes, ($$.count + 1) * sizeof(*new_array)))) { @@ -7439,7 +7432,7 @@ arrays: } $$.sizes = new_array; - $$.sizes[$$.count++] = HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT; + $$.sizes[$$.count++] = $1; } var_modifiers: