Make error, warning and notice give compiler file/line too.

But only when verbosity > 1 (-vv).
This commit is contained in:
Bill Currie 2018-10-13 09:31:00 +09:00
parent 4828934e50
commit 2f2edae43b
3 changed files with 38 additions and 18 deletions

View file

@ -44,21 +44,31 @@ extern diagnostic_hook error_hook;
extern diagnostic_hook warning_hook;
extern diagnostic_hook notice_hook;
struct expr_s *error (struct expr_s *e, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
void
_internal_error (struct expr_s *e, const char *file, int line,
const char *fmt, ...)
struct expr_s *_error (struct expr_s *e, const char *file, int line,
const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
#define error(e, fmt...) _error(e, __FILE__, __LINE__, fmt)
void _internal_error (struct expr_s *e, const char *file, int line,
const char *fmt, ...)
__attribute__ ((format (printf, 4, 5), noreturn));
#define internal_error(e, fmt...) _internal_error(e, __FILE__, __LINE__, fmt)
struct expr_s *warning (struct expr_s *e, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
struct expr_s *notice (struct expr_s *e, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
struct expr_s *_warning (struct expr_s *e, const char *file, int line,
const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
#define warning(e, fmt...) _warning(e, __FILE__, __LINE__, fmt)
struct expr_s *_notice (struct expr_s *e, const char *file, int line,
const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
#define notice(e, fmt...) _notice(e, __FILE__, __LINE__, fmt)
void _debug (struct expr_s *e, const char *file, int line,
const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
#define debug(e, fmt...) _debug(e, __FILE__, __LINE__, fmt)
void _bug (struct expr_s *e, const char *file, int line, const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
#define bug(e, fmt...) _bug(e, __FILE__, __LINE__, fmt)

View file

@ -95,8 +95,9 @@ format_message (dstring_t *message, const char *msg_type, expr_t *e,
}
}
static __attribute__((format(printf, 2, 0))) void
_warning (expr_t *e, const char *fmt, va_list args)
static __attribute__((format(printf, 4, 0))) void
__warning (expr_t *e, const char *file, int line,
const char *fmt, va_list args)
{
dstring_t *message = dstring_new ();
@ -108,6 +109,9 @@ _warning (expr_t *e, const char *fmt, va_list args)
}
format_message (message, "warning", e, fmt, args);
if (options.verbosity > 1) {
dasprintf (message, " (%s:%d)", file, line);
}
if (warning_hook) {
warning_hook (message->str);
} else {
@ -161,7 +165,7 @@ _bug (expr_t *e, const char *file, int line, const char *fmt, ...)
}
expr_t *
notice (expr_t *e, const char *fmt, ...)
_notice (expr_t *e, const char *file, int line, const char *fmt, ...)
{
va_list args;
@ -170,13 +174,16 @@ notice (expr_t *e, const char *fmt, ...)
va_start (args, fmt);
if (options.notices.promote) {
_warning (e, fmt, args);
__warning (e, file, line, fmt, args);
} else {
dstring_t *message = dstring_new ();
report_function (e);
format_message (message, "notice", e, fmt, args);
if (options.verbosity > 1) {
dasprintf (message, " (%s:%d)", file, line);
}
if (notice_hook) {
notice_hook (message->str);
} else {
@ -189,12 +196,12 @@ notice (expr_t *e, const char *fmt, ...)
}
expr_t *
warning (expr_t *e, const char *fmt, ...)
_warning (expr_t *e, const char *file, int line, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
_warning (e, fmt, args);
__warning (e, file, line, fmt, args);
va_end (args);
return e;
}
@ -220,7 +227,7 @@ _internal_error (expr_t *e, const char *file, int line, const char *fmt, ...)
}
expr_t *
error (expr_t *e, const char *fmt, ...)
_error (expr_t *e, const char *file, int line, const char *fmt, ...)
{
va_list args;
@ -233,6 +240,9 @@ error (expr_t *e, const char *fmt, ...)
dstring_t *message = dstring_new ();
format_message (message, "error", e, fmt, args);
if (options.verbosity > 1) {
dasprintf (message, " (%s:%d)", file, line);
}
if (error_hook) {
error_hook (message->str);
} else {

View file

@ -29,5 +29,5 @@ __attribute__((const)) codespace_t *codespace_new (void) {return 0;}
void codespace_addcode (codespace_t *codespace, struct dstatement_s *code, int size) {}
__attribute__((const)) int function_parms (function_t *f, byte *parm_size) {return 0;}
void def_to_ddef (def_t *def, ddef_t *ddef, int aux) {}
__attribute__((const)) expr_t *warning (expr_t *e, const char *fmt, ...) {return 0;}
__attribute__((const)) expr_t *error (expr_t *e, const char *fmt, ...) {return 0;}
__attribute__((const)) expr_t *_warning (expr_t *e, const char *file, int line, const char *fmt, ...) {return 0;}
__attribute__((const)) expr_t *_error (expr_t *e, const char *file, int line, const char *fmt, ...) {return 0;}