@@ -63,11 +63,19 @@ extern void erec_print_list(FILE *f, struct list_head *list);
struct eval_ctx;
-extern int __fmtstring(4, 5) __stmt_binary_error(struct eval_ctx *ctx,
- const struct location *l1,
- const struct location *l2,
- const char *fmt, ...);
+extern int __fmtstring(5, 6) __stmt_binary_msg(enum error_record_types type,
+ struct eval_ctx *ctx,
+ const struct location *l1,
+ const struct location *l2,
+ const char *fmt, ...);
+#define __stmt_binary_warning(ctx, l1, l2, fmt, args...) \
+ __stmt_binary_msg(EREC_WARNING, ctx, l1, l2, fmt, ## args)
+#define stmt_warning(ctx, s1, fmt, args...) \
+ __stmt_binary_warning(ctx, &(s1)->location, NULL, fmt, ## args)
+
+#define __stmt_binary_error(ctx, l1, l2, fmt, args...) \
+ __stmt_binary_msg(EREC_ERROR, ctx, l1, l2, fmt, ## args)
#define stmt_error(ctx, s1, fmt, args...) \
__stmt_binary_error(ctx, &(s1)->location, NULL, fmt, ## args)
#define stmt_binary_error(ctx, s1, s2, fmt, args...) \
@@ -208,19 +208,20 @@ void erec_print_list(FILE *f, struct list_head *list)
}
}
-int __fmtstring(4, 5) __stmt_binary_error(struct eval_ctx *ctx,
- const struct location *l1,
- const struct location *l2,
- const char *fmt, ...)
+int __fmtstring(5, 6) __stmt_binary_msg(enum error_record_types type,
+ struct eval_ctx *ctx,
+ const struct location *l1,
+ const struct location *l2,
+ const char *fmt, ...)
{
struct error_record *erec;
va_list ap;
va_start(ap, fmt);
- erec = erec_vcreate(EREC_ERROR, l1, fmt, ap);
+ erec = erec_vcreate(type, l1, fmt, ap);
if (l2 != NULL)
erec_add_location(erec, l2);
va_end(ap);
erec_queue(erec, ctx->msgs);
- return -1;
+ return type >= EREC_ERROR ? -1 : 0;
}
In order to allow for printing (at least) also warnings, rename __stmt_binary_error to __stmt_binary_msg and pass the severity as first parameter. Then create __stmt_binary_error macro to reestablish the old signature. Finally, add similar macros for printing warnings. And since these are supposed to be non-fatal, make __stmt_binary_msg return 0 if a severity below EREC_ERROR was given. This allows to still use it in return statements. Signed-off-by: Phil Sutter <phil@nwl.cc> --- include/erec.h | 16 ++++++++++++---- src/erec.c | 13 +++++++------ 2 files changed, 19 insertions(+), 10 deletions(-)