From 7741787299407cc27001ecb4a4dc5178133e75bb Mon Sep 17 00:00:00 2001
From: "benjamin.franksen" <benjamin.franksen@helmholtz-berlin.de>
Date: Wed, 2 Oct 2013 01:24:02 +0000
Subject: [PATCH] snc: added new switch -W to turn on extra warnings

This is in preparation of supporting indirect calls which cause foreign
functions to be reported as undefined variables. Without -W (which is
the default) *no* "undefined variable" warnings will be given. This is
ok, since if they really are undefined the C compiler will flag them as
errors anyway.

This makes foreign declarations obsolete. With hindsight introducing
them was a mistake. I should probably deprecate them.
---
 src/snc/analysis.c |  2 +-
 src/snc/main.c     | 16 ++++++++++++++++
 src/snc/main.h     |  4 ++++
 src/snc/types.h    |  3 ++-
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/snc/analysis.c b/src/snc/analysis.c
index 0fa90cc7..c0f27645 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 80be2ccb..e5cdb121 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 0911de82..39d5380c 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 ab0f6a09..d940b470 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 */
 {
-- 
GitLab