summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Lattarini <stefano.lattarini@gmail.com>2012-05-03 10:14:38 +0200
committerStefano Lattarini <stefano.lattarini@gmail.com>2012-05-25 11:05:40 +0200
commit620d1508bb9a008c236d25be822e5fc2d4a0eaca (patch)
tree32310a4f815455e7564927d0906bccf8094f4cf6
parentcec1b21efba4556267776609e0c308181426387c (diff)
downloadautomake-620d1508bb9a008c236d25be822e5fc2d4a0eaca.tar.gz
[ng] VarDef: store comments and values as a perl array
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>
-rw-r--r--Makefile.am1
-rw-r--r--lib/Automake/VarDef.pm37
2 files changed, 19 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am
index 3eeb0327e..c4f6fdc13 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 e67b136fa..c40dc16cb 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";