From e72c2461cd53c27ff4b66a56ee90ad9125d1298a Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 14 Jan 2021 14:47:47 -0600 Subject: [PATCH] vkd3d-shader: Implement __LINE__. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/preproc.l | 20 ++++++++++++++++++++ tests/hlsl_d3d12.c | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 388b77f6..c5c49251 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -471,6 +471,26 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner) } continue; } + + if (!strcmp(text, "__LINE__")) + { + const struct preproc_file *file = preproc_get_top_file(ctx); + + /* Not the current line number, but rather the line + * number before invoking any macros. */ + + if (ctx->current_directive) + { + char string[13]; + + sprintf(string, "%d", file->buffer.location.line); + return return_token(T_INTEGER, lval, string); + } + + if (preproc_is_writing(ctx)) + vkd3d_string_buffer_printf(&ctx->buffer, "%d ", file->buffer.location.line); + continue; + } } if (ctx->current_directive) diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c index 9d8d16d9..03169716 100644 --- a/tests/hlsl_d3d12.c +++ b/tests/hlsl_d3d12.c @@ -350,7 +350,7 @@ static void test_preprocess(void) for (i = 0; i < ARRAY_SIZE(tests); ++i) { vkd3d_test_set_context("Source \"%s\"", tests[i].source); - todo_if (i == 9 || (i >= 12 && i <= 14)) + todo_if (i == 9) check_preprocess(tests[i].source, NULL, NULL, tests[i].present, tests[i].absent); } vkd3d_test_set_context(NULL);