Zebediah Figura : vkd3d-shader: Implement #elif.

Alexandre Julliard julliard at winehq.org
Mon Jan 4 15:15:53 CST 2021


Module: vkd3d
Branch: master
Commit: 6b75fb7b9c56428dd7365ee6c824c0baeb82bbd5
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=6b75fb7b9c56428dd7365ee6c824c0baeb82bbd5

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Tue Dec 15 17:13:23 2020 -0600

vkd3d-shader: Implement #elif.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 Makefile.am                 |  1 -
 libs/vkd3d-shader/preproc.l |  3 +++
 libs/vkd3d-shader/preproc.y | 23 +++++++++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index bf1d7bf..514f050 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -243,7 +243,6 @@ XFAIL_TESTS = \
 	tests/hlsl-vector-indexing.shader_test \
 	tests/hlsl-vector-indexing-uniform.shader_test \
 	tests/math.shader_test \
-	tests/preproc-if.shader_test \
 	tests/preproc-ifdef.shader_test \
 	tests/preproc-if-expr.shader_test \
 	tests/preproc-invalid.shader_test \
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l
index 33860d3..47ad1f1 100644
--- a/libs/vkd3d-shader/preproc.l
+++ b/libs/vkd3d-shader/preproc.l
@@ -100,6 +100,8 @@ IDENTIFIER      [A-Za-z_][A-Za-z0-9_]*
         for (p = yytext + 1; strchr(" \t", *p); ++p)
             ;
 
+        if (!strcmp(p, "elif"))
+            return T_ELIF;
         if (!strcmp(p, "else"))
             return T_ELSE;
         if (!strcmp(p, "endif"))
@@ -189,6 +191,7 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
         {
             switch (token)
             {
+                case T_ELIF:
                 case T_ELSE:
                 case T_ENDIF:
                 case T_IF:
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y
index fc50860..647bb45 100644
--- a/libs/vkd3d-shader/preproc.y
+++ b/libs/vkd3d-shader/preproc.y
@@ -140,6 +140,7 @@ static uint32_t preproc_parse_integer(const char *s)
 
 %token T_NEWLINE
 
+%token T_ELIF "#elif"
 %token T_ELSE "#else"
 %token T_ENDIF "#endif"
 %token T_IF "#if"
@@ -161,6 +162,28 @@ directive
             if (!preproc_push_if(ctx, !!$2))
                 YYABORT;
         }
+    | T_ELIF expr T_NEWLINE
+        {
+            if (ctx->if_count)
+            {
+                struct preproc_if_state *state = &ctx->if_stack[ctx->if_count - 1];
+
+                if (state->seen_else)
+                {
+                    preproc_warning(ctx, &@$, VKD3D_SHADER_WARNING_PP_INVALID_DIRECTIVE, "Ignoring #elif after #else.");
+                }
+                else
+                {
+                    state->current_true = $2 && !state->seen_true && preproc_was_writing(ctx);
+                    state->seen_true = $2 || state->seen_true;
+                }
+            }
+            else
+            {
+                preproc_warning(ctx, &@$, VKD3D_SHADER_WARNING_PP_INVALID_DIRECTIVE,
+                        "Ignoring #elif without prior #if.");
+            }
+        }
     | T_ELSE T_NEWLINE
         {
             if (ctx->if_count)




More information about the wine-cvs mailing list