[PATCH vkd3d v2 2/5] vkd3d-shader: Implement #ifdef.

Zebediah Figura zfigura at codeweavers.com
Thu Jan 7 11:48:07 CST 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 libs/vkd3d-shader/preproc.l | 4 ++++
 libs/vkd3d-shader/preproc.y | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l
index 89c205f1..12a2e9d2 100644
--- a/libs/vkd3d-shader/preproc.l
+++ b/libs/vkd3d-shader/preproc.l
@@ -110,6 +110,8 @@ IDENTIFIER      [A-Za-z_][A-Za-z0-9_]*
             return T_ENDIF;
         if (!strcmp(p, "if"))
             return T_IF;
+        if (!strcmp(p, "ifdef"))
+            return T_IFDEF;
 
         preproc_warning(ctx, yyget_lloc(yyscanner), VKD3D_SHADER_WARNING_PP_UNKNOWN_DIRECTIVE,
                 "Ignoring unknown directive \"%s\".", yytext);
@@ -199,6 +201,7 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
                 case T_ELSE:
                 case T_ENDIF:
                 case T_IF:
+                case T_IFDEF:
                     ctx->current_directive = token;
                     break;
 
@@ -218,6 +221,7 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
             case T_ELSE:
             case T_ENDIF:
             case T_IF:
+            case T_IFDEF:
                 break;
 
             default:
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y
index 45cad443..c16f230f 100644
--- a/libs/vkd3d-shader/preproc.y
+++ b/libs/vkd3d-shader/preproc.y
@@ -183,6 +183,7 @@ static uint32_t preproc_parse_integer(const char *s)
 %token T_ELSE "#else"
 %token T_ENDIF "#endif"
 %token T_IF "#if"
+%token T_IFDEF "#ifdef"
 
 %type <integer> expr
 %type <string> body_token
@@ -219,6 +220,11 @@ directive
             if (!preproc_push_if(ctx, !!$2))
                 YYABORT;
         }
+    | T_IFDEF T_IDENTIFIER T_NEWLINE
+        {
+            preproc_push_if(ctx, !!preproc_find_macro(ctx, $2));
+            vkd3d_free($2);
+        }
     | T_ELIF expr T_NEWLINE
         {
             if (ctx->if_count)
-- 
2.30.0




More information about the wine-devel mailing list