from Raja R Harinath
* lib/Automake/Condition.pm (multiply): New.
* lib/Automake/DisjConditions.pm (_multiply): Use it.
(sub_conditions): Likewise.
diff -u lib/Automake/Condition.pm lib/Automake/Condition.pm
--- lib/Automake/Condition.pm
+++ lib/Automake/Condition.pm
@@ -495,6 +495,37 @@
return @res;
}
+=item C<$cond-Emultiply (@conds)>
+
+Assumption: @conds represent a disjunction of conditions
+
+Return the result of multiplying $self with that disjunction. The
+result will be another list of conditions suitable to construct a
+C.
+
+=cut
+
+sub multiply ($@)
+{
+ my ($self, @set) = @_;
+ my %res = ();
+ for my $cond (@set)
+ {
+ my $ans = $self->merge ($cond);
+ $res{$ans} = $ans;
+ }
+
+ # FALSE can always be removed from a disjunction.
+ delete $res{FALSE};
+
+ # Now, $self is a common factor of the remaining conditions.
+ # If one of the conditions is $self, we can discard the rest.
+ return ($self,())
+ if exists $res{$self};
+
+ return (values %res);
+}
+
=head2 Other helper functions
=over 4
diff -u lib/Automake/DisjConditions.pm lib/Automake/DisjConditions.pm
--- lib/Automake/DisjConditions.pm
+++ lib/Automake/DisjConditions.pm
@@ -317,14 +317,7 @@
sub _multiply ($@)
{
my ($self, @set) = @_;
- my @res = ();
- foreach my $selfcond ($self->conds)
- {
- foreach my $setcond (@set)
- {
- push @res, $selfcond->merge ($setcond);
- }
- }
+ my @res = map { $_->multiply (@set) } $self->conds;
return new Automake::DisjConditions (Automake::Condition::reduce_or @res);
}
@@ -630,7 +623,9 @@
=item C<$self-Esub_conditions ($cond)>
Return the subconditions of C<$self> that contains C<$cond>, with
-C<$cond> stripped.
+C<$cond> stripped. More formally, return $res such that
+$res->_multiply($cond) == $self->_multiply($cond) and $res does not
+mention any of the variables in $cond.
For instance, consider:
@@ -656,17 +651,16 @@
my ($self, $subcond) = @_;
# Make $subcond blindingly apparent in the DisjConditions.
- # For instance `$a->_multiply($b)' (from the POD example) is:
- # new Automake::DisjConditions
+ # For instance `$b->multiply($a->conds)' (from the POD example) is:
# (new Automake::Condition ("FALSE"),
# new Automake::Condition ("A_TRUE", "B_FALSE", "C_FALSE"),
# new Automake::Condition ("A_TRUE", "B_FALSE", "C_TRUE"),
- # new Automake::Condition ("FALSE"));
- my $prod = $self->_multiply ($subcond);
+ # new Automake::Condition ("FALSE"))
+ my @prodconds = $subcond->multiply($self->conds);
# Now, strip $subcond from the remaining (i.e., non-false) Conditions.
my @res;
- foreach my $c ($prod->conds)
+ foreach my $c (@prodconds)
{
push @res, $c->strip ($subcond) unless $c->false;
}