source: branches/port5/SOURCE_TOOLS/postcompile.pl

Last change on this file was 5675, checked in by westram, 16 years ago
  • removed automatic timestamps (the best they were good for, were vc-conflicts)
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
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
13use strict;
14use warnings;
15
16# Note: g++ must be called with -fmessage-length=0
17
18# regexps for whole line:
19my $reg_file = qr/^([^:]+):([0-9]+):\s/;
20my $reg_included = qr/^In\sfile\sincluded\sfrom\s(.*)[,:]/;
21my $reg_included2 = qr/^\s+from\s(.*)[,:]/;
22my $reg_location = qr/^[^:]+:\sIn\sfunction\s/;
23my $reg_location2 = qr/^[^:]+:\sAt\stop\slevel:/;
24
25# regexps for messages:
26my $reg_shadow_warning = qr/^warning:\sdeclaration\sof\s.*\sshadows\s/;
27my $reg_shadow_location = qr/^warning:\sshadowed\s/;
28
29# regexps for files:
30my $reg_user_include = qr/^\/usr\/include\//;
31
32# output buffer
33my @out = ();
34
35sub warning($) {
36  my ($msg) = @_;
37  push @out, '[postcompile]: '.$msg;
38}
39
40
41my $shadow_warning = undef;
42
43sub 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
52my @included = ();
53my $location_info = undef;
54
55foreach (<>) {
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
117store_shadow(undef);
118
119foreach (@out) {
120  print "$_\n";
121}
Note: See TracBrowser for help on using the repository browser.