automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FYI: simplify variable_not_always_defined_in_cond


From: Alexandre Duret-Lutz
Subject: Re: FYI: simplify variable_not_always_defined_in_cond
Date: Wed, 20 Nov 2002 23:32:28 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/20.7 (i386-debian-linux-gnu)

>>> "Raja" == Raja R Harinath <address@hidden> writes:

 Raja> The inner loop can become A::C::strip, as a counterpart
 Raja> to A::C::merge.

Just ask :)  I'm checking this in.

2002-11-20  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/Conditional.pm (strip): New function.
        * lib/Automake/ConditionalSet.pm (sub_conditions): Use it.
        Suggested by Raja R Harinath.

Index: lib/Automake/Conditional.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Conditional.pm,v
retrieving revision 1.7
diff -u -r1.7 Conditional.pm
--- lib/Automake/Conditional.pm 20 Nov 2002 22:03:56 -0000      1.7
+++ lib/Automake/Conditional.pm 20 Nov 2002 22:31:31 -0000
@@ -44,6 +44,10 @@
   # Likewise, but using a list of atomic conditional strings
   my $both2 = $cond->merge_conds ("COND3_FALSE");
 
+  # Strip from $both any subconditions which are in $other.
+  # This is the opposite of merge.
+  $cond = $both->strip ($other);
+
   # Return the list of conditions ("COND1_TRUE", "COND2_FALSE"):
   my @conds = $cond->conds;
 
@@ -226,6 +230,24 @@
 {
   my ($self, @conds) = @_;
   new Automake::Conditional $self->conds, @conds;
+}
+
+=item C<$newcond = $cond-E<gt>strip ($minuscond)>
+
+Return a new condition which has all the subconditions of C<$cond>
+except those of C<$minuscond>.  This is the opposite of C<merge>.
+
+=cut
+
+sub strip ($$)
+{
+  my ($self, $minus) = @_;
+  my @res;
+  foreach my $cond ($self->conds)
+    {
+      push @res, $cond unless $minus->has ($cond);
+    }
+  return new Automake::Conditional @res;
 }
 
 =item C<@list = $cond-E<gt>conds>
Index: lib/Automake/ConditionalSet.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/ConditionalSet.pm,v
retrieving revision 1.8
diff -u -r1.8 ConditionalSet.pm
--- lib/Automake/ConditionalSet.pm      20 Nov 2002 22:03:57 -0000      1.8
+++ lib/Automake/ConditionalSet.pm      20 Nov 2002 22:31:32 -0000
@@ -52,6 +52,13 @@
   # that complements $set.
   my $inv = $set->invert;
 
+  # Multiply two ConditionalSets.
+  my $prod = $set1->multiply ($set2)
+
+  # Return the subconditions of a ConditionalSet with respect to
+  # a Conditional.  See the description for a real example.
+  my $subconds = $set->sub_conditions ($cond)
+
 =head1 DESCRIPTION
 
 A C<ConditionalSet> is a disjunction of atomic conditions.  In
@@ -712,7 +719,6 @@
 sub sub_conditions ($$)
 {
   my ($self, $subcond) = @_;
-  my @res;
 
   # Make $subcond blindingly apparent in the ConditionalSet.
   # For instance `$a->_multiply($b)' (from the POD example) is:
@@ -723,19 +729,11 @@
   #     new Automake::Conditional ("FALSE"));
   my $prod = $self->_multiply ($subcond);
 
-  # Now, strip $subcond from the non-false Conditionals.
+  # Now, strip $subcond from the remaining (i.e., non-false) Conditionals.
+  my @res;
   foreach my $c ($prod->conds)
     {
-      if (! $c->false)
-       {
-         my @rescond;
-         foreach my $cc ($c->conds)
-           {
-             push @rescond, $cc
-               unless $subcond->has ($cc);
-           }
-         push @res, new Automake::Conditional @rescond;
-       }
+      push @res, $c->strip ($subcond) unless $c->false;
     }
   return new Automake::ConditionalSet @res;
 }

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]