[qfcc] Include C function in diagnostic messages

It's kind of redundant with the line number, but it's helpful for seeing
the context at a glance.
This commit is contained in:
Bill Currie 2023-08-20 14:44:59 +09:00
parent b9fd7a46af
commit a64895b98f
4 changed files with 49 additions and 44 deletions

View file

@ -43,33 +43,34 @@ extern diagnostic_hook warning_hook;
extern diagnostic_hook notice_hook;
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)
const char *func, const char *fmt, ...)
__attribute__ ((format (PRINTF, 5, 6)));
#define error(e, fmt...) _error(e, __FILE__, __LINE__, __FUNCTION__, fmt)
void _internal_error (const 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)
const char *func, const char *fmt, ...)
__attribute__ ((format (PRINTF, 5, 6), noreturn));
#define internal_error(e, fmt...) _internal_error(e, __FILE__, __LINE__, __FUNCTION__, fmt)
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)
const char *func, const char *fmt, ...)
__attribute__ ((format (PRINTF, 5, 6)));
#define warning(e, fmt...) _warning(e, __FILE__, __LINE__, __FUNCTION__, 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)
const char *func, const char *fmt, ...)
__attribute__ ((format (PRINTF, 5, 6)));
#define notice(e, fmt...) _notice(e, __FILE__, __LINE__, __FUNCTION__, 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)
const char *func, const char *fmt, ...)
__attribute__ ((format (PRINTF, 5, 6)));
#define debug(e, fmt...) _debug(e, __FILE__, __LINE__, __FUNCTION__, 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)
void _bug (struct expr_s *e, const char *file, int line,
const char * func, const char *fmt, ...)
__attribute__ ((format (PRINTF, 5, 6)));
#define bug(e, fmt...) _bug(e, __FILE__, __LINE__, __FUNCTION__, fmt)
void print_srcline (int rep, const struct expr_s *e);

View file

@ -110,8 +110,8 @@ format_message (dstring_t *message, const char *msg_type, const expr_t *e,
}
}
static __attribute__((format(PRINTF, 4, 0))) void
__warning (expr_t *e, const char *file, int line,
static __attribute__((format(PRINTF, 5, 0))) void
__warning (expr_t *e, const char *file, int line, const char *func,
const char *fmt, va_list args)
{
static int promoted = 0;
@ -130,7 +130,7 @@ __warning (expr_t *e, const char *file, int line,
}
if (options.verbosity > 0) {
dasprintf (message, " (%s:%d)", file, line);
dasprintf (message, " (%s:%d in %s)", file, line, func);
}
if (warning_hook) {
warning_hook (message->str);
@ -141,7 +141,8 @@ __warning (expr_t *e, const char *file, int line,
}
void
_debug (expr_t *e, const char *file, int line, const char *fmt, ...)
_debug (expr_t *e, const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list args;
@ -154,30 +155,31 @@ _debug (expr_t *e, const char *file, int line, const char *fmt, ...)
dstring_t *message = dstring_new ();
format_message (message, "debug", e, fmt, args);
dasprintf (message, " (%s:%d)", file, line);
dasprintf (message, " (%s:%d in %s)", file, line, func);
fprintf (stderr, "%s\n", message->str);
dstring_delete (message);
}
va_end (args);
}
static __attribute__((noreturn, format(PRINTF, 4, 0))) void
static __attribute__((noreturn, format(PRINTF, 5, 0))) void
__internal_error (const expr_t *e, const char *file, int line,
const char *fmt, va_list args)
const char *func, const char *fmt, va_list args)
{
dstring_t *message = dstring_new ();
report_function (e);
format_message (message, "internal error", e, fmt, args);
dasprintf (message, " (%s:%d)", file, line);
dasprintf (message, " (%s:%d in %s)", file, line, func);
fprintf (stderr, "%s\n", message->str);
dstring_delete (message);
abort ();
}
void
_bug (expr_t *e, const char *file, int line, const char *fmt, ...)
_bug (expr_t *e, const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list args;
@ -186,7 +188,7 @@ _bug (expr_t *e, const char *file, int line, const char *fmt, ...)
va_start (args, fmt);
if (options.bug.promote) {
__internal_error (e, file, line, fmt, args);
__internal_error (e, file, line, func, fmt, args);
}
{
@ -195,7 +197,7 @@ _bug (expr_t *e, const char *file, int line, const char *fmt, ...)
report_function (e);
format_message (message, "BUG", e, fmt, args);
dasprintf (message, " (%s:%d)", file, line);
dasprintf (message, " (%s:%d in %s)", file, line, func);
if (bug_hook) {
bug_hook (message->str);
} else {
@ -207,7 +209,7 @@ _bug (expr_t *e, const char *file, int line, const char *fmt, ...)
}
expr_t *
_notice (expr_t *e, const char *file, int line, const char *fmt, ...)
_notice (expr_t *e, const char *file, int line, const char *func, const char *fmt, ...)
{
va_list args;
@ -216,7 +218,7 @@ _notice (expr_t *e, const char *file, int line, const char *fmt, ...)
va_start (args, fmt);
if (options.notices.promote) {
__warning (e, file, line, fmt, args);
__warning (e, file, line, func, fmt, args);
} else {
dstring_t *message = dstring_new ();
@ -224,7 +226,7 @@ _notice (expr_t *e, const char *file, int line, const char *fmt, ...)
format_message (message, "notice", e, fmt, args);
if (options.verbosity > 0) {
dasprintf (message, " (%s:%d)", file, line);
dasprintf (message, " (%s:%d in %s)", file, line, func);
}
if (notice_hook) {
notice_hook (message->str);
@ -238,29 +240,31 @@ _notice (expr_t *e, const char *file, int line, const char *fmt, ...)
}
expr_t *
_warning (expr_t *e, const char *file, int line, const char *fmt, ...)
_warning (expr_t *e, const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
__warning (e, file, line, fmt, args);
__warning (e, file, line, func, fmt, args);
va_end (args);
return e;
}
void
_internal_error (const expr_t *e, const char *file, int line,
const char *fmt, ...)
const char *func, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
__internal_error (e, file, line, fmt, args);
__internal_error (e, file, line, func, fmt, args);
va_end (args);
}
expr_t *
_error (expr_t *e, const char *file, int line, const char *fmt, ...)
_error (expr_t *e, const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list args;
@ -274,7 +278,7 @@ _error (expr_t *e, const char *file, int line, const char *fmt, ...)
format_message (message, "error", e, fmt, args);
if (options.verbosity > 0) {
dasprintf (message, " (%s:%d)", file, line);
dasprintf (message, " (%s:%d in %s)", file, line, func);
}
if (error_hook) {
error_hook (message->str);

View file

@ -927,15 +927,15 @@ entity_compare (int op, expr_t *e1, expr_t *e2)
}
#define invalid_binary_expr(_op, _e1, _e2) \
_invalid_binary_expr(_op, _e1, _e2, __FILE__, __LINE__)
_invalid_binary_expr(_op, _e1, _e2, __FILE__, __LINE__, __FUNCTION__)
static expr_t *
_invalid_binary_expr (int op, expr_t *e1, expr_t *e2,
const char *file, int line)
const char *file, int line, const char *func)
{
type_t *t1, *t2;
t1 = get_type (e1);
t2 = get_type (e2);
return _error (e1, file, line, "invalid binary expression: %s %s %s",
return _error (e1, file, line, func, "invalid binary expression: %s %s %s",
get_type_string (t1), get_op_string (op),
get_type_string (t2));
}

View file

@ -37,9 +37,9 @@ __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__((noreturn)) void _internal_error (const expr_t *e, const char *file, int line, const char *fmt, ...) {abort();}
__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;}
__attribute__((noreturn)) void _internal_error (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {abort();}
__attribute__((const)) expr_t *_warning (expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
__attribute__((const)) expr_t *_error (expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
__attribute__((const)) symbol_t *make_structure (const char *name, int su, struct_def_t *defs, type_t *type) {return 0;}
__attribute__((const)) symbol_t *symtab_addsymbol (symtab_t *symtab, symbol_t *symbol) {return 0;}
__attribute__((const)) symbol_t *new_symbol_type (const char *name, type_t *type) {return 0;}