@@ -1961,124 +1961,32 @@ sub nextDate
1961
1961
1962
1962
package ReadBaselineSource ;
1963
1963
1964
+ use base ' ReadCurrentSource' ;
1965
+
1964
1966
sub new
1965
1967
{
1966
1968
my ($class , $diffData ) = @_ ;
1967
1969
1968
- my $self = [$diffData , ReadCurrentSource-> new()];
1969
- bless $self , $class ;
1970
+ my $self = $class -> SUPER::new();
1971
+ push (@$self , $diffData );
1972
+
1970
1973
return $self ;
1971
1974
}
1972
1975
1973
1976
sub open
1974
1977
{
1975
1978
my ($self , $filename ) = @_ ;
1979
+ my $diffmap = $self -> [1];
1980
+ if (defined ($diffmap ) && $diffmap -> containsFile($filename )) {
1981
+ # if there are any diffs, then need to load the current source, then
1982
+ # walk the diff to insert and remove changed lines
1976
1983
1977
- $self -> [1]-> open ($filename , " baseline " );
1978
- $self -> [1]-> notEmpty() or
1979
- die (" unable to read baseline '$filename '" );
1980
- $self -> [2] = $filename ;
1981
- }
1982
-
1983
- sub close
1984
- {
1985
- my $self = shift ;
1986
- $self -> [1]-> close ();
1987
- }
1988
-
1989
- sub notEmpty
1990
- {
1991
- my $self = shift ;
1992
- return $self -> [1]-> notEmpty();
1993
- }
1994
-
1995
- sub isOutOfRange
1996
- {
1997
- my $self = shift ;
1998
- return $self -> [1]-> isOutOfRange(@_ );
1999
- }
2000
-
2001
- sub isExcluded
2002
- {
2003
- my $self = shift ;
2004
- return $self -> [1]-> isExcluded(@_ );
2005
- }
2006
-
2007
- sub filename
2008
- {
2009
- return $_ [0]-> [2];
2010
- }
2011
-
2012
- sub getLine
2013
- {
2014
- my ($self , $line ) = @_ ;
2015
- my ($map , $reader , $filename ) = @$self ;
2016
- my $type = $map -> type($filename , $map -> OLD, $line );
2017
- if ($type ne ' delete' ) {
2018
- my $currLine = $map -> lookup($filename , $map -> OLD, $line );
2019
- return $reader -> getLine($currLine );
2020
- } else {
2021
- # deleted line...we don't really care what it looked like
2022
- # return empty - so the line gets treated as not conditional
2023
- return undef ;
1984
+ my $currentSrc = $self -> _load($filename , ' baseline' );
1985
+ my $src = $diffmap -> recreateBaseline($filename , $currentSrc );
1986
+ return $self -> parseLines($filename , $src );
2024
1987
}
2025
- }
2026
-
2027
- sub isCharacter
2028
- {
2029
- my $self = shift ;
2030
- return $self -> [1]-> isCharacter(@_ );
2031
- }
2032
-
2033
- sub isCloseBrace
2034
- {
2035
- my ($self , $line ) = @_ ;
2036
- my ($map , $reader , $filename ) = @$self ;
2037
- my $type = $map -> type($filename , $map -> OLD, $line );
2038
- if ($type ne ' delete' ) {
2039
- my $currLine = $map -> lookup($filename , $map -> OLD, $line );
2040
- return $reader -> isCloseBrace($currLine );
2041
- } else {
2042
- return 0;
2043
- }
2044
- }
2045
-
2046
- sub containsConditional
2047
- {
2048
- my ($self , $line ) = @_ ;
2049
- my ($map , $reader , $filename ) = @$self ;
2050
- my $type = $map -> type($filename , $map -> OLD, $line );
2051
- if ($type ne ' delete' ) {
2052
- my $currLine = $map -> lookup($filename , $map -> OLD, $line );
2053
- return $reader -> containsConditional($currLine );
2054
- } else {
2055
- return 1; # we don't know - so just go with what gcov said
2056
- }
2057
- }
2058
-
2059
- sub containsTrivialFunction
2060
- {
2061
- my ($self , $line ) = @_ ;
2062
- my ($map , $reader , $filename ) = @$self ;
2063
- my $type = $map -> type($filename , $map -> OLD, $line );
2064
- if ($type ne ' delete' ) {
2065
- my $currLine = $map -> lookup($filename , $map -> OLD, $line );
2066
- return $reader -> containsTrivialFunction($currLine );
2067
- } else {
2068
- return 0; # we don't know - assume not
2069
- }
2070
- }
2071
-
2072
- sub suppressCloseBrace
2073
- {
2074
- my $self = shift ;
2075
- return $self -> [1]-> isCharacter(@_ );
2076
- }
2077
-
2078
- sub isBlank
2079
- {
2080
- my $self = shift ;
2081
- return $self -> [1]-> isBlank(@_ );
1988
+ # else no diff data here - just read the file
1989
+ return ReadCurrentSource::open ($self , $filename , ' baseline' );
2082
1990
}
2083
1991
2084
1992
package LineData ;
@@ -3176,15 +3084,16 @@ package DiffMap;
3176
3084
# that would be more consistent and might execute faster.
3177
3085
3178
3086
use constant {
3179
- LINEMAP => 0,
3180
- FILEMAP => 1,
3087
+ LINEMAP => 0,
3088
+ FILEMAP => 1,
3089
+ BASELINE => 2,
3181
3090
# keep track of line number where file entry is found in diff file
3182
3091
# - use line number in error messages.
3183
- DIFF_FILENAME => 2 ,
3184
- LOCATION => 3 ,
3185
- UNCHANGED => 4 ,
3186
- ALIASES => 5 ,
3187
- DIFF_ROOT => 6 ,
3092
+ DIFF_FILENAME => 3 ,
3093
+ LOCATION => 4 ,
3094
+ UNCHANGED => 5 ,
3095
+ ALIASES => 6 ,
3096
+ DIFF_ROOT => 7 ,
3188
3097
3189
3098
OLD => 0,
3190
3099
NEW => 1,
@@ -3199,6 +3108,7 @@ sub new
3199
3108
my $class = shift ;
3200
3109
my $self = [{}, # linemap
3201
3110
{}, # filemap
3111
+ {}, # baseline: filename -> baseline lineno -> text
3202
3112
undef , # diff filename
3203
3113
[{}, {}], # def location
3204
3114
# element 0: old filename -> line number where this
@@ -3297,6 +3207,32 @@ sub containsFile
3297
3207
return exists ($self -> [LINEMAP]-> {$file });
3298
3208
}
3299
3209
3210
+ sub recreateBaseline
3211
+ {
3212
+ my ($self , $filename , $currentSrcLines ) = @_ ;
3213
+
3214
+ my $diffs = $self -> [LINEMAP]-> {$self -> findName($filename )};
3215
+ die (" no diff data for $filename " ) unless defined $diffs ;
3216
+
3217
+ my $deleted = $self -> [BASELINE]-> {$self -> findName($filename )};
3218
+ my @lines ;
3219
+ foreach my $chunk (@$diffs ) {
3220
+ if ($chunk -> [TYPE] eq ' equal' ) {
3221
+ my ($from , $to ) = @{$chunk -> [NEW]};
3222
+ push (@lines , @{$currentSrcLines }[($from - 1) .. ($to - 1)]);
3223
+ } elsif ($chunk -> [TYPE] eq ' delete' ) {
3224
+ my $r = $chunk -> [OLD];
3225
+ for (my $i = $r -> [_START]; $i <= $r -> [_END]; ++$i ) {
3226
+ die (" missing baseline line $i " )
3227
+ unless defined ($deleted ) && exists ($deleted -> {$i });
3228
+ push (@lines , $deleted -> {$i });
3229
+ }
3230
+ }
3231
+ # else 'insert': nothing to do/those lines are not in baseline
3232
+ }
3233
+ return \@lines ;
3234
+ }
3235
+
3300
3236
sub lookup
3301
3237
{
3302
3238
my ($self , $file , $vers , $line ) = @_ ;
@@ -3760,20 +3696,31 @@ sub _read_udiff
3760
3696
};
3761
3697
# Line as seen in old file
3762
3698
# <line starts with '-'>
3763
- / ^-/ && do {
3699
+ / ^-(.*) $ / && do {
3764
3700
if ($old_block == 0 && $new_block == 0) {
3765
3701
last ;
3766
3702
}
3703
+ my $baseline_lineno = $chunk -> [OLD]-> [_END] + 1;
3704
+ # really only need to keep track of baseline content if user
3705
+ # is planning on doing any filtering
3706
+ my $lines ;
3707
+ if (exists ($self -> [BASELINE]-> {$file_old })) {
3708
+ $lines = $self -> [BASELINE]-> {$file_old };
3709
+ } else {
3710
+ $lines = {};
3711
+ $self -> [BASELINE]-> {$file_old } = $lines ;
3712
+ }
3713
+ $lines -> {$baseline_lineno } = $1 ;
3714
+
3767
3715
if ($chunk -> [TYPE] ne " delete" ) {
3768
3716
if ($filename ) {
3769
3717
push (@{$self -> [LINEMAP]-> {$filename }}, $chunk );
3770
3718
_printChunk($chunk ) if ($verbose );
3771
3719
}
3772
- $chunk = _newChunk(' delete' ,
3773
- $chunk -> [OLD]-> [_END] + 1,
3720
+ $chunk = _newChunk(' delete' , $baseline_lineno ,
3774
3721
$chunk -> [NEW]-> [_END]);
3775
3722
} else {
3776
- $chunk -> [OLD]-> [_END] += 1 ;
3723
+ $chunk -> [OLD]-> [_END] = $baseline_lineno ;
3777
3724
}
3778
3725
last ;
3779
3726
};
@@ -6824,11 +6771,11 @@ sub print_overall_rate($$$$$)
6824
6771
sub gen_html ()
6825
6772
{
6826
6773
# "Read
6827
- my $readSourceFile = ReadCurrentSource-> new();
6828
6774
6829
6775
# Read in all specified .info files
6830
- my $now = Time::HiRes::gettimeofday();
6831
- ($current_data ) = AggregateTraces::merge(@info_filenames );
6776
+ my $now = Time::HiRes::gettimeofday();
6777
+ my $readSourceFile = ReadCurrentSource-> new();
6778
+ ($current_data ) = AggregateTraces::merge($readSourceFile , @info_filenames );
6832
6779
my $then = Time::HiRes::gettimeofday();
6833
6780
$lcovutil::profileData {parse_current } = $then - $now ;
6834
6781
@@ -6854,7 +6801,7 @@ sub gen_html()
6854
6801
# Read baseline file
6855
6802
6856
6803
$now = Time::HiRes::gettimeofday();
6857
- ($base_data ) = AggregateTraces::merge(@base_filenames );
6804
+ ($base_data ) = AggregateTraces::merge($readBaseSource , @base_filenames );
6858
6805
info(" Found %d baseline entries.\n " , scalar ($base_data -> files()));
6859
6806
$then = Time::HiRes::gettimeofday();
6860
6807
$lcovutil::profileData {parse_baseline } = $then - $now ;
0 commit comments