Zebediah Figura : vkd3d-shader: Handle preprocessor parsing errors.
Alexandre Julliard
julliard at winehq.org
Mon Jan 4 15:15:53 CST 2021
Module: vkd3d
Branch: master
Commit: 5304cabf462ec0454fa75d225473fd6f511661e5
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=5304cabf462ec0454fa75d225473fd6f511661e5
Author: Zebediah Figura <zfigura at codeweavers.com>
Date: Tue Dec 15 17:13:20 2020 -0600
vkd3d-shader: Handle preprocessor parsing errors.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
libs/vkd3d-shader/preproc.h | 4 ++++
libs/vkd3d-shader/preproc.l | 38 +++++++++++++++++++++++++++++++-
libs/vkd3d-shader/preproc.y | 17 +++++++++++++-
libs/vkd3d-shader/vkd3d_shader_private.h | 2 ++
4 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/preproc.h b/libs/vkd3d-shader/preproc.h
index cbd9322..bd9dfdd 100644
--- a/libs/vkd3d-shader/preproc.h
+++ b/libs/vkd3d-shader/preproc.h
@@ -27,7 +27,11 @@ struct preproc_ctx
{
void *scanner;
+ struct vkd3d_shader_message_context *message_context;
struct vkd3d_string_buffer buffer;
+ struct vkd3d_shader_location location;
+
+ bool error;
};
#endif
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l
index 4d809b8..b406af0 100644
--- a/libs/vkd3d-shader/preproc.l
+++ b/libs/vkd3d-shader/preproc.l
@@ -27,6 +27,10 @@
#define YY_DECL static int preproc_lexer_lex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param, yyscan_t yyscanner)
+static void update_location(struct preproc_ctx *ctx);
+
+#define YY_USER_ACTION update_location(yyget_extra(yyscanner));
+
%}
%option 8bit
@@ -88,6 +92,27 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]*
%%
+static void update_location(struct preproc_ctx *ctx)
+{
+ unsigned int i, leng = yyget_leng(ctx->scanner);
+ const char *text = yyget_text(ctx->scanner);
+
+ /* We want to do this here, rather than before calling yylex(), because
+ * some tokens are skipped by the lexer. */
+
+ *yyget_lloc(ctx->scanner) = ctx->location;
+
+ for (i = 0; i < leng; ++i)
+ {
+ ++ctx->location.column;
+ if (text[i] == '\n')
+ {
+ ctx->location.column = 1;
+ ++ctx->location.line;
+ }
+ }
+}
+
int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
{
struct preproc_ctx *ctx = yyget_extra(scanner);
@@ -101,7 +126,7 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
return 0;
text = yyget_text(scanner);
- TRACE("Parsing token %d, string %s.\n", token, debugstr_a(text));
+ TRACE("Parsing token %d, line %d, string %s.\n", token, lloc->line, debugstr_a(text));
vkd3d_string_buffer_printf(&ctx->buffer, "%s ", text);
}
@@ -115,6 +140,10 @@ int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
void *output_code;
vkd3d_string_buffer_init(&ctx.buffer);
+ ctx.message_context = message_context;
+ ctx.location.source_name = compile_info->source_name;
+ ctx.location.line = 1;
+ ctx.location.column = 1;
yylex_init_extra(&ctx, &ctx.scanner);
top_buffer = yy_scan_bytes(compile_info->source.code, compile_info->source.size, ctx.scanner);
@@ -124,6 +153,13 @@ int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
yy_delete_buffer(top_buffer, ctx.scanner);
yylex_destroy(ctx.scanner);
+ if (ctx.error)
+ {
+ WARN("Failed to preprocess.\n");
+ vkd3d_string_buffer_cleanup(&ctx.buffer);
+ return VKD3D_ERROR_INVALID_SHADER;
+ }
+
if (!(output_code = vkd3d_malloc(ctx.buffer.content_size)))
{
vkd3d_string_buffer_cleanup(&ctx.buffer);
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y
index 92448f2..16b84ea 100644
--- a/libs/vkd3d-shader/preproc.y
+++ b/libs/vkd3d-shader/preproc.y
@@ -24,6 +24,8 @@
#include "vkd3d_shader_private.h"
#include "preproc.h"
+#define PREPROC_YYLTYPE struct vkd3d_shader_location
+
}
%code provides
@@ -36,9 +38,22 @@ int preproc_yylex(PREPROC_YYSTYPE *yylval_param, PREPROC_YYLTYPE *yylloc_param,
%code
{
+#define YYLLOC_DEFAULT(cur, rhs, n) (cur) = YYRHSLOC(rhs, !!n)
+
+static void preproc_error(struct preproc_ctx *ctx, const struct vkd3d_shader_location *loc,
+ enum vkd3d_shader_error error, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ vkd3d_shader_verror(ctx->message_context, loc, error, format, args);
+ va_end(args);
+ ctx->error = true;
+}
+
static void yyerror(const YYLTYPE *loc, void *scanner, struct preproc_ctx *ctx, const char *string)
{
- FIXME("Error reporting is not implemented.\n");
+ preproc_error(ctx, loc, VKD3D_SHADER_ERROR_PP_INVALID_SYNTAX, "%s", string);
}
}
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h
index e974b92..882a806 100644
--- a/libs/vkd3d-shader/vkd3d_shader_private.h
+++ b/libs/vkd3d-shader/vkd3d_shader_private.h
@@ -79,6 +79,8 @@ enum vkd3d_shader_error
VKD3D_SHADER_ERROR_RS_INVALID_ROOT_PARAMETER_TYPE = 3002,
VKD3D_SHADER_ERROR_RS_INVALID_DESCRIPTOR_RANGE_TYPE = 3003,
VKD3D_SHADER_ERROR_RS_MIXED_DESCRIPTOR_RANGE_TYPES = 3004,
+
+ VKD3D_SHADER_ERROR_PP_INVALID_SYNTAX = 4000,
};
enum VKD3D_SHADER_INSTRUCTION_HANDLER
More information about the wine-cvs
mailing list