From 8534ffc15c44bfd2f7a72ee745afd284255d17c7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 28 Dec 2019 12:59:11 +0000 Subject: [PATCH] Warnings: Infrastructure for tracking and warning about variables 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 --- generate | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/generate b/generate index 9be1cfb..03aabb0 100755 --- 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(); -- 2.30.2