mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
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:
parent
1a326d16c6
commit
d31f288111
@ -125,6 +125,7 @@ struct preproc_ctx
|
||||
|
||||
bool last_was_newline;
|
||||
bool last_was_eof;
|
||||
bool last_was_defined;
|
||||
|
||||
bool error;
|
||||
};
|
||||
|
@ -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. */
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user