diff --git a/utah/scripts/reduce/c_delta.pl b/utah/scripts/reduce/c_delta.pl index 8615ca621..96316ddec 100755 --- a/utah/scripts/reduce/c_delta.pl +++ b/utah/scripts/reduce/c_delta.pl @@ -62,9 +62,10 @@ ###################################################################### my $varnum = "(\\-?|\\+?)[0-9a-zA-Z\_]+"; +my $varnumexp = "($varnum)|($RE{balanced}{-parens=>'()'})"; my $field = "\\.($varnum)"; my $index = "\\\[($varnum)\\\]"; -my $fullvar = "([\\&\\*]*)($varnum)(($field)|($index))*"; +my $fullvar = "([\\&\\*]*)($varnumexp)(($field)|($index))*"; my $arith = "\\+|\\-|\\%|\\/|\\*"; my $comp = "\\<\\=|\\>\\=|\\<|\\>|\\=\\=|\\!\\=|\\="; my $logic = "\\&\\&|\\|\\|"; @@ -107,7 +108,7 @@ # these match when preceded and followed by $borderorspc my @delimited_regexes_to_replace = ( - ["($varnum)\\s*:", ""], + ["($varnumexp)\\s*:", ""], ["goto\\s+($varnum);", ""], ["char", "int"], ["short", "int"], @@ -139,9 +140,10 @@ push @delimited_regexes_to_replace, ["$x", "0"]; push @delimited_regexes_to_replace, ["$x", "1"]; push @delimited_regexes_to_replace, ["$x", ""]; - push @delimited_regexes_to_replace, ["$x,", "0,"]; - push @delimited_regexes_to_replace, ["$x,", "1,"]; - push @delimited_regexes_to_replace, ["$x,", ""]; + push @delimited_regexes_to_replace, ["$x\\s*,", "0,"]; + push @delimited_regexes_to_replace, ["$x\\s*,", "1,"]; + push @delimited_regexes_to_replace, ["$x\\s*,", ""]; + push @delimited_regexes_to_replace, [",\\s*$x", ""]; } my %regex_worked; @@ -324,7 +326,7 @@ ($) my $first = substr($prog, 0, $pos); my $rest = substr($prog, $pos); if ($rest =~ s/(^$str)/$repl/) { - print "num $n replacing '$1' with '$repl' : "; + print "regex $n replacing '$1' with '$repl' : "; $prog = $first.$rest; if (delta_test ($method, 0)) { $worked = 1; @@ -351,7 +353,7 @@ ($) next if ($repl eq "1," && $rest =~ /^($borderorspc)1,$borderorspc/); if ($rest =~ s/^(?$borderorspc)(?$str)(?$borderorspc)/$+{delim1}$repl$+{delim2}/) { - print "num $n delimited replacing '$+{str}' with '$repl' : "; + print "regex $n delimited replacing '$+{str}' with '$repl' : "; $prog = $first.$rest; if (delta_test ($method, 0)) { $worked = 1; @@ -361,7 +363,7 @@ ($) } } } - } elsif ($method eq "del_blanks_all") { + } elsif ($method eq "blanks_all") { if ($prog =~ s/\s{2,}/ /g) { $worked |= delta_test ($method, 0); } @@ -372,7 +374,7 @@ ($) read_file(); $worked |= delta_test ($method, 1); return 0; - } elsif ($method eq "del_blanks") { + } elsif ($method eq "blanks") { my $rest = substr($prog, $pos); if ($rest =~ /^(\s{2,})/) { my $len = length ($1); @@ -411,6 +413,25 @@ ($) $worked |= delta_test ($method, 0); } } + } elsif ($method eq "ternary") { + my $first = substr($prog, 0, $pos); + my $rest = substr($prog, $pos); + if ($rest =~ s/^(?$borderorspc)(?$varnumexp)\s*\?\s*(?$varnumexp)\s*:\s*(?$varnumexp)(?$borderorspc)/$+{del1}$+{b}$+{del2}/) { + $prog = $first.$rest; + my $n1 = "$+{del1}$+{a} ? $+{b} : $+{c}$+{del2}"; + my $n2 = "$+{del1}$+{b}$+{del2}"; + print "replacing $n1 with $n2\n"; + $worked |= delta_test ($method, 0); + } + $first = substr($prog, 0, $pos); + $rest = substr($prog, $pos); + if ($rest =~ s/^(?$borderorspc)(?$varnumexp)\s*\?\s*(?$varnumexp)\s*:\s*(?$varnumexp)(?$borderorspc)/$+{del1}$+{c}$+{del2}/) { + $prog = $first.$rest; + my $n1 = "$+{del1}$+{a} ? $+{b} : $+{c}$+{del2}"; + my $n2 = "$+{del1}$+{c}$+{del2}"; + print "replacing $n1 with $n2\n"; + $worked |= delta_test ($method, 0); + } } elsif ($method eq "shorten_ints") { my $first = substr($prog, 0, $pos); my $rest = substr($prog, $pos); @@ -421,6 +442,8 @@ ($) print "replacing $n1 with $n2\n"; $worked |= delta_test ($method, 0); } + $first = substr($prog, 0, $pos); + $rest = substr($prog, $pos); my $orig_rest = $rest; if ($rest =~ s/^(?$borderorspc)(?(\\-|\\+)?(0|(0[xX]))?)(?[0-9a-fA-F]+)(?[ULul]*$borderorspc)/$+{pref1}$+{numpart}$+{suf}/ && ($rest ne $orig_rest)) { $prog = $first.$rest; @@ -429,6 +452,8 @@ ($) print "replacing $n1 with $n2\n"; $worked |= delta_test ($method, 0); } + $first = substr($prog, 0, $pos); + $rest = substr($prog, $pos); $orig_rest = $rest; if ($rest =~ s/^(?$borderorspc(\\-|\\+)?(0|(0[xX]))?)(?[0-9a-fA-F]+)(?[ULul]*)(?$borderorspc)/$+{pref}$+{numpart}$+{suf2}/ && ($rest ne $orig_rest)) { $prog = $first.$rest; @@ -463,10 +488,11 @@ ($) my %all_methods = ( - "del_blanks_all" => 0, - "del_blanks" => 1, + "blanks_all" => 0, + "blanks" => 1, "move_func" => 2, "brackets_exclusive" => 2, + "ternary" => 2, "parens_exclusive" => 3, "replace_regex" => 4, "shorten_ints" => 5,