From 4e1bf5e163215c17564775b75b9ad7a2328b8917 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Thu, 16 Nov 2023 15:32:16 -0300 Subject: [PATCH] vkd3d-shader/hlsl: Discern between signed and unsigned ints when parsing. --- libs/vkd3d-shader/hlsl.l | 18 +++++++++++++++--- libs/vkd3d-shader/hlsl.y | 10 ++++++++++ tests/hlsl/initializer-numeric.shader_test | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index c3570990..401fba60 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -203,18 +203,30 @@ while {return KW_WHILE; } yylval->floatval = atof(yytext); return C_FLOAT; } -0x[0-9a-fA-F]+[uU]? { +0x[0-9a-fA-F]+[lL]? { yylval->intval = vkd3d_parse_integer(yytext); return C_INTEGER; } -0[0-7]+[uU]? { +0[0-7]+[lL]? { yylval->intval = vkd3d_parse_integer(yytext); return C_INTEGER; } -[0-9]+[uU]? { +[0-9]+[lL]? { yylval->intval = vkd3d_parse_integer(yytext); return C_INTEGER; } +0x[0-9a-fA-F]+([uU]|[uU][lL]|[lL][uU]) { + yylval->intval = vkd3d_parse_integer(yytext); + return C_UNSIGNED; + } +0[0-7]+([uU]|[uU][lL]|[lL][uU]) { + yylval->intval = vkd3d_parse_integer(yytext); + return C_UNSIGNED; + } +[0-9]+([uU]|[uU][lL]|[lL][uU]) { + yylval->intval = vkd3d_parse_integer(yytext); + return C_UNSIGNED; + } {WS}+ {} {NEWLINE} { diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index c25b101a..67b01293 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4975,6 +4975,7 @@ static void check_duplicated_switch_cases(struct hlsl_ctx *ctx, const struct hls %token C_FLOAT %token C_INTEGER +%token C_UNSIGNED %token PRE_LINE %type type_specs @@ -6709,6 +6710,15 @@ primary_expr: if (!($$ = make_block(ctx, c))) YYABORT; } + | C_UNSIGNED + { + struct hlsl_ir_node *c; + + if (!(c = hlsl_new_uint_constant(ctx, $1, &@1))) + YYABORT; + if (!($$ = make_block(ctx, c))) + YYABORT; + } | boolean { struct hlsl_ir_node *c; diff --git a/tests/hlsl/initializer-numeric.shader_test b/tests/hlsl/initializer-numeric.shader_test index 81d19d06..617b6740 100644 --- a/tests/hlsl/initializer-numeric.shader_test +++ b/tests/hlsl/initializer-numeric.shader_test @@ -57,7 +57,7 @@ float4 main() : sv_target [test] draw quad -todo(sm<6) probe all rgba (3.0, 250.0, 16.0, 4.2949673e+009) 4 +probe all rgba (3.0, 250.0, 16.0, 4.2949673e+009) 4 [require] @@ -73,4 +73,4 @@ float4 main() : sv_target [test] draw quad -todo probe all rgba (-1294967296.0, 3000000000.0, 0.0, 0.0) 4 +probe all rgba (-1294967296.0, 3000000000.0, 0.0, 0.0) 4