diff --git a/src/snc/analysis.c b/src/snc/analysis.c index 0fa90cc776d5d87f0a1e1a949fa877b405cc2f0e..c0f276452ad302513b8f73321102f057586390a8 100644 --- a/src/snc/analysis.c +++ b/src/snc/analysis.c @@ -1108,7 +1108,7 @@ static int connect_variable(Expr *ep, Expr *scope, void *parg) return FALSE; } - warning_at_expr(ep, "variable '%s' used but not declared\n", + extra_warning_at_expr(ep, "variable '%s' used but not declared\n", ep->value); /* create a pseudo declaration so we can finish the analysis phase */ vp = new(Var); diff --git a/src/snc/main.c b/src/snc/main.c index 80be2ccb256de1dce17b61b093dc9f0832e226dd..e5cdb1210dd34affbdf4f597d890d7710af86f9b 100644 --- a/src/snc/main.c +++ b/src/snc/main.c @@ -188,6 +188,9 @@ static void parse_option(char *s) case 'w': options.warn = opt_val; break; + case 'W': + options.xwarn = opt_val; + break; default: report("unknown option ignored: '%s'\n", s); break; @@ -310,6 +313,19 @@ void warning_at_expr(Expr *ep, const char *format, ...) va_end(args); } +void extra_warning_at_expr(Expr *ep, const char *format, ...) +{ + va_list args; + + if (!options.xwarn) return; + report_loc(ep->src_file, ep->line_num); + fprintf(stderr, "warning: "); + + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); +} + void error_at_expr(Expr *ep, const char *format, ...) { va_list args; diff --git a/src/snc/main.h b/src/snc/main.h index 0911de824af7c79a564296a1ef2102a193a23596..39d5380c3af95e9704f0e36f743e5a91296ec1f1 100644 --- a/src/snc/main.h +++ b/src/snc/main.h @@ -52,6 +52,10 @@ __attribute__((format(printf,2,3))); void warning_at_expr(struct expression *ep, const char *format, ...) __attribute__((format(printf,2,3))); +/* with location from this expression but only if extra warnings are enabled */ +void extra_warning_at_expr(struct expression *ep, const char *format, ...) +__attribute__((format(printf,2,3))); + /* with location from this expression and increase error count */ void error_at_expr(struct expression *ep, const char *format, ...) __attribute__((format(printf,2,3))); diff --git a/src/snc/types.h b/src/snc/types.h index ab0f6a09fbf9bc7139ea180e2564852aa99c675d..d940b4703e17d5726f0f9c0b82ea3b780f72a8d8 100644 --- a/src/snc/types.h +++ b/src/snc/types.h @@ -67,9 +67,10 @@ struct options uint main:1; /* generate main program */ uint line:1; /* generate line markers */ uint warn:1; /* compiler warnings */ + uint xwarn:1; /* extra compiler warnings */ }; -#define DEFAULT_OPTIONS {0,1,0,0,0,1,0,1,1} +#define DEFAULT_OPTIONS {0,1,0,0,0,1,0,1,1,0} struct state_options /* run-time state options */ {