error: replace nasm_verror() indirection with preproc callback
Since pp_error_list_macros() was introduced, the only need for pp_verror() is to suppress error messages in certain contexts. Replace this function with a preprocessor callback, preproc->pp_suppress_error(), so we can drop the nasm_verror() function pointer entirely. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
6a4353c4c2
commit
a73ccfebcc
8 changed files with 46 additions and 75 deletions
|
@ -41,12 +41,6 @@
|
|||
#include "nasmlib.h"
|
||||
#include "error.h"
|
||||
|
||||
/*
|
||||
* Global error handling function. If we call this before it is
|
||||
* initialized, it is a fatal error!
|
||||
*/
|
||||
vefunc nasm_verror = (vefunc)nasm_verror_critical;
|
||||
|
||||
/* Common function body */
|
||||
#define nasm_do_error(_sev,_flags) \
|
||||
va_list ap; \
|
||||
|
|
12
asm/nasm.c
12
asm/nasm.c
|
@ -74,7 +74,6 @@ const char *_progname;
|
|||
static void parse_cmdline(int, char **, int);
|
||||
static void assemble_file(const char *, struct strlist *);
|
||||
static bool skip_this_pass(errflags severity);
|
||||
static void nasm_verror_asm(errflags severity, const char *fmt, va_list args);
|
||||
static void usage(void);
|
||||
static void help(FILE *);
|
||||
|
||||
|
@ -474,7 +473,6 @@ int main(int argc, char **argv)
|
|||
{
|
||||
/* Do these as early as possible */
|
||||
error_file = stderr;
|
||||
nasm_set_verror(nasm_verror_asm);
|
||||
_progname = argv[0];
|
||||
if (!_progname || !_progname[0])
|
||||
_progname = "nasm";
|
||||
|
@ -1774,7 +1772,13 @@ static bool is_suppressed(errflags severity)
|
|||
if ((severity & ERR_UNDEAD) && terminate_after_phase)
|
||||
return true;
|
||||
|
||||
return !(warning_state[warn_index(severity)] & WARN_ST_ENABLED);
|
||||
if (!(warning_state[warn_index(severity)] & WARN_ST_ENABLED))
|
||||
return true;
|
||||
|
||||
if (preproc && !(severity & ERR_PP_LISTMACRO))
|
||||
return preproc->suppress_error(severity);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1886,7 +1890,7 @@ fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list args
|
|||
* @param severity the severity of the warning or error
|
||||
* @param fmt the printf style format string
|
||||
*/
|
||||
static void nasm_verror_asm(errflags severity, const char *fmt, va_list args)
|
||||
void nasm_verror(errflags severity, const char *fmt, va_list args)
|
||||
{
|
||||
char msg[1024];
|
||||
char warnsuf[64];
|
||||
|
|
|
@ -182,6 +182,12 @@ static void nop_error_list_macros(errflags severity)
|
|||
(void)severity;
|
||||
}
|
||||
|
||||
static bool nop_suppress_error(errflags severity)
|
||||
{
|
||||
(void)severity;
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct preproc_ops preproc_nop = {
|
||||
nop_init,
|
||||
nop_reset,
|
||||
|
@ -195,4 +201,5 @@ const struct preproc_ops preproc_nop = {
|
|||
nop_pre_command,
|
||||
nop_include_path,
|
||||
nop_error_list_macros,
|
||||
nop_suppress_error
|
||||
};
|
||||
|
|
|
@ -515,8 +515,6 @@ static Token *expand_id(Token * tline);
|
|||
static Context *get_ctx(const char *name, const char **namep);
|
||||
static Token *make_tok_num(int64_t val);
|
||||
static Token *make_tok_qstr(const char *str);
|
||||
static void pp_verror(errflags severity, const char *fmt, va_list ap);
|
||||
static vefunc real_verror;
|
||||
static void *new_Block(size_t size);
|
||||
static void delete_Blocks(void);
|
||||
static Token *new_Token(Token * next, enum pp_token_type type,
|
||||
|
@ -5543,10 +5541,11 @@ static int expand_mmacro(Token * tline)
|
|||
}
|
||||
|
||||
/*
|
||||
* This function adds macro names to error messages, and suppresses
|
||||
* them if necessary.
|
||||
* This function decides if an error message should be suppressed.
|
||||
* It will never be called with a severity level of ERR_FATAL or
|
||||
* higher.
|
||||
*/
|
||||
static void pp_verror(errflags severity, const char *fmt, va_list arg)
|
||||
static bool pp_suppress_error(errflags severity)
|
||||
{
|
||||
/*
|
||||
* If we're in a dead branch of IF or something like it, ignore the error.
|
||||
|
@ -5555,32 +5554,13 @@ static void pp_verror(errflags severity, const char *fmt, va_list arg)
|
|||
* %if 0 ... %else trailing garbage ... %endif
|
||||
* So %else etc should set the ERR_PP_PRECOND flag.
|
||||
*/
|
||||
if ((severity & ERR_MASK) < ERR_FATAL &&
|
||||
istk && istk->conds &&
|
||||
if (istk && istk->conds &&
|
||||
((severity & ERR_PP_PRECOND) ?
|
||||
istk->conds->state == COND_NEVER :
|
||||
!emitting(istk->conds->state)))
|
||||
return;
|
||||
return true;
|
||||
|
||||
/* This doesn't make sense with the macro stack unwinding */
|
||||
if (0) {
|
||||
int32_t delta = 0;
|
||||
|
||||
/* get %macro name */
|
||||
if (!(severity & ERR_NOFILE) && istk && istk->mstk.mmac) {
|
||||
MMacro *mmac = istk->mstk.mmac;
|
||||
char *buf;
|
||||
|
||||
nasm_set_verror(real_verror);
|
||||
buf = nasm_vasprintf(fmt, arg);
|
||||
nasm_error(severity, "(%s:%"PRId32") %s",
|
||||
mmac->name, mmac->lineno - delta, buf);
|
||||
nasm_set_verror(pp_verror);
|
||||
nasm_free(buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
real_verror(severity, fmt, arg);
|
||||
return false;
|
||||
}
|
||||
|
||||
static Token *
|
||||
|
@ -6014,8 +5994,6 @@ static char *pp_getline(void)
|
|||
char *line = NULL;
|
||||
Token *tline;
|
||||
|
||||
real_verror = nasm_set_verror(pp_verror);
|
||||
|
||||
while (true) {
|
||||
tline = pp_tokline();
|
||||
if (tline == &tok_pop) {
|
||||
|
@ -6041,14 +6019,11 @@ static char *pp_getline(void)
|
|||
nasm_free(buf);
|
||||
}
|
||||
|
||||
nasm_set_verror(real_verror);
|
||||
return line;
|
||||
}
|
||||
|
||||
static void pp_cleanup_pass(void)
|
||||
{
|
||||
real_verror = nasm_set_verror(pp_verror);
|
||||
|
||||
if (defining) {
|
||||
if (defining->name) {
|
||||
nasm_nonfatal("end of file while still defining macro `%s'",
|
||||
|
@ -6061,8 +6036,6 @@ static void pp_cleanup_pass(void)
|
|||
defining = NULL;
|
||||
}
|
||||
|
||||
nasm_set_verror(real_verror);
|
||||
|
||||
while (cstk)
|
||||
ctx_pop();
|
||||
free_macros();
|
||||
|
@ -6114,8 +6087,6 @@ static void pp_pre_define(char *definition)
|
|||
Line *l;
|
||||
char *equals;
|
||||
|
||||
real_verror = nasm_set_verror(pp_verror);
|
||||
|
||||
equals = strchr(definition, '=');
|
||||
space = new_Token(NULL, TOK_WHITESPACE, NULL, 0);
|
||||
def = new_Token(space, TOK_PREPROC_ID, "%define", 0);
|
||||
|
@ -6134,8 +6105,6 @@ static void pp_pre_define(char *definition)
|
|||
l->first = def;
|
||||
l->finishes = NULL;
|
||||
predef = l;
|
||||
|
||||
nasm_set_verror(real_verror);
|
||||
}
|
||||
|
||||
static void pp_pre_undefine(char *definition)
|
||||
|
@ -6249,4 +6218,5 @@ const struct preproc_ops nasmpp = {
|
|||
pp_pre_command,
|
||||
pp_include_path,
|
||||
pp_error_list_macros,
|
||||
pp_suppress_error
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* ----------------------------------------------------------------------- *
|
||||
*
|
||||
*
|
||||
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
|
||||
* See the file AUTHORS included with the NASM distribution for
|
||||
* the specific copyright holders.
|
||||
|
@ -14,7 +14,7 @@
|
|||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
|
@ -65,18 +65,19 @@ static const char *help =
|
|||
static void output_ins(uint64_t, uint8_t *, int, char *);
|
||||
static void skip(uint32_t dist, FILE * fp);
|
||||
|
||||
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
|
||||
void nasm_verror(errflags severity, const char *fmt, va_list val)
|
||||
{
|
||||
severity &= ERR_MASK;
|
||||
|
||||
vfprintf(stderr, fmt, val);
|
||||
exit((severity & ERR_MASK) - ERR_FATAL + 2);
|
||||
if (severity >= ERR_FATAL)
|
||||
exit(severity - ERR_FATAL + 1);
|
||||
}
|
||||
|
||||
static void ndisasm_verror(errflags severity, const char *fmt, va_list val)
|
||||
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
|
||||
{
|
||||
if ((severity & ERR_MASK) >= ERR_FATAL)
|
||||
nasm_verror_critical(severity, fmt, val);
|
||||
else
|
||||
vfprintf(stderr, fmt, val);
|
||||
nasm_verror(severity, fmt, val);
|
||||
abort();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -97,7 +98,6 @@ int main(int argc, char **argv)
|
|||
FILE *fp;
|
||||
|
||||
nasm_ctype_init();
|
||||
nasm_set_verror(ndisasm_verror);
|
||||
iflag_clear_all(&prefer);
|
||||
|
||||
offset = 0;
|
||||
|
|
|
@ -72,17 +72,9 @@ fatal_func printf_func(2, 3) nasm_panicf(errflags flags, const char *fmt, ...);
|
|||
fatal_func nasm_panic_from_macro(const char *file, int line);
|
||||
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
||||
|
||||
typedef void (*vefunc) (errflags severity, const char *fmt, va_list ap);
|
||||
extern vefunc nasm_verror;
|
||||
void nasm_verror(errflags severity, const char *fmt, va_list ap);
|
||||
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list ap);
|
||||
|
||||
static inline vefunc nasm_set_verror(vefunc ve)
|
||||
{
|
||||
vefunc old_verror = nasm_verror;
|
||||
nasm_verror = ve;
|
||||
return old_verror;
|
||||
}
|
||||
|
||||
/*
|
||||
* These are the error severity codes which get passed as the first
|
||||
* argument to an efunc.
|
||||
|
|
|
@ -391,6 +391,9 @@ struct preproc_ops {
|
|||
|
||||
/* Unwind the macro stack when printing an error message */
|
||||
void (*error_list_macros)(errflags severity);
|
||||
|
||||
/* Return true if an error message should be suppressed */
|
||||
bool (*suppress_error)(errflags severity);
|
||||
};
|
||||
|
||||
extern const struct preproc_ops nasmpp;
|
||||
|
|
|
@ -228,23 +228,24 @@ int rdf_errno = 0;
|
|||
/* ========================================================================
|
||||
* Hook for nasm_error() to work
|
||||
* ======================================================================== */
|
||||
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
|
||||
void nasm_verror(errflags severity, const char *fmt, va_list val)
|
||||
{
|
||||
severity &= ERR_MASK;
|
||||
|
||||
vfprintf(stderr, fmt, val);
|
||||
exit((severity & ERR_MASK) - ERR_FATAL + 2);
|
||||
if (severity >= ERR_FATAL)
|
||||
exit(severity - ERR_FATAL + 1);
|
||||
}
|
||||
|
||||
static void rdoff_verror(errflags severity, const char *fmt, va_list val)
|
||||
fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
|
||||
{
|
||||
if ((severity & ERR_MASK) >= ERR_FATAL)
|
||||
nasm_verror_critical(severity, fmt, val);
|
||||
else
|
||||
vfprintf(stderr, fmt, val);
|
||||
nasm_verror(severity, fmt, val);
|
||||
abort();
|
||||
}
|
||||
|
||||
void rdoff_init(void)
|
||||
{
|
||||
nasm_set_verror(rdoff_verror);
|
||||
|
||||
}
|
||||
|
||||
/* ========================================================================
|
||||
|
|
Loading…
Reference in a new issue