1 | #!/usr/bin/perl |
---|
2 | # ================================================================= # |
---|
3 | # # |
---|
4 | # File : postcompile.pl # |
---|
5 | # Purpose : filter gcc shadow spam # |
---|
6 | # # |
---|
7 | # Coded by Ralf Westram (coder@reallysoft.de) in September 2007 # |
---|
8 | # Institute of Microbiology (Technical University Munich) # |
---|
9 | # http://www.arb-home.de/ # |
---|
10 | # # |
---|
11 | # ================================================================= # |
---|
12 | |
---|
13 | use strict; |
---|
14 | use warnings; |
---|
15 | |
---|
16 | # Note: g++ must be called with -fmessage-length=0 |
---|
17 | |
---|
18 | # regexps for whole line: |
---|
19 | my $reg_file = qr/^([^:]+):([0-9]+):\s/; |
---|
20 | my $reg_included = qr/^In\sfile\sincluded\sfrom\s(.*)[,:]/; |
---|
21 | my $reg_included2 = qr/^\s+from\s(.*)[,:]/; |
---|
22 | my $reg_location = qr/^[^:]+:\sIn\sfunction\s/; |
---|
23 | my $reg_location2 = qr/^[^:]+:\sAt\stop\slevel:/; |
---|
24 | |
---|
25 | # regexps for messages: |
---|
26 | my $reg_shadow_warning = qr/^warning:\sdeclaration\sof\s.*\sshadows\s/; |
---|
27 | my $reg_shadow_location = qr/^warning:\sshadowed\s/; |
---|
28 | |
---|
29 | # regexps for files: |
---|
30 | my $reg_user_include = qr/^\/usr\/include\//; |
---|
31 | |
---|
32 | # output buffer |
---|
33 | my @out = (); |
---|
34 | |
---|
35 | sub warning($) { |
---|
36 | my ($msg) = @_; |
---|
37 | push @out, '[postcompile]: '.$msg; |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | my $shadow_warning = undef; |
---|
42 | |
---|
43 | sub store_shadow($) { |
---|
44 | my ($warn) = @_; |
---|
45 | if (defined $shadow_warning) { |
---|
46 | warning('unprocessed shadow_warning:'); |
---|
47 | push @out, $shadow_warning; |
---|
48 | } |
---|
49 | $shadow_warning = $warn; |
---|
50 | } |
---|
51 | |
---|
52 | my @included = (); |
---|
53 | my $location_info = undef; |
---|
54 | |
---|
55 | foreach (<>) { |
---|
56 | chomp; |
---|
57 | if ($_ =~ $reg_file) { |
---|
58 | my ($file,$line,$msg) = ($1,$2,$'); |
---|
59 | |
---|
60 | if ($msg =~ $reg_shadow_warning) { |
---|
61 | if (not $' =~ /this/) { # dont store this warnings (no location follows) |
---|
62 | store_shadow($_); |
---|
63 | $_ = undef; |
---|
64 | } |
---|
65 | } |
---|
66 | elsif ($msg =~ $reg_shadow_location) { |
---|
67 | if (not defined $shadow_warning) { warning('no shadow_warning seen'); } |
---|
68 | else { |
---|
69 | if ($file =~ $reg_user_include or $file eq '<built-in>') { |
---|
70 | # dont warn about /usr/include or <built-in> shadowing |
---|
71 | $_ = undef; |
---|
72 | @included = (); |
---|
73 | $location_info = undef; |
---|
74 | } |
---|
75 | else { |
---|
76 | if (defined $location_info) { |
---|
77 | push @out, $location_info; |
---|
78 | $location_info = undef; |
---|
79 | } |
---|
80 | push @out, $shadow_warning; |
---|
81 | } |
---|
82 | $shadow_warning = undef; |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | # if (defined $_) { $_ .= ' [reg_file]'; } # # test |
---|
87 | } |
---|
88 | elsif ($_ =~ $reg_location or $_ =~ $reg_location2) { |
---|
89 | $location_info = $_; |
---|
90 | $_ = undef; |
---|
91 | } |
---|
92 | elsif ($_ =~ $reg_included) { |
---|
93 | push @included, $1; |
---|
94 | $_ = undef; |
---|
95 | } |
---|
96 | elsif (@included) { |
---|
97 | if ($_ =~ $reg_included2) { |
---|
98 | push @included, $1; |
---|
99 | $_ = undef; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | if (defined $_) { |
---|
104 | if (defined $location_info) { |
---|
105 | push @out, $location_info; |
---|
106 | $location_info = undef; |
---|
107 | } |
---|
108 | push @out, $_; |
---|
109 | if (@included) { |
---|
110 | foreach (@included) { |
---|
111 | push @out, $_.': included from here'; |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | store_shadow(undef); |
---|
118 | |
---|
119 | foreach (@out) { |
---|
120 | print "$_\n"; |
---|
121 | } |
---|