]> granicus.if.org Git - yasm/commitdiff
Remove unused yyaccept variables (eliminates warnings from generated code).
authorPeter Johnson <peter@tortall.net>
Sun, 16 Mar 2003 23:47:32 +0000 (23:47 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 16 Mar 2003 23:47:32 +0000 (23:47 -0000)
svn path=/trunk/yasm/; revision=868

tools/re2c/cleanup.pl

index 7034a468fbe35a8ae8eda7740fd5341d104f1195..84f3da1e4d09052c113a5707b6bc7f9c0fd3d3ba 100755 (executable)
@@ -1,10 +1,32 @@
 #!/usr/bin/perl
 my @sourcelines = <>;
 my %usedlabel;
+my %usedvar;
+my $lastusedvarline = 0;
+my $level = 0;
+my $line = 1;
 for (@sourcelines) {
-    $usedlabel{"$1:"} = "$1:" if m/goto\s+(yy[0-9]*)\s*;/
+    $usedlabel{"$1:"} = "$1:" if m/goto\s+(yy[0-9]*)\s*;/;
+    $level = $level + 1 if m/\{/;
+    $level = $level - 1 if m/\}/;
+    if ($level < $usedvar{$lastusedvarline}) {
+       $lastusedvarline = 0;
+    }
+    if (m/int\s+yyaccept/) {
+       $usedvar{$line} = $level;
+       $lastusedvarline = $line;
+    } elsif (m/yyaccept/) {
+       $usedvar{$lastusedvarline} = 1000;
+    }
+    $line = $line + 1;
 }
+$line = 1;
 for (@sourcelines) {
     s/^(yy[0-9]*:)/$usedlabel{$1}/;
-    print;
+    if ($usedvar{$line} != 0 && $usedvar{$line} != 1000) {
+       print "\n";
+    } else {
+       print;
+    }
+    $line = $line + 1;
 }