summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/Porting/fixCORE
blob: 4c586d896981316ae78d1155bcf974607b5b2ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/local/bin/perl -w
use Data::Dumper;

my $targ = shift;
my $inc  = join(' ',map("-I$_",@INC));

my $work = 1;
while ($work)
 {
  open(PIPE,"$^X -w $inc -M$targ -e '' 2>&1 |") || die "Cannot open pipe to child:$!";
  my %fix;
  while (<PIPE>)
   {
    if (/^Ambiguous call resolved as CORE::(\w+)\(\), qualify as such or use \& at (\S+) line (\d+)/
         && -f $2 )
     {
      my ($var,$file,$line) = ($1,$2,$3);
      $fix{$file} = [] unless exists $fix{$file}; 
      push(@{$fix{$file}},[$line => $var]) unless ($var =~ /^PL_/ || $file =~ /\.h$/);
     }
    print;
   }
  close(PIPE);
# warn "Make retured $?\n";
# last unless $?;
  my $changed = 0;
  foreach my $file (keys %fix)
   {          
    my @ar = sort( { $a->[0] <=> $b->[0] } @{delete $fix{$file}});
    my @miss;
    my $fixed = 0;
    @ARGV = ($file);
    $. = 0;
    local $^I = '.sav';
    while (<>)
     {
      while (@ar && $. == $ar[0][0])
       {
        my ($line,$var) = @{shift(@ar)};
        if (s/(?<!CORE::)\b$var\b(?=\s*\()/CORE::$var/)
         {
          warn "$file:$line: FIX $var\n"; 
          $fixed++;
          $changed++;
         }
        else
         {
          push(@miss,[$line,$var,$_]);
         }
       }
      print;
     }
    unless ($fixed)
     {
      rename("$file$^I",$file);
      if (@miss)
       {
        while (@miss)
         {
          my ($line,$var,$txt) = @{shift(@miss)};
          warn "$file:$line:$var | $txt";
         }
       }
     }    
   }
  last unless $changed;
 }