vkd3d-shader: Implement logical operators in #if directives.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-01-21 16:10:45 -06:00 committed by Alexandre Julliard
parent c1d2edc9d5
commit 338399d563
2 changed files with 30 additions and 4 deletions

View File

@ -82,6 +82,8 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]*
<INITIAL>">=" {return T_GE;} <INITIAL>">=" {return T_GE;}
<INITIAL>"==" {return T_EQ;} <INITIAL>"==" {return T_EQ;}
<INITIAL>"!=" {return T_NE;} <INITIAL>"!=" {return T_NE;}
<INITIAL>"&&" {return T_AND;}
<INITIAL>"||" {return T_OR;}
/* We have no use for floats, but shouldn't parse them as integers. */ /* We have no use for floats, but shouldn't parse them as integers. */
@ -95,8 +97,6 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]*
<INITIAL>## {return T_CONCAT;} <INITIAL>## {return T_CONCAT;}
<INITIAL>"&&" {return T_TEXT;}
<INITIAL>"||" {return T_TEXT;}
<INITIAL>"++" {return T_TEXT;} <INITIAL>"++" {return T_TEXT;}
<INITIAL>"--" {return T_TEXT;} <INITIAL>"--" {return T_TEXT;}
<INITIAL>"<<"=? {return T_TEXT;} <INITIAL>"<<"=? {return T_TEXT;}

View File

@ -336,6 +336,8 @@ static void free_parse_arg_names(struct parse_arg_names *args)
%token T_GE ">=" %token T_GE ">="
%token T_EQ "==" %token T_EQ "=="
%token T_NE "!=" %token T_NE "!="
%token T_AND "&&"
%token T_OR "||"
%token T_DEFINED "defined" %token T_DEFINED "defined"
%type <integer> primary_expr %type <integer> primary_expr
@ -347,6 +349,8 @@ static void free_parse_arg_names(struct parse_arg_names *args)
%type <integer> bitand_expr %type <integer> bitand_expr
%type <integer> bitxor_expr %type <integer> bitxor_expr
%type <integer> bitor_expr %type <integer> bitor_expr
%type <integer> logicand_expr
%type <integer> logicor_expr
%type <string> body_token %type <string> body_token
%type <const_string> body_token_const %type <const_string> body_token_const
%type <string_buffer> body_text %type <string_buffer> body_text
@ -499,6 +503,14 @@ body_token_const
{ {
$$ = "!="; $$ = "!=";
} }
| T_AND
{
$$ = "&&";
}
| T_OR
{
$$ = "||";
}
| T_DEFINED | T_DEFINED
{ {
$$ = "defined"; $$ = "defined";
@ -536,7 +548,7 @@ directive
} }
vkd3d_free($2); vkd3d_free($2);
} }
| T_IF bitor_expr T_NEWLINE | T_IF logicor_expr T_NEWLINE
{ {
if (!preproc_push_if(ctx, !!$2)) if (!preproc_push_if(ctx, !!$2))
YYABORT; YYABORT;
@ -551,7 +563,7 @@ directive
preproc_push_if(ctx, !preproc_find_macro(ctx, $2)); preproc_push_if(ctx, !preproc_find_macro(ctx, $2));
vkd3d_free($2); vkd3d_free($2);
} }
| T_ELIF bitor_expr T_NEWLINE | T_ELIF logicor_expr T_NEWLINE
{ {
const struct preproc_file *file = preproc_get_top_file(ctx); const struct preproc_file *file = preproc_get_top_file(ctx);
@ -765,3 +777,17 @@ bitor_expr
{ {
$$ = $1 | $3; $$ = $1 | $3;
} }
logicand_expr
: bitor_expr
| logicand_expr T_AND bitor_expr
{
$$ = $1 && $3;
}
logicor_expr
: logicand_expr
| logicor_expr T_OR logicand_expr
{
$$ = $1 || $3;
}