mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader: Handle preprocessor parsing errors.
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
cdfca2fab7
commit
5304cabf46
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user