From 1f585180597290c7891c43dc0da3c9c06d7cebb1 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 11 Mar 2010 14:08:33 -0800 Subject: [PATCH] Track generation of errors and halt compilation appropriately --- glsl_parser_extras.cpp | 17 ++++++++++++----- glsl_parser_extras.h | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/glsl_parser_extras.cpp b/glsl_parser_extras.cpp index d066ca3cd08..52ae79918a2 100644 --- a/glsl_parser_extras.cpp +++ b/glsl_parser_extras.cpp @@ -38,13 +38,16 @@ #include "ir_print_visitor.h" void -_mesa_glsl_error(YYLTYPE *locp, void *state, const char *fmt, ...) +_mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, + const char *fmt, ...) { char buf[1024]; int len; va_list ap; - (void) state; + if (state) + state->error = true; + len = snprintf(buf, sizeof(buf), "%u:%u(%u): error: ", locp->source, locp->first_line, locp->first_column); @@ -709,6 +712,7 @@ main(int argc, char **argv) state.scanner = NULL; make_empty_list(& state.translation_unit); state.symbols = _mesa_symbol_table_ctor(); + state.error = false; _mesa_glsl_lexer_ctor(& state, shader, shader_len); _mesa_glsl_parse(& state); @@ -721,10 +725,13 @@ main(int argc, char **argv) _mesa_ast_to_hir(&instructions, &state); printf("\n\n"); - foreach_iter(exec_list_iterator, iter, instructions) { - ir_print_visitor v; - ((ir_instruction *)iter.get())->accept(& v); + if (!state.error) { + foreach_iter(exec_list_iterator, iter, instructions) { + ir_print_visitor v; + + ((ir_instruction *)iter.get())->accept(& v); + } } _mesa_symbol_table_dtor(state.symbols); diff --git a/glsl_parser_extras.h b/glsl_parser_extras.h index 1c972623c20..c7cd68c181c 100644 --- a/glsl_parser_extras.h +++ b/glsl_parser_extras.h @@ -41,6 +41,9 @@ struct _mesa_glsl_parse_state { unsigned language_version; enum _mesa_glsl_parser_targets target; + + /** Was there an error during compilation? */ + bool error; }; typedef struct YYLTYPE { @@ -53,7 +56,8 @@ typedef struct YYLTYPE { # define YYLTYPE_IS_DECLARED 1 # define YYLTYPE_IS_TRIVIAL 1 -extern void _mesa_glsl_error(YYLTYPE *locp, void *state, const char *fmt, ...); +extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, + const char *fmt, ...); extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string, size_t len); -- 2.30.2