@@ -61,7 +61,7 @@ our @EXPORT_OK = qw($tool_name $tool_dir $lcov_version $lcov_url
61
61
parse_cov_filters summarize_cov_filters
62
62
disable_cov_filters reenable_cov_filters is_filter_enabled
63
63
filterStringsAndComments simplifyCode balancedParens
64
- set_rtl_extensions set_c_extensions
64
+ set_extensions
65
65
$source_filter_lookahead $source_filter_bitwise_are_conditional
66
66
$exclude_exception_branch
67
67
$derive_function_end_line $derive_function_end_line_all_files
@@ -189,8 +189,6 @@ our $excessive_count_threshold; # default not set: don't check
189
189
190
190
our $br_coverage = 0; # If set, generate branch coverage statistics
191
191
our $func_coverage = 1; # If set, generate function coverage statistics
192
- our $rtlExtensions ;
193
- our $cExtensions ;
194
192
195
193
# for external file filtering
196
194
our @internal_dirs ;
@@ -300,9 +298,12 @@ our $trivial_function_threshold = 5;
300
298
our @omit_line_patterns ;
301
299
our @exclude_function_patterns ;
302
300
303
- our $rtl_file_extensions = ' v|vh|sv|vhdl?' ;
304
- our $c_file_extensions = ' c|h|i||C|H|I|icc|cpp|cc|cxx|hh|hpp|hxx' ;
305
- our $java_file_extensions = ' java' ;
301
+ our %languageExtensions = (' c' => ' c|h|i||C|H|I|icc|cpp|cc|cxx|hh|hpp|hxx' ,
302
+ ' rtl' => ' v|vh|sv|vhdl?' ,
303
+ ' perl' => ' pl|pm' ,
304
+ ' python' => ' py' ,
305
+ ' java' => ' java' );
306
+
306
307
# don't look more than 10 lines ahead when filtering (default)
307
308
our $source_filter_lookahead = 10;
308
309
# by default, don't treat expressions containing bitwise operators '|', '&', '~'
@@ -801,16 +802,11 @@ sub save_profile($)
801
802
}
802
803
}
803
804
804
- sub set_rtl_extensions
805
+ sub set_extensions
805
806
{
806
- my $str = shift ;
807
- $rtl_file_extensions = join (' |' , split ($split_char , $str ));
808
- }
809
-
810
- sub set_c_extensions
811
- {
812
- my $str = shift ;
813
- $c_file_extensions = join (' |' , split ($split_char , $str ));
807
+ my ($type , $str ) = @_ ;
808
+ die (" unknown language '$type '" ) unless exits($languageExtensions {$type });
809
+ $languageExtensions {$type } = join (' |' , split ($split_char , $str ));
814
810
}
815
811
816
812
sub do_mangle_check
@@ -1030,6 +1026,8 @@ my %deprecated_rc = ("genhtml_demangle_cpp" => "demangle_cpp",
1030
1026
" genhtml_function_coverage" => " function_coverage" ,
1031
1027
" genhtml_branch_coverage" => " branch_coverage" ,);
1032
1028
my @deprecated_uses ;
1029
+ my ($cExtensions , $rtlExtensions , $javaExtensions ,
1030
+ $perlExtensions , $pythonExtensions );
1033
1031
1034
1032
my %rc_common = (
1035
1033
' derive_function_end_line' => \$lcovutil::derive_function_end_line ,
@@ -1057,6 +1055,9 @@ my %rc_common = (
1057
1055
' warn_once_per_file' => \$lcovutil::warn_once_per_file ,
1058
1056
" rtl_file_extensions" => \$rtlExtensions ,
1059
1057
" c_file_extensions" => \$cExtensions ,
1058
+ " perl_file_extensions" => \$perlExtensions ,
1059
+ " python_file_extensions" => \$pythonExtensions ,
1060
+ " java_file_extensions" => \$javaExtensions ,
1060
1061
" filter_lookahead" => \$lcovutil::source_filter_lookahead ,
1061
1062
" filter_bitwise_conditional" =>
1062
1063
\$lcovutil::source_filter_bitwise_are_conditional ,
@@ -1198,10 +1199,14 @@ sub apply_rc_params($)
1198
1199
# Copy configuration file and --rc values to variables
1199
1200
$set_value |= apply_config(\%rcHash , $config , \%new_opt_rc );
1200
1201
}
1201
- lcovutil::set_rtl_extensions($rtlExtensions )
1202
- if $rtlExtensions ;
1203
- lcovutil::set_c_extensions($cExtensions )
1204
- if $cExtensions ;
1202
+ foreach my $d ([' rtl' , $rtlExtensions ],
1203
+ [' c' , $cExtensions ],
1204
+ [' perl' , $perlExtensions ],
1205
+ [' python' , $pythonExtensions ],
1206
+ [' java' , $javaExtensions ]
1207
+ ) {
1208
+ lcovutil::set_extensions(@$d ) if $d -> [1];
1209
+ }
1205
1210
1206
1211
return $set_value ;
1207
1212
}
@@ -3473,7 +3478,7 @@ sub hit
3473
3478
sub isLambda
3474
3479
{
3475
3480
my $self = shift ;
3476
- return (TraceFile::is_c_file( $self -> filename()) &&
3481
+ return (TraceFile::is_language( ' c ' , $self -> filename()) &&
3477
3482
$self -> name() =~ / {lambda\( / );
3478
3483
}
3479
3484
@@ -5504,7 +5509,7 @@ sub _eraseFunctions
5504
5509
lcovutil::info(1, " no end line for '$name ' at $key \n " );
5505
5510
} elsif (
5506
5511
defined ($removeTrivial ) &&
5507
- is_c_file( $source_file ) &&
5512
+ is_language( ' c ' , $source_file ) &&
5508
5513
(defined ($srcReader ) &&
5509
5514
$srcReader -> containsTrivialFunction($fcn -> line(), $end_line ))
5510
5515
) {
@@ -5555,17 +5560,19 @@ sub _eraseFunctions
5555
5560
sub _filterFile
5556
5561
{
5557
5562
my ($traceInfo , $source_file , $srcReader , $state ) = @_ ;
5558
- my $region = $cov_filter [$FILTER_EXCLUDE_REGION ];
5559
- my $range = $cov_filter [$lcovutil::FILTER_LINE_RANGE ];
5560
- my $branch_histogram = $cov_filter [$FILTER_BRANCH_NO_COND ];
5561
- my $brace_histogram = $cov_filter [$FILTER_LINE_CLOSE_BRACE ];
5563
+ my $region = $cov_filter [$FILTER_EXCLUDE_REGION ];
5564
+ my $branch_region = $cov_filter [$FILTER_EXCLUDE_BRANCH ];
5565
+ my $range = $cov_filter [$lcovutil::FILTER_LINE_RANGE ];
5566
+ my $branch_histogram = $cov_filter [$FILTER_BRANCH_NO_COND ]
5567
+ if (is_language(' c' , $source_file ));
5568
+ my $brace_histogram = $cov_filter [$FILTER_LINE_CLOSE_BRACE ]
5569
+ if (is_language(' c' , $source_file ));
5562
5570
my $blank_histogram = $cov_filter [$FILTER_BLANK_LINE ];
5563
5571
my $function_alias_histogram = $cov_filter [$FILTER_FUNCTION_ALIAS ];
5564
5572
my $trivial_histogram = $cov_filter [$FILTER_TRIVIAL_FUNCTION ];
5565
5573
5566
5574
my $context = MessageContext-> new(" filtering $source_file " );
5567
- if (is_c_file($source_file ) &&
5568
- lcovutil::is_filter_enabled()) {
5575
+ if (lcovutil::is_filter_enabled()) {
5569
5576
lcovutil::info(1, " reading $source_file for lcov filtering\n " );
5570
5577
$srcReader -> open ($source_file );
5571
5578
} else {
@@ -5617,8 +5624,7 @@ sub _filterFile
5617
5624
}
5618
5625
5619
5626
return
5620
- unless (is_c_file($source_file ) &&
5621
- $srcReader -> notEmpty() &&
5627
+ unless ($srcReader -> notEmpty() &&
5622
5628
lcovutil::is_filter_enabled());
5623
5629
5624
5630
my ($testdata , $sumcount , $funcdata , $checkdata ,
@@ -5668,29 +5674,32 @@ sub _filterFile
5668
5674
# $testbrcount is undef if there are no branches in the scope
5669
5675
if ($lcovutil::br_coverage &&
5670
5676
defined ($testbrcount ) &&
5671
- ($branch_histogram || $region || $range )) {
5677
+ ($branch_histogram || $region || $branch_region || $ range )) {
5672
5678
foreach my $line ($testbrcount -> keylist()) {
5679
+ # for counting: keep track filter which triggered exclusion -
5673
5680
my $remove ;
5674
5681
# omit if line excluded or branches excluded on this line
5675
5682
if ($srcReader -> isOutOfRange($line , ' branch' )) {
5676
5683
# only counting line coverpoints that got excluded
5677
- $remove = 1;
5678
- } elsif ($region &&
5684
+ die (" inconsistent state" ) unless $range ;
5685
+ $remove = $range ;
5686
+ } elsif (($region || $branch_region ) &&
5679
5687
$srcReader -> isExcluded($line , 2)) {
5680
5688
# all branches here
5681
- $remove = 1;
5689
+ $remove = $region ? $region : $branch_region ;
5690
+ die (" inconsistent" ) unless $remove ;
5682
5691
} elsif ($branch_histogram &&
5683
5692
!$srcReader -> containsConditional($line )) {
5684
- $remove = 1;
5693
+ $remove = $branch_histogram ;
5694
+ }
5695
+ if ($remove ) {
5685
5696
my $brdata = $testbrcount -> value($line );
5686
- ++$branch_histogram -> [0]; # one line where we skip
5687
- $branch_histogram -> [1] += scalar ($brdata -> blocks ());
5697
+ ++$remove -> [0]; # one line where we skip
5698
+ $remove -> [1] += ($brdata -> totals ())[0] ;
5688
5699
lcovutil::info(2,
5689
5700
" filter BRDA '" .
5690
5701
$srcReader -> getLine($line ) .
5691
5702
" ' $source_file :$line \n " );
5692
- }
5693
- if ($remove ) {
5694
5703
# now remove this branch everywhere...
5695
5704
foreach my $tn ($testbrdata -> keylist()) {
5696
5705
my $d = $testbrdata -> value($tn );
@@ -6190,15 +6199,20 @@ sub applyFilters
6190
6199
delete ($self -> [FILES]-> {$source_file });
6191
6200
next ;
6192
6201
}
6193
- # derive function end line for C/C++ code if requested
6194
- # (not trying to handle python nested functions, etc)
6202
+ # derive function end line for C/C++ and java code if requested
6203
+ # (not trying to handle python nested functions, etc.)
6204
+ # However, see indent handling in the py2lcov script. Arguably, that
6205
+ # could/should be done here/in Perl rather than in Python.)
6206
+ # Jacoco pretends to report function end line - but it appears
6207
+ # to be the last line executed - not the actual last line of
6208
+ # the function - so broken/completely useless.
6195
6209
DERIVE:
6196
6210
if (0 == ($self -> [STATE] & DID_DERIVE) &&
6197
6211
defined ($lcovutil::derive_function_end_line ) &&
6198
6212
$lcovutil::derive_function_end_line != 0 &&
6199
6213
defined ($lcovutil::func_coverage ) &&
6200
6214
($lcovutil::derive_end_line_all_files ||
6201
- is_c_file( $source_file ))
6215
+ is_language( ' c|java|perl ' , $source_file ))
6202
6216
) {
6203
6217
my @lines = sort { $a <=> $b } $traceInfo -> sum()-> keylist();
6204
6218
# sort functions by start line number
@@ -6311,7 +6325,7 @@ sub applyFilters
6311
6325
(0 != scalar (@lcovutil::exclude_function_patterns ) ||
6312
6326
defined ($lcovutil::cov_filter [$FILTER_TRIVIAL_FUNCTION ]))
6313
6327
) ||
6314
- (is_c_file( $source_file ) &&
6328
+ (is_language( ' c|perl|python|java ' , $source_file ) &&
6315
6329
lcovutil::is_filter_enabled()));
6316
6330
push (@filter_workList , [$traceInfo , $name ]);
6317
6331
} # foreach file
@@ -6325,22 +6339,15 @@ sub applyFilters
6325
6339
}
6326
6340
}
6327
6341
6328
- sub is_rtl_file
6342
+ sub is_language
6329
6343
{
6330
- my $filename = shift ;
6331
- return $filename =~ / \. ($rtl_file_extensions )$ / ? 1 : 0;
6332
- }
6333
-
6334
- sub is_java_file
6335
- {
6336
- my $filename = shift ;
6337
- return $filename =~ / \. ($java_file_extensions )$ / ? 1 : 0;
6338
- }
6339
-
6340
- sub is_c_file
6341
- {
6342
- my $filename = shift ;
6343
- return $filename =~ / \. ($c_file_extensions )$ / ? 1 : 0;
6344
+ my ($lang , $filename ) = @_ ;
6345
+ foreach my $l (split (' \|' , $lang )) {
6346
+ die (" unknown language '$l '" )
6347
+ unless exists ($lcovutil::languageExtensions {$l });
6348
+ return 1 if $filename =~ / \. ($lcovutil::languageExtensions {$l })$ / ;
6349
+ }
6350
+ return 0;
6344
6351
}
6345
6352
6346
6353
# Read in the contents of the .info file specified by INFO_FILENAME. Data will
@@ -6476,7 +6483,7 @@ sub _read_info
6476
6483
# at the source for some previous file.
6477
6484
$readSourceCallback -> close ();
6478
6485
undef $currentBranchLine ;
6479
- if (is_c_file( $filename )) {
6486
+ if (is_language( ' c ' , $filename )) {
6480
6487
$readSourceCallback -> open ($filename );
6481
6488
}
6482
6489
}
@@ -6686,7 +6693,7 @@ sub _read_info
6686
6693
# generate an CNF or truth-table like entry corresponding
6687
6694
# to the branch.
6688
6695
6689
- if (!is_c_file( $filename )) {
6696
+ if (!is_language( ' c ' , $filename )) {
6690
6697
# At least at present, Verilog/SystemVerilog/VHDL,
6691
6698
# java, python, etc don't need branch number fixing
6692
6699
my $key = " $line ,$block " ;
@@ -6737,7 +6744,7 @@ sub _read_info
6737
6744
$fileData -> version($version )
6738
6745
if (defined ($version ) && $version ne " " );
6739
6746
}
6740
- if (is_c_file( $filename )) {
6747
+ if (is_language( ' c ' , $filename )) {
6741
6748
# RTL code was added directly - no issue with
6742
6749
# duplicate data entries in geninfo result
6743
6750
my $testcaseBranchData = $fileData -> testbr($testname )
0 commit comments