From c1d2edc9d57d8c584b90b487f9f301bdf3b55b15 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 21 Jan 2021 16:10:44 -0600 Subject: [PATCH] vkd3d-shader: Implement bitwise operators in #if directives. Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/preproc.l | 2 +- libs/vkd3d-shader/preproc.y | 40 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index d21ddd1f..4c82babf 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -162,7 +162,7 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* } {WS}+ {} -[-()\[\]{},+!*/<>] {return yytext[0];} +[-()\[\]{},+!*/<>&|^] {return yytext[0];} . {return T_TEXT;} %% diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 089fd760..fa5e5ccc 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -344,6 +344,9 @@ static void free_parse_arg_names(struct parse_arg_names *args) %type add_expr %type ineq_expr %type eq_expr +%type bitand_expr +%type bitxor_expr +%type bitor_expr %type body_token %type body_token_const %type body_text @@ -464,6 +467,18 @@ body_token_const { $$ = ">"; } + | '&' + { + $$ = "&"; + } + | '|' + { + $$ = "|"; + } + | '^' + { + $$ = "^"; + } | T_CONCAT { $$ = "##"; @@ -521,7 +536,7 @@ directive } vkd3d_free($2); } - | T_IF eq_expr T_NEWLINE + | T_IF bitor_expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT; @@ -536,7 +551,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); } - | T_ELIF eq_expr T_NEWLINE + | T_ELIF bitor_expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx); @@ -729,3 +744,24 @@ eq_expr { $$ = $1 != $3; } + +bitand_expr + : eq_expr + | bitand_expr '&' eq_expr + { + $$ = $1 & $3; + } + +bitxor_expr + : bitand_expr + | bitxor_expr '^' bitand_expr + { + $$ = $1 ^ $3; + } + +bitor_expr + : bitxor_expr + | bitor_expr '|' bitxor_expr + { + $$ = $1 | $3; + }