error: Cover all levels with helpers

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2018-11-24 22:17:47 +03:00
parent 3351072306
commit c3527dd6b2
6 changed files with 73 additions and 38 deletions

View File

@ -91,39 +91,65 @@ void nasm_error(int severity, const char *fmt, ...)
va_end(ap);
}
#define nasm_error_generatorf(__sev, __flags, __fmt) \
va_list __ap; \
va_start(__ap, __fmt); \
nasm_verror(__sev | __flags, __fmt, __ap)
#define nasm_error_generator(__sev, __fmt) \
nasm_error_generatorf(__sev, 0, __fmt)
void nasm_debug(const char *fmt, ...)
{
nasm_error_generator(ERR_DEBUG, fmt);
}
void nasm_debugf(int flags, const char *fmt, ...)
{
nasm_error_generatorf(ERR_DEBUG, flags, fmt);
}
void nasm_warn(const char *fmt, ...)
{
nasm_error_generator(ERR_WARNING, fmt);
}
void nasm_warnf(int flags, const char *fmt, ...)
{
nasm_error_generatorf(ERR_WARNING, flags, fmt);
}
void nasm_nonfatal(const char *fmt, ...)
{
nasm_error_generator(ERR_NONFATAL, fmt);
}
void nasm_nonfatalf(int flags, const char *fmt, ...)
{
nasm_error_generatorf(ERR_NONFATAL, flags, fmt);
}
fatal_func nasm_fatal(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
nasm_verror(ERR_FATAL, fmt, ap);
nasm_error_generator(ERR_FATAL, fmt);
abort();
}
fatal_func nasm_fatal_fl(int flags, const char *fmt, ...)
fatal_func nasm_fatalf(int flags, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
nasm_verror(flags | ERR_FATAL, fmt, ap);
nasm_error_generatorf(ERR_FATAL, flags, fmt);
abort();
}
fatal_func nasm_panic(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
nasm_verror(ERR_PANIC, fmt, ap);
nasm_error_generator(ERR_PANIC, fmt);
abort();
}
fatal_func nasm_panic_fl(int flags, const char *fmt, ...)
fatal_func nasm_panicf(int flags, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
nasm_verror(flags | ERR_PANIC, fmt, ap);
nasm_error_generatorf(ERR_PANIC, flags, fmt);
abort();
}
@ -137,6 +163,9 @@ fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
nasm_panic("assertion %s failed at %s:%d", msg, file, line);
}
#undef nasm_error_generator
#undef nasm_error_generatorf
/*
* This is called when processing a -w or -W option, or a warning directive.
* Returns true if if the action was successful.

View File

@ -489,7 +489,7 @@ int main(int argc, char **argv)
} else {
dfmt = dfmt_find(ofmt, debug_format);
if (!dfmt) {
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
"unrecognized debug format `%s' for"
" output format `%s'",
debug_format, ofmt->shortname);
@ -549,9 +549,9 @@ int main(int argc, char **argv)
if (outname) {
ofile = nasm_open_write(outname, NF_TEXT);
if (!ofile)
nasm_fatal_fl(ERR_NOFILE,
"unable to open output file `%s'",
outname);
nasm_fatalf(ERR_NOFILE,
"unable to open output file `%s'",
outname);
} else
ofile = NULL;
@ -594,7 +594,7 @@ int main(int argc, char **argv)
if (operating_mode & OP_NORMAL) {
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
if (!ofile)
nasm_fatal_fl(ERR_NOFILE,
nasm_fatalf(ERR_NOFILE,
"unable to open output file `%s'", outname);
ofmt->init();
@ -892,7 +892,7 @@ static bool process_arg(char *p, char *q, int pass)
if (pass == 1) {
ofmt = ofmt_find(param, &ofmt_alias);
if (!ofmt) {
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
"unrecognised output format `%s' - "
"use -hf for a list", param);
}
@ -992,9 +992,9 @@ static bool process_arg(char *p, char *q, int pass)
else if (nasm_stricmp("gnu", param) == 0)
nasm_set_verror(nasm_verror_gnu);
else
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
"unrecognized error reporting format `%s'",
param);
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
"unrecognized error reporting format `%s'",
param);
}
break;
@ -1391,19 +1391,19 @@ static void parse_cmdline(int argc, char **argv, int pass)
return;
if (!inname)
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, "no input file specified");
nasm_fatalf(ERR_NOFILE | ERR_USAGE, "no input file specified");
else if ((errname && !strcmp(inname, errname)) ||
(outname && !strcmp(inname, outname)) ||
(listname && !strcmp(inname, listname)) ||
(depend_file && !strcmp(inname, depend_file)))
nasm_fatal_fl(ERR_USAGE, "will not overwrite input file");
nasm_fatalf(ERR_USAGE, "will not overwrite input file");
if (errname) {
error_file = nasm_open_write(errname, NF_TEXT);
if (!error_file) {
error_file = stderr; /* Revert to default! */
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
"cannot open file `%s' for error messages",
errname);
}

View File

@ -70,7 +70,7 @@ static void nop_reset(const char *file, int pass, struct strlist *deplist)
nop_fp = nasm_open_read(file, NF_TEXT);
if (!nop_fp)
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
nasm_fatalf(ERR_NOFILE, "unable to open input file `%s'", file);
(void)pass; /* placate compilers */
strlist_add(deplist, file);

View File

@ -4950,7 +4950,7 @@ pp_reset(const char *file, int apass, struct strlist *dep_list)
src_set(0, file);
istk->lineinc = 1;
if (!istk->fp)
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
nasm_fatalf(ERR_NOFILE, "unable to open input file `%s'", file);
defining = NULL;
nested_mac_count = 0;
nested_rep_count = 0;

View File

@ -44,10 +44,16 @@
* An error reporting function should look like this.
*/
void printf_func(2, 3) nasm_error(int 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(1, 2) nasm_warn(const char *fmt, ...);
void printf_func(2, 3) nasm_warnf(int 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, ...);
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(1, 2) nasm_panic(const char *fmt, ...);
fatal_func printf_func(2, 3) nasm_fatal_fl(int flags, const char *fmt, ...);
fatal_func printf_func(2, 3) nasm_panic_fl(int flags, const char *fmt, ...);
fatal_func printf_func(2, 3) nasm_panicf(int flags, const char *fmt, ...);
fatal_func nasm_panic_from_macro(const char *file, int line);
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);

View File

@ -119,8 +119,8 @@ FILE *nasm_open_read(const char *filename, enum file_flags flags)
f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb");
if (!f && (flags & NF_FATAL))
nasm_fatal_fl(ERR_NOFILE, "unable to open input file: `%s': %s",
filename, strerror(errno));
nasm_fatalf(ERR_NOFILE, "unable to open input file: `%s': %s",
filename, strerror(errno));
return f;
}
@ -132,8 +132,8 @@ FILE *nasm_open_write(const char *filename, enum file_flags flags)
f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb");
if (!f && (flags & NF_FATAL))
nasm_fatal_fl(ERR_NOFILE, "unable to open output file: `%s': %s",
filename, strerror(errno));
nasm_fatalf(ERR_NOFILE, "unable to open output file: `%s': %s",
filename, strerror(errno));
return f;
}