chiark / gitweb /
Warnings: Infrastructure for tracking and warning about variables
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Dec 2019 12:59:11 +0000 (12:59 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 11:35:16 +0000 (11:35 +0000)
We are going to track when we see FOO or &FOO.  If we see both, we
issue a warning, as that might mean the programmer forgot a &.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
generate

index 9be1cfb8bf4b5d9f6ceabb91bd1174724cf8a69b..03aabb056787e4e98a1d6d6f6167ec32b24620ec 100755 (executable)
--- a/generate
+++ b/generate
@@ -152,6 +152,8 @@ Makefile run-main.mk:
 END
 }
 
+our %varref;
+
 our ($dir_prefix, $dir_suffix, $dir_name,
      $var_prefix, $var_prefix_name);
 
@@ -235,6 +237,13 @@ sub process_input_mk ($$$$) {
        $ddbl = (shift @nest)[1];
     };
 
+    # Our detection of variable settings does not have to be completely
+    # accurate, since it is only going to be used for advice to the user.
+    my $note_varref = sub {
+       my ($vn,$amp) = @_;
+       $varref{$vn}{$amp}{"$f:$."} = 1;
+    };
+
     while (<$input>) {
        if (s#^\s*$esc\:changequote\s+(\S+)\s+$##) {
            $$esclitr = $1;
@@ -440,6 +449,20 @@ sub process_tree() {
     oraw "include \$(SUBDIRMK_MAKEFILES)\n";
 }
 
+sub print_varref_warnings () {
+    foreach my $vn (sort keys %varref) {
+       my $vv = $varref{$vn};
+       next unless $vv->{''} && $vv->{1};
+       print STDERR "subdirmk: warning: saw both $vn and &$vn\n";
+       foreach my $amp ('', 1) {
+           printf STDERR " saw %s%s at %s\n",
+               ($amp ? '&' : ''), $vn, $_
+               foreach sort keys %{ $vv->{$amp} };
+       }
+    }
+}
+
 build_tree();
 process_tree();
+print_varref_warnings();
 install_output_files();