implement compiler "notices": potentially important information that isn't

really a warning (unless requested) and can be silenced.
This commit is contained in:
Bill Currie 2002-06-20 19:29:06 +00:00
parent 3476138988
commit f8e4215ba9
4 changed files with 63 additions and 3 deletions

View File

@ -168,6 +168,7 @@ void emit_expr (expr_t *e);
expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
void warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
void notice (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
const char *get_op_string (int op);

View File

@ -49,9 +49,15 @@ typedef struct {
qboolean integer_divide; // Warn on integer constant division
} warn_options_t;
typedef struct {
qboolean promote; // Promote notices to warnings
qboolean silent; // don't even bother (overrides promote)
} notice_options_t;
typedef struct {
code_options_t code; // Code generation options
warn_options_t warnings; // Warning options
notice_options_t notices; // Notice options
int verbosity; // 0=silent, goes up to 2 currently
qboolean save_temps; // save temporary files

View File

@ -245,9 +245,8 @@ error (expr_t *e, const char *fmt, ...)
}
void
warning (expr_t *e, const char *fmt, ...)
_warning (expr_t *e, const char *fmt, va_list args)
{
va_list args;
string_t file = s_file;
int line = pr_source_line;
@ -257,7 +256,6 @@ warning (expr_t *e, const char *fmt, ...)
pr_error_count++;
}
va_start (args, fmt);
if (e) {
file = e->file;
line = e->line;
@ -265,6 +263,41 @@ warning (expr_t *e, const char *fmt, ...)
fprintf (stderr, "%s:%d: warning: ", pr.strings + file, line);
vfprintf (stderr, fmt, args);
fputs ("\n", stderr);
}
void
warning (expr_t *e, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
_warning (e, fmt, args);
va_end (args);
}
void
notice (expr_t *e, const char *fmt, ...)
{
va_list args;
if (options.notices.silent)
return;
va_start (args, fmt);
if (options.notices.promote) {
_warning (e, fmt, args);
} else {
string_t file = s_file;
int line = pr_source_line;
if (e) {
file = e->file;
line = e->line;
}
fprintf (stderr, "%s:%d: notice: ", pr.strings + file, line);
vfprintf (stderr, fmt, args);
fputs ("\n", stderr);
}
va_end (args);
}
@ -1227,6 +1260,8 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if ((op == '&' || op == '|')
&& e1->type == ex_uexpr && e1->e.expr.op == '!' && !e1->paren) {
if (options.traditional) {
notice (e1, "precedence of `!' and `%c' inverted for traditional "
"code", op);
e1->e.expr.e1->paren = 1;
return unary_expr ('!', binary_expr (op, e1->e.expr.e1, e2));
} else {

View File

@ -70,6 +70,7 @@ static struct option const long_options[] = {
{"include", required_argument, 0, 'I'},
{"undefine", required_argument, 0, 'U'},
{"cpp", required_argument, 0, 256},
{"notice", required_argument, 0, 'N'},
{NULL, 0, NULL, 0}
};
@ -89,6 +90,7 @@ static const char *short_options =
"D:" // define
"I:" // set includes
"U:" // undefine
"N:" // notice options
;
static void
@ -104,6 +106,7 @@ usage (int status)
" -g, Generate debuggin info\n"
" -C, --code OPTION,... Set code generation options\n"
" -W, --warn OPTION,... Set warning options\n"
" -N, --notice OPTION,... Set notice options\n"
" -h, --help Display this help and exit\n"
" -V, --version Output version information and exit\n\n"
" -S, --save-temps Do not delete temporary files\n"
@ -244,6 +247,21 @@ DecodeArgs (int argc, char **argv)
free (opts);
}
break;
case 'N':{ // notice options
char *opts = strdup (optarg);
char *temp = strtok (opts, ",");
while (temp) {
if (!(strcasecmp (temp, "none"))) {
options.notices.silent = true;
} else if (!(strcasecmp (temp, "warn"))) {
options.notices.promote = true;
}
temp = strtok (NULL, ",");
}
free (opts);
}
break;
case 256: // --cpp=
cpp_name = strdup (optarg);
break;