From 58445da64bb894cd092be4aa142a620842dd26b1 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 13 Sep 2021 22:40:09 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Allow the final expression in a for loop initializer to be omitted. --- libs/vkd3d-shader/hlsl.y | 14 +++++++++----- tests/return.shader_test | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d5e2b2a9..3bad2acc 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3647,6 +3647,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl %type declaration_statement %type equality_expr %type expr +%type expr_optional %type expr_statement %type initializer_expr %type jump_statement @@ -4875,24 +4876,27 @@ loop_statement: { $$ = create_loop(ctx, LOOP_DO_WHILE, NULL, $5, NULL, $2, @1); } - | KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement + | KW_FOR '(' scope_start expr_statement expr_statement expr_optional ')' statement { $$ = create_loop(ctx, LOOP_FOR, $4, $5, $6, $8, @1); hlsl_pop_scope(ctx); } - | KW_FOR '(' scope_start declaration expr_statement expr ')' statement + | KW_FOR '(' scope_start declaration expr_statement expr_optional ')' statement { $$ = create_loop(ctx, LOOP_FOR, $4, $5, $6, $8, @1); hlsl_pop_scope(ctx); } -expr_statement: - ';' +expr_optional: + %empty { if (!($$ = make_empty_list(ctx))) YYABORT; } - | expr ';' + | expr + +expr_statement: + expr_optional ';' { $$ = $1; } diff --git a/tests/return.shader_test b/tests/return.shader_test index a66d8756..2660c6dd 100644 --- a/tests/return.shader_test +++ b/tests/return.shader_test @@ -215,7 +215,7 @@ todo draw quad todo probe all rgba (0.2, 0.2, 0.2, 0.2) uniform 0 float 0.8 todo draw quad -todo probe all rgba (0.5, 0.5, 0.5, 0.5) +probe all rgba (0.5, 0.5, 0.5, 0.5) [pixel shader todo]