[Top][All Lists]
[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
- Re: [Automake-NG] [PATCH 02/15] [ng] vars: get rid of VAR_SORTED type, (continued)
[Automake-NG] [PATCH 04/15] [ng] tests: spy behaviour of '+=' with GNU make, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 05/15] [ng] tests: Automake should let us append to undefined variables (someday), Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 07/15] [ng] VarDef: store comments and values as a perl array,
Stefano Lattarini <=
[Automake-NG] [PATCH 03/15] [ng] vars: get rid of VAR_SILENT type, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 08/15] [ng] vars: simplify logic for appending conditionally, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 06/15] [ng] refactor: support comments only for VarDef, not for ItemDef too, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 09/15] [ng] vars: keep track of conditionals in appended values and comments, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 11/15] [ng] refactor: change signature of 'define_variable()', Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 13/15] [ng] rename: define_pretty_variable -> define_cond_variable(), Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 10/15] [ng] vars: get rid of VAR_ASIS / VAR_PRETTY distinction, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 15/15] [ng] vars: remove some safety checks in Automake::Variable::define, Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 12/15] [ng] cleanup: prefer 'define_variable' over 'define_pretty_variable', Stefano Lattarini, 2012/05/25
[Automake-NG] [PATCH 14/15] [ng] cosmetics: avoid redundant use of '&' in subroutine calls, Stefano Lattarini, 2012/05/25