vkd3d-shader/preproc: Stringify text immediately in macro invocations.

This commit is contained in:
Zebediah Figura 2023-07-29 18:15:14 -05:00 committed by Alexandre Julliard
parent cbb1d84069
commit 6fc3ae2b5c
Notes: Alexandre Julliard 2023-08-02 21:24:27 +09:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/291
2 changed files with 36 additions and 0 deletions

View File

@ -664,6 +664,21 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
break;
}
/* Stringification is another special case. Unsurprisingly,
* we need to stringify if this is an argument. More
* surprisingly, we need to stringify even if it's not. */
case T_HASHSTRING:
{
struct vkd3d_string_buffer buffer;
vkd3d_string_buffer_init(&buffer);
preproc_stringify(ctx, &buffer, text);
if (current_arg)
preproc_text_add(current_arg, buffer.buffer);
vkd3d_string_buffer_cleanup(&buffer);
break;
}
case T_NEWLINE:
if (current_arg)
preproc_text_add(current_arg, " ");

View File

@ -236,6 +236,27 @@ static void test_preprocess(void)
"#",
},
{
"#define KEY2(x) x\n"
"#define KEY(a) KEY2(#a)\n"
"KEY(apple)",
"\"apple\"",
},
{
"#define KEY2(x) #x\n"
"#define KEY(a) KEY2(#a)\n"
"KEY(apple)",
"\"\\\"apple\\\"\"",
},
{
"#define KEY2(x) #x\n"
"#define KEY(a) KEY2(#x)\n"
"KEY(apple)",
"\"\\\"x\\\"\"",
},
/* #pragma is preserved. */
{