automake-ng
[Top][All Lists]
Advanced

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

[Automake-NG] [PATCH 07/15] [ng] VarDef: store comments and values as a


From: Stefano Lattarini
Subject: [Automake-NG] [PATCH 07/15] [ng] VarDef: store comments and values as a perl array
Date: Fri, 25 May 2012 13:38:29 +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 <address@hidden>
---
 Makefile.am            |    1 +
 lib/Automake/VarDef.pm |   37 ++++++++++++++++++-------------------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3eeb032..c4f6fdc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/lib/Automake/VarDef.pm b/lib/Automake/VarDef.pm
index e67b136..c40dc16 100644
--- a/lib/Automake/VarDef.pm
+++ b/lib/Automake/VarDef.pm
@@ -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";
-- 
1.7.9.5




reply via email to

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