[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm
From: |
Alexandre Duret-Lutz |
Subject: |
FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm |
Date: |
Wed, 13 Nov 2002 20:16:24 +0100 |
User-agent: |
Gnus/5.090008 (Oort Gnus v0.08) Emacs/20.7 (i386-debian-linux-gnu) |
I'm installing this.
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.
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:10:15 -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:10:16 -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
--
Alexandre Duret-Lutz
- FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm,
Alexandre Duret-Lutz <=
- Re: FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm, Alexandre Duret-Lutz, 2002/11/13
- Re: FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm, Raja R Harinath, 2002/11/13
- Re: FYI: move TRUE, FALSE, & variable_conditions_reduce to Conditional.pm, Alexandre Duret-Lutz, 2002/11/14
- lib/Automake/ test suite, Alexandre Duret-Lutz, 2002/11/18
- Re: lib/Automake/ test suite, Raja R Harinath, 2002/11/18
- Re: lib/Automake/ test suite, Alexandre Duret-Lutz, 2002/11/18