automake-patches
[Top][All Lists]
Advanced

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

Re: FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.p


From: Alexandre Duret-Lutz
Subject: Re: FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm
Date: Wed, 13 Nov 2002 21:11:03 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/20.7 (i386-debian-linux-gnu)

>>> "adl" == Alexandre Duret-Lutz <address@hidden> writes:

 adl> I'm installing this.

Hmm no, I forgot to update cond12.test.  
I'm installing this instead.

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

        * automake.in: Don't declare TRUE and FALSE, import them from
        Automake::Conditional.
        * lib/Automake/Conditional.pm (TRUE, FALSE): New constants.
        (new): Simplify using FALSE.
        (reduce): New function, moved from ...
        * automake.in (variable_conditions_reduce): ... here.
        (variable_conditions_recursive_sub, invert_conditions):
        Adjust calls to Automake::Conditional::reduce.
        * tests/cond12.test: Adjust to use Automake::Conditional.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1383
diff -u -r1.1383 automake.in
--- automake.in 7 Nov 2002 23:03:15 -0000       1.1383
+++ automake.in 13 Nov 2002 19:26:10 -0000
@@ -116,7 +116,7 @@
 use Automake::XFile;
 use Automake::Channels;
 use Automake::Location;
-use Automake::Conditional;
+use Automake::Conditional qw/TRUE FALSE/;
 use File::Basename;
 use Tie::RefHash;
 use Carp;
@@ -294,10 +294,6 @@
 # We can't always associate a location to a variable or a rule,
 # when its defined by Automake.  We use INTERNAL in this case.
 use constant INTERNAL => new Automake::Location;
-
-# The TRUE and FALSE conditionals.
-use constant TRUE => new Automake::Conditional;
-use constant FALSE => new Automake::Conditional "FALSE";
 
 
 ## ---------------------------------- ##
@@ -6784,7 +6780,7 @@
        }
       else
        {
-         push (@new_conds, variable_conditions_reduce (@subvar_conds));
+         push (@new_conds, Automake::Conditional::reduce (@subvar_conds));
        }
     }
 
@@ -6824,33 +6820,6 @@
 }
 
 
-# Filter a list of conditionals so that only the exclusive ones are
-# retained.  For example, if both `COND1_TRUE COND2_TRUE' and
-# `COND1_TRUE' are in the list, discard the latter.
-# If the list is empty, return TRUE
-sub variable_conditions_reduce
-{
-  my (@conds) = @_;
-  my @ret = ();
-  my $cond;
-  while (@conds > 0)
-    {
-      $cond = shift @conds;
-
-      # FALSE is absorbent.
-      return FALSE
-       if $cond == FALSE;
-
-      if (! $cond->redundant_wrt (@ret, @conds))
-       {
-         push (@ret, $cond);
-       }
-    }
-
-  return TRUE if @ret == 0;
-  return @ret;
-}
-
 # @CONDS
 # invert_conditions (@CONDS)
 # --------------------------
@@ -6873,7 +6842,7 @@
     # Generate all permutation for all inputs.
     my @perm = map { variable_conditions_permutations ($_->conds); } @conds;
     # Remove redundant conditions.
-    @perm = variable_conditions_reduce @perm;
+    @perm = Automake::Conditional::reduce @perm;
 
     # Now remove all conditions which imply one of the input conditions.
     foreach my $perm (@perm)
Index: lib/Automake/Conditional.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Conditional.pm,v
retrieving revision 1.2
diff -u -r1.2 Conditional.pm
--- lib/Automake/Conditional.pm 8 Oct 2002 17:37:56 -0000       1.2
+++ lib/Automake/Conditional.pm 13 Nov 2002 19:26:12 -0000
@@ -19,6 +19,11 @@
 use strict;
 use Carp;
 
+require Exporter;
+use vars '@ISA', '@EXPORT_OK';
address@hidden = qw/Exporter/;
address@hidden = qw/TRUE FALSE reduce/;
+
 =head1 NAME
 
 Automake::Conditional - record a conjunction of conditions
@@ -67,6 +72,11 @@
   # (Not in this example)
   if ($cond->implies_any ($other, $both)) { ... }
 
+  # Remove superfluous conditions.
+  # (Returns @cons = ($both) in this example, because
+  # $other and $cond are implied by $both.)
+  @conds = Automake::Conditional::reduce ($other, $both, $cond);
+
 =head1 DESCRIPTION
 
 A C<Conditional> is a conjunction of atomic conditions.  In Automake they
@@ -138,7 +148,10 @@
 # associated object conditions.  This is used by `new' to reuse
 # Conditional objects with identical conditions.
 use vars '%_conditional_singletons';
-%_conditional_singletons = ();
+# Do NOT reset this hash here.  It's already empty by default,
+# and any reset would otherwise occur AFTER the `TRUE' and `FALSE'
+# constants definitions.
+#   %_conditional_singletons = ();
 
 sub new ($;@)
 {
@@ -166,7 +179,7 @@
          || ($cond =~ /^(.*)_TRUE$/ && exists $self->{'hash'}{"${1}_FALSE"})
          || ($cond =~ /^(.*)_FALSE$/ && exists $self->{'hash'}{"${1}_TRUE"}))
        {
-         return new Automake::Conditional 'FALSE';
+         return &FALSE;
        }
 
       $self->{'hash'}{$cond} = 1;
@@ -370,10 +383,6 @@
 
 =cut
 
-# $BOOLEAN
-# &conditional_implies_any ($COND, @CONDS)
-# ----------------------------------------
-# Returns true iff $COND implies any of the conditions in @CONDS.
 sub implies_any ($@)
 {
   my ($self, @conds) = @_;
@@ -383,6 +392,55 @@
       return 1 if $cond->true_when ($self);
     }
   return 0;
+}
+
+=head2 Other helper functions
+
+=over 4
+
+=item C<TRUE>
+
+The C<"TRUE"> conditional.
+
+=item C<FALSE>
+
+The C<"FALSE"> conditional.
+
+=cut
+
+use constant TRUE => new Automake::Conditional "TRUE";
+use constant FALSE => new Automake::Conditional "FALSE";
+
+=item C<reduce (@conds)>
+
+Filter a list of conditionals so that only the exclusive ones are
+retained.  For example, if both C<COND1_TRUE COND2_TRUE> and
+C<COND1_TRUE> are in the list, discard the latter.
+If the input list is empty, return C<(TRUE)>.
+
+=cut
+
+sub reduce (@)
+{
+  my (@conds) = @_;
+  my @ret = ();
+  my $cond;
+  while (@conds > 0)
+    {
+      $cond = shift @conds;
+
+      # FALSE is absorbent.
+      return FALSE
+       if $cond == FALSE;
+
+      if (! $cond->redundant_wrt (@ret, @conds))
+       {
+         push (@ret, $cond);
+       }
+    }
+
+  return TRUE if @ret == 0;
+  return @ret;
 }
 
 =head1 HISTORY
Index: tests/cond12.test
===================================================================
RCS file: /cvs/automake/automake/tests/cond12.test,v
retrieving revision 1.4
diff -u -r1.4 cond12.test
--- tests/cond12.test   7 Oct 2002 09:23:33 -0000       1.4
+++ tests/cond12.test   13 Nov 2002 19:26:13 -0000
@@ -18,24 +18,23 @@
 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-# Test behaviour of variable_conditions_reduce()
-# This checks the result of variable_conditions_reduce() for a wide variety
-# of cases.
+# This checks the result of Automake::Conditional::reduce() for
+# a wide variety of cases.
 
 . ./defs || exit 1
 
-# FIXME: probably ought to let use override this like we do in `defs'.
-amfile=../../automake
+set -e
+
+cat << 'END' > run
+use Automake::Conditional;
 
-sed 1q $amfile >>automake_tmp
-cat << 'END' >> automake_tmp
 my $failed = 0;
 sub check_reduce($$) {
  my ($inref, $outref) = @_;
  my @inconds = map { new Automake::Conditional $_ } @$inref;
  my @outconds = map { (new Automake::Conditional $_)->string } @$outref;
  my @res =
-    map { $_->string } (&Automake::variable_conditions_reduce (@inconds));
+    map { $_->string } (Automake::Conditional::reduce (@inconds));
  my $result = join (",", sort @res);
  my $exresult = join (",", @outconds);
 
@@ -99,7 +98,5 @@
 
 exit $failed;
 END
-cat $amfile >>automake_tmp
-chmod +x automake_tmp
-
-./automake_tmp
+chmod +x run
+$PERL -w -I $perllibdir ./run

-- 
Alexandre Duret-Lutz





reply via email to

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