@@ -4075,10 +4075,7 @@ use constant {
4075
4075
4076
4076
sub new
4077
4077
{
4078
- # countdata may be 'undef'
4079
- my ($class , $filepath , $fileSummary , $fileCovInfo , $countdata ,
4080
- $hasNoBaselineData )
4081
- = @_ ;
4078
+ my ($class , $filepath , $fileSummary , $fileCovInfo , $hasNoBaselineData ) = @_ ;
4082
4079
4083
4080
(ref ($fileSummary ) eq ' SummaryInfo' &&
4084
4081
ref ($fileCovInfo ) eq " FileCoverageInfo" ) or
@@ -4097,7 +4094,7 @@ sub new
4097
4094
4098
4095
# use the line coverage count to synthesize a fake file, if we can't
4099
4096
# find an actual file
4100
- $self -> _load($countdata , $ fileCovInfo-> version( ' current ' ) );
4097
+ $self -> _load($fileCovInfo );
4101
4098
4102
4099
if ($hasNoBaselineData ) {
4103
4100
my $fileAge = $self -> age();
@@ -4957,7 +4954,7 @@ sub _computeAge
4957
4954
4958
4955
sub _load
4959
4956
{
4960
- my ($self , $countdata , $currentVersion ) = @_ ;
4957
+ my ($self , $fileCovInfo ) = @_ ;
4961
4958
4962
4959
my $start = Time::HiRes::gettimeofday();
4963
4960
++$totalFiles ;
@@ -4980,7 +4977,8 @@ sub _load
4980
4977
4981
4978
# check for version mismatch...
4982
4979
if (@lcovutil::extractVersionScript ) {
4983
- my $version = lcovutil::extractFileVersion($repo_path );
4980
+ my $currentVersion = $fileCovInfo -> version(' current' );
4981
+ my $version = lcovutil::extractFileVersion($repo_path );
4984
4982
if (defined ($version ) &&
4985
4983
' ' ne $version ) {
4986
4984
if (defined ($currentVersion )) {
@@ -5055,7 +5053,7 @@ sub _load
5055
5053
$lcovutil::profileData {annotate }{$self -> path()} = $end - $begin ;
5056
5054
5057
5055
++$annotatedFiles if $found ;
5058
- $self -> _synthesize($countdata , 1); # fake annotations too
5056
+ $self -> _synthesize($fileCovInfo , 1); # fake annotations too
5059
5057
return $self ;
5060
5058
} else {
5061
5059
@@ -5085,7 +5083,7 @@ sub _load
5085
5083
0 == scalar (@lcovutil::extractVersionScript ) &&
5086
5084
!lcovutil::is_filter_enabled())
5087
5085
) {
5088
- $self -> _synthesize($countdata ,
5086
+ $self -> _synthesize($fileCovInfo ,
5089
5087
defined ($SourceFile::annotateCallback ));
5090
5088
my $end = Time::HiRes::gettimeofday();
5091
5089
$lcovutil::profileData {synth }{$self -> path()} = $end - $begin ;
@@ -5096,25 +5094,39 @@ sub _load
5096
5094
);
5097
5095
}
5098
5096
$self -> _bare_load($path );
5099
- $self -> _synthesize($countdata , defined ($SourceFile::annotateCallback ));
5097
+ $self -> _synthesize($fileCovInfo , defined ($SourceFile::annotateCallback ));
5100
5098
my $end = Time::HiRes::gettimeofday();
5101
5099
$lcovutil::profileData {load }{$self -> path()} = $end - $begin ;
5102
5100
return $self ;
5103
5101
}
5104
5102
5105
5103
sub _synthesize
5106
5104
{
5107
- my ($self , $countdata , $annotate ) = @_ ;
5108
-
5109
- return $self if (!defined ($countdata ));
5105
+ my ($self , $fileCovInfo , $annotate ) = @_ ;
5110
5106
5111
- my $last_line = 0;
5112
- my @lines = sort ({ $a <=> $b } $countdata -> keylist());
5113
- if (@lines ) {
5114
- $last_line = $lines [scalar (@lines ) - 1];
5115
- }
5107
+ my $lineData = $fileCovInfo -> lineMap();
5116
5108
my $currentLast = scalar (@{$self -> [LINES]});
5117
-
5109
+ my $last_line = 0;
5110
+ while (my ($l , $d ) = each (%$lineData )) {
5111
+ $last_line = $l if (' <' ne substr ($l , 0, 1) && $l > $last_line );
5112
+ }
5113
+ my %functionDecls ;
5114
+ while (my ($fnName , $funcEntry ) = each (%{$fileCovInfo -> functionMap()})) {
5115
+ my $line = $funcEntry -> line();
5116
+ my $end = $funcEntry -> end_line();
5117
+ $last_line = $line if $line > $last_line ;
5118
+ $functionDecls {$line } = " /* BEGIN: function \" $fnName \" */"
5119
+ if ($line >= $currentLast );
5120
+ if (defined ($end )) {
5121
+ $functionDecls {$end } = " /* END: function \" $fnName \" */"
5122
+ if ($end >= $currentLast );
5123
+ if ($end > $last_line ) {
5124
+ # function end is not an executable line,
5125
+ # but is after last executable line
5126
+ $last_line = $end ;
5127
+ }
5128
+ }
5129
+ }
5118
5130
return $self if ($last_line < 1 ||
5119
5131
$currentLast >= $last_line );
5120
5132
my $why ;
@@ -5144,7 +5156,7 @@ sub _synthesize
5144
5156
}
5145
5157
# Simulate gcov behavior
5146
5158
my $notFound = " /* " . $self -> path() . " $why */" ;
5147
- my $synth = " /* (content generated from line coverage data) */" ;
5159
+ my $synth = " /* (content generated from coverage data) */" ;
5148
5160
my $idx = 1;
5149
5161
my @fakeline = (undef , # line number
5150
5162
undef ); # source text
@@ -5161,10 +5173,16 @@ sub _synthesize
5161
5173
}
5162
5174
for (my $line = $currentLast + 1; $line <= $last_line ; $line ++) {
5163
5175
my $mod = $idx ++ % 20;
5164
- my $l = (($mod == 1) ? $notFound :
5165
- ($mod == 2) ? $synth :
5166
- " /* ... */" );
5167
- splice (@fakeline , 0, 2, $line , $l );
5176
+ my $text ;
5177
+ # if there is function decl here...mark it.
5178
+ if (exists ($functionDecls {$line })) {
5179
+ $text = $functionDecls {$line };
5180
+ } else {
5181
+ $text = (($mod == 1) ? $notFound :
5182
+ ($mod == 2) ? $synth :
5183
+ " /* ... */" );
5184
+ }
5185
+ splice (@fakeline , 0, 2, $line , $text );
5168
5186
push (@{$self -> [LINES]}, SourceLine-> new(@fakeline ));
5169
5187
}
5170
5188
return $self ;
@@ -7398,7 +7416,7 @@ sub process_file($$$$$)
7398
7416
# - $fileCovInfo: change GIC->CBC, UIC->UBC if $fineNotInBaseline and
7399
7417
# source code is older than baseline file
7400
7418
my $srcfile = SourceFile-> new($filename , $fileSummary , $fileCovInfo ,
7401
- $sumcount , $ fileHasNoBaselineInfo );
7419
+ $fileHasNoBaselineInfo );
7402
7420
my $endSrc = Time::HiRes::gettimeofday();
7403
7421
$lcovutil::profileData {source }{$filename } = $endSrc - $then ;
7404
7422
0 commit comments