]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] vars: keep track of conditionals in appended values and comments
authorStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 3 May 2012 13:08:39 +0000 (15:08 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 31 May 2012 08:34:21 +0000 (10:34 +0200)
This is a refactoring only needed by later changes.

* lib/Automake/VarDef.pm: Updated methods and constructor.
* lib/Automake/Variable.pm: Callers adjusted.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/Automake/VarDef.pm
lib/Automake/Variable.pm

index c40dc16cb5affda45d3731cd881cb2546ee715a4..be956f281c4124ccac12db8c0debd9227421c860 100644 (file)
@@ -136,9 +136,10 @@ be one of C<VAR_ASIS>, C<VAR_PRETTY>.
 
 =cut
 
-sub new ($$$$$$$$)
+sub new ($$$$$$$$$)
 {
-  my ($class, $var, $value, $comment, $location, $type, $owner, $pretty) = @_;
+  my ($class, $var, $value, $comment, $cond, $location, $type,
+      $owner, $pretty) = @_;
 
   # A user variable must be set by either '=' or ':=', and later
   # promoted to '+='.
@@ -148,28 +149,28 @@ sub new ($$$$$$$$)
     }
 
   my $self = Automake::ItemDef::new ($class, $location, $owner);
-  $self->{'value_list'} = [$value];
+  $self->{'value_list'} = [ { value => $value, cond => $cond } ];
   $self->{'type'} = $type;
   $self->{'pretty'} = $pretty;
   $self->{'seen'} = 0;
-  $self->{'comment_list'} = [$comment];
+  $self->{'comment_list'} = [ { text => $comment, cond => $cond } ];
   return $self;
 }
 
-=item C<$def-E<gt>append ($value, $comment)>
+=item C<$def-E<gt>append ($value, $comment, $cond)>
 
-Append C<$value> and <$comment> to the existing value and comment of
-C<$def>.  This is normally called on C<+=> definitions.
+Append C<$value> and C<$comment> to the existing value and comment of
+C<$def> in condition C<$cond>.  This is normally called on C<+=>
+definitions.
 
 =cut
 
 sub append ($$$)
 {
-  my ($self, $value, $comment) = @_;
+  my ($self, $value, $comment, $cond) = @_;
 
-  push @{$self->{'comment_list'}}, $comment;
-
-  push @{$self->{'value_list'}}, $value;
+  push @{$self->{'comment_list'}}, { text => $comment, cond => $cond };
+  push @{$self->{'value_list'}}, { value => $value, cond => $cond };
   # Turn ASIS appended variables into PRETTY variables.  This is to
   # cope with 'make' implementation that cannot read very long lines.
   $self->{'pretty'} = VAR_PRETTY if $self->{'pretty'} == VAR_ASIS;
@@ -204,13 +205,13 @@ sub value ($)
 sub comment ($)
 {
   my ($self) = @_;
-  return join ("", @{$self->{'comment_list'}});
+  return join ("", map { $_->{text} } @{$self->{'comment_list'}});
 }
 
 sub raw_value ($)
 {
   my ($self) = @_;
-  my @values = @{$self->{'value_list'}};
+  my @values = map { $_->{value} } @{$self->{'value_list'}};
 
   # Strip comments from augmented variables.  This is so that
   #   VAR = foo # com
index 0c83b6650466ac7b627880286d8557740a51b263..9c51c9e74837b29eb0d76d1630200d17d2e8ceab 100644 (file)
@@ -797,7 +797,7 @@ sub define ($$$$$$$$)
   # 1. append (+=) to a variable defined for current condition
   if ($type eq '+' && ! $new_var)
     {
-      $def->append ($value, $comment);
+      $def->append ($value, $comment, $cond);
       # Only increase owners.  A VAR_CONFIGURE variable augmented in a
       # Makefile.am becomes a VAR_MAKEFILE variable.
       $def->set_owner ($owner, $where->clone)
@@ -872,8 +872,8 @@ sub define ($$$$$$$$)
       # Assignments to a macro set its location.  We don't adjust
       # locations for '+='.  Ideally I suppose we would associate
       # line numbers with random bits of text.
-      $def = new Automake::VarDef ($var, $value, $comment, $where->clone,
-                                  $type, $owner, $pretty);
+      $def = new Automake::VarDef ($var, $value, $comment, $cond,
+                                   $where->clone, $type, $owner, $pretty);
       $self->set ($cond, $def);
       push @_var_order, $var;
     }