vkd3d-shader: Implement the "defined" keyword.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-01-14 14:47:51 -06:00 committed by Alexandre Julliard
parent 1a326d16c6
commit d31f288111
3 changed files with 32 additions and 0 deletions

View File

@ -125,6 +125,7 @@ struct preproc_ctx
bool last_was_newline;
bool last_was_eof;
bool last_was_defined;
bool error;
};

View File

@ -73,6 +73,8 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]*
<ERROR>(\\{NEWLINE}|[^\n])* {return T_STRING;}
<INITIAL>defined/\( {return T_DEFINED;}
<INITIAL>defined {return T_DEFINED;}
<INITIAL>{IDENTIFIER}/\( {return T_IDENTIFIER_PAREN;}
<INITIAL>{IDENTIFIER} {return T_IDENTIFIER;}
@ -377,6 +379,9 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
ctx->last_was_newline = (token == T_NEWLINE);
}
if (ctx->current_directive && token == T_DEFINED)
ctx->last_was_defined = true;
func_state = ctx->current_directive ? &ctx->directive_func : &ctx->text_func;
TRACE("Parsing token %d%s, line %d, in directive %d, state %#x, string %s.\n",
@ -471,6 +476,17 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
case T_UNDEF:
/* Return identifiers verbatim. */
return return_token(token, lval, text);
case T_IF:
case T_ELIF:
/* Return identifiers verbatim only if they're the
* argument to "defined". */
if (ctx->last_was_defined)
{
ctx->last_was_defined = false;
return return_token(token, lval, text);
}
break;
}
/* Otherwise, expand a macro if there is one. */

View File

@ -331,6 +331,7 @@ static void free_parse_arg_names(struct parse_arg_names *args)
%token T_UNDEF "#undef"
%token T_CONCAT "##"
%token T_DEFINED "defined"
%type <integer> expr
%type <string> body_token
@ -429,6 +430,10 @@ body_token_const
{
$$ = "##";
}
| T_DEFINED
{
$$ = "defined";
}
directive
: T_DEFINE T_IDENTIFIER body_text T_NEWLINE
@ -583,3 +588,13 @@ expr
$$ = preproc_parse_integer($1);
vkd3d_free($1);
}
| T_DEFINED T_IDENTIFIER
{
$$ = !!preproc_find_macro(ctx, $2);
vkd3d_free($2);
}
| T_DEFINED '(' T_IDENTIFIER ')'
{
$$ = !!preproc_find_macro(ctx, $3);
vkd3d_free($3);
}