]> sourceware.org Git - automake.git/commitdiff
* lib/Automake/DisjConditions.pm (ambiguous_p): Simplify slightly.
authorRaja R Harinath <harinath@acm.org>
Sat, 9 Aug 2003 20:11:45 +0000 (20:11 +0000)
committerRaja R Harinath <harinath@acm.org>
Sat, 9 Aug 2003 20:11:45 +0000 (20:11 +0000)
* lib/Automake/tests/DisjConditions.pl (test_ambig): Test
Automake::Disjunctions::ambiguous_p.

ChangeLog
lib/Automake/DisjConditions.pm
lib/Automake/tests/DisjConditions.pl

index 48ed31bef2007c8215975ae1ef3e5aa2ad78ce2d..684306da2e0e1216077c342f847431b09e68177a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-08-09  Raja R Harinath  <harinath@acm.org>
+
+       * 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  <adl@gnu.org>
 
        * lib/Automake/Variable.pm (condition_ambiguous_p): Move ...
index 633ba5b9395bf3e5be01c1cf15467dbc5ec5f934..ae183314b91a3c2ce9396afec86e63d1d0715421 100644 (file)
@@ -444,8 +444,8 @@ sub sub_conditions ($$)
 =item C<($string, $ambig_cond) = $condset-E<gt>ambiguous_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<Condition> 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
index 629908760d01d9249f2144462e5219d40e84bf07..02ab61c3f6bd9606e4797b6abb652764fc21fb8b 100644 (file)
@@ -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:
This page took 0.037459 seconds and 5 git commands to generate.