From e15b884e1a9f149ee0c07abdb83f0d287d4bd5af Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 21 Jan 2021 16:10:46 -0600 Subject: [PATCH] vkd3d-shader: Implement the ternary operator 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 | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 37acc5e0..1bf14ff4 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 051f94bc..aa381e8a 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -351,6 +351,7 @@ static void free_parse_arg_names(struct parse_arg_names *args) %type bitor_expr %type logicand_expr %type logicor_expr +%type expr %type body_token %type body_token_const %type body_text @@ -483,6 +484,14 @@ body_token_const { $$ = "^"; } + | '?' + { + $$ = "?"; + } + | ':' + { + $$ = ":"; + } | T_CONCAT { $$ = "##"; @@ -548,7 +557,7 @@ directive } vkd3d_free($2); } - | T_IF logicor_expr T_NEWLINE + | T_IF expr T_NEWLINE { if (!preproc_push_if(ctx, !!$2)) YYABORT; @@ -563,7 +572,7 @@ directive preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); vkd3d_free($2); } - | T_ELIF logicor_expr T_NEWLINE + | T_ELIF expr T_NEWLINE { const struct preproc_file *file = preproc_get_top_file(ctx); @@ -791,3 +800,10 @@ logicor_expr { $$ = $1 || $3; } + +expr + : logicor_expr + | expr '?' logicor_expr ':' logicor_expr + { + $$ = $1 ? $3 : $5; + }