From: Raja R Harinath Date: Sat, 9 Aug 2003 20:11:45 +0000 (+0000) Subject: * lib/Automake/DisjConditions.pm (ambiguous_p): Simplify slightly. X-Git-Tag: Release-1-7b~80 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=b3a9ce5aeb7f679446ea1ea714e9b1bb8f222600;p=automake.git * lib/Automake/DisjConditions.pm (ambiguous_p): Simplify slightly. * lib/Automake/tests/DisjConditions.pl (test_ambig): Test Automake::Disjunctions::ambiguous_p. --- diff --git a/ChangeLog b/ChangeLog index 48ed31be..684306da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-08-09 Raja R Harinath + + * lib/Automake/DisjConditions.pm (ambiguous_p): Simplify slightly. + * lib/Automake/tests/DisjConditions.pl (test_ambig): Test + Automake::Disjunctions::ambiguous_p. + 2003-08-07 Alexandre Duret-Lutz * lib/Automake/Variable.pm (condition_ambiguous_p): Move ... diff --git a/lib/Automake/DisjConditions.pm b/lib/Automake/DisjConditions.pm index 633ba5b9..ae183314 100644 --- a/lib/Automake/DisjConditions.pm +++ b/lib/Automake/DisjConditions.pm @@ -444,8 +444,8 @@ sub sub_conditions ($$) =item C<($string, $ambig_cond) = $condset-Eambiguous_p ($what, $cond)> Check for an ambiguous condition. Return an error message and the -other condition involved if we have an ambiguity. Return two empty -strings otherwise. +other condition involved if we have an ambiguity. Return an empty +string and FALSE otherwise. C<$what> is the name of the thing being defined, to use in the error message. C<$cond> is the C under which it is being @@ -456,41 +456,35 @@ already been defined. sub ambiguous_p ($$$) { - my ($condset, $var, $cond) = @_; - - foreach my $vcond ($condset->conds) + my ($self, $var, $cond) = @_; + + # Note that these rules doesn't consider the following + # example as ambiguous. + # + # if COND1 + # FOO = foo + # endif + # if COND2 + # FOO = bar + # endif + # + # It's up to the user to not define COND1 and COND2 + # simultaneously. + + return ("$var multiply defined in condition " . $cond->human, $cond) + if exists $self->{'hash'}{$cond}; + + foreach my $vcond ($self->conds) { - # Note that these rules doesn't consider the following - # example as ambiguous. - # - # if COND1 - # FOO = foo - # endif - # if COND2 - # FOO = bar - # endif - # - # It's up to the user to not define COND1 and COND2 - # simultaneously. - my $message; - if ($vcond eq $cond) - { - return ("$var multiply defined in condition " . $cond->human, - $vcond); - } - elsif ($vcond->true_when ($cond)) - { - return ("$var was already defined in condition " . $vcond->human - . ", which implies condition ". $cond->human, $vcond); - } - elsif ($cond->true_when ($vcond)) - { - return ("$var was already defined in condition " - . $vcond->human . ", which is implied by condition " - . $cond->human, $vcond); - } + return ("$var was already defined in condition " . $vcond->human + . ", which includes condition ". $cond->human, $vcond) + if $vcond->true_when ($cond); + + return ("$var was already defined in condition " . $vcond->human + . ", which is included in condition " . $cond->human, $vcond) + if $cond->true_when ($vcond); } - return ('', ''); + return ('', FALSE); } =head1 SEE ALSO diff --git a/lib/Automake/tests/DisjConditions.pl b/lib/Automake/tests/DisjConditions.pl index 62990876..02ab61c3 100644 --- a/lib/Automake/tests/DisjConditions.pl +++ b/lib/Automake/tests/DisjConditions.pl @@ -314,10 +314,58 @@ sub test_sub_conditions () } } +sub test_ambig () +{ + my @tests = ([[["TRUE"]], + ["TRUE"], + "multiply defined"], + [[["C1_TRUE"]], + ["C1_TRUE"], + "multiply defined"], + [[["TRUE"]], + ["C1_FALSE"], + "which includes"], + [[["C1_TRUE"]], + ["C1_TRUE", "C2_TRUE"], + "which includes"], + [[["C1_TRUE", "C2_TRUE"]], + ["C2_TRUE"], + "which is included in"], + [[["C1_TRUE"]], + ["C2_TRUE"], + ''], + [[["C1_TRUE"], + ["C2_FALSE"]], + ["C1_FALSE", "C2_TRUE"], + '']); + + for my $t (@tests) + { + my $t1 = build_set @{$t->[0]}; + my $t2 = new Automake::Condition @{$t->[1]}; + my $t3 = $t->[2]; + my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2); + if ($t3 && $ans !~ /FOO.*$t3/) + { + print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t" + . "Error message '$ans' does not match '$t3'\n"; + return 1; + } + if (!$t3 && $ans ne '') + { + print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t" + . "Unexpected error message: $ans\n"; + return 1; + } + } + return 0; +} + exit (test_basics || test_invert || test_simplify - || test_sub_conditions); + || test_sub_conditions + || test_ambig); ### Setup "GNU" style for perl-mode and cperl-mode. ## Local Variables: