]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] VarDef: store comments and values as a perl array
authorStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 3 May 2012 08:14:38 +0000 (10:14 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 25 May 2012 09:05:40 +0000 (11:05 +0200)
This is a preparatory refactoring in view of a planned change to
how the definitions of make variables augmented with '+=' are
output in the generated Makefiles.

* t/comments-in-var-def.sh: New xfailing test, shows an example of the
improved semantic for variable definitions/additions we want to reach
eventually.
* Makefile.am (XFAIL_TESTS): Add it.
* lib/Automake/VarDef.pm (new): Store values and comments for the
variable in array references, not in scalars.
(append): Just append the passed value and comment to those arrays,
without preprocessing.  The existing preprocessing has been moved ...
(raw_value): ... to this accessor function.
(comment, dump): Adjust.

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

index 3eeb0327ec869debd90547b97a53441e511651ce..c4f6fdc136977f0b156b754218fd4231b0aef96c 100644 (file)
@@ -375,6 +375,7 @@ XFAIL_TESTS = \
   t/all.sh \
   t/yacc-bison-skeleton-cxx.sh \
   t/yacc-bison-skeleton.sh \
+  t/comments-in-var-def.sh \
   t/cond17.sh \
   t/dist-srcdir2.sh \
   t/gcj6.sh \
index e67b136fabc675d2a6548faf2a76512d47be71da..c40dc16cb5affda45d3731cd881cb2546ee715a4 100644 (file)
@@ -148,11 +148,11 @@ sub new ($$$$$$$$)
     }
 
   my $self = Automake::ItemDef::new ($class, $location, $owner);
-  $self->{'comment'} = $comment;
-  $self->{'value'} = $value;
+  $self->{'value_list'} = [$value];
   $self->{'type'} = $type;
   $self->{'pretty'} = $pretty;
   $self->{'seen'} = 0;
+  $self->{'comment_list'} = [$comment];
   return $self;
 }
 
@@ -166,21 +166,10 @@ C<$def>.  This is normally called on C<+=> definitions.
 sub append ($$$)
 {
   my ($self, $value, $comment) = @_;
-  $self->{'comment'} .= $comment;
 
-  my $val = $self->{'value'};
+  push @{$self->{'comment_list'}}, $comment;
 
-  # Strip comments from augmented variables.  This is so that
-  #   VAR = foo # com
-  #   VAR += bar
-  # does not become
-  #   VAR = foo # com bar
-  # Furthermore keeping '#' would not be portable if the variable is
-  # output on multiple lines.
-  $val =~ s/ ?#.*//;
-  # Insert a separator, if required.
-  $val .= ' ' if $val;
-  $self->{'value'} = $val . $value;
+  push @{$self->{'value_list'}}, $value;
   # 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;
@@ -203,6 +192,7 @@ sub value ($)
 {
   my ($self) = @_;
   my $val = $self->raw_value;
+
   # Strip anything past '#'.  '#' characters cannot be escaped
   # in Makefiles, so we don't have to be smart.
   $val =~ s/#.*$//s;
@@ -214,13 +204,23 @@ sub value ($)
 sub comment ($)
 {
   my ($self) = @_;
-  return $self->{'comment'};
+  return join ("", @{$self->{'comment_list'}});
 }
 
 sub raw_value ($)
 {
   my ($self) = @_;
-  return $self->{'value'};
+  my @values = @{$self->{'value_list'}};
+
+  # Strip comments from augmented variables.  This is so that
+  #   VAR = foo # com
+  #   VAR += bar
+  # does not become
+  #   VAR = foo # com bar
+  # Furthermore keeping '#' would not be portable if the variable is
+  # output on multiple lines.
+  map { s/ ?#.*// } @values;
+  return join (' ', @values);
 }
 
 sub type ($)
@@ -306,13 +306,12 @@ sub dump ($)
     }
 
   my $where = $self->location->dump;
-  my $comment = $self->comment;
   my $value = $self->raw_value;
   my $type = $self->type;
 
   return "{
       type: $type=
-      where: $where      comment: $comment
+      where: $where
       value: $value
       owner: $owner
     }\n";