=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
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
}
}
+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: