blib/lib/Parse/H.pm

filter: Statementstmt 100% 615 / 615 Branchbran 99.5% 601 / 604 Conditioncond 100% 240 / 240 MC/DCmcdc 100% 152 / 152 Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 99.8% 1622 / 1625 CC 383 SCAR 47.6
CC
383
Cov
100%
parse_struct
130.0
parse_union
126.0
parse_file
114.0
CRAP 116.8
↑ Summary
1 #!/usr/bin/perl -w
2 # Parse::H - A parser for C header files that calls the given
3 # subroutines when a symbol of a specified type is encountered.
4 #
5 # Copyright (C) 2022-2025 Bogdan 'bogdro' Drozdowski,
6 # bogdro (at) users . sourceforge . net
7 # bogdro /at\ cpan . org
8 #
9 # This program is free software; you can redistribute it and/or modify it
10 # under the same terms as Perl itself.
11 #
12  
13 package Parse::H;
14  
15 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 require Exporter;
18 3 @ISA = (Exporter);
19 3 @EXPORT = qw();
20 3 @EXPORT_OK = qw(parse_struct parse_union parse_file);
21  
22 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 =head1 NAME
25  
26 Parse::H - A parser for C header files that calls the given subroutines when a symbol of a specified type is encountered.
27  
28 =head1 VERSION
29  
30 Version 0.30
31  
32 =cut
33  
34 3 our $VERSION = '0.30';
35  
36 =head1 DESCRIPTION
37  
38 This module provides subroutines for parsing C language header files
39 (*.h files) while calling user-provided callback subroutines on various
40 found elements.
41  
42 =head1 SYNOPSIS
43  
44 use Parse::H qw(parse_file);
45  
46 open (my $infile, '<', 'test.h') or die "Cannot open test.h: $!\n";
47  
48 my $extern_sub = sub { ... }
49 my $comment_sub = sub { ... }
50 my $preproc_sub = sub { ... }
51 my $typedef_sub = sub { ... }
52 my $struct_start_sub = sub { ... }
53 my $struct_entry_sub = sub { ... }
54 my $struct_end_sub = sub { ... }
55 my $enum_start_sub = sub { ... }
56 my $enum_entry_sub = sub { ... }
57 my $enum_end_sub = sub { ... }
58 my $union_start_sub = sub { ... }
59 my $union_entry_sub = sub { ... }
60 my $union_end_sub = sub { ... }
61 my $output_sub = sub { ... }
62  
63 my %params = (
64 'infile' => $infile,
65 'output_sub' => $output_sub,
66 'comment_sub' => $comment_sub,
67 'preproc_sub' => $preproc_sub,
68 'extern_sub' => $extern_sub,
69 'typedef_sub' => $typedef_sub,
70 'struct_start_sub' => $struct_start_sub,
71 'struct_entry_sub' => $struct_entry_sub,
72 'struct_end_sub' => $struct_end_sub,
73 'union_start_sub' => $union_start_sub,
74 'union_entry_sub' => $union_entry_sub,
75 'union_end_sub' => $union_end_sub,
76 'enum_start_sub' => $enum_start_sub,
77 'enum_entry_sub' => $enum_entry_sub,
78 'enum_end_sub' => $enum_end_sub,
79 'pointer_size' => 8,
80 );
81  
82 parse_file (%params);
83  
84 close $infile;
85  
86 =head1 EXPORT
87  
88 Nothing is exported by default.
89  
90 The following functions are exported on request:
91 parse_struct
92 parse_union
93 parse_file
94  
95 These parse a C "struct" type, a C "union" type or a whole C header
96 file, respectively.
97  
98 =head1 DATA
99  
100 =cut
101  
102 # =head2 _max
103 #
104 # PRIVATE SUBROUTINE.
105 # Returns the greater of 2 numbers.
106 #
107 # =cut
108 sub _max
109 2842 ▶{
Subroutine _max: called CC=2 SCAR=6.9
110 2842 my ($a, $b) = @_;
111 2842 ▶ return $a if $a > $b;
Branch: 1 branch
BranchTrueFalseTotal
if $a > $b 435 2407 2842
112 2407 return $b;
113 }
114  
115 # =head2 _get_param
116 #
117 # PRIVATE SUBROUTINE.
118 # Returns the value specified by name (parameter 2) from the
119 # hashref specified in parameter 1, or undef.
120 #
121 # =cut
122 sub _get_param
123 17920 ▶{
Subroutine _get_param: called CC=2 SCAR=6.9
124 17920 my ($hash, $name) = @_;
125 17920 ▶ return defined($hash->{$name})? $hash->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{$name} ? : 15061 2859 17920
126 }
127  
128 # =head2 _is_a_number
129 #
130 # PRIVATE SUBROUTINE.
131 # Returns 1 if the provided parameter string looks like a valid number, 0 otherwise.
132 #
133 # =cut
134 sub _is_a_number
135 2436 ▶{
Subroutine _is_a_number: called CC=2 SCAR=6.9
136 2436 my $v = shift;
137 2436 ▶ return ($v =~ /^((0?x[0-9a-f]+)|(0?b[01]+)|(0?o[0-7]+)|([0-9]+))$/oi)? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /^((0?x[0-9a-f]+)|(0?b[01]+)|(0?o[0-7]+)|([0-9]+))$/io ? : 1305 1131 2436
138 }
139  
140 # =head2 _output_array_entry_size
141 #
142 # PRIVATE SUBROUTINE.
143 # Outputs an entry for the given array count and element size.
144 # Params: entry sub ref (struct or union), output sub ref,
145 # variable name, element count, element size.
146 # Returns the element count, converted to a number if possible.
147 #
148 # =cut
149 sub _output_array_entry_size
150 2378 ▶{
Subroutine _output_array_entry_size: called CC=8 SCAR=20.8
151 2378 my ($entry_sub, $output_sub, $var_name, $count, $size) = @_;
152 2378 my $line = '';
153 2378 ▶ if ( $count =~ /^(0?[xbo])[0-9a-f_]+$/oi )
Branch: 2 branches
BranchTrueFalseTotal
if ($count =~ /^(0?[xbo])[0-9a-f_]+$/io) { } 58 2320 2378
elsif ($count =~ /^[0-9_]+$/o) { } 1218 1102 2320
154 {
155 # looks like a hex/bin/oct number - convert
156 58 $count = oct($count);
157 58 ▶ $line = &$entry_sub($var_name, $size * $count) if $entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $entry_sub 56 2 58
158 }
159 elsif ( $count =~ /^[0-9_]+$/o )
160 {
161 # looks like a dec number - convert
162 1218 $count = int($count);
163 1218 ▶ $line = &$entry_sub($var_name, $size * $count) if $entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $entry_sub 1176 42 1218
164 }
165 else
166 {
167 # not a number - emit a string
168 1102 ▶ $line = &$entry_sub($var_name, "$size * $count") if $entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $entry_sub 1064 38 1102
169 }
170 2378 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 2132 246 2378
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
821642132
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
171 # remove the parsed element
172 2378 s/^[^;]*;//o;
173 2378 return $count;
174 }
175  
176 # =head2 _split_decl
177 #
178 # PRIVATE SUBROUTINE.
179 # Splits a declaration line of multiple variables into separate declarations.
180 # Params: the input file handle.
181 #
182 # =cut
183 sub _split_decl
184 12615 ▶{
Subroutine _split_decl: called CC=6 SCAR=17.9
185 12615 my $infile = shift;
186  
187 # joining lines
188 12615 ▶ while ( /\\$/o || (/,/o && ! /;/o) )
Branch: 1 branch
BranchTrueFalseTotal
if (/\\$/o or /,/o and not /;/o) 174 12615 12789
Condition100%6/6
/\\$/o or /,/o and not /;/o
l!l&&r!l&&!r
5811612615
/,/o and not /;/o
!ll&&!rl&&r
114551160116
MC/DC100%3/3
/\\$/o or /,/o and not /;/o
/\\$/o /,/o not /;/o
Truth table100%4/4
A or B and not(C)
A= /\\$/oB= /,/oC= not /;/o
ABCresult
1XX1
0111
00X0
0100
189 {
190 174 s/\\[\r\n]+//o;
191 174 $_ .= <$infile>;
192 174 s/[\r\n]//go;
193 }
194 12615 s#(.*)/\*(.*)\*/(.*)#$1 $3 ;$2#o;
195 12615 s#(.*)//(.*)#$1 ;$2#o;
196 # many variables of the same type - we put each on a separate line together with its type
197 12615 ▶ while ( /,/o )#&& !/\(/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/,/o) 1508 12615 14123
198 {
199 1508 ▶ if ( m#\[.*#o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\[.*/o) { } 58 1450 1508
200 {
201 58 s/([\w*\s]+)\s+([()\w\s*]+)\s*(\[\w+\]),\s*(.*)/$1 $2$3;\n$1 $4/;
202 }
203 else
204 {
205 1450 s/([\w*\s]+)\s+([()\w\s*]+)\s*,\s*(.*)/$1 $2;\n$1 $3/;
206 }
207 }
208 }
209  
210 # =head2 _remove_attrs
211 #
212 # PRIVATE SUBROUTINE.
213 # Removes attributes from the current line.
214 #
215 # =cut
216 sub _remove_attrs
217 19111 ▶{
Subroutine _remove_attrs: called CC=1 SCAR=0.0
218 19111 s/__attribute__\s*\(\(.*\)\)//go;
219 19111 s/\[\[.*\]\]//go;
220 }
221  
222 sub parse_union(\%);
223 sub parse_struct(\%);
224  
225 =head2 parse_struct
226  
227 Parses a C "structure" type, calling the provided subroutines when
228 a symbol of a specified type is encountered.
229 Parameters: a hash containing the input file handle and references to
230 the subroutines. All subroutines should return a line of text (which
231 may later go to $output_sub) after their processing of the given parameter.
232 If a key is not present in the hash, its functionality is not used
233 (unless a default value is specified).
234 Hash keys:
235  
236 'infile' => input file handle (required),
237 'line' => the current line to process (default: empty line),
238 'output_sub' => a subroutine that processes the output.
239 Takes the line to output as its single parameter,
240 'comment_sub' => a subroutine that processes comments.
241 Takes the current line as its single parameter,
242 'preproc_sub' => a subroutine that processes preprocessor lines.
243 Takes the current line as its single parameter,
244 'struct_start_sub' => a subroutine that processes the beginning of a structure.
245 Takes the structure name as its single parameter,
246 'struct_entry_sub' => a subroutine that processes an entry of a structure.
247 Takes the symbol name as its first parameter, its size as the second and the structure name as the third,
248 'struct_end_sub' => a subroutine that processes the end of a structure.
249 Takes the structure name as its first parameter and its size as the second,
250 'union_start_sub' => a subroutine that processes the beginning of a union.
251 Takes the union name as its single parameter,
252 'union_entry_sub' => a subroutine that processes an entry of a union.
253 Takes the symbol name as its first parameter and its size as the second,
254 'union_end_sub' => a subroutine that processes the end of a union.
255 Takes the symbol name as its first parameter, its size as the second and the union name as the third,
256 'pointer_size' => the pointer size to use, in bytes (default: 8),
257  
258 =cut
259  
260 sub parse_struct(\%)
261 755 ▶{
Subroutine parse_struct: called CC=130 SCAR=48.7
Pod documented
262 755 my $params = shift;
263  
264 755 my $infile = _get_param($params, 'infile'); # input file handle
265 755 my $output_sub = _get_param($params, 'output_sub'); # output subroutine
266 755 $_ = _get_param($params, 'line');
267 755 ▶ $_ = '' unless defined($_);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 1 754 755
268 755 my $struct_start_sub = _get_param($params, 'struct_start_sub'); # subroutine that converts structures
269 755 my $struct_entry_sub = _get_param($params, 'struct_entry_sub'); # subroutine that converts structures
270 755 my $struct_end_sub = _get_param($params, 'struct_end_sub'); # subroutine that converts structures
271 755 my $union_start_sub = _get_param($params, 'union_start_sub'); # subroutine that converts unions
272 755 my $union_entry_sub = _get_param($params, 'union_entry_sub'); # subroutine that converts unions
273 755 my $union_end_sub = _get_param($params, 'union_end_sub'); # subroutine that converts unions
274 755 my $comment_sub = _get_param($params, 'comment_sub'); # subroutine that converts comments
275 755 my $preproc_sub = _get_param($params, 'preproc_sub'); # subroutine that converts proceprocessor directives
276 755 my $pointer_size = _get_param($params, 'pointer_size'); # pointer size in bytes
277 755 ▶ $pointer_size = 8 unless defined($pointer_size);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pointer_size 1 754 755
278  
279 755 ▶ return unless $infile;
Branch: 1 branch
BranchTrueFalseTotal
unless $infile 1 754 755
280  
281 754 my %sub_params = (
282 'infile' => $infile,
283 'output_sub' => $output_sub,
284 'comment_sub' => $comment_sub,
285 'preproc_sub' => $preproc_sub,
286 'extern_sub' => undef,
287 'typedef_sub' => undef,
288 'struct_start_sub' => undef,
289 'struct_entry_sub' => undef,
290 'struct_end_sub' => undef,
291 'union_start_sub' => undef,
292 'union_entry_sub' => undef,
293 'union_end_sub' => undef,
294 'enum_start_sub' => undef,
295 'enum_entry_sub' => undef,
296 'enum_end_sub' => undef,
297 'pointer_size' => $pointer_size,
298 );
299  
300 754 &_remove_attrs;
301 # skip over "struct foo;"
302 754 ▶ if ( /^\s*struct\s+[\w\s\$\*]+(\[[^\]]*\])?;/o )#&& ! /{/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*struct\s+[\w\s\$\*]+(\[[^\]]*\])?;/o) 87 667 754
303 {
304 87 s/^\s*struct\s+[\w\s\$\*]+(\[[^\]]*\])?;\s*//o;
305 # processing the comments
306 87 ▶ if ( $comment_sub && (m#/\*#o || m#//#o) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[/\*]o || m[//]o) 56 31 87
Condition100%6/6
$comment_sub and m[/\*]o || m[//]o
!ll&&!rl&&r
32856
m[/\*]o or m[//]o
l!l&&r!l&&!r
282828
MC/DC100%3/3
$comment_sub and m[/\*]o || m[//]o
$comment_sub m[/\*]o m[//]o
Truth table100%4/4
A and B or C
A= $comment_subB= m[/\*]oC= m[//]o
ABCresult
0XX0
1000
11X1
1011
307 {
308 56 $_ = &$comment_sub($_);
309 56 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 52 4 56
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
2252
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
310 }
311 87 return (0, '');
312 }
313  
314 # skip over "struct {};" (syntax error, but causes an infinite loop)
315 667 ▶ if ( /^\s*struct\s*\{\s*\}\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*struct\s*\{\s*\}\s*;/o) 87 580 667
316 {
317 87 s/^\s*struct\s*\{\s*\}\s*;\s*//o;
318 # processing the comments
319 87 ▶ if ( $comment_sub and ( m#//#o or m#/\*#o ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[//]o || m[/\*]o) 56 31 87
Condition100%6/6
$comment_sub and m[//]o || m[/\*]o
!ll&&!rl&&r
32856
m[//]o or m[/\*]o
l!l&&r!l&&!r
282828
MC/DC100%3/3
$comment_sub and m[//]o || m[/\*]o
$comment_sub m[//]o m[/\*]o
Truth table100%4/4
A and B or C
A= $comment_subB= m[//]oC= m[/\*]o
ABCresult
0XX0
1000
11X1
1011
320 {
321 56 $_ = &$comment_sub($_);
322 56 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 52 4 56
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
2252
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
323 }
324 87 return (0, '');
325 }
326  
327 # the name of the structure
328 580 my $str_name = '';
329 580 ▶ if ( /^\s*struct\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*struct\s+(\w+)/o) { } 435 145 580
330 {
331 435 $str_name = $1;
332 435 s/^\s*struct\s+\w+//o;
333 }
334 else
335 {
336 # remove 'struct' so that the start line is not interpreted
337 # as a structure inside a structure
338 145 s/^\s*struct\s*\{?//o;
339 }
340 580 my $size = 0;
341 580 my ($memb_size, $name);
342 580 my $line;
343 580 ▶ $line = &$struct_start_sub($str_name) if $struct_start_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_start_sub 392 188 580
344 580 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 286 294 580
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
20274286
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
345  
346 # a structure can end on the same line or contain many declaration per line
347 # - we simply put a newline after each semicolon and go on
348  
349 580 s/;/;\n/go;
350 # processing the comments
351 580 ▶ if ( $comment_sub and ( m#//#o or m#/\*#o ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[//]o || m[/\*]o) 84 496 580
Condition100%6/6
$comment_sub and m[//]o || m[/\*]o
!ll&&!rl&&r
2047684
m[//]o or m[/\*]o
l!l&&r!l&&!r
2856476
MC/DC100%3/3
$comment_sub and m[//]o || m[/\*]o
$comment_sub m[//]o m[/\*]o
Truth table100%4/4
A and B or C
A= $comment_subB= m[//]oC= m[/\*]o
ABCresult
0XX0
1000
11X1
1011
352 {
353 84 $line = &$comment_sub($_);
354 84 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 81 3 84
355 }
356  
357 do
358 580 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $infile) and do { do { s/^\s*{\s*$//go; &_remove_attrs; &_split_decl($infile); while (/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) { $line = &$struct_entry_sub($2, 0) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o; } ; while (/.*union\s+(\w+)\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($2, 0) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*union\s+\w+\s+\w+\s*;//o; } ; while (/^\s*union/o) { unless (/^\s*union\s+(\w+)/o) { until (/\{/o) { s/\\[\r\n]+//o; $_ .= readline $infile; } ; &_remove_attrs; unless (/^\s*union\s+(\w+)/o) { s/^\s*union\s*//o; } ; } ; $sub_params{"line"} = $_; () = &parse_union(\%sub_params); $line = &$struct_entry_sub($name, $memb_size) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; $_ = ""; $size += $memb_size; goto STR_END; } ; s/(.*):\s*\d+\s*/$1/g; s/^[^;]*_*volatile_*//gio; while (/^[^};]+\(\s*\*\s*(\w+)\s*\)\s*\([^)]*\)\s*;/o) { $line = &$struct_entry_sub($1, $pointer_size) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += $pointer_size; } ; while (/^[^};]+\*+\s*(\w+)\s*;/o) { $line = &$struct_entry_sub($1, $pointer_size) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += $pointer_size; } ; while (/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) { $line = &$struct_entry_sub($2, 0) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o; } ; while (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $3, $4, 8); $size += 8 * $count if _is_a_number($count); } ; while (/.*long\s+double\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $1, $2, 10); $size += 10 * $count if _is_a_number($count); } ; while (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $2, $3, 1); $size += 1 * $count if _is_a_number($count); } ; while (/.*float\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $1, $2, 4); $size += 4 * $count if _is_a_number($count); } ; while (/.*double\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $1, $2, 8); $size += 8 * $count if _is_a_number($count); } ; while (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $3, $4, 2); $size += 2 * $count if _is_a_number($count); } ; while (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $3, $4, $pointer_size); $size += $pointer_size * $count if _is_a_number($count); } ; while (/.*(signed\s+|unsigned\s+)?int\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $2, $3, 4); $size += 4 * $count if _is_a_number($count); } ; while (/.*u?int(\d+)_t\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($struct_entry_sub, $output_sub, $2, $3, $1 / 8); $size += $1 / 8 * $count if _is_a_number($count); } ; while (/.*struct\s+(\w+)\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($2, 0) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*struct\s+\w+\s+\w+\s*;//o; } ; while (/^\s*struct/o) { unless (/^\s*struct\s+(\w+)/o) { until (/\{/o) { s/\\[\r\n]+//o; $_ .= readline $infile; } ; &_remove_attrs; unless (/^\s*struct\s+(\w+)/o) { s/^\s*struct\s*//o; } ; } ; $sub_params{"line"} = $_; () = &parse_struct(\%sub_params); $line = &$struct_entry_sub($name, $memb_size) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; $_ = ""; $size += $memb_size; goto STR_END; } ; while (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($3, 8) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 8; } ; while (/.*long\s+double\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($1, 10) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 10; } ; while (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($2, 1) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 1; } ; while (/.*float\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($1, 4) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 4; } ; while (/.*double\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($1, 8) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 8; } ; while (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($3, 2) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 2; } ; while (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($3, $pointer_size) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += $pointer_size; } ; while (/.*(unsigned\s+|signed\s+)?int\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($2, 4) if $struct_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size += 4; } ; while (/.*u?int(\d+)_t\s+(\w+)\s*;/o) { $line = &$struct_entry_sub($2, $1 / 8) if $struct_entry_sub; $size += $1 / 8; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; } ; if (/}/o) { my $var_name = ""; if (/\}\s*(\*?)\s*(\w+)[^;]*;/o) { $var_name = $2; } ; if (/\}\s*\*/o) { $size = $pointer_size; } ; $line = &$struct_end_sub($var_name, $size, $str_name) if $struct_end_sub; &$output_sub($line) if $output_sub and $line; s/.*;(.*)/$1/o; &$output_sub($_) if $output_sub; $_ = ""; return $size, $var_name; } ; if ($preproc_sub and /^\s*#/o) { $_ = &$preproc_sub($_); } ; if ($_) { $_ .= "\n" unless /[\r\n]$/o; } ; &$output_sub($_) if $output_sub and $_; STR_END: } } 6148 0 6148
359 6728 s/^\s*{\s*$//go;
360  
361 6728 &_remove_attrs;
362 6728 &_split_decl($infile);
363  
364 # union/struct arrays must be processed first
365 6728 ▶ while ( /.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 6728 6786
366 {
367 58 ▶ $line = &$struct_entry_sub($2, 0) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 56 2 58
368 58 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 54 4 58
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2254
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
369 # remove the parsed element
370 58 s/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o;
371 }
372 6728 ▶ while ( /.*union\s+(\w+)\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*union\s+(\w+)\s+(\w+)\s*;/o) 29 6728 6757
373 {
374 29 ▶ $line = &$struct_entry_sub($2, 0) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 28 1 29
375 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
376 # remove the parsed element
377 29 s/.*union\s+\w+\s+\w+\s*;//o;
378 }
379 # while ( /^\s*union\s+(\w+)/o )
380 # {
381 # $sub_params{'line'} = $_;
382 # ($memb_size, $name) = parse_union(%sub_params);
383 # $line = &$struct_entry_sub($name, $memb_size) if $struct_entry_sub;
384 # &$output_sub($line) if $output_sub and $line;
385 # $_ = '';
386 # $size += $memb_size;
387 # goto STR_END;
388 # }
389  
390 6728 ▶ while ( /^\s*union/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*union/o) 145 6583 6728
391 {
392 145 ▶ if ( ! /^\s*union\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*union\s+(\w+)/o) 87 58 145
393 {
394 # no name on the first line - look for it
395 87 ▶ while ( ! /\{/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/\{/o) 116 87 203
396 {
397 116 s/\\[\r\n]+//o;
398 116 $_ .= <$infile>;
399 }
400 87 &_remove_attrs;
401 87 ▶ if ( ! /^\s*union\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*union\s+(\w+)/o) 58 29 87
402 {
403 # no name at all - delete 'union' to
404 # avoid endless loop
405 58 s/^\s*union\s*//o;
406 }
407 }
408 145 $sub_params{'line'} = $_;
409 145 my ($memb_size, $name) = parse_union(%sub_params);
410 145 ▶ $line = &$struct_entry_sub($name, $memb_size) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 140 5 145
411 145 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 57 88 145
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
58357
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
412 145 $_ = '';
413 145 $size += $memb_size;
414 145 goto STR_END;
415 }
416  
417 # first we remove the ":digit" from the structure fields
418 6583 s/(.*):\s*\d+\s*/$1/g;
419  
420 # skip over 'volatile'
421 6583 s/^[^;]*_*volatile_*//gio;
422  
423 # pointers to functions
424 6583 ▶ while ( /^[^};]+\(\s*\*\s*(\w+)\s*\)\s*\([^)]*\)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^};]+\(\s*\*\s*(\w+)\s*\)\s*\([^)]*\)\s*;/o) 435 6583 7018
425 {
426 435 ▶ $line = &$struct_entry_sub($1, $pointer_size) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 420 15 435
427 435 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 405 30 435
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1515405
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
428 # remove the parsed element
429 435 s/^[^;]*;//o;
430 435 $size += $pointer_size;
431 }
432 # pointer type
433 6583 ▶ while ( /^[^};]+\*+\s*(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^};]+\*+\s*(\w+)\s*;/o) 1653 6583 8236
434 {
435 1653 ▶ $line = &$struct_entry_sub($1, $pointer_size) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 1596 57 1653
436 1653 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 1539 114 1653
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
57571539
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
437 # remove the parsed element
438 1653 s/^[^;]*;//o;
439 1653 $size += $pointer_size;
440 }
441  
442 # arrays
443 6583 ▶ while ( /.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 6583 6641
444 {
445 58 ▶ $line = &$struct_entry_sub($2, 0) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 56 2 58
446 58 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 54 4 58
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2254
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
447 # remove the parsed element
448 58 s/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o;
449 }
450 6583 ▶ while ( /.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 6583 6757
451 {
452 174 my $count = &_output_array_entry_size ($struct_entry_sub,
453 $output_sub, $3, $4, 8);
454 174 ▶ $size += 8 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
455 }
456 6583 ▶ while ( /.*long\s+double\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*long\s+double\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 6583 6641
457 {
458 58 my $count = &_output_array_entry_size ($struct_entry_sub,
459 $output_sub, $1, $2, 10);
460 58 ▶ $size += 10 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
461 }
462 6583 ▶ while ( /.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*\[(\w+)\]\s*;/o) 203 6583 6786
463 {
464 203 my $count = &_output_array_entry_size ($struct_entry_sub,
465 $output_sub, $2, $3, 1);
466 203 ▶ $size += 1 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 116 87 203
467 }
468 6583 ▶ while ( /.*float\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*float\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 6583 6641
469 {
470 58 my $count = &_output_array_entry_size ($struct_entry_sub,
471 $output_sub, $1, $2, 4);
472 58 ▶ $size += 4 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
473 }
474 6583 ▶ while ( /.*double\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*double\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 6583 6641
475 {
476 58 my $count = &_output_array_entry_size ($struct_entry_sub,
477 $output_sub, $1, $2, 8);
478 58 ▶ $size += 8 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
479 }
480 6583 ▶ while ( /.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 6583 6757
481 {
482 174 my $count = &_output_array_entry_size ($struct_entry_sub,
483 $output_sub, $3, $4, 2);
484 174 ▶ $size += 2 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
485 }
486 6583 ▶ while ( /.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) 290 6583 6873
487 {
488 # NOTE: assuming 'long int' is the same size as a pointer (should be on 32- and 64-bit systems)
489 290 my $count = &_output_array_entry_size ($struct_entry_sub,
490 $output_sub, $3, $4, $pointer_size);
491 290 ▶ $size += $pointer_size * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 203 87 290
492 }
493 6583 ▶ while ( /.*(signed\s+|unsigned\s+)?int\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(signed\s+|unsigned\s+)?int\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 6583 6757
494 {
495 174 my $count = &_output_array_entry_size ($struct_entry_sub,
496 $output_sub, $2, $3, 4);
497 174 ▶ $size += 4 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
498 }
499 6583 ▶ while ( /.*u?int(\d+)_t\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*u?int(\d+)_t\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 6583 6641
500 {
501 58 my $count = &_output_array_entry_size ($struct_entry_sub,
502 $output_sub, $2, $3, $1/8);
503 58 ▶ $size += $1/8 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
504 }
505  
506 # variables' types
507 6583 ▶ while ( /.*struct\s+(\w+)\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*struct\s+(\w+)\s+(\w+)\s*;/o) 29 6583 6612
508 {
509 29 ▶ $line = &$struct_entry_sub($2, 0) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 28 1 29
510 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
511 # remove the parsed element
512 29 s/.*struct\s+\w+\s+\w+\s*;//o;
513 }
514 6583 ▶ while ( /^\s*struct/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*struct/o) 87 6496 6583
515 {
516 87 ▶ if ( ! /^\s*struct\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*struct\s+(\w+)/o) 58 29 87
517 {
518 # no name on the first line - look for it
519 58 ▶ while ( ! /\{/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/\{/o) 87 58 145
520 {
521 87 s/\\[\r\n]+//o;
522 87 $_ .= <$infile>;
523 }
524 58 &_remove_attrs;
525 58 ▶ if ( ! /^\s*struct\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*struct\s+(\w+)/o) 29 29 58
526 {
527 # no name at all - delete 'struct' to
528 # avoid endless loop
529 29 s/^\s*struct\s*//o;
530 }
531 }
532 87 $sub_params{'line'} = $_;
533 87 my ($memb_size, $name) = parse_struct(%sub_params);
534 87 ▶ $line = &$struct_entry_sub($name, $memb_size) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 84 3 87
535 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 29 58 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
35529
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
536 87 $_ = '';
537 87 $size += $memb_size;
538 87 goto STR_END;
539 }
540  
541 # all "\w+" stand for the variable name
542 6496 ▶ while ( /.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*;/o) 87 6496 6583
543 {
544 87 ▶ $line = &$struct_entry_sub($3, 8) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 84 3 87
545 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
546 # remove the parsed element
547 87 s/^[^;]*;//o;
548 87 $size += 8;
549 }
550 6496 ▶ while ( /.*long\s+double\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*long\s+double\s+(\w+)\s*;/o) 58 6496 6554
551 {
552 58 ▶ $line = &$struct_entry_sub($1, 10) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 56 2 58
553 58 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 54 4 58
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2254
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
554 # remove the parsed element
555 58 s/^[^;]*;//o;
556 58 $size += 10;
557 }
558 6496 ▶ while ( /.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*;/o) 464 6496 6960
559 {
560 464 ▶ $line = &$struct_entry_sub($2, 1) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 280 184 464
561 464 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 268 196 464
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
16180268
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
562 # remove the parsed element
563 464 s/^[^;]*;//o;
564 464 $size += 1;
565 }
566 6496 ▶ while ( /.*float\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*float\s+(\w+)\s*;/o) 116 6496 6612
567 {
568 116 ▶ $line = &$struct_entry_sub($1, 4) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 112 4 116
569 116 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 108 8 116
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
44108
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
570 # remove the parsed element
571 116 s/^[^;]*;//o;
572 116 $size += 4;
573 }
574 6496 ▶ while ( /.*double\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*double\s+(\w+)\s*;/o) 29 6496 6525
575 {
576 29 ▶ $line = &$struct_entry_sub($1, 8) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 28 1 29
577 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
578 # remove the parsed element
579 29 s/^[^;]*;//o;
580 29 $size += 8;
581 }
582 6496 ▶ while ( /.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*;/o) 174 6496 6670
583 {
584 174 ▶ $line = &$struct_entry_sub($3, 2) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 168 6 174
585 174 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 162 12 174
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
66162
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
586 # remove the parsed element
587 174 s/^[^;]*;//o;
588 174 $size += 2;
589 }
590 6496 ▶ while ( /.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*;/o) 87 6496 6583
591 {
592 # NOTE: assuming 'long int' is the same size as a pointer (should be on 32- and 64-bit systems)
593 87 ▶ $line = &$struct_entry_sub($3, $pointer_size) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 84 3 87
594 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
595 # remove the parsed element
596 87 s/^[^;]*;//o;
597 87 $size += $pointer_size;
598 }
599 6496 ▶ while ( /.*(unsigned\s+|signed\s+)?int\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(unsigned\s+|signed\s+)?int\s+(\w+)\s*;/o) 261 6496 6757
600 {
601 261 ▶ $line = &$struct_entry_sub($2, 4) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 252 9 261
602 261 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 243 18 261
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
99243
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
603 # remove the parsed element
604 261 s/^[^;]*;//o;
605 261 $size += 4;
606 }
607 6496 ▶ while ( /.*u?int(\d+)_t\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*u?int(\d+)_t\s+(\w+)\s*;/o) 29 6496 6525
608 {
609 29 ▶ $line = &$struct_entry_sub($2, $1/8) if $struct_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_entry_sub 28 1 29
610 29 $size += $1/8;
611 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
612 # remove the parsed element
613 29 s/^[^;]*;//o;
614 }
615  
616 # look for the end of the structure
617 6496 ▶ if ( /}/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/}/o) 580 5916 6496
618 {
619 # add a structure size definition
620 580 my $var_name = '';
621 580 ▶ if ( /\}\s*(\*?)\s*(\w+)[^;]*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\}\s*(\*?)\s*(\w+)[^;]*;/o) 145 435 580
622 {
623 145 $var_name = $2;
624 }
625 580 ▶ if ( /\}\s*\*/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\}\s*\*/o) 29 551 580
626 {
627 29 $size = $pointer_size;
628 }
629 580 ▶ $line = &$struct_end_sub($var_name, $size, $str_name) if $struct_end_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $struct_end_sub 392 188 580
630 580 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 89 491 580
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2047189
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
631 580 s/.*;(.*)/$1/o;
632 580 ▶ &$output_sub($_) if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 560 20 580
633 580 $_ = '';
634 580 return ($size, $var_name);
635 }
636  
637 # processing of conditional compiling directives
638 5916 ▶ if ( $preproc_sub && /^\s*#/o )
Branch: 1 branch
BranchTrueFalseTotal
if ($preproc_sub and /^\s*#/o) 56 5860 5916
Condition100%3/3
$preproc_sub and /^\s*#/o
!ll&&!rl&&r
204565656
MC/DC100%2/2
$preproc_sub and /^\s*#/o
$preproc_sub /^\s*#/o
Truth table100%3/3
A and B
A= $preproc_subB= /^\s*#/o
ABresult
0X0
100
111
639 {
640 56 $_ = &$preproc_sub($_);
641 }
642 5916 ▶ if ( $_ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 5392 524 5916
643 {
644 5392 ▶ $_ .= "\n" unless /[\r\n]$/o;
Branch: 1 branch
BranchTrueFalseTotal
unless /[\r\n]$/o 29 5363 5392
645 }
646 5916 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 5206 710 5916
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
2045065206
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
647  
648 6148 STR_END: } while ( <$infile> );
649 }
650  
651 =head2 parse_union
652  
653 Parses a C "union" type, calling the provided subroutines when
654 a symbol of a specified type is encountered.
655 Parameters: a hash containing the input file handle and references to
656 the subroutines. All subroutines should return a line of text (which
657 may later go to $output_sub) after their processing of the given parameter.
658 If a key is not present in the hash, its functionality is not used
659 (unless a default value is specified).
660 Hash keys:
661  
662 'infile' => input file handle (required),
663 'line' => the current line to process (default: empty line),
664 'output_sub' => a subroutine that processes the output.
665 Takes the line to output as its single parameter,
666 'comment_sub' => a subroutine that processes comments.
667 Takes the current line as its single parameter,
668 'preproc_sub' => a subroutine that processes preprocessor lines.
669 Takes the current line as its single parameter,
670 'struct_start_sub' => a subroutine that processes the beginning of a structure.
671 Takes the structure name as its single parameter,
672 'struct_entry_sub' => a subroutine that processes an entry of a structure.
673 Takes the symbol name as its first parameter, its size as the second and the structure name as the third,
674 'struct_end_sub' => a subroutine that processes the end of a structure.
675 Takes the structure name as its first parameter and its size as the second,
676 'union_start_sub' => a subroutine that processes the beginning of a union.
677 Takes the union name as its single parameter,
678 'union_entry_sub' => a subroutine that processes an entry of a union.
679 Takes the symbol name as its first parameter and its size as the second,
680 'union_end_sub' => a subroutine that processes the end of a union.
681 Takes the symbol name as its first parameter, its size as the second and the union name as the third,
682 'pointer_size' => the pointer size to use, in bytes (default: 8),
683  
684  
685 =cut
686  
687 sub parse_union(\%)
688 697 ▶{
Subroutine parse_union: called CC=126 SCAR=48.4
Pod documented
689 697 my $params = shift;
690  
691 697 my $infile = _get_param($params, 'infile'); # input file handle
692 697 my $output_sub = _get_param($params, 'output_sub'); # output subroutine
693 697 $_ = _get_param($params, 'line');
694 697 ▶ $_ = '' unless defined($_);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 1 696 697
695 697 my $struct_start_sub = _get_param($params, 'struct_start_sub'); # subroutine that converts structures
696 697 my $struct_entry_sub = _get_param($params, 'struct_entry_sub'); # subroutine that converts structures
697 697 my $struct_end_sub = _get_param($params, 'struct_end_sub'); # subroutine that converts structures
698 697 my $union_start_sub = _get_param($params, 'union_start_sub'); # subroutine that converts unions
699 697 my $union_entry_sub = _get_param($params, 'union_entry_sub'); # subroutine that converts unions
700 697 my $union_end_sub = _get_param($params, 'union_end_sub'); # subroutine that converts unions
701 697 my $comment_sub = _get_param($params, 'comment_sub'); # subroutine that converts comments
702 697 my $preproc_sub = _get_param($params, 'preproc_sub'); # subroutine that converts proceprocessor directives
703 697 my $pointer_size = _get_param($params, 'pointer_size'); # pointer size in bytes
704 697 ▶ $pointer_size = 8 unless defined($pointer_size);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pointer_size 1 696 697
705  
706 697 ▶ return unless $infile;
Branch: 1 branch
BranchTrueFalseTotal
unless $infile 1 696 697
707  
708 696 my %sub_params = (
709 'infile' => $infile,
710 'output_sub' => $output_sub,
711 'comment_sub' => $comment_sub,
712 'preproc_sub' => $preproc_sub,
713 'extern_sub' => undef,
714 'typedef_sub' => undef,
715 'struct_start_sub' => undef,
716 'struct_entry_sub' => undef,
717 'struct_end_sub' => undef,
718 'union_start_sub' => undef,
719 'union_entry_sub' => undef,
720 'union_end_sub' => undef,
721 'enum_start_sub' => undef,
722 'enum_entry_sub' => undef,
723 'enum_end_sub' => undef,
724 'pointer_size' => $pointer_size,
725 );
726  
727 696 &_remove_attrs;
728 # skip over "union foo;"
729 696 ▶ if ( /^\s*union\s+[^;{}]*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*union\s+[^;{}]*;/o) 87 609 696
730 {
731 87 s/^\s*union\s+[^;{}]*;\s*//o;
732 # processing the comments
733 87 ▶ if ( $comment_sub && (m#/\*#o || m#//#o) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[/\*]o || m[//]o) 56 31 87
Condition100%6/6
$comment_sub and m[/\*]o || m[//]o
!ll&&!rl&&r
32856
m[/\*]o or m[//]o
l!l&&r!l&&!r
282828
MC/DC100%3/3
$comment_sub and m[/\*]o || m[//]o
$comment_sub m[/\*]o m[//]o
Truth table100%4/4
A and B or C
A= $comment_subB= m[/\*]oC= m[//]o
ABCresult
0XX0
1000
11X1
1011
734 {
735 56 $_ = &$comment_sub($_);
736 56 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 52 4 56
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
2252
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
737 }
738 87 return (0, '');
739 }
740  
741 # skip over "union {};" (syntax error, but causes an infinite loop)
742 609 ▶ if ( /^\s*union\s*\{\s*\}\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*union\s*\{\s*\}\s*;/o) 87 522 609
743 {
744 87 s/^\s*union\s*\{\s*\}\s*;\s*//o;
745 # processing the comments
746 87 ▶ if ( $comment_sub && (m#/\*#o || m#//#o) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[/\*]o || m[//]o) 56 31 87
Condition100%6/6
$comment_sub and m[/\*]o || m[//]o
!ll&&!rl&&r
32856
m[/\*]o or m[//]o
l!l&&r!l&&!r
282828
MC/DC100%3/3
$comment_sub and m[/\*]o || m[//]o
$comment_sub m[/\*]o m[//]o
Truth table100%4/4
A and B or C
A= $comment_subB= m[/\*]oC= m[//]o
ABCresult
0XX0
1000
11X1
1011
747 {
748 56 $_ = &$comment_sub($_);
749 56 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 52 4 56
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
2252
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
750 }
751 87 return (0, '');
752 }
753  
754 # the name of the union
755 522 my $union_name = '';
756  
757 522 ▶ if ( /^\s*union\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*union\s+(\w+)/o) { } 348 174 522
758 {
759 348 $union_name = $1;
760 348 s/^\s*union\s+\w+//o;
761 }
762 else
763 {
764 # remove 'union' so that the start line is not interpreted
765 # as a union inside a union
766 174 s/^\s*union\s*\{?//o;
767 }
768 522 my $size = 0;
769 522 my ($memb_size, $name);
770 522 my $line;
771 522 ▶ $line = &$union_start_sub($union_name) if $union_start_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_start_sub 280 242 522
772 522 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 182 340 522
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
18322182
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
773  
774 # if there was a '{' in the first line, we put it in the second
775 # if ( /{/o )
776 # {
777 # s/\s*\{/\n\{\n/o;
778 # }
779  
780 # an union can end on the same line or contain many declaration per line
781 # - we simply put a newline after each semicolon and go on
782  
783 522 s/;/;\n/go;
784  
785 do
786 522 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $infile) and do { do { s/^\s*{\s*$//go; &_remove_attrs; &_split_decl($infile); while (/^[^};]+\(\s*\*\s*(\w+)\s*\)\s*\([^)]*\)\s*;/o) { $line = &$union_entry_sub($1, $pointer_size) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, $pointer_size); } ; while (/^[^};]+\*+\s*(\w+)\s*;/o) { $line = &$union_entry_sub($1, $pointer_size) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, $pointer_size); } ; while (/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) { $line = &$union_entry_sub($2, 0) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o; } ; while (/.*union\s+(\w+)\s+(\w+)\s*;/o) { $line = &$union_entry_sub($2, 0) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*union\s+\w+\s+\w+\s*;//o; } ; while (/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) { $line = &$union_entry_sub($2, 0) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o; } ; while (/.*struct\s+(\w+)\s+(\w+)\s*;/o) { $line = &$union_entry_sub($2, 0) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/.*struct\s+\w+\s+\w+\s*;//o; } ; while (/^\s*struct/o) { unless (/^\s*struct\s+(\w+)/o) { until (/\{/o) { s/\\[\r\n]+//o; $_ .= readline $infile; } ; &_remove_attrs; unless (/^\s*struct\s+(\w+)/o) { s/^\s*struct\s*//o; } ; } ; $sub_params{"line"} = $_; () = &parse_struct(\%sub_params); $line = &$union_entry_sub($name, $memb_size) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; $size = _max($size, $memb_size); $_ = ""; goto STR_END; } ; while (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*;/o) { $line = &$union_entry_sub($3, 8) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 8); } ; while (/.*long\s+double\s+(\w+)\s*;/o) { $line = &$union_entry_sub($1, 10) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 10); } ; while (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*;/o) { $line = &$union_entry_sub($2, 1) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 1); } ; while (/.*float\s+(\w+)\s*;/o) { $line = &$union_entry_sub($1, 4) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 4); } ; while (/.*double\s+(\w+)\s*;/o) { $line = &$union_entry_sub($1, 8) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 8); } ; while (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*;/o) { $line = &$union_entry_sub($3, 2) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 2); } ; while (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*;/o) { $line = &$union_entry_sub($3, $pointer_size) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, $pointer_size); } ; while (/.*(unsigned\s+|signed\s+)?int\s+(\w+)\s*;/o) { $line = &$union_entry_sub($2, 4) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; $size = _max($size, 4); } ; while (/.*u?int(\d+)_t\s+(\w+)\s*;/o) { $line = &$union_entry_sub($2, $1 / 8) if $union_entry_sub; $size += $1 / 8; &$output_sub($line) if $output_sub and $line; s/^[^;]*;//o; } ; while (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $3, $4, 8); $size = _max($size, 8 * $count) if _is_a_number($count); } ; while (/.*long\s+double\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $1, $2, 10); $size = _max($size, 10 * $count) if _is_a_number($count); } ; while (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $2, $3, 1); $size = _max($size, 1 * $count) if _is_a_number($count); } ; while (/.*float\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $1, $2, 4); $size = _max($size, 4 * $count) if _is_a_number($count); } ; while (/.*double\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $1, $2, 8); $size = _max($size, 8 * $count) if _is_a_number($count); } ; while (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $3, $4, 2); $size = _max($size, 2 * $count) if _is_a_number($count); } ; while (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $3, $4, $pointer_size); $size = _max($size, $pointer_size * $count) if _is_a_number($count); } ; while (/.*(signed\s+|unsigned\s+)?int\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $2, $3, 4); $size = _max($size, 4 * $count) if _is_a_number($count); } ; while (/.*u?int(\d+)_t\s+(\w+)\s*\[(\w+)\]\s*;/o) { my $count = &_output_array_entry_size($union_entry_sub, $output_sub, $2, $3, $1 / 8); $size += $1 / 8 * $count if _is_a_number($count); } ; while (/^\s*union/o) { unless (/^\s*union\s+(\w+)/o) { until (/\{/o) { s/\\[\r\n]+//o; $_ .= readline $infile; } ; &_remove_attrs; unless (/^\s*union\s+(\w+)/o) { s/^\s*union\s*//o; } ; } ; $sub_params{"line"} = $_; () = &parse_union(\%sub_params); $line = &$union_entry_sub($name, $memb_size) if $union_entry_sub; &$output_sub($line) if $output_sub and $line; $_ = ""; $size = _max($size, $memb_size); } ; if (/\s*\}.*/o) { my $var_name = ""; if (/\}\s*(\*?)\s*(\w+)[^;]*;/o) { $var_name = $2; } ; if (/\}\s*\*/o) { $size = $pointer_size; } ; $line = &$union_end_sub($var_name, $size, $union_name) if $union_end_sub; &$output_sub($line) if $output_sub and $line; s/.*;(.*)/$1/o; &$output_sub($_) if $output_sub; $_ = ""; return $size, $var_name; } ; if ($preproc_sub and /^\s*#/o) { $_ = &$preproc_sub($_); } ; if ($_) { $_ .= "\n" unless /[\r\n]$/o; } ; &$output_sub($_) if $output_sub and $_; STR_END: } } 5046 0 5046
787 5568 s/^\s*{\s*$//go;
788  
789 5568 &_remove_attrs;
790 5568 &_split_decl($infile);
791  
792 # pointers to functions
793 5568 ▶ while ( /^[^};]+\(\s*\*\s*(\w+)\s*\)\s*\([^)]*\)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^};]+\(\s*\*\s*(\w+)\s*\)\s*\([^)]*\)\s*;/o) 145 5568 5713
794 {
795 145 ▶ $line = &$union_entry_sub($1, $pointer_size) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 140 5 145
796 145 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 135 10 145
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
55135
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
797 # remove the parsed element
798 145 s/^[^;]*;//o;
799 145 $size = _max($size, $pointer_size);
800 }
801 # pointer type
802 5568 ▶ while ( /^[^};]+\*+\s*(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^[^};]+\*+\s*(\w+)\s*;/o) 580 5568 6148
803 {
804 580 ▶ $line = &$union_entry_sub($1, $pointer_size) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 560 20 580
805 580 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 540 40 580
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2020540
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
806 # remove the parsed element
807 580 s/^[^;]*;//o;
808 580 $size = _max($size, $pointer_size);
809 }
810  
811 # union/struct arrays must be processed first
812 5568 ▶ while ( /.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 5568 5626
813 {
814 58 ▶ $line = &$union_entry_sub($2, 0) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 56 2 58
815 58 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 54 4 58
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2254
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
816 # remove the parsed element
817 58 s/.*union\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o;
818 }
819  
820 5568 ▶ while ( /.*union\s+(\w+)\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*union\s+(\w+)\s+(\w+)\s*;/o) 29 5568 5597
821 {
822 29 ▶ $line = &$union_entry_sub($2, 0) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 28 1 29
823 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
824 # remove the parsed element
825 29 s/.*union\s+\w+\s+\w+\s*;//o;
826 }
827  
828 5568 ▶ while ( /.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 5568 5626
829 {
830 58 ▶ $line = &$union_entry_sub($2, 0) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 56 2 58
831 58 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 54 4 58
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2254
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
832 # remove the parsed element
833 58 s/.*struct\s+(\w+)\s+(\w+)\s*\[(\w+)\]\s*;//o;
834 }
835  
836 5568 ▶ while ( /.*struct\s+(\w+)\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*struct\s+(\w+)\s+(\w+)\s*;/o) 29 5568 5597
837 {
838 29 ▶ $line = &$union_entry_sub($2, 0) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 28 1 29
839 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
840 # remove the parsed element
841 29 s/.*struct\s+\w+\s+\w+\s*;//o;
842 }
843  
844 5568 ▶ while ( /^\s*struct/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*struct/o) 87 5481 5568
845 {
846 87 ▶ if ( ! /^\s*struct\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*struct\s+(\w+)/o) 58 29 87
847 {
848 # no name on the first line - look for it
849 58 ▶ while ( ! /\{/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/\{/o) 87 58 145
850 {
851 87 s/\\[\r\n]+//o;
852 87 $_ .= <$infile>;
853 }
854 58 &_remove_attrs;
855 58 ▶ if ( ! /^\s*struct\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*struct\s+(\w+)/o) 29 29 58
856 {
857 # no name at all - delete 'struct' to
858 # avoid endless loop
859 29 s/^\s*struct\s*//o;
860 }
861 }
862 87 $sub_params{'line'} = $_;
863 87 my ($memb_size, $name) = parse_struct(%sub_params);
864 87 ▶ $line = &$union_entry_sub($name, $memb_size) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 84 3 87
865 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 29 58 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
35529
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
866 87 $size = _max($size, $memb_size);
867 87 $_ = '';
868 87 goto STR_END;
869 }
870  
871 # variables' types
872 # all "\w+" stand for the variable name
873 5481 ▶ while ( /.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*;/o) 87 5481 5568
874 {
875 87 ▶ $line = &$union_entry_sub($3, 8) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 84 3 87
876 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
877 # remove the parsed element
878 87 s/^[^;]*;//o;
879 87 $size = _max($size, 8);
880 }
881  
882 5481 ▶ while ( /.*long\s+double\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*long\s+double\s+(\w+)\s*;/o) 29 5481 5510
883 {
884 29 ▶ $line = &$union_entry_sub($1, 10) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 28 1 29
885 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
886 # remove the parsed element
887 29 s/^[^;]*;//o;
888 29 $size = _max($size, 10);
889 }
890  
891 5481 ▶ while ( /.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*;/o) 609 5481 6090
892 {
893 609 ▶ $line = &$union_entry_sub($2, 1) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 252 357 609
894 609 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 241 368 609
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
21347241
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
895 # remove the parsed element
896 609 s/^[^;]*;//o;
897 609 $size = _max($size, 1);
898 }
899  
900 5481 ▶ while ( /.*float\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*float\s+(\w+)\s*;/o) 116 5481 5597
901 {
902 116 ▶ $line = &$union_entry_sub($1, 4) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 112 4 116
903 116 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 108 8 116
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
44108
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
904 # remove the parsed element
905 116 s/^[^;]*;//o;
906 116 $size = _max($size, 4);
907 }
908  
909 5481 ▶ while ( /.*double\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*double\s+(\w+)\s*;/o) 29 5481 5510
910 {
911 29 ▶ $line = &$union_entry_sub($1, 8) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 28 1 29
912 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
913 # remove the parsed element
914 29 s/^[^;]*;//o;
915 29 $size = _max($size, 8);
916 }
917  
918 5481 ▶ while ( /.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*;/o) 174 5481 5655
919 {
920 174 ▶ $line = &$union_entry_sub($3, 2) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 168 6 174
921 174 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 162 12 174
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
66162
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
922 # remove the parsed element
923 174 s/^[^;]*;//o;
924 174 $size = _max($size, 2);
925 }
926  
927 5481 ▶ while ( /.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*;/o) 87 5481 5568
928 {
929 # NOTE: assuming 'long int' is the same size as a pointer (should be on 32- and 64-bit systems)
930 87 ▶ $line = &$union_entry_sub($3, $pointer_size) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 84 3 87
931 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
932 # remove the parsed element
933 87 s/^[^;]*;//o;
934 87 $size = _max($size, $pointer_size);
935 }
936  
937 5481 ▶ while ( /.*(unsigned\s+|signed\s+)?int\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(unsigned\s+|signed\s+)?int\s+(\w+)\s*;/o) 261 5481 5742
938 {
939 261 ▶ $line = &$union_entry_sub($2, 4) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 252 9 261
940 261 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 243 18 261
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
99243
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
941 # remove the parsed element
942 261 s/^[^;]*;//o;
943 261 $size = _max($size, 4);
944 }
945  
946 5481 ▶ while ( /.*u?int(\d+)_t\s+(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*u?int(\d+)_t\s+(\w+)\s*;/o) 87 5481 5568
947 {
948 87 ▶ $line = &$union_entry_sub($2, $1/8) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 84 3 87
949 87 $size += $1/8;
950 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
951 # remove the parsed element
952 87 s/^[^;]*;//o;
953 }
954  
955 # arrays
956  
957 5481 ▶ while ( /.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(signed|unsigned)?\s+long\s+long(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 5481 5655
958 {
959 174 my $count = &_output_array_entry_size ($union_entry_sub,
960 $output_sub, $3, $4, 8);
961 174 ▶ $size = _max($size, 8 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
962 }
963  
964 5481 ▶ while ( /.*long\s+double\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*long\s+double\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 5481 5539
965 {
966 58 my $count = &_output_array_entry_size ($union_entry_sub,
967 $output_sub, $1, $2, 10);
968 58 ▶ $size = _max($size, 10 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
969 }
970  
971 5481 ▶ while ( /.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(char|unsigned\s+char|signed\s+char)\s+(\w+)\s*\[(\w+)\]\s*;/o) 203 5481 5684
972 {
973 203 my $count = &_output_array_entry_size ($union_entry_sub,
974 $output_sub, $2, $3, 1);
975 203 ▶ $size = _max($size, 1 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 116 87 203
976 }
977  
978 5481 ▶ while ( /.*float\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*float\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 5481 5539
979 {
980 58 my $count = &_output_array_entry_size ($union_entry_sub,
981 $output_sub, $1, $2, 4);
982 58 ▶ $size = _max($size, 4 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
983 }
984  
985 5481 ▶ while ( /.*double\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*double\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 5481 5539
986 {
987 58 my $count = &_output_array_entry_size ($union_entry_sub,
988 $output_sub, $1, $2, 8);
989 58 ▶ $size = _max($size, 8 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
990 }
991  
992 5481 ▶ while ( /.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(short|signed\s+short|unsigned\s+short)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 5481 5655
993 {
994 174 my $count = &_output_array_entry_size ($union_entry_sub,
995 $output_sub, $3, $4, 2);
996 174 ▶ $size = _max($size, 2 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
997 }
998  
999 5481 ▶ while ( /.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(long|signed\s+long|unsigned\s+long)(\s+int)?\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 5481 5655
1000 {
1001 # NOTE: assuming 'long int' is the same size as a pointer (should be on 32- and 64-bit systems)
1002 174 my $count = &_output_array_entry_size ($union_entry_sub,
1003 $output_sub, $3, $4, $pointer_size);
1004 174 ▶ $size = _max($size, $pointer_size * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
1005 }
1006  
1007 5481 ▶ while ( /.*(signed\s+|unsigned\s+)?int\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*(signed\s+|unsigned\s+)?int\s+(\w+)\s*\[(\w+)\]\s*;/o) 174 5481 5655
1008 {
1009 174 my $count = &_output_array_entry_size ($union_entry_sub,
1010 $output_sub, $2, $3, 4);
1011 174 ▶ $size = _max($size, 4 * $count) if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 87 87 174
1012 }
1013  
1014 5481 ▶ while ( /.*u?int(\d+)_t\s+(\w+)\s*\[(\w+)\]\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/.*u?int(\d+)_t\s+(\w+)\s*\[(\w+)\]\s*;/o) 58 5481 5539
1015 {
1016 58 my $count = &_output_array_entry_size ($union_entry_sub,
1017 $output_sub, $2, $3, $1/8);
1018 58 ▶ $size += $1/8 * $count if _is_a_number ($count);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($count) 29 29 58
1019 }
1020  
1021 5481 ▶ while ( /^\s*union/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*union/o) 87 5481 5568
1022 {
1023 87 ▶ if ( ! /^\s*union\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*union\s+(\w+)/o) 58 29 87
1024 {
1025 # no name on the first line - look for it
1026 58 ▶ while ( ! /\{/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/\{/o) 87 58 145
1027 {
1028 87 s/\\[\r\n]+//o;
1029 87 $_ .= <$infile>;
1030 }
1031 58 &_remove_attrs;
1032 58 ▶ if ( ! /^\s*union\s+(\w+)/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*union\s+(\w+)/o) 29 29 58
1033 {
1034 # no name at all - delete 'union' to
1035 # avoid endless loop
1036 29 s/^\s*union\s*//o;
1037 }
1038 }
1039 87 $sub_params{'line'} = $_;
1040 87 my ($memb_size, $name) = parse_union(%sub_params);
1041 87 ▶ $line = &$union_entry_sub($name, $memb_size) if $union_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_entry_sub 84 3 87
1042 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 29 58 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
35529
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1043 87 $_ = '';
1044 87 $size = _max($size, $memb_size);
1045 }
1046  
1047 # look for the end of the union
1048 5481 ▶ if ( /\s*\}.*/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\s*\}.*/o) 522 4959 5481
1049 {
1050 522 my $var_name = '';
1051 522 ▶ if ( /\}\s*(\*?)\s*(\w+)[^;]*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\}\s*(\*?)\s*(\w+)[^;]*;/o) 174 348 522
1052 {
1053 174 $var_name = $2;
1054 }
1055 522 ▶ if ( /\}\s*\*/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\}\s*\*/o) 29 493 522
1056 {
1057 29 $size = $pointer_size;
1058 }
1059 522 ▶ $line = &$union_end_sub($var_name, $size, $union_name) if $union_end_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $union_end_sub 280 242 522
1060 522 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 86 436 522
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1841886
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1061 522 s/.*;(.*)/$1/o;
1062 522 ▶ &$output_sub($_) if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 504 18 522
1063 522 $_ = '';
1064 522 return ($size, $var_name);
1065 }
1066  
1067 # processing of conditional compiling directives
1068 4959 ▶ if ( $preproc_sub && /^\s*#/o )
Branch: 1 branch
BranchTrueFalseTotal
if ($preproc_sub and /^\s*#/o) 28 4931 4959
Condition100%3/3
$preproc_sub and /^\s*#/o
!ll&&!rl&&r
171476028
MC/DC100%2/2
$preproc_sub and /^\s*#/o
$preproc_sub /^\s*#/o
Truth table100%3/3
A and B
A= $preproc_subB= /^\s*#/o
ABresult
0X0
100
111
1069 {
1070 28 $_ = &$preproc_sub($_);
1071 }
1072 4959 ▶ if ( $_ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_) 4407 552 4959
1073 {
1074 4407 ▶ $_ .= "\n" unless /[\r\n]$/o;
Branch: 1 branch
BranchTrueFalseTotal
unless /[\r\n]$/o 29 4378 4407
1075 }
1076 4959 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 4255 704 4959
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
1715334255
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
1077  
1078 5046 STR_END: } while ( <$infile> );
1079 }
1080  
1081 =head2 parse_file
1082  
1083 Parses a C header file, calling the provided subroutines when
1084 a symbol of a specified type is encountered.
1085 Parameters: a hash containing the input file handle and references to
1086 the subroutines. All subroutines should return a line of text (which
1087 may later go to $output_sub) after their processing of the given parameter.
1088 If a key is not present in the hash, its functionality is not used
1089 (unless a default value is specified).
1090 Hash keys:
1091  
1092 'infile' => input file handle (required),
1093 'output_sub' => a subroutine that processes the output.
1094 Takes the line to output as its single parameter,
1095 'comment_sub' => a subroutine that processes comments.
1096 Takes the current line as its single parameter,
1097 'preproc_sub' => a subroutine that processes preprocessor lines.
1098 Takes the current line as its single parameter,
1099 'extern_sub' => a subroutine that processes external symbol declarations.
1100 Takes the symbol name as its single parameter,
1101 'typedef_sub' => a subroutine that processes typedefs.
1102 Takes the old type's name as its first parameter and the new type's name as the second,
1103 'struct_start_sub' => a subroutine that processes the beginning of a structure.
1104 Takes the structure name as its single parameter,
1105 'struct_entry_sub' => a subroutine that processes an entry of a structure.
1106 Takes the symbol name as its first parameter, its size as the second and the structure name as the third,
1107 'struct_end_sub' => a subroutine that processes the end of a structure.
1108 Takes the structure name as its first parameter and its size as the second,
1109 'union_start_sub' => a subroutine that processes the beginning of a union.
1110 Takes the union name as its single parameter,
1111 'union_entry_sub' => a subroutine that processes an entry of a union.
1112 Takes the symbol name as its first parameter and its size as the second,
1113 'union_end_sub' => a subroutine that processes the end of a union.
1114 Takes the symbol name as its first parameter, its size as the second and the union name as the third,
1115 'enum_start_sub' => a subroutine that processes the beginning of an enumeration.
1116 Takes the enum's name as its single parameter,
1117 'enum_entry_sub' => a subroutine that processes an entry of an enumeration.
1118 Takes the symbol name as its first parameter and its value as the second,
1119 'enum_end_sub' => a subroutine that processes the end of an enumeration.
1120 Takes no parameters,
1121 'pointer_size' => the pointer size to use, in bytes (default: 8),
1122  
1123 =cut
1124  
1125 sub parse_file(\%)
1126 31 ▶{
Subroutine parse_file: called CC=114 SCAR=47.4
Pod documented
1127 31 my $params = shift;
1128  
1129 31 my $infile = _get_param($params, 'infile'); # input file handle
1130 31 my $output_sub = _get_param($params, 'output_sub'); # output subroutine
1131 31 my $extern_sub = _get_param($params, 'extern_sub'); # subroutine that converts external declarations
1132 31 my $typedef_sub = _get_param($params, 'typedef_sub'); # subroutine that converts typedefs
1133 31 my $comment_sub = _get_param($params, 'comment_sub'); # subroutine that converts comments
1134 31 my $preproc_sub = _get_param($params, 'preproc_sub'); # subroutine that converts proceprocessor directives
1135 31 my $pointer_size = _get_param($params, 'pointer_size'); # pointer size in bytes
1136 31 ▶ $pointer_size = 8 unless defined($pointer_size);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pointer_size 3 28 31
1137 31 my $struct_start_sub = _get_param($params, 'struct_start_sub'); # subroutine that converts structures
1138 31 my $struct_entry_sub = _get_param($params, 'struct_entry_sub'); # subroutine that converts structures
1139 31 my $struct_end_sub = _get_param($params, 'struct_end_sub'); # subroutine that converts structures
1140 31 my $union_start_sub = _get_param($params, 'union_start_sub'); # subroutine that converts unions
1141 31 my $union_entry_sub = _get_param($params, 'union_entry_sub'); # subroutine that converts unions
1142 31 my $union_end_sub = _get_param($params, 'union_end_sub'); # subroutine that converts unions
1143 31 my $enum_start_sub = _get_param($params, 'enum_start_sub'); # subroutine that converts enumerations
1144 31 my $enum_entry_sub = _get_param($params, 'enum_entry_sub'); # subroutine that converts enumerations
1145 31 my $enum_end_sub = _get_param($params, 'enum_end_sub'); # subroutine that converts enumerations
1146  
1147 31 ▶ return unless $infile;
Branch: 1 branch
BranchTrueFalseTotal
unless $infile 2 29 31
1148  
1149 29 my %sub_params = (
1150 'infile' => $infile,
1151 'output_sub' => $output_sub,
1152 'comment_sub' => $comment_sub,
1153 'preproc_sub' => $preproc_sub,
1154 'extern_sub' => $extern_sub,
1155 'typedef_sub' => $typedef_sub,
1156 'struct_start_sub' => $struct_start_sub,
1157 'struct_entry_sub' => $struct_entry_sub,
1158 'struct_end_sub' => $struct_end_sub,
1159 'union_start_sub' => $union_start_sub,
1160 'union_entry_sub' => $union_entry_sub,
1161 'union_end_sub' => $union_end_sub,
1162 'enum_start_sub' => $enum_start_sub,
1163 'enum_entry_sub' => $enum_entry_sub,
1164 'enum_end_sub' => $enum_end_sub,
1165 'pointer_size' => $pointer_size,
1166 );
1167  
1168 29 my $line;
1169 29 ▶ READ: while ( <$infile> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $infile)) 4640 29 4669
1170 {
1171 # empty lines go without change
1172 4640 ▶ if ( /^\s*$/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*$/o) 1595 3045 4640
1173 {
1174 1595 ▶ &$output_sub("\n") if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 1540 55 1595
1175 1595 next;
1176 }
1177  
1178 # joining lines
1179 3045 ▶ while ( /[\\,]$/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/[\\,]$/o) 58 3045 3103
1180 {
1181 58 s/\\[\r\n]+//o;
1182 58 s/,[\r\n]+/,/o;
1183 58 $_ .= <$infile>;
1184 }
1185  
1186 3045 &_remove_attrs;
1187 # check if a comment is the only thing on this line
1188 3045 ▶ if ( m#^\s*/\*.*\*/\s*$#o || m#^\s*//#o )
Branch: 1 branch
BranchTrueFalseTotal
if (m[^\s*/\*.*\*/\s*$]o or m[^\s*//]o) 232 2813 3045
Condition100%3/3
m[^\s*/\*.*\*/\s*$]o or m[^\s*//]o
l!l&&r!l&&!r
203292813
MC/DC100%2/2
m[^\s*/\*.*\*/\s*$]o or m[^\s*//]o
m[^\s*/\*.*\*/\s*$]o m[^\s*//]o
Truth table100%3/3
A or B
A= m[^\s*/\*.*\*/\s*$]oB= m[^\s*//]o
ABresult
1X1
011
000
1189 {
1190 232 ▶ if ( $comment_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub) { } 224 8 232
1191 {
1192 224 $line = &$comment_sub($_);
1193 224 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 216 8 224
1194 }
1195 else
1196 {
1197 8 $_ = '';
1198 }
1199 232 ▶ &$output_sub($_) if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 224 8 232
1200  
1201 232 next;
1202 }
1203  
1204 # processing of preprocessor directives
1205 2813 ▶ if ( /^\s*#/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*#/o) 87 2726 2813
1206 {
1207 87 ▶ if ( $comment_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub) 84 3 87
1208 {
1209 84 $line = &$comment_sub($_);
1210 84 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 81 3 84
1211 }
1212 87 ▶ if ( $preproc_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($preproc_sub) { } 84 3 87
1213 {
1214 84 $_ = &$preproc_sub($_);
1215 }
1216 else
1217 {
1218 3 $_ = '';
1219 }
1220 87 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 78 9 87
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
3678
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
1221  
1222 87 next;
1223 }
1224  
1225 # externs
1226 2726 ▶ if ( /^\s*extern/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*extern/o) 899 1827 2726
1227 {
1228 899 ▶ if ( $comment_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub) 868 31 899
1229 {
1230 868 $line = &$comment_sub($_);
1231 868 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 837 31 868
1232 }
1233  
1234 899 ▶ if ( ! /^\s*extern\s+"C/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*extern\s+"C/o) 870 29 899
1235 {
1236 # joining lines
1237 870 ▶ while ( ! /;/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/;/o) 29 870 899
1238 {
1239 29 s/[\r\n]+//o;
1240 29 $_ .= <$infile>;
1241 }
1242 }
1243  
1244 899 &_remove_attrs;
1245 # external functions
1246  
1247 # extern "C", extern "C++"
1248 899 s/^\s*extern\s+"C"\s*{//o;
1249 899 s/^\s*extern\s+"C"/extern/o;
1250 899 s/^\s*extern\s+"C\+\+"\s*{//o;
1251 899 s/^\s*extern\s+"C\+\+"/extern/o;
1252  
1253 # first remove: extern MACRO_NAME ( fcn name, args, ... )
1254 899 s/^\s*\w*\s*extern\s+\w+\s*\([^*].*//o;
1255 # type ^^^
1256  
1257 # extern pointers to functions:
1258 899 ▶ if ( /^\s*\w*\s*extern\s+[\w\*\s]+\(\s*\*\s*(\w+)[()\*\s\w]*\)\s*\(.*/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\w*\s*extern\s+[\w\*\s]+\(\s*\*\s*(\w+)[()\*\s\w]*\)\s*\(.*/o) 29 870 899
1259 {
1260 29 ▶ if ( $extern_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($extern_sub) { } 28 1 29
1261 {
1262 28 $line = &$extern_sub($1);
1263 28 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 27 1 28
1264 }
1265 else
1266 {
1267 1 $_ = '';
1268 }
1269 29 ▶ &$output_sub($_) if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 28 1 29
1270 }
1271  
1272 899 ▶ if ( /^\s*\w*\s*extern\s+[\w\*\s]+?(\w+)\s*\(.*/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\w*\s*extern\s+[\w\*\s]+?(\w+)\s*\(.*/o) 262 637 899
1273 {
1274 262 ▶ if ( $extern_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($extern_sub) { } 253 9 262
1275 {
1276 253 $line = &$extern_sub($1);
1277 253 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 243 10 253
1278 }
1279 else
1280 {
1281 9 $_ = '';
1282 }
1283 262 ▶ &$output_sub($_) if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 253 9 262
1284 }
1285  
1286 # external variables
1287 899 ▶ if ( /^\s*extern[\w\*\s]+\s+\**(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*extern[\w\*\s]+\s+\**(\w+)\s*;/o) 580 319 899
1288 {
1289 580 ▶ if ( $extern_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($extern_sub) { } 560 20 580
1290 {
1291 560 $line = &$extern_sub($1);
1292 560 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 540 20 560
1293 }
1294 else
1295 {
1296 20 $_ = '';
1297 }
1298 580 ▶ &$output_sub($_) if $output_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 560 20 580
1299 }
1300  
1301 899 next;
1302 }
1303  
1304 # typedef
1305 1827 ▶ if ( /^\s*typedef/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*typedef/o) 435 1392 1827
1306 {
1307 435 ▶ if ( ! /\b(struct|union|enum)\b/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/\b(struct|union|enum)\b/o) 290 145 435
1308 {
1309 # joining lines
1310 290 ▶ while ( ! /;/o )
Branch: 1 branch
BranchTrueFalseTotal
unless (/;/o) 29 290 319
1311 {
1312 29 s/[\r\n]+//o;
1313 29 $_ .= <$infile>;
1314 }
1315 }
1316  
1317 435 &_remove_attrs;
1318 # split typedefs, but not within function parameters
1319 435 ▶ &_split_decl($infile) unless /\([^)]*,/o or /enum/o;
Branch: 1 branch
BranchTrueFalseTotal
unless /\([^)]*,/o or /enum/o 319 116 435
Condition100%3/3
/\([^)]*,/o or /enum/o
l!l&&r!l&&!r
8729319
MC/DC100%2/2
/\([^)]*,/o or /enum/o
/\([^)]*,/o /enum/o
Truth table100%3/3
A or B
A= /\([^)]*,/oB= /enum/o
ABresult
1X1
011
000
1320  
1321 435 ▶ if ( /\(/o )
Branch: 3 branches
BranchTrueFalseTotal
if (/\(/o) { } 145 290 435
elsif (/(struct|union|enum)/o) { } 145 145 290
elsif (not /{/o) { } 116 29 145
1322 {
1323 145 s/^.*$/\n/o;
1324 }
1325 # "typedef struct ...." ----> "struct ....."
1326 elsif ( /(struct|union|enum)/o )
1327 {
1328 145 s/^\s*typedef\s+//o;
1329 }
1330 elsif ( ! /{/o ) #&& /;/o ) # lines already joined
1331 {
1332 116 ▶ while ( /\btypedef\s+[^;]+\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\btypedef\s+[^;]+\s*;/o) 145 116 261
1333 {
1334 # cannot do function pointers, take
1335 # just simple types
1336 145 ▶ if ( /\btypedef([\w*\s]+)\b(\w+)\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\btypedef([\w*\s]+)\b(\w+)\s*;/o) 116 29 145
1337 {
1338 116 ▶ if ( $typedef_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($typedef_sub) { } 112 4 116
1339 {
1340 112 my $old = $1;
1341 112 my $new = $2;
1342 112 $old =~ s/^\s+//o;
1343 112 $new =~ s/^\s+//o;
1344 112 $old =~ s/\s+$//o;
1345 112 $new =~ s/\s+$//o;
1346 112 $line = &$typedef_sub($old, $new);
1347 }
1348 else
1349 {
1350 4 $line = '';
1351 }
1352 116 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 104 12 116
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
48104
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1353 }
1354 145 s/^\s*typedef\s+[^;]+\s*;//o;
1355 }
1356  
1357 116 next;
1358 }
1359 # no NEXT here
1360 }
1361  
1362 # structures:
1363  
1364 1711 ▶ if ( /^\s*struct/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*struct/o) 609 1102 1711
1365 {
1366 # skip over expressions of the type:
1367 # struct xxx function(arg1, ...);
1368 609 ▶ if ( /\(/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\(/o) { } 29 580 609
1369 {
1370 29 $_ = '';
1371 }
1372 else
1373 {
1374 580 $sub_params{'line'} = $_;
1375 580 parse_struct(%sub_params);
1376 }
1377 609 next;
1378 }
1379  
1380 # enumerations
1381 1102 ▶ if ( /^\s*enum/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*enum/o) 319 783 1102
1382 {
1383 # skip over expressions of the type:
1384 # enum xxx function(arg1, ...);
1385 319 ▶ if ( /\(/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\(/o) 29 290 319
1386 {
1387 29 $_ = '';
1388 29 next;
1389 }
1390 # remove the 'enum' and its name
1391 290 ▶ if ( /^.*enum\s+(\w+)\s*\{?/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^.*enum\s+(\w+)\s*\{?/o) { } 261 29 290
1392 {
1393 261 ▶ $line = &$enum_start_sub($1) if $enum_start_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_start_sub 252 9 261
1394 261 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 236 25 261
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
916236
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1395 261 s/^.*enum\s+\w+\s*\{?//o;
1396 }
1397 else
1398 {
1399 29 s/^.*enum\s*\{?//o;
1400 }
1401 290 my $curr_value = 0;
1402  
1403 #&_split_decl($infile);
1404 # check if one-line enum
1405 290 ▶ if ( /}/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/}/o) { } 116 174 290
1406 {
1407 # there are no conditional compiling directives in one-line enums
1408 #if ( $preproc_sub )
1409 #{
1410 # $_ = &$preproc_sub($_);
1411 #}
1412 #else
1413 #{
1414 # $_ = '';
1415 #}
1416  
1417 116 ▶ while ( /,.*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/,.*;/o) 116 116 232
1418 {
1419 116 ▶ if ( /([\w\s]*)\s+(\w+)\s*=\s*(\w+)\s*,/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/([\w\s]*)\s+(\w+)\s*=\s*(\w+)\s*,/o) 29 87 116
1420 {
1421 29 ▶ $line = &$enum_entry_sub ($2, $3) if $enum_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_entry_sub 28 1 29
1422 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1423 29 $curr_value = $3+1;
1424 29 s/[\w\s]*\s+\w+\s*=\s*\w+\s*,//o
1425 }
1426 116 ▶ if ( /([\w\s]*)\s+(\w+)\s*,/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/([\w\s]*)\s+(\w+)\s*,/o) 87 29 116
1427 {
1428 87 ▶ $line = &$enum_entry_sub ($2, $curr_value) if $enum_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_entry_sub 84 3 87
1429 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1430 87 $curr_value++;
1431 87 s/[\w\s]*\s+\w+\s*,//o
1432 }
1433 }
1434  
1435 # the last line has no comma
1436 116 ▶ if ( /^\s*(\w+)\s*=\s*(\w+)\s*\}\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*(\w+)\s*=\s*(\w+)\s*\}\s*;/o) 29 87 116
1437 {
1438 29 ▶ $line = &$enum_entry_sub ($1, $2) if $enum_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_entry_sub 28 1 29
1439 29 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 27 2 29
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
1127
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1440 29 s/^\s*\w+\s*=\s*\w+\s*\}\s*;//o
1441 }
1442 116 ▶ if ( /^\s*(\w+)\s*\}\s*;/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*(\w+)\s*\}\s*;/o) 87 29 116
1443 {
1444 87 ▶ $line = &$enum_entry_sub ($1, $curr_value) if $enum_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_entry_sub 84 3 87
1445 87 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 81 6 87
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
3381
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1446 87 s/^\s*\w+\s*\}\s*;//o
1447 }
1448  
1449 116 ▶ $line = &$enum_end_sub() if $enum_end_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_end_sub 112 4 116
1450 116 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 4 112 116
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
41084
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1451 # processing the comments
1452 116 ▶ if ( $comment_sub and ( m#//# or m#/\*# ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[//] || m[/\*]) 56 60 116
Condition100%6/6
$comment_sub and m[//] || m[/\*]
!ll&&!rl&&r
45656
m[//] or m[/\*]
l!l&&r!l&&!r
282856
MC/DC100%3/3
$comment_sub and m[//] || m[/\*]
$comment_sub m[//] m[/\*]
Truth table100%4/4
A and B or C
A= $comment_subB= m[//]C= m[/\*]
ABCresult
0XX0
1000
11X1
1011
1453 {
1454 56 $_ = &$comment_sub($_);
1455 56 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 52 4 56
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
2252
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
1456 }
1457 116 next;
1458 }
1459 else
1460 {
1461 174 ▶ while ( <$infile> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $infile)) 754 0 754
1462 {
1463 # processing of conditional compiling directives
1464 754 ▶ if ( /^\s*#/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*#/o) 29 725 754
1465 {
1466 29 ▶ if ( $preproc_sub )
Branch: 1 branch
BranchTrueFalseTotal
if ($preproc_sub) { } 28 1 29
1467 {
1468 28 $_ = &$preproc_sub($_);
1469 }
1470 else
1471 {
1472 1 $_ = '';
1473 }
1474 29 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 26 3 29
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
1226
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
1475  
1476 29 next;
1477 }
1478  
1479 725 &_remove_attrs;
1480 # skip over the first '{' character
1481 #next if /^\s*\{\s*$/o;
1482 725 s/^\s*{\s*$//go;
1483  
1484 725 ▶ next if /^\s*$/o;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/o 174 551 725
1485  
1486 # if the constant has a value, we don't touch it
1487 551 ▶ if ( /=/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/=/o) { } 87 464 551
1488 {
1489 87 ▶ if ( /^\s*(\w+)\s*=\s*([-*\/+\w]+)\s*,?/o )
Branch: 1 branch
BranchTrueFalseTotal
if (m[^\s*(\w+)\s*=\s*([-*/+\w]+)\s*,?]o) 58 29 87
1490 {
1491 58 ▶ $line = &$enum_entry_sub ($1, $2) if $enum_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_entry_sub 56 2 58
1492 58 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 54 4 58
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
2254
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1493 58 ▶ $curr_value = $2 + 1 if _is_a_number ($2);
Branch: 1 branch
BranchTrueFalseTotal
if _is_a_number($2) 29 29 58
1494 58 s/^\s*\w+\s*=\s*\w+\s*,?//o;
1495 }
1496 }
1497 else
1498 {
1499 # assign a subsequent value
1500 464 ▶ if ( /^\s*(\w+)\s*,?/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*(\w+)\s*,?/o) 232 232 464
1501 {
1502 232 ▶ $line = &$enum_entry_sub ($1, $curr_value) if $enum_entry_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_entry_sub 224 8 232
1503 232 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 213 19 232
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
811213
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1504 232 $curr_value++;
1505 232 s/^\s*\w+\s*,?//o;
1506 }
1507 }
1508  
1509 # processing the comments
1510 551 ▶ if ( $comment_sub and ( m#//# or m#/\*# ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[//] || m[/\*]) 56 495 551
Condition100%6/6
$comment_sub and m[//] || m[/\*]
!ll&&!rl&&r
1947656
m[//] or m[/\*]
l!l&&r!l&&!r
2828476
MC/DC100%3/3
$comment_sub and m[//] || m[/\*]
$comment_sub m[//] m[/\*]
Truth table100%4/4
A and B or C
A= $comment_subB= m[//]C= m[/\*]
ABCresult
0XX0
1000
11X1
1011
1511 {
1512 56 $line = &$comment_sub($_);
1513 56 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 54 2 56
1514 }
1515  
1516 # look for the end of the enum
1517 551 ▶ if ( /\s*\}.*/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\s*\}.*/o) 174 377 551
1518 {
1519 174 ▶ $line = &$enum_end_sub() if $enum_end_sub;
Branch: 1 branch
BranchTrueFalseTotal
if $enum_end_sub 168 6 174
1520 174 ▶ &$output_sub($line) if $output_sub and $line;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $line 6 168 174
Condition100%3/3
$output_sub and $line
!ll&&!rl&&r
61626
MC/DC100%2/2
$output_sub and $line
$output_sub $line
Truth table100%3/3
A and B
A= $output_subB= $line
ABresult
0X0
100
111
1521 174 next READ;
1522 }
1523  
1524 377 ▶ &$output_sub($_) if $output_sub and $_;
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub and $_ 224 153 377
Condition100%3/3
$output_sub and $_
!ll&&!rl&&r
13140224
MC/DC100%2/2
$output_sub and $_
$output_sub $_
Truth table100%3/3
A and B
A= $output_subB= $_
ABresult
0X0
100
111
1525 }
1526 }
1527 }
1528  
1529 783 ▶ if ( /^\s*union/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*union/o) 493 290 783
1530 {
1531 # skip over expressions of the type:
1532 # union xxx function(arg1, ...);
1533 493 ▶ if ( /\(/o )
Branch: 1 branch
BranchTrueFalseTotal
if (/\(/o) { } 29 464 493
1534 {
1535 29 $_ = '';
1536 }
1537 else
1538 {
1539 464 $sub_params{'line'} = $_;
1540 464 parse_union(%sub_params);
1541 }
1542 493 next;
1543 }
1544  
1545 290 s/^\s*{\s*$//go;
1546 # remove any }'s left after <extern "C">, for example
1547 290 s/^\s*}\s*$//go;
1548 290 ▶ if ( $comment_sub and m#/\*# ) # single-line comments should be processed at the top
Branch: 1 branch
BranchTrueFalseTotal
if ($comment_sub and m[/\*]) 28 262 290
Condition100%3/3
$comment_sub and m[/\*]
!ll&&!rl&&r
1025228
MC/DC100%2/2
$comment_sub and m[/\*]
$comment_sub m[/\*]
Truth table100%3/3
A and B
A= $comment_subB= m[/\*]
ABresult
0X0
100
111
1549 {
1550 28 $line = &$comment_sub($_);
1551 28 ▶ $_ = $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 27 1 28
1552 }
1553 290 ▶ &$output_sub($_) if $output_sub; # and $_; # the line won't be empty here
Branch: 1 branch
BranchTrueFalseTotal
if $output_sub 280 10 290
1554 }
1555 }
1556  
1557  
1558 =head1 SUPPORT AND DOCUMENTATION
1559  
1560 After installing, you can find documentation for this module with the perldoc command.
1561  
1562 perldoc Parse::H
1563  
1564 You can also look for information at:
1565  
1566 Search CPAN
1567 https://metacpan.org/release/Parse-H
1568  
1569 CPAN Request Tracker:
1570 https://rt.cpan.org/Public/Dist/Display.html?Name=Parse-H
1571  
1572 =head1 AUTHOR
1573  
1574 Bogdan Drozdowski, C<< <bogdro /at cpan . org> >>
1575  
1576 =head1 COPYRIGHT
1577  
1578 Copyright 2022-2025 Bogdan Drozdowski, all rights reserved.
1579  
1580 =head1 LICENSE
1581  
1582 This program is free software; you can redistribute it and/or modify it
1583 under the same terms as Perl itself.
1584  
1585 =cut
1586  
1587 3 1; # End of Parse::H
↑ Summary