From 29b2c1f68bafeda5c8967b03460f8fdf647b309e Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Wed, 13 Nov 2002 20:11:31 +0000 Subject: [PATCH] * 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. --- ChangeLog | 12 +++++++ automake.in | 37 ++----------------- lib/Automake/Conditional.pm | 72 +++++++++++++++++++++++++++++++++---- tests/cond12.test | 21 +++++------ 4 files changed, 89 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87f54cd3..e2c036ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2002-11-13 Alexandre Duret-Lutz + + * 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. + 2002-11-09 Jim Meyering Make install-sh work even when names contain spaces or diff --git a/automake.in b/automake.in index 13c7edd2..aa75ec2f 100755 --- a/automake.in +++ b/automake.in @@ -116,7 +116,7 @@ use Automake::General; 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 @@ use constant COMPILE_ORDINARY => 2; # 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 @@ sub variable_conditions_recursive_sub } else { - push (@new_conds, variable_conditions_reduce (@subvar_conds)); + push (@new_conds, Automake::Conditional::reduce (@subvar_conds)); } } @@ -6824,33 +6820,6 @@ sub variable_conditions_recursive_sub } -# 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 @@ sub invert_conditions # 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) diff --git a/lib/Automake/Conditional.pm b/lib/Automake/Conditional.pm index 26a16a5c..31e02515 100644 --- a/lib/Automake/Conditional.pm +++ b/lib/Automake/Conditional.pm @@ -19,6 +19,11 @@ package Automake::Conditional; use strict; use Carp; +require Exporter; +use vars '@ISA', '@EXPORT_OK'; +@ISA = qw/Exporter/; +@EXPORT_OK = qw/TRUE FALSE reduce/; + =head1 NAME Automake::Conditional - record a conjunction of conditions @@ -67,6 +72,11 @@ Automake::Conditional - record a conjunction of conditions # (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 is a conjunction of atomic conditions. In Automake they @@ -138,7 +148,10 @@ both create the C<"FALSE"> conditional). # 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 @@ sub new ($;@) || ($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 @@ Return 0 otherwise. =cut -# $BOOLEAN -# &conditional_implies_any ($COND, @CONDS) -# ---------------------------------------- -# Returns true iff $COND implies any of the conditions in @CONDS. sub implies_any ($@) { my ($self, @conds) = @_; @@ -385,13 +394,62 @@ sub implies_any ($@) return 0; } +=head2 Other helper functions + +=over 4 + +=item C + +The C<"TRUE"> conditional. + +=item C + +The C<"FALSE"> conditional. + +=cut + +use constant TRUE => new Automake::Conditional "TRUE"; +use constant FALSE => new Automake::Conditional "FALSE"; + +=item C + +Filter a list of conditionals so that only the exclusive ones are +retained. For example, if both C and +C 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 Cs and supporting code were added to Automake 1.1o by Ian Lance Taylor in 1997. Since then it has been improved by Tom Tromey , Richard Boulton , Raja R Harinath , and -Akim Demaile . Alexandre Duret-Lutz +Akim Demaille . Alexandre Duret-Lutz extracted the code out of Automake to create this package in 2002. =cut diff --git a/tests/cond12.test b/tests/cond12.test index cfcd7e3f..a5170270 100755 --- a/tests/cond12.test +++ b/tests/cond12.test @@ -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 @@ check_reduce(["FOO BAR", "BAR FOO"], ["BAR FOO"]); exit $failed; END -cat $amfile >>automake_tmp -chmod +x automake_tmp - -./automake_tmp +chmod +x run +$PERL -w -I $perllibdir ./run -- 2.43.5