Technically we shouldn't allow "uu" or "ll" either, but we also don't really handle preprocessor parsing errors the way we should.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/preproc.l | 7 ++++--- tests/preproc-if-expr.shader_test | 33 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index bf4d669f3..54542331b 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -57,6 +57,7 @@ static void update_location(struct preproc_ctx *ctx); NEWLINE \r?\n WS [ \t] IDENTIFIER [A-Za-z_][A-Za-z0-9_]* +INT_SUFFIX [uUlL]{0,2}
%%
@@ -92,9 +93,9 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* <INITIAL>[0-9]+.([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} <INITIAL>[0-9]+([eE][+-]?[0-9]+)?[hHfF] {return T_TEXT;} <INITIAL>[0-9]+[eE][+-]?[0-9]+ {return T_TEXT;} -<INITIAL,LINE>0[xX][0-9a-fA-f]+[ul]{0,2} {return T_INTEGER;} -<INITIAL,LINE>0[0-7]*[ul]{0,2} {return T_INTEGER;} -<INITIAL,LINE>[1-9][0-9]*[ul]{0,2} {return T_INTEGER;} +<INITIAL,LINE>0[xX][0-9a-fA-f]+{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>0[0-7]*{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>[1-9][0-9]*{INT_SUFFIX} {return T_INTEGER;}
<INITIAL>## {return T_CONCAT;}
diff --git a/tests/preproc-if-expr.shader_test b/tests/preproc-if-expr.shader_test index 61c5a397d..823b9b0e3 100644 --- a/tests/preproc-if-expr.shader_test +++ b/tests/preproc-if-expr.shader_test @@ -99,6 +99,39 @@ pass pass #endif
+[preproc] +#if 2u == 2 +pass +#else +fail +#endif + +[preproc] +#if 2l == 2 +pass +#else +fail +#endif + +[preproc] +#if 2Ul == 2 +pass +#else +fail +#endif + +[preproc] +#if 2uL == 2 +pass +#else +fail +#endif + +[preproc] +#if 012lu == 10 +pass +#endif + [preproc] /* All math is done using unsigned 32-bit integers. */ #if 8 / -3 == 2
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 11/01/22 00:48, Zebediah Figura ha scritto:
Technically we shouldn't allow "uu" or "ll" either, but we also don't really handle preprocessor parsing errors the way we should.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/preproc.l | 7 ++++--- tests/preproc-if-expr.shader_test | 33 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index bf4d669f3..54542331b 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -57,6 +57,7 @@ static void update_location(struct preproc_ctx *ctx); NEWLINE \r?\n WS [ \t] IDENTIFIER [A-Za-z_][A-Za-z0-9_]* +INT_SUFFIX [uUlL]{0,2}
%%
@@ -92,9 +93,9 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* <INITIAL>[0-9]+.([eE][+-]?[0-9]+)?[hHfF]? {return T_TEXT;} <INITIAL>[0-9]+([eE][+-]?[0-9]+)?[hHfF] {return T_TEXT;} <INITIAL>[0-9]+[eE][+-]?[0-9]+ {return T_TEXT;} -<INITIAL,LINE>0[xX][0-9a-fA-f]+[ul]{0,2} {return T_INTEGER;} -<INITIAL,LINE>0[0-7]*[ul]{0,2} {return T_INTEGER;} -<INITIAL,LINE>[1-9][0-9]*[ul]{0,2} {return T_INTEGER;} +<INITIAL,LINE>0[xX][0-9a-fA-f]+{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>0[0-7]*{INT_SUFFIX} {return T_INTEGER;} +<INITIAL,LINE>[1-9][0-9]*{INT_SUFFIX} {return T_INTEGER;}
<INITIAL>## {return T_CONCAT;}
diff --git a/tests/preproc-if-expr.shader_test b/tests/preproc-if-expr.shader_test index 61c5a397d..823b9b0e3 100644 --- a/tests/preproc-if-expr.shader_test +++ b/tests/preproc-if-expr.shader_test @@ -99,6 +99,39 @@ pass pass #endif
+[preproc] +#if 2u == 2 +pass +#else +fail +#endif
+[preproc] +#if 2l == 2 +pass +#else +fail +#endif
+[preproc] +#if 2Ul == 2 +pass +#else +fail +#endif
+[preproc] +#if 2uL == 2 +pass +#else +fail +#endif
+[preproc] +#if 012lu == 10 +pass +#endif
- [preproc] /* All math is done using unsigned 32-bit integers. */ #if 8 / -3 == 2
Hi,
just a couple of curiosities:
Il 11/01/22 00:48, Zebediah Figura ha scritto:
+[preproc] +#if 2uL == 2 +pass +#else +fail +#endif
What's the point of the "fail" branch? If the shader doesn't produce "pass" it's already considered failing, isn't it?
+[preproc] +#if 012lu == 10 +pass +#endif
And why doesn't this have the "fail" branch?
Giovanni.
On 1/13/22 08:21, Giovanni Mascellani wrote:
Hi,
just a couple of curiosities:
Il 11/01/22 00:48, Zebediah Figura ha scritto:
+[preproc] +#if 2uL == 2 +pass +#else +fail +#endif
What's the point of the "fail" branch? If the shader doesn't produce "pass" it's already considered failing, isn't it?
The native preprocessor has the excellent behaviour of emitting an error when unable to parse an if condition and then outputting both branches without actually failing compilation. Which is to say that it emits a warning, only it uses the word "error".
We don't replicate this behaviour (yet).
Writing the test in this form validates both that native can actually parse the condition and that it's true.
+[preproc] +#if 012lu == 10 +pass +#endif
And why doesn't this have the "fail" branch?
Mostly because I was less worried about the idea that native couldn't parse the token when I wrote it.