@@ -4075,10 +4075,7 @@ use constant {
40754075
40764076sub new
40774077{
4078- # countdata may be 'undef'
4079- my ($class , $filepath , $fileSummary , $fileCovInfo , $countdata ,
4080- $hasNoBaselineData )
4081- = @_ ;
4078+ my ($class , $filepath , $fileSummary , $fileCovInfo , $hasNoBaselineData ) = @_ ;
40824079
40834080 (ref ($fileSummary ) eq ' SummaryInfo' &&
40844081 ref ($fileCovInfo ) eq " FileCoverageInfo" ) or
@@ -4097,7 +4094,7 @@ sub new
40974094
40984095 # use the line coverage count to synthesize a fake file, if we can't
40994096 # find an actual file
4100- $self -> _load($countdata , $ fileCovInfo-> version( ' current ' ) );
4097+ $self -> _load($fileCovInfo );
41014098
41024099 if ($hasNoBaselineData ) {
41034100 my $fileAge = $self -> age();
@@ -4957,7 +4954,7 @@ sub _computeAge
49574954
49584955sub _load
49594956{
4960- my ($self , $countdata , $currentVersion ) = @_ ;
4957+ my ($self , $fileCovInfo ) = @_ ;
49614958
49624959 my $start = Time::HiRes::gettimeofday();
49634960 ++$totalFiles ;
@@ -4980,7 +4977,8 @@ sub _load
49804977
49814978 # check for version mismatch...
49824979 if (@lcovutil::extractVersionScript ) {
4983- my $version = lcovutil::extractFileVersion($repo_path );
4980+ my $currentVersion = $fileCovInfo -> version(' current' );
4981+ my $version = lcovutil::extractFileVersion($repo_path );
49844982 if (defined ($version ) &&
49854983 ' ' ne $version ) {
49864984 if (defined ($currentVersion )) {
@@ -5055,7 +5053,7 @@ sub _load
50555053 $lcovutil::profileData {annotate }{$self -> path()} = $end - $begin ;
50565054
50575055 ++$annotatedFiles if $found ;
5058- $self -> _synthesize($countdata , 1); # fake annotations too
5056+ $self -> _synthesize($fileCovInfo , 1); # fake annotations too
50595057 return $self ;
50605058 } else {
50615059
@@ -5085,7 +5083,7 @@ sub _load
50855083 0 == scalar (@lcovutil::extractVersionScript ) &&
50865084 !lcovutil::is_filter_enabled())
50875085 ) {
5088- $self -> _synthesize($countdata ,
5086+ $self -> _synthesize($fileCovInfo ,
50895087 defined ($SourceFile::annotateCallback ));
50905088 my $end = Time::HiRes::gettimeofday();
50915089 $lcovutil::profileData {synth }{$self -> path()} = $end - $begin ;
@@ -5096,25 +5094,39 @@ sub _load
50965094 );
50975095 }
50985096 $self -> _bare_load($path );
5099- $self -> _synthesize($countdata , defined ($SourceFile::annotateCallback ));
5097+ $self -> _synthesize($fileCovInfo , defined ($SourceFile::annotateCallback ));
51005098 my $end = Time::HiRes::gettimeofday();
51015099 $lcovutil::profileData {load }{$self -> path()} = $end - $begin ;
51025100 return $self ;
51035101}
51045102
51055103sub _synthesize
51065104{
5107- my ($self , $countdata , $annotate ) = @_ ;
5108-
5109- return $self if (!defined ($countdata ));
5105+ my ($self , $fileCovInfo , $annotate ) = @_ ;
51105106
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();
51165108 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+ }
51185130 return $self if ($last_line < 1 ||
51195131 $currentLast >= $last_line );
51205132 my $why ;
@@ -5144,7 +5156,7 @@ sub _synthesize
51445156 }
51455157 # Simulate gcov behavior
51465158 my $notFound = " /* " . $self -> path() . " $why */" ;
5147- my $synth = " /* (content generated from line coverage data) */" ;
5159+ my $synth = " /* (content generated from coverage data) */" ;
51485160 my $idx = 1;
51495161 my @fakeline = (undef , # line number
51505162 undef ); # source text
@@ -5161,10 +5173,16 @@ sub _synthesize
51615173 }
51625174 for (my $line = $currentLast + 1; $line <= $last_line ; $line ++) {
51635175 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 );
51685186 push (@{$self -> [LINES]}, SourceLine-> new(@fakeline ));
51695187 }
51705188 return $self ;
@@ -7398,7 +7416,7 @@ sub process_file($$$$$)
73987416 # - $fileCovInfo: change GIC->CBC, UIC->UBC if $fineNotInBaseline and
73997417 # source code is older than baseline file
74007418 my $srcfile = SourceFile-> new($filename , $fileSummary , $fileCovInfo ,
7401- $sumcount , $ fileHasNoBaselineInfo );
7419+ $fileHasNoBaselineInfo );
74027420 my $endSrc = Time::HiRes::gettimeofday();
74037421 $lcovutil::profileData {source }{$filename } = $endSrc - $then ;
74047422
0 commit comments