errors: change the severity parameter from "int" to "errflags"

Change the severity parameter to the error function from "int" to an
unsigned typedef, currently uint32_t.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2018-12-13 19:39:41 -08:00
parent 9f89eb38fc
commit 6bde2ed880
10 changed files with 38 additions and 32 deletions

View file

@ -95,13 +95,13 @@ vefunc nasm_verror;
nasm_verror((s), fmt, ap); \
va_end(ap);
void nasm_error(int severity, const char *fmt, ...)
void nasm_error(errflags severity, const char *fmt, ...)
{
nasm_do_error(severity);
}
#define nasm_err_helpers(_type, _name, _sev) \
_type nasm_ ## _name ## f (int flags, const char *fmt, ...) \
_type nasm_ ## _name ## f (errflags flags, const char *fmt, ...) \
{ \
nasm_do_error((_sev)|flags); \
if (_sev >= ERR_FATAL) \

View file

@ -330,7 +330,7 @@ static void list_downlevel(int type)
}
}
static void list_error(int severity, const char *fmt, ...)
static void list_error(errflags severity, const char *fmt, ...)
{
struct list_error *le;
va_list ap;

View file

@ -96,7 +96,7 @@ struct lfmt {
/*
* Called on a warning or error, with the error message.
*/
void printf_func(2, 3) (*error)(int severity, const char *fmt, ...);
void printf_func(2, 3) (*error)(errflags severity, const char *fmt, ...);
/*
* Update the current offset. Used to give the listing generator

View file

@ -76,8 +76,8 @@ struct forwrefinfo { /* info held on forward refs. */
static void parse_cmdline(int, char **, int);
static void assemble_file(const char *, struct strlist *);
static bool skip_this_pass(int severity);
static void nasm_verror_asm(int severity, const char *fmt, va_list args);
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(char xopt);
@ -1700,7 +1700,7 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
/**
* get warning index; 0 if this is non-suppressible.
*/
static size_t warn_index(int severity)
static size_t warn_index(errflags severity)
{
size_t index;
@ -1717,7 +1717,7 @@ static size_t warn_index(int severity)
return index;
}
static bool skip_this_pass(int severity)
static bool skip_this_pass(errflags severity)
{
/*
* See if it's a pass-specific error or warning which should be skipped.
@ -1742,7 +1742,7 @@ static bool skip_this_pass(int severity)
* @param severity the severity of the warning or error
* @return true if we should abort error/warning printing
*/
static bool is_suppressed(int severity)
static bool is_suppressed(errflags severity)
{
if ((severity & ERR_MASK) >= ERR_FATAL)
return false; /* Fatal errors can never be suppressed */
@ -1758,7 +1758,7 @@ static bool is_suppressed(int severity)
* @param severity the severity of the warning or error
* @return true if we should error out
*/
static int true_error_type(int severity)
static errflags true_error_type(errflags severity)
{
const uint8_t warn_is_err = WARN_ST_ENABLED|WARN_ST_ERROR;
int type;
@ -1785,14 +1785,14 @@ static int true_error_type(int severity)
* @param severity the severity of the warning or error
* @param fmt the printf style format string
*/
static void nasm_verror_asm(int severity, const char *fmt, va_list args)
static void nasm_verror_asm(errflags severity, const char *fmt, va_list args)
{
char msg[1024];
char warnsuf[64];
char linestr[64];
const char *pfx;
int spec_type = severity & ERR_MASK; /* type originally specified */
int true_type = true_error_type(severity);
errflags spec_type = severity & ERR_MASK; /* type originally specified */
errflags true_type = true_error_type(severity);
const char *currentfile = NULL;
int32_t lineno = 0;
static const char * const pfx_table[ERR_MASK+1] = {

View file

@ -175,7 +175,7 @@ static void nop_include_path(struct strlist *list)
(void)list;
}
static void nop_error_list_macros(int severity)
static void nop_error_list_macros(errflags severity)
{
(void)severity;
}

View file

@ -451,7 +451,7 @@ static Token *expand_smacro(Token * tline);
static Token *expand_id(Token * tline);
static Context *get_ctx(const char *name, const char **namep);
static void make_tok_num(Token * tok, int64_t val);
static void pp_verror(int severity, const char *fmt, va_list ap);
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);
@ -2203,7 +2203,7 @@ static int do_directive(Token *tline, char **output)
MMacro *tmp_defining; /* Used when manipulating rep_nest */
int64_t count;
size_t len;
int severity;
errflags severity;
*output = NULL; /* No output generated */
origline = tline;
@ -4828,7 +4828,7 @@ static int expand_mmacro(Token * tline)
* This function adds macro names to error messages, and suppresses
* them if necessary.
*/
static void pp_verror(int severity, const char *fmt, va_list arg)
static void pp_verror(errflags severity, const char *fmt, va_list arg)
{
char buff[BUFSIZ];
MMacro *mmac = NULL;
@ -5315,7 +5315,7 @@ static void make_tok_num(Token * tok, int64_t val)
tok->type = TOK_NUMBER;
}
static void pp_list_one_macro(MMacro *m, int severity)
static void pp_list_one_macro(MMacro *m, errflags severity)
{
if (!m)
return;
@ -5329,7 +5329,7 @@ static void pp_list_one_macro(MMacro *m, int severity)
}
}
static void pp_error_list_macros(int severity)
static void pp_error_list_macros(errflags severity)
{
struct src_location saved;

View file

@ -69,7 +69,7 @@ static const char *help =
static void output_ins(uint64_t, uint8_t *, int, char *);
static void skip(uint32_t dist, FILE * fp);
static void ndisasm_verror(int severity, const char *fmt, va_list va)
static void ndisasm_verror(errflags severity, const char *fmt, va_list va)
{
vfprintf(stderr, fmt, va);

View file

@ -45,26 +45,31 @@
*/
extern FILE *error_file; /* Error file descriptor */
/*
* Typedef for the severity field
*/
typedef uint32_t errflags;
/*
* An error reporting function should look like this.
*/
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
void printf_func(2, 3) nasm_error(errflags severity, const char *fmt, ...);
void printf_func(1, 2) nasm_debug(const char *fmt, ...);
void printf_func(2, 3) nasm_debugf(int flags, const char *fmt, ...);
void printf_func(2, 3) nasm_debugf(errflags flags, const char *fmt, ...);
void printf_func(1, 2) nasm_note(const char *fmt, ...);
void printf_func(2, 3) nasm_notef(int flags, const char *fmt, ...);
void printf_func(2, 3) nasm_notef(errflags flags, const char *fmt, ...);
void printf_func(1, 2) nasm_warn(const char *fmt, ...);
void printf_func(2, 3) nasm_warnf(int flags, const char *fmt, ...);
void printf_func(2, 3) nasm_warnf(errflags flags, const char *fmt, ...);
void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...);
void printf_func(2, 3) nasm_nonfatalf(int flags, const char *fmt, ...);
void printf_func(2, 3) nasm_nonfatalf(errflags flags, const char *fmt, ...);
fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
fatal_func printf_func(2, 3) nasm_fatalf(int flags, const char *fmt, ...);
fatal_func printf_func(2, 3) nasm_fatalf(errflags flags, const char *fmt, ...);
fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
fatal_func printf_func(2, 3) nasm_panicf(int flags, const char *fmt, ...);
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) (int severity, const char *fmt, va_list ap);
typedef void (*vefunc) (errflags severity, const char *fmt, va_list ap);
extern vefunc nasm_verror;
static inline vefunc nasm_set_verror(vefunc ve)
@ -104,9 +109,9 @@ static inline vefunc nasm_set_verror(vefunc ve)
*/
#define WARN_SHR 12 /* how far to shift right */
#define WARN(x) ((x) << WARN_SHR)
#define WARN(x) (((errflags)(x)) << WARN_SHR)
#define WARN_MASK WARN(~0)
#define WARN_IDX(x) ((x) >> WARN_SHR)
#define WARN_IDX(x) (((errflags)(x)) >> WARN_SHR)
#define WARN_MACRO_PARAMS WARN( 1) /* macro-num-parameters warning */
#define WARN_MACRO_SELFREF WARN( 2) /* macro self-reference */

View file

@ -53,6 +53,7 @@
#include "opflags.h"
#include "regs.h"
#include "srcfile.h"
#include "error.h"
/* Time stamp for the official start of compilation */
struct compile_time {
@ -368,7 +369,7 @@ struct preproc_ops {
void (*include_path)(struct strlist *ipath);
/* Unwind the macro stack when printing an error message */
void (*error_list_macros)(int severity);
void (*error_list_macros)(errflags severity);
};
extern const struct preproc_ops nasmpp;

View file

@ -229,7 +229,7 @@ int rdf_errno = 0;
/* ========================================================================
* Hook for nasm_error() to work
* ======================================================================== */
static void rdoff_verror(int severity, const char *fmt, va_list val)
static void rdoff_verror(errflags severity, const char *fmt, va_list val)
{
vfprintf(stderr, fmt, val);