From 79f22ffebfb6c698624100b4383fab8ef285e454 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 21 Dec 2020 20:15:43 +0900 Subject: [PATCH] [util] Propagate cexpr errors back to the caller Not much point in error detection when it's ignored. --- include/QF/cexpr.h | 1 + libs/util/cexpr-lex.l | 7 +++++-- libs/util/cexpr-vars.c | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/QF/cexpr.h b/include/QF/cexpr.h index fcdeaad57..7524dec0c 100644 --- a/include/QF/cexpr.h +++ b/include/QF/cexpr.h @@ -82,6 +82,7 @@ typedef struct exprctx_s { const struct plitem_s *item; struct plitem_s *messages; struct hashlink_s *hashlinks; + int errors; } exprctx_t; typedef struct exprenum_s { diff --git a/libs/util/cexpr-lex.l b/libs/util/cexpr-lex.l index cfb1b99c6..cdae1ee04 100644 --- a/libs/util/cexpr-lex.l +++ b/libs/util/cexpr-lex.l @@ -82,6 +82,8 @@ cexpr_error(exprctx_t *ctx, const char *fmt, ...) va_list args; dstring_t *string; + ctx->errors++; + string = dstring_new (); va_start (args, fmt); @@ -211,6 +213,7 @@ cexpr_eval_string (const char *str, exprctx_t *context) yylex_init_extra (context, &scanner); yy_scan_string (str, scanner); + context->errors = 0; do { CEXPR_YYSTYPE lval; int token = yylex (&lval, scanner); @@ -219,7 +222,7 @@ cexpr_eval_string (const char *str, exprctx_t *context) yylex_destroy (scanner); cexpr_yypstate_delete (ps); - return status; + return status || context->errors; } static exprval_t *parse_int (const char *str, exprctx_t *context) @@ -271,7 +274,7 @@ parse_variable (const char *name, exprctx_t *context) if (sym) { val = cexpr_value_reference (sym->type, sym->value, context); } else { - val = cexpr_cvar (name, context); + //val = cexpr_cvar (name, context); } } if (!val) { diff --git a/libs/util/cexpr-vars.c b/libs/util/cexpr-vars.c index 9f01e3134..6ec8ce3d9 100644 --- a/libs/util/cexpr-vars.c +++ b/libs/util/cexpr-vars.c @@ -34,7 +34,6 @@ #include "QF/cmem.h" #include "QF/cvar.h" #include "QF/hash.h" -#include "QF/qfplist.h" #include "libs/util/cexpr-parse.h" @@ -65,7 +64,7 @@ cvar_get (const exprval_t *a, const exprval_t *b, exprval_t *c, exprctx_t *ctx) __auto_type name = (const char *) b->value; exprval_t *var = cexpr_cvar (name, ctx); if (!var) { - PL_Message (ctx->messages, ctx->item, "unknown cvar %s", name); + cexpr_error (ctx, "unknown cvar %s", name); } *(exprval_t **) c->value = var; }