blib/lib/Affix/Wrap.pm

filter: Statementstmt 48.3% 513 / 1061 Branchbran 27.5% 142 / 516 Conditioncond 13.3% 47 / 352 MC/DCmcdc 3.6% 7 / 194 Subroutinesub 56.6% 77 / 136 Podpod 75.0% 3 / 4 totaltotal 34.8% 789 / 2263 CC 432 SCAR 46.0
CC
432
Cov
36%
list_symbols
506.0
_walk
420.0
parse_doc
306.0
CRAP 99.6
« blib/lib/Affix/Platform/BSD.pm ↑ Summary blib/lib/Test2/Tools/Affix.pm »
1 2 package Affix::Wrap v1.4.0 {
2 2 ▶ use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶ use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶ no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶ no warnings 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶ use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use Capture::Tiny qw[capture];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶ use File::Basename qw[basename];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶ use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶ use Affix qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
12 #
13 class #
14 2 Affix::Wrap::Type {
15 2 ▶ use Affix qw[Void];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 field $name : reader : param //= 'void';
17 2 field $is_const : reader : param //= 0;
18 0 ▶ method to_string { ( $is_const ? 'const ' : '' ) . $self->name }
Subroutine to_string: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$is_const ? : 0 0 0
19 2 ▶ use overload '""' => 'to_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
20
21 # Factory method to parse a C type string into objects
22 47 ▶ sub parse ( $class, $t ) {
Subroutine parse: called CC=9 SCAR=25.5
23 47 ▶ return $class->new( name => 'void' ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 47 47
24
25 # Cleanup
26 47 $t =~ s/__attribute__\s*\(\(.*\)\)//g;
27 47 $t =~ s/\b(restrict|volatile)\b//g;
28 47 $t =~ s/^\s+|\s+$//g;
29
30 # Function Pointers: Ret (*)(Args)
31 47 ▶ if ( $t =~ /^(.+?)\s*\(\*\)\s*\((.*)\)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /^(.+?)\s*\(\*\)\s*\((.*)\)$/u) 0 47 47
32 0 my ( $ret_str, $args_str ) = ( $1, $2 );
33 0 my @args;
34 0 ▶ if ( $args_str ne '' && $args_str ne 'void' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args_str ne "" and $args_str ne "void") 0 0 0
Condition0%0/3
$args_str ne "" and $args_str ne "void"
!ll&&!rl&&r
000
MC/DC0%0/2
$args_str ne "" and $args_str ne "void"
$args_str ne "" $args_str ne "void"
Truth table0%0/3
A and B
A= $args_str ne ""B= $args_str ne "void"
ABresult
0X0
100
111
35
36 # Simple split; for complex nested pointers, Clang driver is preferred
37 0 @args = map { $class->parse($_) } split( /\s*,\s*/, $args_str );
38 }
39 0 return Affix::Wrap::Type::CodeRef->new( ret => $class->parse($ret_str), params => \@args );
40 }
41
42 # Arrays: Type[N]
43 47 ▶ if ( $t =~ /^(.*)\s*\[(\d+)\]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /^(.*)\s*\[(\d+)\]$/u) 4 43 47
44 4 return Affix::Wrap::Type::Array->new( of => $class->parse($1), count => $2 );
45 }
46
47 # Pointers: Type * [const]
48 # We match the outermost pointer and its trailing const qualifier
49 43 ▶ if ( $t =~ /^(.*)\s*\*\s*(const)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /^(.*)\s*\*\s*(const)?$/u) 5 38 43
50 5 my ( $inner, $is_ptr_const ) = ( $1, $2 );
51 5 ▶ return Affix::Wrap::Type::Pointer->new( of => $class->parse($inner), is_const => ( $is_ptr_const ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$is_ptr_const ? : 1 4 5
52 }
53
54 # Base Types: [const] Name
55 # Only strip the const if it's at this level
56 38 ▶ my $const = ( $t =~ s/\bconst\b//g ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$t =~ s/\bconst\b//gu ? : 1 37 38
57 38 $t =~ s/^\s+|\s+$//g;
58 38 return $class->new( name => $t, is_const => $const );
59 }
60
61 38 ▶ sub _type_map ( $self //= () ) {
Subroutine _type_map: called CC=2 SCAR=6.9
62 38 state $type_map = {
63 void => 'Void',
64 bool => 'Bool',
65 short => 'Short',
66 'unsigned short' => 'UShort',
67 char => 'Char',
68 'signed char' => 'SChar',
69 'unsigned char' => 'UChar',
70 int => 'Int',
71 'unsigned int' => 'UInt',
72 long => 'Long',
73 'unsigned long' => 'ULong',
74 'long long' => 'LongLong',
75 'unsigned long long' => 'ULongLong',
76 float => 'Float',
77 double => 'Double',
78 'long double' => 'LongDouble',
79
80 # Extended stdint.h
81 int8_t => 'Int8',
82 sint8_t => 'SInt8',
83 uint8_t => 'UInt8',
84 int16_t => 'Int16',
85 sint16_t => 'SInt16',
86 uint16_t => 'UInt16',
87 int32_t => 'Int32',
88 sint32_t => 'SInt32',
89 uint32_t => 'UInt32',
90 int64_t => 'Int64',
91 sint64_t => 'SInt64',
92 uint64_t => 'UInt64',
93 int128_t => 'Int128',
94 sint128_t => 'SInt128',
95 uint128_t => 'UInt128',
96
97 # Fast & Least stdint.h types
98 uint_fast8_t => 'UInt8',
99 int_fast8_t => 'Int8',
100 uint_fast16_t => 'UInt16',
101 int_fast16_t => 'Int16',
102 uint_fast32_t => 'UInt32',
103 int_fast32_t => 'Int32',
104 uint_fast64_t => 'UInt64',
105 int_fast64_t => 'Int64',
106 uint_least8_t => 'UInt8',
107 int_least8_t => 'Int8',
108 uint_least16_t => 'UInt16',
109 int_least16_t => 'Int16',
110 uint_least32_t => 'UInt32',
111 int_least32_t => 'Int32',
112 uint_least64_t => 'UInt64',
113 int_least64_t => 'Int64',
114
115 # Architecture specific
116 size_t => 'Size_t',
117 ssize_t => 'SSize_t',
118 ptrdiff_t => 'SSize_t',
119 intptr_t => 'SSize_t',
120 uintptr_t => 'Size_t',
121 off_t => 'SSize_t',
122 pid_t => 'Int',
123 wchar_t => 'WChar',
124 time_t => 'Int64',
125
126 # Variadic
127 '...' => 'VarArgs',
128 va_list => 'VarArgs',
129 '__builtin_va_list' => 'VarArgs',
130
131 # Standard library structures mapped to pointers
132 'char[]' => 'String',
133 'file*' => 'File',
134 file => 'Void',
135 jmp_buf => 'Void',
136 _jbtype => 'Void',
137 tm => 'Void',
138 'struct tm' => 'Void'
139 };
140 38 return $type_map;
141 }
142
143 38 ▶ method _clean_name {
Subroutine _clean_name: called CC=1 SCAR=0.0
144 38 my $t = $self->name;
145 38 $t =~ s/^(?:struct|union|enum)\s+//;
146 38 $t =~ s/\s*\*+$//;
147 38 $t =~ s/^\s+|\s+$//g;
148 38 return $t;
149 }
150
151 37 ▶ method affix_type {
Subroutine affix_type: called CC=4 SCAR=14.6
152 37 my $clean = $self->_clean_name;
153 37 my $map = $self->_type_map;
154 37 my $key = lc $clean;
155
156 # Get the CamelCase Perl sub name (e.g. 'Int', 'Double', or the cleaned Custom Name with parens)
157 37 ▶ my $out = exists $map->{$key} ? $map->{$key} : ( $clean =~ /^[a-zA-Z_]\w*$/ ? "$clean()" : 'Void' );
Branch: 2 branches
BranchTrueFalseTotal
exists $map->{$key} ? : 37 0 37
$clean =~ /^[a-zA-Z_]\w*$/u ? : 0 0 0
158
159 # Apply Const wrapper if this level is qualified
160 37 ▶ return $is_const ? "Const[$out]" : $out;
Branch: 1 branch
BranchTrueFalseTotal
$is_const ? : 1 36 37
161 }
162
163 1 ▶ method affix {
Subroutine affix: called CC=5 SCAR=17.1
164 2 ▶ use Affix qw[Void Const];
Subroutine BEGIN: called CC=1 SCAR=0.0
165 1 my $clean = lc $self->_clean_name;
166 1 my $map = $self->_type_map;
167 1 my $res;
168 1 ▶ if ( exists $map->{$clean} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map->{$clean}) { } 1 0 1
169 1 my $mapped = $map->{$clean};
170 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
171 1 my $fn = "Affix::$mapped";
172 1 ▶ $res = defined &{$fn} ? $fn->() : "\@$mapped";
Branch: 1 branch
BranchTrueFalseTotal
defined &{$fn;} ? : 1 0 1
173 }
174 else {
175 0 my $raw_name = $self->_clean_name;
176 0 ▶ $res = ( $raw_name =~ /^[a-z_]\w*$/i ) ? "\@$raw_name" : Void();
Branch: 1 branch
BranchTrueFalseTotal
$raw_name =~ /^[a-z_]\w*$/iu ? : 0 0 0
177 }
178 1 ▶ return $is_const ? Const [$res] : $res;
Branch: 1 branch
BranchTrueFalseTotal
$is_const ? : 0 1 1
179 }
180 }
181 class #
182 2 Affix::Wrap::Type::Pointer : isa(Affix::Wrap::Type) {
183 2 ▶ use Affix qw[Pointer Const];
Subroutine BEGIN: called CC=1 SCAR=0.0
184 2 field $of : reader : param;
185 0 ▶ method name { $of->name . '*' }
Subroutine name: not called CC=1 SCAR=6.9
186
187 5 ▶ method affix_type {
Subroutine affix_type: called CC=2 SCAR=6.9
188 5 my $res = 'Pointer[' . $of->affix_type . ']';
189 5 ▶ return $self->is_const ? "Const[$res]" : $res;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_const ? : 1 4 5
190 }
191
192 0 ▶ method affix {
Subroutine affix: not called CC=2 SCAR=17.9
193 0 my $res = Pointer [ $of->affix ];
194 0 ▶ return $self->is_const ? Const [$res] : $res;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_const ? : 0 0 0
195 }
196 };
197 class #
198 2 Affix::Wrap::Type::Array : isa(Affix::Wrap::Type) {
199 2 ▶ use Affix qw[Array];
Subroutine BEGIN: called CC=1 SCAR=0.0
200 2 field $of : reader : param;
201 2 field $count : reader : param;
202 0 ▶ method name { $of->name . '[' . $count . ']' }
Subroutine name: not called CC=1 SCAR=6.9
203 4 ▶ method affix_type { 'Array[' . $of->affix_type . ', ' . $count . ']' }
Subroutine affix_type: called CC=1 SCAR=0.0
204 0 ▶ method affix { Array [ $of->affix, $count ] }
Subroutine affix: not called CC=1 SCAR=6.9
205 };
206 class #
207 2 Affix::Wrap::Type::CodeRef : isa(Affix::Wrap::Type) {
208 2 ▶ use Affix qw[Callback];
Subroutine BEGIN: called CC=1 SCAR=0.0
209 2 field $ret : reader : param;
210 2 field $params : reader : param; # ArrayRef of Types
211
212 0 ▶ method name {
Subroutine name: not called CC=1 SCAR=6.9
213 0 sprintf '%s (*)(%s)', $ret->name, join( ', ', map { $_->name } @$params );
214 }
215
216 1 ▶ method affix_type {
Subroutine affix_type: called CC=1 SCAR=0.0
217 1 sprintf 'Callback[[%s] => %s]', join( ', ', map { $_->affix_type } @$params ), $ret->affix_type;
218 }
219
220 0 ▶ method affix {
Subroutine affix: not called CC=1 SCAR=6.9
221 0 Callback [ [ map { $_->affix } @$params ], $ret->affix ];
222 }
223 };
224 class #
225 2 Affix::Wrap::Argument {
226 2 field $type : reader : param;
227 2 field $name : reader : param //= '';
228 0 ▶ method to_string { length($name) ? $type->to_string . ' ' . $name : $type->to_string }
Subroutine to_string: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
length $name ? : 0 0 0
229 2 ▶ use overload '""' => 'to_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
230 9 ▶ method affix_type { $type->affix_type }
Subroutine affix_type: called CC=1 SCAR=0.0
231 0 ▶ method affix { $type->affix }
Subroutine affix: not called CC=1 SCAR=6.9
232 }
233 class #
234 2 Affix::Wrap::Entity {
235 2 field $name : reader : param //= '';
236 2 field $doc : reader : param //= ();
237 2 field $file : reader : param //= '';
238 2 field $line : reader : param //= 0;
239 2 field $end_line : reader : param //= 0;
240 2 field $start_offset : reader : param //= 0;
241 2 field $end_offset : reader : param //= 0;
242 2 field $is_merged : reader = 0;
243 2 field $doc_data = undef;
244 0 ▶ method mark_merged { $is_merged = 1 }
Subroutine mark_merged: not called CC=1 SCAR=6.9
245 0 ▶ method _base($p) { return '' unless defined $p; $p =~ s{^.*[/\\]}{}; return $p }
Subroutine _base: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 0 0
246
247 0 ▶ method describe {
Subroutine describe: not called CC=1 SCAR=6.9
248 0 return sprintf '[%s] %s (%s:%d)', __CLASS__ =~ s/^Affix::Wrap:://r, $name, $self->_base($file), $line;
249 }
250
251 # Helper to convert Doxygen/Markdown to POD
252 0 ▶ method _format_pod($text) {
Subroutine _format_pod: not called CC=1 SCAR=6.9
253 0 $text =~ s/^\s+|\s+$//g;
254 0 $text =~ s/`([^`]+)`/C<$1>/g; # Code blocks: `code` -> C<code>
255 0 $text =~ s/\*\*([^*]+)\*\*/B<$1>/g; # Bold: **text** -> B<text>
256 0 $text =~ s/\*([^*]+)\*/I<$1>/g; # Italic: *text* -> I<text>
257 0 $text =~ s/\[([^\]]+)\]\(([^)]+)\)/L<$1|$2>/g; # Links: [foo](bar) -> L<foo|bar>
258 0 return $text;
259 }
260
261 0 ▶ method parse_doc () {
Subroutine parse_doc: not called CC=17 SCAR=57.2
262 0 ▶ return $doc_data if defined $doc_data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $doc_data 0 0 0
263 0 ▶ my $raw = $doc // '';
Condition0%0/2
$doc // ""
l!l
00
MC/DC0%0/1
$doc // ""
$doc
Truth table0%0/2
A
A= $doc
Aresult
11
00
264 0 my $data = { brief => '', desc => '', params => {}, return => '', };
265 0 my @lines = split /\n/, $raw;
266 0 my $current_tag = 'desc';
267 0 my $current_param = undef;
268 0 foreach my $line (@lines) {
269 0 $line =~ s/^\s+|\s+$//g;
270 0 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
271 0 ▶ if ( $line =~ /^[@\\]brief\s+(.*)/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /^[\@\\]brief\s+(.*)/u) { } 0 0 0
elsif ($line =~ /^[\@\\]param(?:\[.*?\])?\s+(\w+)\s+(.*)/u) { } 0 0 0
elsif ($line =~ /^[\@\\]returns?\s+(.*)/u) { } 0 0 0
elsif ($line =~ /^[\@\\](\w+)\s*(.*)/u) { } 0 0 0
272 0 $data->{brief} = $1;
273 0 $current_tag = 'brief';
274 }
275 elsif ( $line =~ /^[@\\]param(?:\[.*?\])?\s+(\w+)\s+(.*)/ ) {
276 0 $data->{params}{$1} = $2;
277 0 $current_param = $1;
278 0 $current_tag = 'param';
279 }
280 elsif ( $line =~ /^[@\\]returns?\s+(.*)/ ) {
281 0 $data->{return} = $1;
282 0 $current_tag = 'return';
283 }
284 elsif ( $line =~ /^[@\\](\w+)\s*(.*)/ ) {
285 0 my $tag = ucfirst($1);
286 0 $data->{desc} .= "\n\nB<$tag:> $2";
287 0 $current_tag = 'desc';
288 }
289 else {
290 0 ▶ if ( $current_tag eq 'brief' ) { $data->{brief} .= ' ' . $line; }
Branch: 3 branches
BranchTrueFalseTotal
if ($current_tag eq 'brief') { } 0 0 0
elsif ($current_tag eq 'param' and defined $current_param) { } 0 0 0
elsif ($current_tag eq 'return') { } 0 0 0
291 0 ▶ elsif ( $current_tag eq 'param' && defined $current_param ) { $data->{params}{$current_param} .= ' ' . $line; }
Condition0%0/3
$current_tag eq "param" and defined $current_param
!ll&&!rl&&r
000
MC/DC0%0/2
$current_tag eq "param" and defined $current_param
$current_tag eq "param" defined $current_param
Truth table0%0/3
A and B
A= $current_tag eq "param"B= defined $current_param
ABresult
0X0
100
111
292 0 elsif ( $current_tag eq 'return' ) { $data->{return} .= ' ' . $line; }
293 0 ▶ else { $data->{desc} .= ( length( $data->{desc} ) ? "\n" : '' ) . $line; }
Branch: 1 branch
BranchTrueFalseTotal
length $data->{'desc'} ? : 0 0 0
294 }
295 }
296 0 ▶ if ( length( $data->{brief} ) == 0 && length( $data->{desc} ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data->{"brief"} == 0 and length $data->{"desc"} > 0) 0 0 0
Condition0%0/3
length $data->{"brief"} == 0 and length $data->{"desc"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
length $data->{"brief"} == 0 and length $data->{"desc"} > 0
length $data->{"brief"} == 0 length $data->{"desc"} > 0
Truth table0%0/3
A and B
A= length $data->{"brief"} == 0B= length $data->{"desc"} > 0
ABresult
0X0
100
111
297 0 ▶ if ( $data->{desc} =~ s/^(.+?\.)\s+//s ) { $data->{brief} = $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"desc"} =~ s/^(.+?\.)\s+//su) 0 0 0
298 }
299 0 return $doc_data = $data;
300 }
301
302 0 ▶ method pod {
Subroutine pod: not called CC=8 SCAR=42.8
303 0 my $d = $self->parse_doc;
304 0 my $out = '=head2 ' . $self->name . "\n\n";
305 0 ▶ $out .= $self->_format_pod( $d->{brief} ) . "\n\n" if length $d->{brief};
Branch: 1 branch
BranchTrueFalseTotal
if length $d->{"brief"} 0 0 0
306 0 ▶ $out .= $self->_format_pod( $d->{desc} ) . "\n\n" if length $d->{desc};
Branch: 1 branch
BranchTrueFalseTotal
if length $d->{"desc"} 0 0 0
307
308 # Format parameters
309 0 ▶ if ( keys %{ $d->{params} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$d{"params"};}) 0 0 0
310 0 $out .= "=over\n\n";
311 0 my @param_names = sort keys %{ $d->{params} };
312
313 # If we have args metadata (e.g. Function), use it for ordering
314 0 ▶ if ( $self->can('args') && ref( $self->args ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("args") and ref $self->args eq "ARRAY") 0 0 0
Condition0%0/3
$self->can("args") and ref $self->args eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can("args") and ref $self->args eq "ARRAY"
$self->can("args") ref $self->args eq "ARRAY"
Truth table0%0/3
A and B
A= $self->can("args")B= ref $self->args eq "ARRAY"
ABresult
0X0
100
111
315 0 @param_names = map { $_->name } grep { exists $d->{params}{ $_->name } } @{ $self->args };
316
317 # Fallback for params documented but not in signature (rare but possible in C macros/varargs)
318 0 my %seen = map { $_ => 1 } @param_names;
319 0 push @param_names, grep { !$seen{$_} } sort keys %{ $d->{params} };
320 }
321 0 for my $name (@param_names) {
322 0 $out .= "=item C<$name>\n\n" . $self->_format_pod( $d->{params}{$name} ) . "\n\n";
323 }
324 0 $out .= "=back\n\n";
325 }
326
327 # Format return value
328 0 ▶ if ( length $d->{return} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $d->{"return"}) 0 0 0
329 0 $out .= "B<Returns:> " . $self->_format_pod( $d->{return} ) . "\n\n";
330 }
331 0 $out;
332 }
333 0 ▶ method affix( $lib //= (), $pkg //= () ) { return undef }
Subroutine affix: not called CC=3 SCAR=24.8
334 }
335 class #
336 2 Affix::Wrap::Member {
337 2 ▶ use Affix qw[Void];
Subroutine BEGIN: called CC=1 SCAR=0.0
338 2 field $name : reader : param //= '';
339 2 field $type : reader : param //= '';
340 2 field $doc : reader : param //= ();
341 2 field $definition : reader : param //= ();
342
343 4 ▶ method affix_type {
Subroutine affix_type: called CC=2 SCAR=7.2
344 4 ▶ return $definition->affix_type if defined $definition;
Branch: 1 branch
BranchTrueFalseTotal
if defined $definition 0 4 4
345 4 return $type->affix_type;
346 }
347
348 1 ▶ method affix {
Subroutine affix: called CC=4 SCAR=20.1
349 1 ▶ return $definition->affix if defined $definition;
Branch: 1 branch
BranchTrueFalseTotal
if defined $definition 0 1 1
350 1 ▶ return $type->affix if builtin::blessed($type);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($type) 1 0 1
351
352 # Fallback: if it's just a string, wrap it in a Reference object
353 0 ▶ return Affix::Type::Reference->new( name => $type =~ s/^@//r ) if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 0 0 0
354 0 return Affix::Void();
355 }
356 }
357 class #
358 2 Affix::Wrap::Macro : isa(Affix::Wrap::Entity) {
359 2 field $value : reader : param //= ();
360 6 ▶ method set_value ($v) { $value = $v }
Subroutine set_value: called CC=1 SCAR=0.0
361
362 10 ▶ method affix_type {
Subroutine affix_type: called CC=7 SCAR=19.7
363 10 ▶ my $v = $self->value // return '';
Condition50%1/2
$self->value // (return "")
l!l
100
MC/DC0%0/1
$self->value // (return "")
$self->value
Truth table50%1/2
A
A= $self->value
Aresult
11
00
364
365 # Sanitize C string concatenations in macros (e.g. "a" "b" -> "ab")
366 10 $v =~ s/"\s+"//g;
367
368 # Strip outer quotes from C string literals
369 10 ▶ if ( $v =~ /^"(.*)"$/ ) { $v = $1; $v =~ s/\\(.)/$1/g; }
Branch: 2 branches
BranchTrueFalseTotal
if ($v =~ /^"(.*)"$/u) { } 2 8 10
elsif ($v =~ /^'(.*)'$/u) { } 0 8 8
370 0 elsif ( $v =~ /^'(.*)'$/ ) { $v = $1; }
371
372 # Protect against Perl-internal reserved names (starting with __)
373 # and macros containing unresolved C calls or backslashes
374 10 ▶ if ( $self->name =~ /^__/ || $v =~ /[\\()]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->name =~ /^__/u or $v =~ /[\\()]/u) 1 9 10
Condition66%2/3
$self->name =~ /^__/u or $v =~ /[\\()]/u
l!l&&r!l&&!r
019
MC/DC50%1/2
$self->name =~ /^__/u or $v =~ /[\\()]/u
$self->name =~ /^__/u $v =~ /[\\()]/u
Truth table66%2/3
A or B
A= $self->name =~ /^__/uB= $v =~ /[\\()]/u
ABresult
1X1
011
000
375 1 return '# use constant ' . $self->name . " => $v";
376 }
377 9 ▶ if ( $v =~ /^-?(?:0x[\da-fA-F]+|\d+(?:\.\d+)?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^-?(?:0x[\da-fA-F]+|\d+(?:\.\d+)?)$/u) 7 2 9
378 7 return sprintf 'use constant %s => %s', $self->name, $v;
379 }
380 2 $v =~ s/'/\\'/g;
381 2 return "use constant " . $self->name . " => '$v'";
382 }
383
384 2 ▶ method affix ( $lib //= (), $pkg //= () ) {
Subroutine affix: called CC=10 SCAR=26.2
385 2 ▶ if ( $pkg && defined $value && length $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg and defined $value and length $value) 2 0 2
Condition33%2/6
$pkg and defined $value and length $value
!ll&&!rl&&r
002
$pkg and defined $value
!ll&&!rl&&r
002
MC/DC0%0/3
$pkg and defined $value and length $value
$pkg defined $value length $value
Truth table25%1/4
A and B and C
A= $pkgB= defined $valueC= length $value
ABCresult
0XX0
10X0
1100
1111
386 2 my $val = $value;
387 0 ▶ if ( $val =~ /^"(.*)"$/ || $val =~ /^'(.*)'$/ ) { $val = $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^"(.*)"$/u or $val =~ /^'(.*)'$/u) 0 2 2
Condition33%1/3
$val =~ /^"(.*)"$/u or $val =~ /^'(.*)'$/u
l!l&&r!l&&!r
002
MC/DC0%0/2
$val =~ /^"(.*)"$/u or $val =~ /^'(.*)'$/u
$val =~ /^"(.*)"$/u $val =~ /^'(.*)'$/u
Truth table33%1/3
A or B
A= $val =~ /^"(.*)"$/uB= $val =~ /^'(.*)'$/u
ABresult
1X1
011
000
388 2 ▶ if ( $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/ && $self->name =~ /^[a-zA-Z_]\w*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u and $self->name =~ /^[a-zA-Z_]\w*$/u) 1 1 2
Condition66%2/3
$pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u and $self->name =~ /^[a-zA-Z_]\w*$/u
!ll&&!rl&&r
011
MC/DC50%1/2
$pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u and $self->name =~ /^[a-zA-Z_]\w*$/u
$pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u $self->name =~ /^[a-zA-Z_]\w*$/u
Truth table66%2/3
A and B
A= $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/uB= $self->name =~ /^[a-zA-Z_]\w*$/u
ABresult
0X0
100
111
389 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
390 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
391 0 ▶ *{ "${pkg}::" . $self->name } = sub () {$val};
Subroutine __ANON__: not called CC=1 SCAR=0.4
392 }
393 }
394 0 ▶ sub () {$value};
Subroutine __ANON__: not called CC=1 SCAR=1.2
395 }
396 };
397 class #
398 2 Affix::Wrap::Variable : isa(Affix::Wrap::Entity) {
399 2 field $type : reader : param;
400
401 0 ▶ method affix_type {
Subroutine affix_type: not called CC=1 SCAR=6.9
402
403 # Safely declare the package var, then attempt to pin it
404 0 sprintf "our \$%s;\n try { Affix::pin(\$%s, \$lib, '%s', %s) } catch(\$e) { }", $self->name, $self->name, $self->name,
405 $type->affix_type;
406 }
407
408 0 ▶ method affix ( $lib, $pkg //= () ) {
Subroutine affix: not called CC=2 SCAR=17.9
409 0 my $var;
410 0 try {
411 0 Affix::pin( $var, $lib, $self->name, $type->affix );
412 }
413 catch ($e) {
414
415 # Symbol missing; that's fine
416 }
417 0 return $var;
418 }
419 };
420 class #
421 2 Affix::Wrap::Typedef : isa(Affix::Wrap::Entity) {
422 2 field $underlying : reader : param;
423
424 3 ▶ method affix_type {
Subroutine affix_type: called CC=1 SCAR=0.0
425
426 # Return ONLY the underlying expression (e.g. 'Int' or 'Struct[...]')
427 # This prevents the "typedef 'name' => typedef 'name' => ..." recursion.
428 3 return $underlying->affix_type;
429 }
430
431 1 ▶ method affix ( $lib //= (), $pkg //= () ) {
Subroutine affix: called CC=4 SCAR=14.5
432
433 # If the underlying is a complex type (Struct/Enum), we want to return
434 # that object so the batch gets "@Name = {body}"
435 # If it's another Typedef, we return a Reference to prevent infinite recursion.
436 1 my $t = $underlying->affix;
437 1 ▶ if ( $underlying isa Affix::Wrap::Typedef ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($underlying isa "Affix::Wrap::Typedef") 0 1 1
438 0 return Affix::Type::Reference->new( name => $underlying->name ) . '()';
439 }
440 1 return $t . '( )';
441 }
442 }
443 #
444 class #
445 2 Affix::Wrap::Struct : isa(Affix::Wrap::Entity) {
446 2 field $tag : reader : param //= 'struct';
447 2 field $members : reader : param //= [];
448
449 3 ▶ method affix_type {
Subroutine affix_type: called CC=2 SCAR=6.9
450 3 ▶ my $type_name = $tag eq 'union' ? 'Union' : 'Struct';
Branch: 1 branch
BranchTrueFalseTotal
$tag eq 'union' ? : 1 2 3
451 3 sprintf '%s[ %s ]', $type_name, join( ', ', map { $_->name . ' => ' . $_->affix_type } @$members );
452 }
453
454 1 ▶ method affix ( $lib //= (), $pkg //= () ) {
Subroutine affix: called CC=4 SCAR=14.2
455 2 ▶ use Affix qw[Struct Union];
Subroutine BEGIN: called CC=1 SCAR=0.0
456 0 ▶ return ( $tag eq 'union' ) ? Union [ map { $_->name, $_->affix } @$members ] : Struct [ map { $_->name, $_->affix } @$members ];
Branch: 1 branch
BranchTrueFalseTotal
$tag eq 'union' ? : 0 1 1
457 }
458 };
459 class #
460 2 Affix::Wrap::Enum : isa(Affix::Wrap::Entity) {
461 2 field $constants : reader : param //= [];
462
463 1 ▶ method affix_type {
Subroutine affix_type: called CC=4 SCAR=13.9
464 1 my @defs;
465 1 for my $c (@$constants) {
466 3 my $v = $c->{value};
467 3 ▶ if ( !defined $v ) { push @defs, "'$c->{name}'"; next; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 2 1 3
468 1 ▶ $v = "'$v'" if $v !~ /^-?\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /^-?\d+$/u 0 1 1
469 1 push @defs, sprintf( "[ %s => %s ]", $c->{name}, $v );
470 }
471
472 # Return only the expression
473 1 return sprintf 'Enum[ %s ]', join( ', ', @defs );
474 }
475
476 0 ▶ method perl_constants {
Subroutine perl_constants: not called CC=5 SCAR=34.0
477 0 my @out;
478 0 for my $c (@$constants) {
479 0 my $v = $c->{value};
480 0 ▶ $v = "'$v'" if defined $v && $v !~ /^-?\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and not $v =~ /^-?\d+$/u 0 0 0
Condition0%0/3
defined $v and not $v =~ /^-?\d+$/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not $v =~ /^-?\d+$/u
defined $v not $v =~ /^-?\d+$/u
Truth table0%0/3
A and not(B)
A= defined $vB= not $v =~ /^-?\d+$/u
ABresult
0X0
100
111
481 0 ▶ $v //= 0;
Condition0%0/2
$v //= 0
l!l
00
MC/DC0%0/1
$v //= 0
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
482 0 push @out, "sub $c->{name} () { $v }";
483 }
484 0 return join( "\n ", @out );
485 }
486
487 0 ▶ method affix ( $lib //= (), $pkg //= () ) {
Subroutine affix: not called CC=10 SCAR=42.3
488 2 ▶ use Affix qw[Enum];
Subroutine BEGIN: called CC=1 SCAR=0.0
489 0 my @defs;
490 0 for my $c (@$constants) {
491 0 ▶ if ( !defined $c->{value} ) { push @defs, $c->{name}; next; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c->{"value"}) 0 0 0
492 0 push @defs, [ $c->{name}, $c->{value} ];
493 }
494 0 my $type = Enum [@defs];
495 0 ▶ if ( $pkg && $self->name && $self->name ne '(anonymous)' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg and $self->name and $self->name ne "(anonymous)") 0 0 0
Condition0%0/6
$pkg and $self->name and $self->name ne "(anonymous)"
!ll&&!rl&&r
000
$pkg and $self->name
!ll&&!rl&&r
000
MC/DC0%0/3
$pkg and $self->name and $self->name ne "(anonymous)"
$pkg $self->name $self->name ne "(anonymous)"
Truth table0%0/4
A and B and C
A= $pkgB= $self->nameC= $self->name ne "(anonymous)"
ABCresult
0XX0
10X0
1100
1111
496 0 my ( $const_map, $val_map ) = $type->resolve();
497 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
498 0 ▶ while ( my ( $const_name, $val ) = each %$const_map ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$const_map) 0 0 0
499 0 ▶ next unless $const_name =~ /^[a-zA-Z_]\w*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $const_name =~ /^[a-zA-Z_]\w*$/u 0 0 0
500 0 ▶ *{"${pkg}::${const_name}"} = sub () {$val};
Subroutine __ANON__: not called CC=1 SCAR=6.9
501 }
502 }
503 0 return $type;
504 }
505 };
506 class #
507 2 Affix::Wrap::Function : isa(Affix::Wrap::Entity) {
508 2 ▶ use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
509 2 ▶ use Affix qw[CodeRef];
Subroutine BEGIN: called CC=1 SCAR=0.0
510 2 field $ret : reader : param;
511 2 field $args : reader : param //= [];
512 2 field $mangled_name : reader : param //= ();
513
514 10 ▶ method affix_type {
Subroutine affix_type: called CC=5 SCAR=21.7
515 10 my $sym = $self->name;
516 10 ▶ if ( defined $self->mangled_name && $self->mangled_name ne $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->mangled_name and $self->mangled_name ne $self->name) 0 10 10
Condition33%1/3
defined $self->mangled_name and $self->mangled_name ne $self->name
!ll&&!rl&&r
0100
MC/DC0%0/2
defined $self->mangled_name and $self->mangled_name ne $self->name
defined $self->mangled_name $self->mangled_name ne $self->name
Truth table33%1/3
A and B
A= defined $self->mangled_nameB= $self->mangled_name ne $self->name
ABresult
0X0
100
111
517 0 $sym = $self->mangled_name;
518
519 # Mach-O prepends a leading underscore to C symbols (e.g., _return_six)
520 # but dlsym expects the source-level name without it.
521 0 ▶ $sym = $self->name if $sym eq '_' . $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $sym eq '_' . $self->name 0 0 0
522 }
523 sprintf "affix \$lib, %s => [%s], %s",
524 ( $sym ne $self->name ? ( sprintf q[[%s => '%s']], $sym, $self->name ) : ( sprintf q['%s'], $self->name ) ),
525 10 ▶ join( ', ', map { $_->affix_type } @$args ), $ret->affix_type;
Branch: 1 branch
BranchTrueFalseTotal
$sym ne $self->name ? : 0 10 10
526 }
527
528 0 ▶ method affix ( $lib, $pkg //= () ) {
Subroutine affix: not called CC=12 SCAR=46.2
529 0 ▶ if ($lib) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lib) 0 0 0
530 0 my $arg_types = [ map { $_->affix } @$args ];
531 0 my $_lib = Affix::load_library($lib);
532 0 my $ret_type = $ret->affix;
533 0 ▶ if ($pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg) { } 0 0 0
534 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
535 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
536 0 ▶ Affix::affix(
Branch: 1 branch
BranchTrueFalseTotal
defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($_lib, scalar $self->mangled_name) ? : 0 0 0
Condition0%0/9
&Affix::affix($lib, [defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($_lib, scalar $self->mangled_name) ? $self->mangled_name : $self->name, $pkg . '::' . $self->name], $arg_types, $ret_type) // Carp::carp(&Affix::errno())
l!l&&r!l&&!r
000
defined $self->mangled_name and $self->mangled_name ne $self->name and &Affix::find_symbol($_lib, scalar $self->mangled_name)
!ll&&!rl&&r
000
defined $self->mangled_name and $self->mangled_name ne $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
&Affix::affix($lib, [defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($_lib, scalar $self->mangled_name) ? $self->mangled_name : $self->name, $pkg . '::' . $self->name], $arg_types, $ret_type) // Carp::carp(&Affix::errno())
&Affix::affix($lib, [defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($_lib, scalar $self->mangled_name) ? $self->mangled_name : $self->name, $pkg . '::' . $self->name], $arg_types, $ret_type) Carp::carp(&Affix::errno())
MC/DC0%0/3
defined $self->mangled_name and $self->mangled_name ne $self->name and &Affix::find_symbol($_lib, scalar $self->mangled_name)
defined $self->mangled_name $self->mangled_name ne $self->name &Affix::find_symbol($_lib, scalar $self->mangled_name)
Truth table0%0/3
A // B
A= &Affix::affix($lib, [defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($_lib, scalar $self->mangled_name) ? $self->mangled_name : $self->name, $pkg . '::' . $self->name], $arg_types, $ret_type)B= Carp::carp(&Affix::errno())
ABresult
1X1
011
000
Truth table0%0/4
A and B and C
A= defined $self->mangled_nameB= $self->mangled_name ne $self->nameC= &Affix::find_symbol($_lib, scalar $self->mangled_name)
ABCresult
0XX0
10X0
1100
1111
537 $lib,
538 [ (
539 defined $self->mangled_name &&
540 $self->mangled_name ne $self->name &&
541 Affix::find_symbol( $_lib, $self->mangled_name ) ? $self->mangled_name : $self->name
542 ),
543 $pkg . '::' . $self->name
544 ],
545 $arg_types,
546 $ret_type
547 ) // Carp::carp Affix::errno();
548 }
549 else {
550 0 ▶ Affix::affix(
Branch: 1 branch
BranchTrueFalseTotal
defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($lib, scalar $self->mangled_name) ? : 0 0 0
Condition0%0/9
&Affix::affix($lib, scalar(defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($lib, scalar $self->mangled_name) ? [$self->mangled_name, $self->name] : $self->name), $arg_types, $ret_type) // Carp::carp(&Affix::errno())
l!l&&r!l&&!r
000
defined $self->mangled_name and $self->mangled_name ne $self->name and &Affix::find_symbol($lib, scalar $self->mangled_name)
!ll&&!rl&&r
000
defined $self->mangled_name and $self->mangled_name ne $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
&Affix::affix($lib, scalar(defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($lib, scalar $self->mangled_name) ? [$self->mangled_name, $self->name] : $self->name), $arg_types, $ret_type) // Carp::carp(&Affix::errno())
&Affix::affix($lib, scalar(defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($lib, scalar $self->mangled_name) ? [$self->mangled_name, $self->name] : $self->name), $arg_types, $ret_type) Carp::carp(&Affix::errno())
MC/DC0%0/3
defined $self->mangled_name and $self->mangled_name ne $self->name and &Affix::find_symbol($lib, scalar $self->mangled_name)
defined $self->mangled_name $self->mangled_name ne $self->name &Affix::find_symbol($lib, scalar $self->mangled_name)
Truth table0%0/3
A // B
A= &Affix::affix($lib, scalar(defined $self->mangled_name && $self->mangled_name ne $self->name && &Affix::find_symbol($lib, scalar $self->mangled_name) ? [$self->mangled_name, $self->name] : $self->name), $arg_types, $ret_type)B= Carp::carp(&Affix::errno())
ABresult
1X1
011
000
Truth table0%0/4
A and B and C
A= defined $self->mangled_nameB= $self->mangled_name ne $self->nameC= &Affix::find_symbol($lib, scalar $self->mangled_name)
ABCresult
0XX0
10X0
1100
1111
551 $lib,
552 defined $self->mangled_name &&
553 $self->mangled_name ne $self->name &&
554 Affix::find_symbol( $lib, $self->mangled_name ) ? [ $self->mangled_name, $self->name ] : $self->name,
555 $arg_types,
556 $ret_type
557 ) // Carp::carp Affix::errno();
558 }
559 }
560 }
561 0 ▶ method affix_ret { $ret->affix_type }
Subroutine affix_ret: not called CC=1 SCAR=6.9
562
563 0 ▶ method affix_args {
Subroutine affix_args: not called CC=1 SCAR=6.9
564 0 [ map { $_->affix_type } @$args ]
565 }
566 0 ▶ method call_ret { $ret->affix }
Subroutine call_ret: not called CC=1 SCAR=6.9
567
568 0 ▶ method call_args {
Subroutine call_args: not called CC=1 SCAR=6.9
569 0 [ map { $_->affix } @$args ]
570 }
571 } class #
572 2 Affix::Wrap::Driver::Clang {
573 2 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
574 2 field $project_files : param : reader;
575 2 field $allowed_files = {};
576 2 field $project_dirs = [];
577 2 field $paths_seen = {};
578 2 field $file_cache = {};
579 2 field $last_seen_file = undef;
580 2 field $clang //= 'clang';
581 0 ▶ method _basename ($path) { return '' unless defined $path; $path =~ s{^.*[/\\]}{}; return lc($path); }
Subroutine _basename: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
582
583 0 ▶ method _normalize ($path) {
Subroutine _normalize: not called CC=3 SCAR=24.8
584 0 ▶ return '' unless defined $path && length $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 0 0 0
Condition0%0/3
defined $path and length $path
!ll&&!rl&&r
000
MC/DC0%0/2
defined $path and length $path
defined $path length $path
Truth table0%0/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
585 0 my $abs = Path::Tiny::path($path)->absolute->stringify;
586 0 $abs =~ s{\\}{/}g;
587 0 return $abs;
588 }
589 0 ▶ ADJUST {
Subroutine __ANON__: not called CC=6 SCAR=37.4
590 0 my %seen_dirs;
591 0 for my $f (@$project_files) {
592 0 ▶ next unless defined $f && length $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length $f 0 0 0
Condition0%0/3
defined $f and length $f
!ll&&!rl&&r
000
MC/DC0%0/2
defined $f and length $f
defined $f length $f
Truth table0%0/3
A and B
A= defined $fB= length $f
ABresult
0X0
100
111
593 0 my $abs = $self->_normalize($f);
594 0 ▶ next unless length $abs;
Branch: 1 branch
BranchTrueFalseTotal
unless length $abs 0 0 0
595 0 $allowed_files->{$abs} = 1;
596 0 my $dir = Path::Tiny::path($abs)->parent->stringify;
597 0 $dir =~ s{\\}{/}g;
598 0 ▶ unless ( $seen_dirs{$dir}++ ) { push @$project_dirs, $dir; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen_dirs{$dir}++) 0 0 0
599 }
600 }
601
602 0 ▶ method parse ( $entry_point, $include_dirs //= [] ) {
Subroutine parse: not called CC=14 SCAR=53.5
603 0 ▶ if ( !defined $entry_point || !length $entry_point ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $entry_point and length $entry_point) 0 0 0
Condition0%0/3
defined $entry_point and length $entry_point
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entry_point and length $entry_point
defined $entry_point length $entry_point
Truth table0%0/3
A and B
A= defined $entry_pointB= length $entry_point
ABresult
0X0
100
111
604 0 ▶ ($entry_point) = grep { defined $_ && length $_ } @$project_files;
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
605 }
606 0 ▶ return () unless defined $entry_point && length $entry_point;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry_point and length $entry_point 0 0 0
Condition0%0/3
defined $entry_point and length $entry_point
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entry_point and length $entry_point
defined $entry_point length $entry_point
Truth table0%0/3
A and B
A= defined $entry_pointB= length $entry_point
ABresult
0X0
100
111
607 0 my $ep_abs = $self->_normalize($entry_point);
608 0 ▶ return () unless length $ep_abs;
Branch: 1 branch
BranchTrueFalseTotal
unless length $ep_abs 0 0 0
609 0 $allowed_files->{$ep_abs} = 1;
610 0 $last_seen_file = $ep_abs;
611 0 my $ep_dir = Path::Tiny::path($ep_abs)->parent->stringify;
612 0 $ep_dir =~ s{\\}{/}g;
613 0 my $found = 0;
614
615 0 for my $pd (@$project_dirs) {
616 0 ▶ if ( $ep_dir eq $pd ) { $found = 1; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ep_dir eq $pd) 0 0 0
617 }
618 0 ▶ push @$project_dirs, $ep_dir unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 0 0
619 0 my @includes = map { "-I" . $self->_normalize($_) } @$include_dirs;
620 0 for my $d (@$project_dirs) { push @includes, "-I$d"; }
621 0 my @cmd = (
622 $clang, '-target', $self->_get_triple(), '-Xclang',
623 '-ast-dump=json', '-Xclang', '-detailed-preprocessing-record', '-fsyntax-only',
624 '-fparse-all-comments', '-Wno-everything', @includes, $ep_abs
625 );
626 0 ▶ my ( $stdout, $stderr, $exit ) = Capture::Tiny::capture { system(@cmd); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
627 0 ▶ if ( $exit != 0 ) { die "Clang Error:\n$stderr"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($exit != 0) 0 0 0
628 0 ▶ if ( $stdout =~ /^.*?(\{.*)/s ) { $stdout = $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($stdout =~ /^.*?(\{.*)/su) 0 0 0
629 0 my $ast = JSON::PP::decode_json($stdout);
630 0 my @objects;
631 0 $self->_walk( $ast, \@objects, $ep_abs );
632 0 $self->_scan_macros_fallback( \@objects );
633 0 $self->_merge_typedefs( \@objects );
634 0 $self->_wrap_named_types( \@objects );
635
636 #~ @objects = sort { ( $a->file cmp $b->file ) || ( $a->start_offset <=> $b->start_offset ) } @objects;
637 0 @objects;
638 }
639
640 0 ▶ method _walk( $node, $acc, $current_file ) {
Subroutine _walk: not called CC=20 SCAR=60.4
641 0 ▶ return unless ref $node eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" 0 0 0
642 0 ▶ my $kind = $node->{kind} // 'Unknown';
Condition0%0/2
$node->{"kind"} // "Unknown"
l!l
00
MC/DC0%0/1
$node->{"kind"} // "Unknown"
$node->{"kind"}
Truth table0%0/2
A
A= $node->{"kind"}
Aresult
11
00
643 0 my $node_file = $self->_get_node_file($node);
644 0 ▶ if ($node_file) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node_file) { } 0 0 0
elsif (defined $last_seen_file) { } 0 0 0
645 0 $current_file = $self->_normalize($node_file);
646 0 $last_seen_file = $current_file;
647 }
648 0 elsif ( defined $last_seen_file ) { $current_file = $last_seen_file; }
649 0 ▶ if ( $self->_is_valid_file($current_file) && !$node->{isImplicit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_valid_file($current_file) and not $node->{"isImplicit"}) 0 0 0
Condition0%0/3
$self->_is_valid_file($current_file) and not $node->{"isImplicit"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_valid_file($current_file) and not $node->{"isImplicit"}
$self->_is_valid_file($current_file) not $node->{"isImplicit"}
Truth table0%0/3
A and not(B)
A= $self->_is_valid_file($current_file)B= not $node->{"isImplicit"}
ABresult
0X0
100
111
650 0 ▶ if ( $kind eq 'MacroDefinitionRecord' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($kind eq 'MacroDefinitionRecord') { } 0 0 0
elsif ($kind eq 'TypedefDecl') { } 0 0 0
elsif ($kind eq 'RecordDecl' or $kind eq 'CXXRecordDecl') { } 0 0 0
elsif ($kind eq 'EnumDecl') { } 0 0 0
elsif ($kind eq 'VarDecl') { } 0 0 0
elsif ($kind eq 'FunctionDecl') { } 0 0 0
elsif ($kind eq 'BuiltinType') { } 0 0 0
651 0 ▶ if ( $node->{range} ) { $self->_macro( $node, $acc, $current_file ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"range"}) 0 0 0
652 }
653 0 elsif ( $kind eq 'TypedefDecl' ) { $self->_typedef( $node, $acc, $current_file ); }
654 ▶ elsif ( $kind eq 'RecordDecl' || $kind eq 'CXXRecordDecl' ) {
Condition0%0/3
$kind eq "RecordDecl" or $kind eq "CXXRecordDecl"
l!l&&r!l&&!r
000
MC/DC0%0/2
$kind eq "RecordDecl" or $kind eq "CXXRecordDecl"
$kind eq "RecordDecl" $kind eq "CXXRecordDecl"
Truth table0%0/3
A or B
A= $kind eq "RecordDecl"B= $kind eq "CXXRecordDecl"
ABresult
1X1
011
000
655 0 $self->_record( $node, $acc, $current_file );
656 0 return;
657 }
658 elsif ( $kind eq 'EnumDecl' ) {
659 0 $self->_enum( $node, $acc, $current_file );
660 0 return;
661 }
662 elsif ( $kind eq 'VarDecl' ) {
663 0 ▶ if ( ( $node->{storageClass} // '' ) ne 'static' ) { $self->_var( $node, $acc, $current_file ); }
Branch: 1 branch
BranchTrueFalseTotal
if (($node->{"storageClass"} // "") ne "static") 0 0 0
Condition0%0/2
$node->{"storageClass"} // ""
l!l
00
MC/DC0%0/1
$node->{"storageClass"} // ""
$node->{"storageClass"}
Truth table0%0/2
A
A= $node->{"storageClass"}
Aresult
11
00
664 }
665 elsif ( $kind eq 'FunctionDecl' ) {
666 0 $self->_func( $node, $acc, $current_file );
667 0 return;
668 }
669 0 elsif ( $kind eq 'BuiltinType' ) { return; }
670 }
671 0 ▶ if ( $node->{inner} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"inner"}) 0 0 0
672 0 for ( @{ $node->{inner} } ) { $self->_walk( $_, $acc, $current_file ); }
673 }
674 }
675
676 0 ▶ method _is_valid_file ($f) {
Subroutine _is_valid_file: not called CC=10 SCAR=47.0
677 0 ▶ return 0 unless defined $f && length $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length $f 0 0 0
Condition0%0/3
defined $f and length $f
!ll&&!rl&&r
000
MC/DC0%0/2
defined $f and length $f
defined $f length $f
Truth table0%0/3
A and B
A= defined $fB= length $f
ABresult
0X0
100
111
678 0 ▶ return 0 if $f =~ m{^/usr/(include|lib|share|local/include)};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[^/usr/(include|lib|share|local/include)]u 0 0 0
679 0 ▶ return 0 if $f =~ m{^/System/Library};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[^/System/Library]u 0 0 0
680 0 ▶ return 1 if $allowed_files->{$f};
Branch: 1 branch
BranchTrueFalseTotal
if $allowed_files->{$f} 0 0 0
681 0 for my $dir (@$project_dirs) {
682 0 ▶ return 1 if index( $f, $dir ) == 0 && ( length($f) == length($dir) || substr( $f, length($dir), 1 ) eq '/' );
Branch: 1 branch
BranchTrueFalseTotal
if index($f, $dir) == 0 and length $f == length $dir || substr($f, length $dir, 1) eq "/" 0 0 0
Condition0%0/6
index($f, $dir) == 0 and length $f == length $dir || substr($f, length $dir, 1) eq "/"
!ll&&!rl&&r
000
length $f == length $dir or substr($f, length $dir, 1) eq "/"
l!l&&r!l&&!r
000
MC/DC0%0/3
index($f, $dir) == 0 and length $f == length $dir || substr($f, length $dir, 1) eq "/"
index($f, $dir) == 0 length $f == length $dir substr($f, length $dir, 1) eq "/"
Truth table0%0/4
A and B or C
A= index($f, $dir) == 0B= length $f == length $dirC= substr($f, length $dir, 1) eq "/"
ABCresult
0XX0
1000
11X1
1011
683 }
684 0 return 0;
685 }
686
687 0 ▶ method _get_node_file($node) {
Subroutine _get_node_file: not called CC=13 SCAR=52.0
688 0 my $loc = $node->{loc};
689 0 ▶ return undef unless $loc;
Branch: 1 branch
BranchTrueFalseTotal
unless $loc 0 0 0
690 0 my $f;
691 0 ▶ if ( ref($loc) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $loc eq "HASH") 0 0 0
692 0 ▶ $f = $loc->{presumedLoc}{file} || $loc->{expansionLoc}{file} || $loc->{spellingLoc}{file} || $loc->{file};
Condition0%0/9
$loc->{'presumedLoc'}{'file'} || $loc->{'expansionLoc'}{'file'} || $loc->{'spellingLoc'}{'file'} || $loc->{'file'}
l!l&&r!l&&!r
000
$loc->{"presumedLoc"}{"file"} or $loc->{"expansionLoc"}{"file"} or $loc->{"spellingLoc"}{"file"}
l!l&&r!l&&!r
000
$loc->{"presumedLoc"}{"file"} or $loc->{"expansionLoc"}{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$loc->{'presumedLoc'}{'file'} || $loc->{'expansionLoc'}{'file'} || $loc->{'spellingLoc'}{'file'} || $loc->{'file'}
$loc->{"presumedLoc"}{"file"} $loc->{"expansionLoc"}{"file"} $loc->{"spellingLoc"}{"file"} $loc->{'file'}
Truth table0%0/5
A or B or C || D
A= $loc->{"presumedLoc"}{"file"}B= $loc->{"expansionLoc"}{"file"}C= $loc->{"spellingLoc"}{"file"}D= $loc->{'file'}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
693 }
694 0 ▶ if ( !$f && $node->{range} && $node->{range}{begin} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $f and $node->{"range"} and $node->{"range"}{"begin"}) 0 0 0
Condition0%0/6
not $f and $node->{"range"} and $node->{"range"}{"begin"}
!ll&&!rl&&r
000
not $f and $node->{"range"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $f and $node->{"range"} and $node->{"range"}{"begin"}
not $f $node->{"range"} $node->{"range"}{"begin"}
Truth table0%0/4
not(A) and B and C
A= not $fB= $node->{"range"}C= $node->{"range"}{"begin"}
ABCresult
0XX0
10X0
1100
1111
695 0 my $b = $node->{range}{begin};
696 0 ▶ $f = $b->{presumedLoc}{file} || $b->{expansionLoc}{file} || $b->{spellingLoc}{file} || $b->{file};
Condition0%0/9
$b->{'presumedLoc'}{'file'} || $b->{'expansionLoc'}{'file'} || $b->{'spellingLoc'}{'file'} || $b->{'file'}
l!l&&r!l&&!r
000
$b->{"presumedLoc"}{"file"} or $b->{"expansionLoc"}{"file"} or $b->{"spellingLoc"}{"file"}
l!l&&r!l&&!r
000
$b->{"presumedLoc"}{"file"} or $b->{"expansionLoc"}{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$b->{'presumedLoc'}{'file'} || $b->{'expansionLoc'}{'file'} || $b->{'spellingLoc'}{'file'} || $b->{'file'}
$b->{"presumedLoc"}{"file"} $b->{"expansionLoc"}{"file"} $b->{"spellingLoc"}{"file"} $b->{'file'}
Truth table0%0/5
A or B or C || D
A= $b->{"presumedLoc"}{"file"}B= $b->{"expansionLoc"}{"file"}C= $b->{"spellingLoc"}{"file"}D= $b->{'file'}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
697 }
698 0 ▶ return undef unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 0 0
699 0 $f =~ s{\\}{/}g;
700 0 $paths_seen->{$f}++;
701 0 return $f;
702 }
703
704 0 ▶ method _meta($n) {
Subroutine _meta: not called CC=11 SCAR=48.8
705 0 ▶ my $s = $n->{range}{begin}{offset} // 0;
Condition0%0/2
$n->{"range"}{"begin"}{"offset"} // 0
l!l
00
MC/DC0%0/1
$n->{"range"}{"begin"}{"offset"} // 0
$n->{"range"}{"begin"}{"offset"}
Truth table0%0/2
A
A= $n->{"range"}{"begin"}{"offset"}
Aresult
11
00
706 0 ▶ my $e = $n->{range}{end}{offset} // 0;
Condition0%0/2
$n->{"range"}{"end"}{"offset"} // 0
l!l
00
MC/DC0%0/1
$n->{"range"}{"end"}{"offset"} // 0
$n->{"range"}{"end"}{"offset"}
Truth table0%0/2
A
A= $n->{"range"}{"end"}{"offset"}
Aresult
11
00
707 0 my $line = 0;
708 0 my $end_line = 0;
709 0 ▶ if ( ref( $n->{loc} ) eq 'HASH' ) { $line = $n->{loc}{presumedLoc}{line} || $n->{loc}{line}; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n->{"loc"} eq "HASH") 0 0 0
Condition0%0/3
$n->{'loc'}{'presumedLoc'}{'line'} || $n->{'loc'}{'line'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$n->{'loc'}{'presumedLoc'}{'line'} || $n->{'loc'}{'line'}
$n->{'loc'}{'presumedLoc'}{'line'} $n->{'loc'}{'line'}
Truth table0%0/3
A || B
A= $n->{'loc'}{'presumedLoc'}{'line'}B= $n->{'loc'}{'line'}
ABresult
1X1
011
000
710 0 ▶ $line ||= $n->{range}{begin}{line} // 0;
Condition0%0/5
$line ||= $n->{"range"}{"begin"}{"line"} // 0
l!l&&r!l&&!r
000
$n->{"range"}{"begin"}{"line"} // 0
l!l
00
MC/DC0%0/2
$line ||= $n->{"range"}{"begin"}{"line"} // 0
$line $n->{"range"}{"begin"}{"line"}
Truth table0%0/3
A ||= B
A= $lineB= $n->{"range"}{"begin"}{"line"}
ABresult
1X1
011
000
711 0 ▶ if ( $n->{range}{end} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{'range'}{'end'}) { } 0 0 0
712 0 ▶ $end_line = $n->{range}{end}{presumedLoc}{line} || $n->{range}{end}{line} || $n->{range}{end}{expansionLoc}{line} || $line;
Condition0%0/9
$n->{'range'}{'end'}{'presumedLoc'}{'line'} || $n->{'range'}{'end'}{'line'} || $n->{'range'}{'end'}{'expansionLoc'}{'line'} || $line
l!l&&r!l&&!r
000
$n->{"range"}{"end"}{"presumedLoc"}{"line"} or $n->{"range"}{"end"}{"line"} or $n->{"range"}{"end"}{"expansionLoc"}{"line"}
l!l&&r!l&&!r
000
$n->{"range"}{"end"}{"presumedLoc"}{"line"} or $n->{"range"}{"end"}{"line"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$n->{'range'}{'end'}{'presumedLoc'}{'line'} || $n->{'range'}{'end'}{'line'} || $n->{'range'}{'end'}{'expansionLoc'}{'line'} || $line
$n->{"range"}{"end"}{"presumedLoc"}{"line"} $n->{"range"}{"end"}{"line"} $n->{"range"}{"end"}{"expansionLoc"}{"line"} $line
Truth table0%0/5
A or B or C || D
A= $n->{"range"}{"end"}{"presumedLoc"}{"line"}B= $n->{"range"}{"end"}{"line"}C= $n->{"range"}{"end"}{"expansionLoc"}{"line"}D= $line
ABCDresult
1XXX1
01XX1
001X1
00011
00000
713 }
714 0 else { $end_line = $line; }
715 0 return ( $s, $e, $line, $end_line );
716 }
717
718 0 ▶ method _doc_w_trail( $f, $s, $e ) {
Subroutine _doc_w_trail: not called CC=5 SCAR=34.0
719 0 my $d = $self->_extract_doc( $f, $s );
720 0 my $t = $self->_extract_trailing( $f, $e );
721 0 ▶ return $d unless defined $t && length $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t and length $t 0 0 0
Condition0%0/3
defined $t and length $t
!ll&&!rl&&r
000
MC/DC0%0/2
defined $t and length $t
defined $t length $t
Truth table0%0/3
A and B
A= defined $tB= length $t
ABresult
0X0
100
111
722 0 ▶ return $t unless defined $d && length $d;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d and length $d 0 0 0
Condition0%0/3
defined $d and length $d
!ll&&!rl&&r
000
MC/DC0%0/2
defined $d and length $d
defined $d length $d
Truth table0%0/3
A and B
A= defined $dB= length $d
ABresult
0X0
100
111
723 0 return "$d\n$t";
724 }
725
726 0 ▶ method _macro( $n, $acc, $f ) {
Subroutine _macro: not called CC=1 SCAR=6.9
727 0 my ( $s, $e, $l, $el ) = $self->_meta($n);
728 0 my $val = $self->_extract_macro_val( $n, $f );
729 push @$acc,
730 Affix::Wrap::Macro->new(
731 name => $n->{name},
732 0 file => $f,
733 line => $l,
734 end_line => $el,
735 value => $val,
736 doc => $self->_extract_doc( $f, $s ),
737 start_offset => $s,
738 end_offset => $e
739 );
740 }
741
742 0 ▶ method _typedef( $n, $acc, $f ) {
Subroutine _typedef: not called CC=1 SCAR=6.9
743 0 my ( $s, $e, $l, $el ) = $self->_meta($n);
744 push @$acc,
745 Affix::Wrap::Typedef->new(
746 name => $n->{name},
747 file => $f,
748 line => $l,
749 end_line => $el,
750 0 underlying => Affix::Wrap::Type->parse( $n->{type}{qualType} ),
751 doc => $self->_doc_w_trail( $f, $s, $e ),
752 start_offset => $s,
753 end_offset => $e
754 );
755 }
756
757 0 ▶ method _record( $n, $acc, $f ) {
Subroutine _record: not called CC=5 SCAR=34.0
758 0 my ( $s, $e, $l, $el ) = $self->_meta($n);
759 0 my $m_list = $self->_extract_members( $n, $f );
760 0 ▶ return unless ( $n->{name} || @$m_list );
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"name"} or @$m_list 0 0 0
Condition0%0/3
$n->{"name"} or @$m_list
l!l&&r!l&&!r
000
MC/DC0%0/2
$n->{"name"} or @$m_list
$n->{"name"} @$m_list
Truth table0%0/3
A or B
A= $n->{"name"}B= @$m_list
ABresult
1X1
011
000
761 0 ▶ my $tag = $n->{tagUsed} // 'struct';
Condition0%0/2
$n->{"tagUsed"} // "struct"
l!l
00
MC/DC0%0/1
$n->{"tagUsed"} // "struct"
$n->{"tagUsed"}
Truth table0%0/2
A
A= $n->{"tagUsed"}
Aresult
11
00
762 push @$acc,
763 Affix::Wrap::Struct->new(
764 0 ▶ name => $n->{name} // '(anonymous)',
Condition0%0/2
$n->{"name"} // "(anonymous)"
l!l
00
MC/DC0%0/1
$n->{"name"} // "(anonymous)"
$n->{"name"}
Truth table0%0/2
A
A= $n->{"name"}
Aresult
11
00
765 tag => $tag,
766 file => $f,
767 line => $l,
768 end_line => $el,
769 members => $m_list,
770 doc => $self->_doc_w_trail( $f, $s, $e ),
771 start_offset => $s,
772 end_offset => $e
773 );
774 }
775
776 0 ▶ method _extract_members( $n, $f ) {
Subroutine _extract_members: not called CC=15 SCAR=54.8
777 0 my @members;
778 0 ▶ return \@members unless $n->{inner};
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"inner"} 0 0 0
779 0 my @pending_anonymous_records;
780 0 for my $child ( @{ $n->{inner} } ) {
781 0 ▶ my $kind = $child->{kind} // '';
Condition0%0/2
$child->{"kind"} // ""
l!l
00
MC/DC0%0/1
$child->{"kind"} // ""
$child->{"kind"}
Truth table0%0/2
A
A= $child->{"kind"}
Aresult
11
00
782 0 ▶ if ( $kind eq 'RecordDecl' || $kind eq 'CXXRecordDecl' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'RecordDecl' or $kind eq 'CXXRecordDecl') { } 0 0 0
elsif ($kind eq 'FieldDecl') { } 0 0 0
Condition0%0/3
$kind eq "RecordDecl" or $kind eq "CXXRecordDecl"
l!l&&r!l&&!r
000
MC/DC0%0/2
$kind eq "RecordDecl" or $kind eq "CXXRecordDecl"
$kind eq "RecordDecl" $kind eq "CXXRecordDecl"
Truth table0%0/3
A or B
A= $kind eq "RecordDecl"B= $kind eq "CXXRecordDecl"
ABresult
1X1
011
000
783 0 my $sub_members = $self->_extract_members( $child, $f );
784 my $rec = Affix::Wrap::Struct->new(
785 name => $child->{name} // '',
786 tag => $child->{tagUsed} // 'struct',
787 file => $f,
788 line => $child->{loc}{line} // 0,
789 0 ▶ end_line => $child->{loc}{line} // 0,
Condition0%0/8
$child->{"name"} // ""
l!l
00
$child->{"tagUsed"} // "struct"
l!l
00
$child->{"loc"}{"line"} // 0
l!l
00
$child->{"loc"}{"line"} // 0
l!l
00
MC/DC0%0/1
$child->{"name"} // ""
$child->{"name"}
MC/DC0%0/1
$child->{"tagUsed"} // "struct"
$child->{"tagUsed"}
MC/DC0%0/1
$child->{"loc"}{"line"} // 0
$child->{"loc"}{"line"}
MC/DC0%0/1
$child->{"loc"}{"line"} // 0
$child->{"loc"}{"line"}
Truth table0%0/2
A
A= $child->{"name"}
Aresult
11
00
Truth table0%0/2
A
A= $child->{"tagUsed"}
Aresult
11
00
Truth table0%0/2
A
A= $child->{"loc"}{"line"}
Aresult
11
00
Truth table0%0/2
A
A= $child->{"loc"}{"line"}
Aresult
11
00
790 members => $sub_members,
791 doc => undef
792 );
793 0 ▶ my $name = $child->{name} // '';
Condition0%0/2
$child->{"name"} // ""
l!l
00
MC/DC0%0/1
$child->{"name"} // ""
$child->{"name"}
Truth table0%0/2
A
A= $child->{"name"}
Aresult
11
00
794 0 ▶ if ( $name eq '' ) { push @pending_anonymous_records, $rec; }
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "") 0 0 0
795 }
796 elsif ( $kind eq 'FieldDecl' ) {
797 0 ▶ my $name = $child->{name} // '';
Condition0%0/2
$child->{"name"} // ""
l!l
00
MC/DC0%0/1
$child->{"name"} // ""
$child->{"name"}
Truth table0%0/2
A
A= $child->{"name"}
Aresult
11
00
798 0 my $raw_type = $child->{type}{qualType};
799 0 my $type_obj = Affix::Wrap::Type->parse($raw_type);
800 0 my $def = undef;
801 0 ▶ if (@pending_anonymous_records) { $def = pop @pending_anonymous_records; }
Branch: 1 branch
BranchTrueFalseTotal
if (@pending_anonymous_records) 0 0 0
802 0 my $f_offset = $child->{range}{begin}{offset};
803 0 my $f_end = $child->{range}{end}{offset};
804 0 my $f_doc = $self->_doc_w_trail( $f, $f_offset, $f_end );
805 0 push @members, Affix::Wrap::Member->new( name => $name, type => $type_obj, doc => $f_doc, definition => $def );
806 }
807 }
808 0 return \@members;
809 }
810
811 0 ▶ method _enum( $n, $acc, $f ) {
Subroutine _enum: not called CC=11 SCAR=48.8
812 0 my ( $s, $e, $l, $el ) = $self->_meta($n);
813 0 my @c;
814 0 my $cnt = 0;
815 0 my $src = $self->_get_content($f);
816 0 for my $ch ( @{ $n->{inner} } ) {
817 0 ▶ if ( ( $ch->{kind} // '' ) eq 'EnumConstantDecl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($ch->{"kind"} // "") eq "EnumConstantDecl") 0 0 0
Condition0%0/2
$ch->{"kind"} // ""
l!l
00
MC/DC0%0/1
$ch->{"kind"} // ""
$ch->{"kind"}
Truth table0%0/2
A
A= $ch->{"kind"}
Aresult
11
00
818 0 my $name = $ch->{name};
819 0 my $val = undef;
820 0 my $off = $ch->{range}{begin}{offset};
821 0 ▶ if ( defined $off ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $off) 0 0 0
822 0 my $chunk = substr( $src, $off );
823 0 ▶ if ( $chunk =~ /^\s*\Q$name\E\s*(?:=\s*(.*?))?\s*(?:,|}|$)/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk =~ /^\s*\Q$name\E\s*(?:=\s*(.*?))?\s*(?:,|}|$)/su) 0 0 0
824 0 $val = $1;
825 0 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
826 0 $val =~ s/\/\/.*$//mg;
827 0 $val =~ s/\/\*.*?\*\///sg;
828 0 $val =~ s/^\s+|\s+$//g;
829 }
830 }
831 }
832
833 # Fallback calc for next value
834 0 ▶ if ( defined $val && $val =~ /^-?\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val =~ /^-?\d+$/u) { } 0 0 0
Condition0%0/3
defined $val and $val =~ /^-?\d+$/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val =~ /^-?\d+$/u
defined $val $val =~ /^-?\d+$/u
Truth table0%0/3
A and B
A= defined $valB= $val =~ /^-?\d+$/u
ABresult
0X0
100
111
835 0 $cnt = $val + 1;
836 }
837 else {
838 0 ▶ if ( !defined $val ) { $val = $cnt; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
839 0 $cnt++; # Approximation for symbolic
840 }
841 0 push @c, { name => $name, value => $val };
842 }
843 }
844 push @$acc,
845 Affix::Wrap::Enum->new(
846 0 ▶ name => $n->{name} // '(anonymous)',
Condition0%0/2
$n->{"name"} // "(anonymous)"
l!l
00
MC/DC0%0/1
$n->{"name"} // "(anonymous)"
$n->{"name"}
Truth table0%0/2
A
A= $n->{"name"}
Aresult
11
00
847 file => $f,
848 line => $l,
849 end_line => $el,
850 constants => \@c,
851 doc => $self->_doc_w_trail( $f, $s, $e ),
852 start_offset => $s,
853 end_offset => $e
854 );
855 }
856
857 0 ▶ method _var( $n, $acc, $f ) {
Subroutine _var: not called CC=1 SCAR=6.9
858 0 my ( $s, $e, $l, $el ) = $self->_meta($n);
859 push @$acc,
860 Affix::Wrap::Variable->new(
861 name => $n->{name},
862 file => $f,
863 line => $l,
864 end_line => $el,
865 0 type => Affix::Wrap::Type->parse( $n->{type}{qualType} ),
866 doc => $self->_doc_w_trail( $f, $s, $e ),
867 start_offset => $s,
868 end_offset => $e
869 );
870 }
871
872 0 ▶ method _func( $n, $acc, $f ) {
Subroutine _func: not called CC=8 SCAR=42.8
873 0 ▶ return if ( $n->{storageClass} // '' ) eq 'static';
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"storageClass"} // "") eq "static" 0 0 0
Condition0%0/2
$n->{"storageClass"} // ""
l!l
00
MC/DC0%0/1
$n->{"storageClass"} // ""
$n->{"storageClass"}
Truth table0%0/2
A
A= $n->{"storageClass"}
Aresult
11
00
874 0 my ( $s, $e, $l, $el ) = $self->_meta($n);
875 0 my $ret_str = $n->{type}{qualType};
876 0 $ret_str =~ s/\(.*\)//;
877 0 my $ret_obj = Affix::Wrap::Type->parse($ret_str);
878 0 my @args;
879 0 for ( @{ $n->{inner} } ) {
880 0 ▶ if ( ( $_->{kind} // '' ) eq 'ParmVarDecl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($_->{"kind"} // "") eq "ParmVarDecl") 0 0 0
Condition0%0/2
$_->{"kind"} // ""
l!l
00
MC/DC0%0/1
$_->{"kind"} // ""
$_->{"kind"}
Truth table0%0/2
A
A= $_->{"kind"}
Aresult
11
00
881 0 my $pt = Affix::Wrap::Type->parse( $_->{type}{qualType} );
882 0 ▶ my $pn = $_->{name} // '';
Condition0%0/2
$_->{"name"} // ""
l!l
00
MC/DC0%0/1
$_->{"name"} // ""
$_->{"name"}
Truth table0%0/2
A
A= $_->{"name"}
Aresult
11
00
883 0 push @args, Affix::Wrap::Argument->new( type => $pt, name => $pn );
884 }
885 }
886 0 ▶ push @args, Affix::Wrap::Argument->new( type => Affix::Wrap::Type->new( name => '...' ) ) if $n->{variadic};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"variadic"} 0 0 0
887 push @$acc,
888 Affix::Wrap::Function->new(
889 name => $n->{name},
890 mangled_name => $n->{mangledName},
891 0 file => $f,
892 line => $l,
893 end_line => $el,
894 ret => $ret_obj,
895 args => \@args,
896 doc => $self->_doc_w_trail( $f, $s, $e ),
897 start_offset => $s,
898 end_offset => $e
899 );
900 }
901
902 0 ▶ method _get_content($f) {
Subroutine _get_content: not called CC=3 SCAR=24.8
903 0 my $abs = $self->_normalize($f);
904 0 ▶ return $file_cache->{$abs} if exists $file_cache->{$abs};
Branch: 1 branch
BranchTrueFalseTotal
if exists $file_cache->{$abs} 0 0 0
905 0 ▶ if ( -e $abs ) { return $file_cache->{$abs} = Path::Tiny::path($abs)->slurp_utf8; }
Branch: 1 branch
BranchTrueFalseTotal
if (-e $abs) 0 0 0
906 0 return '';
907 }
908
909 0 ▶ method _extract_doc( $f, $off ) {
Subroutine _extract_doc: not called CC=14 SCAR=53.5
910 0 ▶ return undef unless defined $off;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $off 0 0 0
911 0 my $content = $self->_get_content($f);
912 0 ▶ return undef unless length($content);
Branch: 1 branch
BranchTrueFalseTotal
unless length $content 0 0 0
913 0 my $pre = substr( $content, 0, $off );
914 0 my @lines = split /\n/, $pre;
915 0 my @d;
916 0 my $cap = 0;
917 0 ▶ while ( my $line = pop @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = pop @lines) 0 0 0
918 0 ▶ next if !$cap && $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not $cap and $line =~ /^\s*$/u 0 0 0
Condition0%0/3
not $cap and $line =~ /^\s*$/u
!ll&&!rl&&r
000
MC/DC0%0/2
not $cap and $line =~ /^\s*$/u
not $cap $line =~ /^\s*$/u
Truth table0%0/3
not(A) and B
A= not $capB= $line =~ /^\s*$/u
ABresult
0X0
100
111
919 0 ▶ if ( $line =~ /\*\/\s*$/ ) { $cap = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ m[\*/\s*$]u) { } 0 0 0
elsif ($line =~ m[^\s*//]u) { } 0 0 0
920 0 elsif ( $line =~ /^\s*\/\// ) { $cap = 1; }
921 0 ▶ if ($cap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap) { } 0 0 0
922 0 unshift @d, $line;
923 0 ▶ last if $line =~ /^\s*\/\*/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ m[^\s*/\*]u 0 0 0
924 0 ▶ if ( $line =~ /^\s*\/\// && ( !@lines || $lines[-1] !~ /^\s*\/\// ) ) { last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[^\s*//]u and not @lines && $lines[-1] =~ m[^\s*//]u) 0 0 0
Condition0%0/6
$line =~ m[^\s*//]u and not @lines && $lines[-1] =~ m[^\s*//]u
!ll&&!rl&&r
000
@lines && $lines[-1] =~ m[^\s*//]u
!ll&&!rl&&r
000
MC/DC0%0/3
$line =~ m[^\s*//]u and not @lines && $lines[-1] =~ m[^\s*//]u
$line =~ m[^\s*//]u @lines $lines[-1] =~ m[^\s*//]u
Truth table0%0/4
A and not(B && C)
A= $line =~ m[^\s*//]uB= @linesC= $lines[-1] =~ m[^\s*//]u
ABCresult
0XX0
1110
10X1
1101
925 }
926 0 else { last; }
927 }
928 0 ▶ return undef unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
929 0 my $t = join( "\n", @d );
930 0 $t =~ s/^\s*\/\*\*?//mg;
931 0 $t =~ s/\s*\*\/$//mg;
932 0 $t =~ s/^\s*\*\s?//mg;
933 0 $t =~ s/^\s*\/\/\s?//mg;
934 0 $t =~ s/^\s+|\s+$//g;
935 0 return $t;
936 }
937
938 0 ▶ method _extract_trailing( $f, $off ) {
Subroutine _extract_trailing: not called CC=5 SCAR=34.0
939 0 ▶ return '' unless defined $off;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $off 0 0 0
940 0 my $content = $self->_get_content($f);
941 0 ▶ return '' unless length($content);
Branch: 1 branch
BranchTrueFalseTotal
unless length $content 0 0 0
942 0 my $post = substr( $content, $off );
943 0 my ($line) = split /\R/, $post, 2;
944 0 ▶ return '' unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
945 0 ▶ if ( $line =~ /\/\/(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[//(.*)$]u) 0 0 0
946 0 my $c = $1;
947 0 $c =~ s/^\s+|\s+$//g;
948 0 return $c;
949 }
950 0 return '';
951 }
952
953 0 ▶ method _extract_raw( $f, $s, $e ) {
Subroutine _extract_raw: not called CC=4 SCAR=30.0
954 0 ▶ return '' unless defined $s && defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and defined $e 0 0 0
Condition0%0/3
defined $s and defined $e
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s and defined $e
defined $s defined $e
Truth table0%0/3
A and B
A= defined $sB= defined $e
ABresult
0X0
100
111
955 0 my $content = $self->_get_content($f);
956 0 ▶ return '' unless length($content) >= $e;
Branch: 1 branch
BranchTrueFalseTotal
unless length $content >= $e 0 0 0
957 0 return substr( $content, $s, $e - $s );
958 }
959
960 0 ▶ method _extract_macro_val( $n, $f ) {
Subroutine _extract_macro_val: not called CC=5 SCAR=34.0
961 0 my $off = $n->{range}{begin}{offset};
962 0 ▶ return '' unless defined $off;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $off 0 0 0
963 0 my $content = $self->_get_content($f);
964 0 ▶ return '' unless length($content);
Branch: 1 branch
BranchTrueFalseTotal
unless length $content 0 0 0
965 0 my $r = substr( $content, $off );
966 0 ▶ if ( $r =~ /^(.*?)$/m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /^(.*?)$/mu) 0 0 0
967 0 my $line = $1;
968 0 my $name = $n->{name};
969 0 ▶ if ( $line =~ /#\s*define\s+\Q$name\E\s+(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /#\s*define\s+\Q$name\E\s+(.*)/u) 0 0 0
970 0 my $v = $1;
971 0 $v =~ s/\/\/.*$//;
972 0 $v =~ s/\/\*.*?\*\///g;
973 0 $v =~ s/^\s+|\s+$//g;
974 0 return $v;
975 }
976 }
977 0 '';
978 }
979
980 0 ▶ method _scan_macros_fallback($acc) {
Subroutine _scan_macros_fallback: not called CC=6 SCAR=37.4
981 0 my %seen = map { $_->name => 1 } grep { ref($_) eq 'Affix::Wrap::Macro' } @$acc;
982 0 for my $f ( keys %$allowed_files ) {
983 0 ▶ next unless $self->_is_valid_file($f);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid_file($f) 0 0 0
984 0 my $c = $self->_get_content($f);
985 0 ▶ while ( $c =~ /^\s*#\s*define\s+(\w+)(?:[ \t]+(.*?))?\s*$/mg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /^\s*#\s*define\s+(\w+)(?:[ \t]+(.*?))?\s*$/gmu) 0 0 0
986 0 my $name = $1;
987 0 ▶ next if $seen{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$name} 0 0 0
988 0 ▶ my $val = $2 // '';
Condition0%0/2
$2 // ""
l!l
00
MC/DC0%0/1
$2 // ""
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
989 0 my $off = $-[0];
990 0 my $end = $+[0];
991 0 my $pre = substr( $c, 0, $off );
992 0 my $line = ( $pre =~ tr/\n// ) + 1;
993 0 $val =~ s/\/\/.*$//;
994 0 $val =~ s/\/\*.*?\*\///g;
995 0 $val =~ s/^\s+|\s+$//g;
996 0 push @$acc,
997 Affix::Wrap::Macro->new(
998 name => $name,
999 file => $f,
1000 line => $line,
1001 end_line => $line,
1002 value => $val,
1003 doc => $self->_extract_doc( $f, $off ),
1004 start_offset => $off,
1005 end_offset => $end
1006 );
1007 }
1008 }
1009 }
1010
1011 0 ▶ method _merge_typedefs($objs) {
Subroutine _merge_typedefs: not called CC=16 SCAR=56.1
1012 0 my @tds = grep { ref($_) eq 'Affix::Wrap::Typedef' } @$objs;
1013 0 for my $td (@tds) {
1014 0 ▶ next if $td->is_merged;
Branch: 1 branch
BranchTrueFalseTotal
if $td->is_merged 0 0 0
1015 my ($child) = grep {
1016 0 ▶ !$_->is_merged &&
Condition0%0/24
!$_->is_merged && $_->file eq $td->file && ($_->name eq '(anonymous)' || $_->name eq '' || $_->name eq $td->name) && (ref $_ eq 'Affix::Wrap::Enum' || ref $_ eq 'Affix::Wrap::Struct') && (abs $_->end_line - $td->line <= 2 || abs $_->end_line - $td->end_line <= 2)
!ll&&!rl&&r
000
not $_->is_merged and $_->file eq $td->file and $_->name eq "(anonymous)" || $_->name eq "" || $_->name eq $td->name and ref $_ eq "Affix::Wrap::Enum" || ref $_ eq "Affix::Wrap::Struct"
!ll&&!rl&&r
000
not $_->is_merged and $_->file eq $td->file and $_->name eq "(anonymous)" || $_->name eq "" || $_->name eq $td->name
!ll&&!rl&&r
000
not $_->is_merged and $_->file eq $td->file
!ll&&!rl&&r
000
$_->name eq "(anonymous)" or $_->name eq "" or $_->name eq $td->name
l!l&&r!l&&!r
000
$_->name eq "(anonymous)" or $_->name eq ""
l!l&&r!l&&!r
000
ref $_ eq "Affix::Wrap::Enum" or ref $_ eq "Affix::Wrap::Struct"
l!l&&r!l&&!r
000
abs $_->end_line - $td->line <= 2 or abs $_->end_line - $td->end_line <= 2
l!l&&r!l&&!r
000
MC/DC0%0/9
!$_->is_merged && $_->file eq $td->file && ($_->name eq '(anonymous)' || $_->name eq '' || $_->name eq $td->name) && (ref $_ eq 'Affix::Wrap::Enum' || ref $_ eq 'Affix::Wrap::Struct') && (abs $_->end_line - $td->line <= 2 || abs $_->end_line - $td->end_line <= 2)
not $_->is_merged $_->file eq $td->file $_->name eq "(anonymous)" $_->name eq "" $_->name eq $td->name ref $_ eq "Affix::Wrap::Enum" ref $_ eq "Affix::Wrap::Struct" abs $_->end_line - $td->line <= 2 abs $_->end_line - $td->end_line <= 2
Truth table0%0/24
not(A) and B and C or D or E and F or G && H or I
A= not $_->is_mergedB= $_->file eq $td->fileC= $_->name eq "(anonymous)"D= $_->name eq ""E= $_->name eq $td->nameF= ref $_ eq "Affix::Wrap::Enum"G= ref $_ eq "Affix::Wrap::Struct"H= abs $_->end_line - $td->line <= 2I= abs $_->end_line - $td->end_line <= 2
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
11000XXXX0
111XX00XX0
1101X00XX0
1100100XX0
111XX1X000
111XX01000
1101X1X000
1101X01000
110011X000
1100101000
111XX1X1X1
111XX1X011
111XX011X1
111XX01011
1101X1X1X1
1101X1X011
1101X011X1
1101X01011
110011X1X1
110011X011
11001011X1
1100101011
1017 $_->file eq $td->file &&
1018 ( $_->name eq '(anonymous)' || $_->name eq '' || $_->name eq $td->name ) &&
1019 ( ref($_) eq 'Affix::Wrap::Enum' || ref($_) eq 'Affix::Wrap::Struct' ) &&
1020 ( abs( $_->end_line - $td->line ) <= 2 || abs( $_->end_line - $td->end_line ) <= 2 )
1021 } @$objs;
1022 0 ▶ if ($child) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child) 0 0 0
1023 0 ▶ my $new = Affix::Wrap::Typedef->new(
Condition0%0/6
($td->doc // $child->doc) // $self->_extract_doc($td->file, $td->start_offset)
l!l&&r!l&&!r
000
$td->doc // $child->doc
l!l&&r!l&&!r
000
MC/DC0%0/3
($td->doc // $child->doc) // $self->_extract_doc($td->file, $td->start_offset)
$td->doc $child->doc $self->_extract_doc($td->file, $td->start_offset)
Truth table0%0/4
A // B // C
A= $td->docB= $child->docC= $self->_extract_doc($td->file, $td->start_offset)
ABCresult
1XX1
01X1
0011
0000
1024 name => $td->name,
1025 underlying => $child,
1026 file => $td->file,
1027 line => $td->line,
1028 end_line => $child->end_line,
1029 doc => $td->doc // $child->doc // $self->_extract_doc( $td->file, $td->start_offset ),
1030 start_offset => $td->start_offset,
1031 end_offset => $td->end_offset
1032 );
1033 0 ▶ for ( my $i = 0; $i < @$objs; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$objs) 0 0 0
1034 0 ▶ if ( $objs->[$i] == $td ) { $objs->[$i] = $new; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($objs->[$i] == $td) 0 0 0
1035 }
1036 0 $child->mark_merged();
1037 }
1038 }
1039 0 @$objs = grep { !$_->is_merged } @$objs;
1040 }
1041
1042 0 ▶ method _wrap_named_types($objs) {
Subroutine _wrap_named_types: not called CC=9 SCAR=45.0
1043 0 ▶ for ( my $i = 0; $i < @$objs; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$objs) 0 0 0
1044 0 my $node = $objs->[$i];
1045 0 ▶ next if $node->is_merged;
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_merged 0 0 0
1046 0 ▶ if ( ( ref($node) eq 'Affix::Wrap::Struct' || ref($node) eq 'Affix::Wrap::Enum' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "Affix::Wrap::Struct" || ref $node eq "Affix::Wrap::Enum" and length $node->name and $node->name ne "(anonymous)") 0 0 0
Condition0%0/9
ref $node eq "Affix::Wrap::Struct" || ref $node eq "Affix::Wrap::Enum" and length $node->name and $node->name ne "(anonymous)"
!ll&&!rl&&r
000
ref $node eq "Affix::Wrap::Struct" || ref $node eq "Affix::Wrap::Enum" and length $node->name
!ll&&!rl&&r
000
ref $node eq "Affix::Wrap::Struct" or ref $node eq "Affix::Wrap::Enum"
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $node eq "Affix::Wrap::Struct" || ref $node eq "Affix::Wrap::Enum" and length $node->name and $node->name ne "(anonymous)"
ref $node eq "Affix::Wrap::Struct" ref $node eq "Affix::Wrap::Enum" length $node->name $node->name ne "(anonymous)"
Truth table0%0/7
A or B and C and D
A= ref $node eq "Affix::Wrap::Struct"B= ref $node eq "Affix::Wrap::Enum"C= length $node->nameD= $node->name ne "(anonymous)"
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
1047 length( $node->name ) &&
1048 $node->name ne '(anonymous)' ) {
1049
1050 # If there's already a typedef for this name, skip it
1051 0 ▶ next if grep { $_ isa Affix::Wrap::Typedef && $_->name eq $node->name } @$objs;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ isa "Affix::Wrap::Typedef" and $_->name eq $node->name;} @$objs 0 0 0
Condition0%0/3
$_ isa 'Affix::Wrap::Typedef' && $_->name eq $node->name
!ll&&!rl&&r
000
MC/DC0%0/2
$_ isa 'Affix::Wrap::Typedef' && $_->name eq $node->name
$_ isa 'Affix::Wrap::Typedef' $_->name eq $node->name
Truth table0%0/3
A && B
A= $_ isa 'Affix::Wrap::Typedef'B= $_->name eq $node->name
ABresult
0X0
100
111
1052 0 my $new = Affix::Wrap::Typedef->new(
1053 name => $node->name,
1054 underlying => $node,
1055 file => $node->file,
1056 line => $node->line,
1057 end_line => $node->end_line,
1058 doc => $node->doc,
1059 start_offset => $node->start_offset,
1060 end_offset => $node->end_offset
1061 );
1062 0 $node->mark_merged();
1063 0 $objs->[$i] = $new;
1064 }
1065 }
1066 }
1067
1068 0 ▶ method _get_triple {
Subroutine _get_triple: not called CC=10 SCAR=47.0
1069 0 ▶ my $arch = $Config{archname} =~ /aarch64|arm64/i ? 'aarch64' : $Config{archname} =~ /x64|x86_64/i ? 'x86_64' : 'i686';
Branch: 2 branches
BranchTrueFalseTotal
$Affix::Wrap::Driver::Clang::Config{'archname'} =~ /aarch64|arm64/iu ? : 0 0 0
$Affix::Wrap::Driver::Clang::Config{'archname'} =~ /x64|x86_64/iu ? : 0 0 0
1070 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
elsif ($^O eq 'cygwin') { } 0 0 0
elsif ($^O eq 'linux') { } 0 0 0
elsif ($^O eq 'darwin') { } 0 0 0
1071 0 ▶ if ( $Config{cc} =~ /gcc/i ) { return "$arch-pc-windows-gnu"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($Affix::Wrap::Driver::Clang::Config{'cc'} =~ /gcc/iu) { } 0 0 0
1072 0 else { return "$arch-pc-windows-msvc"; }
1073 }
1074 0 elsif ( $^O eq 'cygwin' ) { return "$arch-pc-cygwin"; }
1075 0 elsif ( $^O eq 'linux' ) { return "$arch-unknown-linux-gnu"; }
1076 0 elsif ( $^O eq 'darwin' ) { return "$arch-apple-darwin"; }
1077 0 ▶ my ($out) = Capture::Tiny::capture { system $clang, '-print-target-triple' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1078 0 ▶ $out =~ s/\s+//g if $out;
Branch: 1 branch
BranchTrueFalseTotal
if $out 0 0 0
1079 0 ▶ return $out // "$arch-unknown-unknown";
Condition0%0/2
$out // "$arch-unknown-unknown"
l!l
00
MC/DC0%0/1
$out // "$arch-unknown-unknown"
$out
Truth table0%0/2
A
A= $out
Aresult
11
00
1080 }
1081 }
1082 class #
1083 2 Affix::Wrap::Driver::Regex {
1084 2 field $project_files : param : reader;
1085 2 field $file_cache = {};
1086
1087 47 ▶ method _normalize ($path) {
Subroutine _normalize: called CC=3 SCAR=12.0
1088 47 ▶ return '' unless defined $path && length $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and length $path 0 47 47
Condition33%1/3
defined $path and length $path
!ll&&!rl&&r
0047
MC/DC0%0/2
defined $path and length $path
defined $path length $path
Truth table33%1/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
1089 47 my $abs = Path::Tiny::path($path)->absolute->stringify;
1090 47 $abs =~ s{\\}{/}g;
1091 47 return $abs;
1092 }
1093
1094 16 ▶ method _is_valid_file ($f) {
Subroutine _is_valid_file: called CC=6 SCAR=20.7
1095 16 ▶ return 0 unless defined $f && length $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and length $f 0 16 16
Condition33%1/3
defined $f and length $f
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $f and length $f
defined $f length $f
Truth table33%1/3
A and B
A= defined $fB= length $f
ABresult
0X0
100
111
1096 16 ▶ return 0 if $f =~ m{^/usr/(include|lib|share|local/include)};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[^/usr/(include|lib|share|local/include)]u 0 16 16
1097 16 ▶ return 0 if $f =~ m{^/System/Library};
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[^/System/Library]u 0 16 16
1098 16 ▶ return 0 if $f =~ m{/(?:Windows|Program Files|Strawberry|MinGW)/}i;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ m[/(?:Windows|Program Files|Strawberry|MinGW)/]iu 0 16 16
1099 16 return 1;
1100 }
1101
1102 16 ▶ method parse( $entry_point, $ids //= [] ) {
Subroutine parse: called CC=7 SCAR=19.9
1103 16 my @objs;
1104 16 for my $f (@$project_files) {
1105 16 my $abs = $self->_normalize($f);
1106 16 ▶ next unless length $abs;
Branch: 1 branch
BranchTrueFalseTotal
unless length $abs 0 16 16
1107 16 ▶ next unless $self->_is_valid_file($abs);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid_file($abs) 0 16 16
1108 16 ▶ if ( $f =~ /\.h(pp|xx)?$/i ) { $self->_scan( $f, \@objs ); $self->_scan_funcs( $f, \@objs ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /\.h(pp|xx)?$/iu) { } 15 1 16
1109 1 else { $self->_scan_funcs( $f, \@objs ); }
1110 }
1111 16 ▶ @objs = sort { ( $a->file cmp $b->file ) || ( $a->start_offset <=> $b->start_offset ) } @objs;
Condition33%1/3
$a->file cmp $b->file || $a->start_offset <=> $b->start_offset
l!l&&r!l&&!r
0300
MC/DC0%0/2
$a->file cmp $b->file || $a->start_offset <=> $b->start_offset
$a->file cmp $b->file $a->start_offset <=> $b->start_offset
Truth table33%1/3
A || B
A= $a->file cmp $b->fileB= $a->start_offset <=> $b->start_offset
ABresult
1X1
011
000
1112 16 @objs;
1113 }
1114
1115 31 ▶ method _read($f) {
Subroutine _read: called CC=2 SCAR=6.9
1116 31 my $abs = $self->_normalize($f);
1117 31 ▶ return $file_cache->{$abs} if exists $file_cache->{$abs};
Branch: 1 branch
BranchTrueFalseTotal
if exists $file_cache->{$abs} 23 8 31
1118 8 return $file_cache->{$abs} = Path::Tiny::path($f)->slurp_utf8;
1119 }
1120
1121 15 ▶ method _scan( $f, $acc ) {
Subroutine _scan: called CC=23 SCAR=42.8
1122 15 my $c = $self->_read($f);
1123
1124 # Macros
1125 15 ▶ while ( $c =~ /^\s*#\s*define\s+(\w+)(?:[ \t]+(.*?))?$/gm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /^\s*#\s*define\s+(\w+)(?:[ \t]+(.*?))?$/gmu) 13 15 28
1126 13 my $name = $1;
1127 13 ▶ my $val = $2 // '';
Condition50%1/2
$2 // ""
l!l
130
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
1128 13 my $s = $-[0];
1129 13 my $e = $+[0];
1130 13 $val =~ s/\/\/.*$//;
1131 13 $val =~ s/\/\*.*?\*\///g;
1132 13 $val =~ s/^\s+|\s+$//g;
1133 13 push @$acc,
1134 Affix::Wrap::Macro->new(
1135 name => $name,
1136 value => $val,
1137 file => $f,
1138 line => $self->_ln( $c, $s ),
1139 end_line => $self->_ln( $c, $e ),
1140 doc => $self->_doc( $c, $s ),
1141 start_offset => $s,
1142 end_offset => $e
1143 );
1144 }
1145
1146 # Structs
1147 15 ▶ while ( $c =~ /typedef\s+struct\s*(?:\w+\s*)?(\{(?:[^{}]++|(?1))*\})\s*(\w+)\s*;/gs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /typedef\s+struct\s*(?:\w+\s*)?(\{(?:[^{}]++|(?1))*\})\s*(\w+)\s*;/gsu) 4 15 19
1148 4 my $s = $-[0];
1149 4 my $e = $+[0];
1150 4 my $mem = $self->_mem( substr( $1, 1, -1 ) );
1151 4 my $struct = Affix::Wrap::Struct->new(
1152 name => '',
1153 tag => 'struct',
1154 members => $mem,
1155 file => $f,
1156 line => $self->_ln( $c, $s ),
1157 end_line => $self->_ln( $c, $e ),
1158 doc => undef,
1159 start_offset => $s,
1160 end_offset => $e
1161 );
1162 4 push @$acc,
1163 Affix::Wrap::Typedef->new(
1164 name => $2,
1165 underlying => $struct,
1166 file => $f,
1167 line => $self->_ln( $c, $s ),
1168 end_line => $self->_ln( $c, $e ),
1169 doc => $self->_doc( $c, $s ),
1170 start_offset => $s,
1171 end_offset => $e
1172 );
1173 }
1174
1175 # Enums (typedef)
1176 15 ▶ while ( $c =~ /typedef\s+enum\s*(?:\w+\s*)?(\{(?:[^{}]++|(?1))*\})\s*(\w+)\s*;/gs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /typedef\s+enum\s*(?:\w+\s*)?(\{(?:[^{}]++|(?1))*\})\s*(\w+)\s*;/gsu) 0 15 15
1177 0 my $s = $-[0];
1178 0 my $e = $+[0];
1179 0 my $enum = Affix::Wrap::Enum->new(
1180 name => '',
1181 constants => $self->_enum_consts( substr( $1, 1, -1 ) ),
1182 file => $f,
1183 line => $self->_ln( $c, $s ),
1184 end_line => $self->_ln( $c, $e ),
1185 doc => undef,
1186 start_offset => $s,
1187 end_offset => $e
1188 );
1189 0 push @$acc,
1190 Affix::Wrap::Typedef->new(
1191 name => $2,
1192 underlying => $enum,
1193 file => $f,
1194 line => $self->_ln( $c, $s ),
1195 end_line => $self->_ln( $c, $e ),
1196 doc => $self->_doc( $c, $s ),
1197 start_offset => $s,
1198 end_offset => $e
1199 );
1200 }
1201
1202 # Enums (standard)
1203 15 ▶ while ( $c =~ /enum\s+(\w+)\s*(\{(?:[^{}]++|(?2))*\})\s*;/gs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /enum\s+(\w+)\s*(\{(?:[^{}]++|(?2))*\})\s*;/gsu) 1 15 16
1204 1 my $s = $-[0];
1205 1 my $e = $+[0];
1206 1 my $enum = Affix::Wrap::Enum->new(
1207 name => $1,
1208 constants => $self->_enum_consts( substr( $2, 1, -1 ) ),
1209 file => $f,
1210 line => $self->_ln( $c, $s ),
1211 end_line => $self->_ln( $c, $e ),
1212 doc => $self->_doc( $c, $s ),
1213 start_offset => $s,
1214 end_offset => $e
1215 );
1216 1 push @$acc,
1217 Affix::Wrap::Typedef->new(
1218 name => $1,
1219 underlying => $enum,
1220 file => $f,
1221 line => $self->_ln( $c, $s ),
1222 end_line => $self->_ln( $c, $e ),
1223 doc => $self->_doc( $c, $s ),
1224 start_offset => $s,
1225 end_offset => $e
1226 );
1227 }
1228
1229 # Global variables
1230 15 ▶ while ( $c
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ m(^\s*extern\s+((?:const\s+|unsigned\s+|struct\s+|[\w:<>]+(?:\s*::\s*[\w:<>]+)*\s*\*?\s*)+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)\s*(?:=\s*[^;]+)?\s*;\s*(?://([^\r\n]*))?)gmu) 1 15 16
1231 =~ /^\s*extern\s+((?:const\s+|unsigned\s+|struct\s+|[\w:<>]+(?:\s*::\s*[\w:<>]+)*\s*\*?\s*)+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)\s*(?:=\s*[^;]+)?\s*;\s*(?:\/\/([^\r\n]*))?/gm
1232 ) {
1233 1 my $s = $-[0];
1234 1 my $e = $+[0];
1235 1 my $type_str = $1 . $2;
1236 1 my $name = $3;
1237 1 my $trail = $4;
1238
1239 # Strip likely API macros (uppercase words) from the type definition
1240 1 $type_str =~ s/\b[A-Z_][A-Z0-9_]*\b//g;
1241 1 $type_str =~ s/^\s+|\s+$//g;
1242
1243 # Handle array syntax: "int vars[10]" -> type="int[10]", name="vars"
1244 0 ▶ if ( $name =~ s/(\[.*\])$// ) { $type_str .= $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/(\[.*\])$//u) 0 1 1
1245
1246 # Merge standard preceding doc with captured trailing doc
1247 1 my $doc = $self->_doc( $c, $s );
1248 1 ▶ if ( defined $trail && length $trail ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trail and length $trail) 0 1 1
Condition33%1/3
defined $trail and length $trail
!ll&&!rl&&r
100
MC/DC0%0/2
defined $trail and length $trail
defined $trail length $trail
Truth table33%1/3
A and B
A= defined $trailB= length $trail
ABresult
0X0
100
111
1249 0 $trail =~ s/^\s+|\s+$//g;
1250 0 ▶ $doc = defined $doc ? "$doc\n$trail" : $trail;
Branch: 1 branch
BranchTrueFalseTotal
defined $doc ? : 0 0 0
1251 }
1252 1 push @$acc,
1253 Affix::Wrap::Variable->new(
1254 name => $name,
1255 type => Affix::Wrap::Type->parse($type_str),
1256 file => $f,
1257 line => $self->_ln( $c, $s ),
1258 end_line => $self->_ln( $c, $e ),
1259 doc => $doc,
1260 start_offset => $s,
1261 end_offset => $e
1262 );
1263 }
1264
1265 # Typedefs
1266 15 ▶ while ( $c =~ /typedef\s+(?!struct\s*(?:\w+\s*)?\{|enum\s*(?:\w+\s*)?\{)(.+?)\s*;/gs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /typedef\s+(?!struct\s*(?:\w+\s*)?\{|enum\s*(?:\w+\s*)?\{)(.+?)\s*;/gsu) 2 15 17
1267 2 my $content = $1;
1268 2 my $s = $-[0];
1269 2 my $e = $+[0];
1270 2 $content =~ s/\s+/ /g;
1271 2 $content =~ s/^\s+|\s+$//g;
1272 2 ▶ if ( $content =~ /^(.+?)\s*\(\*\s*(\w+)\)\s*\((.*?)\)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($content =~ /^(.+?)\s*\(\*\s*(\w+)\)\s*\((.*?)\)$/u) { } 0 2 2
elsif ($content =~ /^(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)$/u) { } 2 0 2
1273 0 my ( $ret_str, $name, $args_str ) = ( $1, $2, $3 );
1274 0 my $ret = Affix::Wrap::Type->parse($ret_str);
1275 0 my @args;
1276 0 ▶ if ( defined $args_str && length $args_str && $args_str ne 'void' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args_str and length $args_str and $args_str ne "void") 0 0 0
Condition0%0/6
defined $args_str and length $args_str and $args_str ne "void"
!ll&&!rl&&r
000
defined $args_str and length $args_str
!ll&&!rl&&r
000
MC/DC0%0/3
defined $args_str and length $args_str and $args_str ne "void"
defined $args_str length $args_str $args_str ne "void"
Truth table0%0/4
A and B and C
A= defined $args_strB= length $args_strC= $args_str ne "void"
ABCresult
0XX0
10X0
1100
1111
1277 0 my @args_raw = grep {length} map { s/^\s+|\s+$//g; $_ } split /,(?![^(]*\))/, $args_str;
1278 0 ▶ if ( @args_raw == 1 && $args_raw[0] =~ /^void$/ ) { @args_raw = (); }
Branch: 1 branch
BranchTrueFalseTotal
if (@args_raw == 1 and $args_raw[0] =~ /^void$/u) 0 0 0
Condition0%0/3
@args_raw == 1 and $args_raw[0] =~ /^void$/u
!ll&&!rl&&r
000
MC/DC0%0/2
@args_raw == 1 and $args_raw[0] =~ /^void$/u
@args_raw == 1 $args_raw[0] =~ /^void$/u
Truth table0%0/3
A and B
A= @args_raw == 1B= $args_raw[0] =~ /^void$/u
ABresult
0X0
100
111
1279 0 for my $raw (@args_raw) {
1280 0 ▶ if ( $raw =~ /^(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /^(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)$/u) { } 0 0 0
1281 0 my ( $t, $sep, $n ) = ( $1, $2, $3 );
1282 0 $t .= $sep;
1283 0 ▶ if ( $n =~ s/(\[.*\])$// ) { $t .= $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ s/(\[.*\])$//u) 0 0 0
1284 0 push @args, Affix::Wrap::Type->parse($t);
1285 }
1286 else {
1287 0 push @args, Affix::Wrap::Type->parse($raw);
1288 }
1289 }
1290 }
1291 0 my $coderef = Affix::Wrap::Type::CodeRef->new( ret => $ret, params => \@args );
1292 0 push @$acc,
1293 Affix::Wrap::Typedef->new(
1294 name => $name,
1295 underlying => $coderef,
1296 file => $f,
1297 line => $self->_ln( $c, $s ),
1298 end_line => $self->_ln( $c, $e ),
1299 doc => $self->_doc( $c, $s ),
1300 start_offset => $s,
1301 end_offset => $e
1302 );
1303 }
1304 elsif ( $content =~ /^(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)$/ ) {
1305 2 my ( $type_str, $sep, $name ) = ( $1, $2, $3 );
1306 2 $type_str .= $sep;
1307 2 ▶ if ( $name =~ s/(\[.*\])$// ) { $type_str .= $1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/(\[.*\])$//u) 1 1 2
1308 2 push @$acc,
1309 Affix::Wrap::Typedef->new(
1310 name => $name,
1311 underlying => Affix::Wrap::Type->parse($type_str),
1312 file => $f,
1313 line => $self->_ln( $c, $s ),
1314 end_line => $self->_ln( $c, $e ),
1315 doc => $self->_doc( $c, $s ),
1316 start_offset => $s,
1317 end_offset => $e
1318 );
1319 }
1320 }
1321 }
1322
1323 1 ▶ method _enum_consts($body) {
Subroutine _enum_consts: called CC=8 SCAR=24.4
1324 1 my @cs;
1325 1 my $v = 0;
1326 1 for ( split /,/, $body ) {
1327 3 s/\/\/.*$//;
1328 3 s/\/\*.*?\*\///s;
1329 3 s/^\s+|\s+$//g;
1330 3 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 3 3
1331 3 ▶ if (/^(\w+)\s*(?:=\s*(.+?))?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\w+)\s*(?:=\s*(.+?))?$/u) 3 0 3
1332 3 my $name = $1;
1333 3 my $val = $2; # Capture string or undef
1334
1335 # Safe hex handling without string eval
1336 3 ▶ if ( defined $val && $val =~ /^(-?)0x([\da-fA-F]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val =~ /^(-?)0x([\da-fA-F]+)$/u) 0 3 3
Condition66%2/3
defined $val and $val =~ /^(-?)0x([\da-fA-F]+)$/u
!ll&&!rl&&r
210
MC/DC0%0/2
defined $val and $val =~ /^(-?)0x([\da-fA-F]+)$/u
defined $val $val =~ /^(-?)0x([\da-fA-F]+)$/u
Truth table66%2/3
A and B
A= defined $valB= $val =~ /^(-?)0x([\da-fA-F]+)$/u
ABresult
0X0
100
111
1337 0 ▶ my $sign = $1 || '';
Condition0%0/2
$1 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
1338 0 my $num = hex($2);
1339 0 ▶ $val = $sign eq '-' ? -$num : $num;
Branch: 1 branch
BranchTrueFalseTotal
$sign eq '-' ? : 0 0 0
1340 }
1341 3 push @cs, { name => $name, value => $val };
1342 }
1343 }
1344 1 return \@cs;
1345 }
1346
1347 16 ▶ method _scan_funcs( $f, $acc ) {
Subroutine _scan_funcs: called CC=12 SCAR=26.2
1348 16 my $c = $self->_read($f);
1349 16 ▶ while ( $c
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /^\s*((?:const\s+|unsigned\s+|struct\s+|[\w:<>]+(?:\s*::\s*[\w:<>]+)*\s*\*?\s*)+?)\s*(\w+)\s*(\((?:[^()]++|(?3))*\))(?:\s*;|\s*\{)/gmu) 13 16 29
1350 =~ /^\s*((?:const\s+|unsigned\s+|struct\s+|[\w:<>]+(?:\s*::\s*[\w:<>]+)*\s*\*?\s*)+?)\s*(\w+)\s*(\((?:[^()]++|(?3))*\))(?:\s*;|\s*\{)/gm
1351 ) {
1352 13 ▶ next if $2 =~ /^(if|while|for|return|switch|typedef)$/ || $1 =~ /static/;
Branch: 1 branch
BranchTrueFalseTotal
if $2 =~ /^(if|while|for|return|switch|typedef)$/u or $1 =~ /static/u 0 13 13
Condition33%1/3
$2 =~ /^(if|while|for|return|switch|typedef)$/u or $1 =~ /static/u
l!l&&r!l&&!r
0013
MC/DC0%0/2
$2 =~ /^(if|while|for|return|switch|typedef)$/u or $1 =~ /static/u
$2 =~ /^(if|while|for|return|switch|typedef)$/u $1 =~ /static/u
Truth table33%1/3
A or B
A= $2 =~ /^(if|while|for|return|switch|typedef)$/uB= $1 =~ /static/u
ABresult
1X1
011
000
1353 13 my $s = $-[0];
1354 13 my $e = $+[0];
1355 13 my ( $ret_str, $func_name, $args_str ) = ( $1, $2, substr( $3, 1, -1 ) );
1356 #
1357 13 $ret_str =~ s/\b[A-Z_][A-Z0-9_]*\b//g;
1358 13 $ret_str =~ s/^\s+|\s+$//g;
1359 13 my $ret_obj = Affix::Wrap::Type->parse($ret_str);
1360
1361 # Split args respecting commas inside parentheses (function pointers, etc.)
1362 13 my @args_raw = grep {length} map { s/^\s+|\s+$//g; $_ } split /,(?![^(]*\))/, $args_str;
1363 0 ▶ if ( @args_raw == 1 && $args_raw[0] =~ /^void$/ ) { @args_raw = (); }
Branch: 1 branch
BranchTrueFalseTotal
if (@args_raw == 1 and $args_raw[0] =~ /^void$/u) 0 13 13
Condition66%2/3
@args_raw == 1 and $args_raw[0] =~ /^void$/u
!ll&&!rl&&r
1120
MC/DC0%0/2
@args_raw == 1 and $args_raw[0] =~ /^void$/u
@args_raw == 1 $args_raw[0] =~ /^void$/u
Truth table66%2/3
A and B
A= @args_raw == 1B= $args_raw[0] =~ /^void$/u
ABresult
0X0
100
111
1364 13 my @args;
1365 13 for my $raw (@args_raw) {
1366 12 ▶ if ( $raw =~ /^(.+?)\s*\(\*\s*(\w+)\)\s*\((.*)\)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raw =~ /^(.+?)\s*\(\*\s*(\w+)\)\s*\((.*)\)$/u) { } 1 11 12
elsif ($raw =~ /^(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)$/u) { } 11 0 11
1367 1 my ( $r_type, $cb_name, $cb_args ) = ( $1, $2, $3 );
1368 1 my $ret = Affix::Wrap::Type->parse($r_type);
1369 1 my @p;
1370 1 ▶ if ( $cb_args ne '' && $cb_args ne 'void' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb_args ne "" and $cb_args ne "void") 1 0 1
Condition33%1/3
$cb_args ne "" and $cb_args ne "void"
!ll&&!rl&&r
001
MC/DC0%0/2
$cb_args ne "" and $cb_args ne "void"
$cb_args ne "" $cb_args ne "void"
Truth table33%1/3
A and B
A= $cb_args ne ""B= $cb_args ne "void"
ABresult
0X0
100
111
1371 1 @p = map { Affix::Wrap::Type->parse($_) } split /,(?![^(]*\))/, $cb_args;
1372 }
1373 1 my $code_ref = Affix::Wrap::Type::CodeRef->new( ret => $ret, params => \@p );
1374 1 push @args, Affix::Wrap::Argument->new( type => $code_ref, name => $cb_name );
1375 }
1376 elsif ( $raw =~ /^(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)$/ ) {
1377 11 my ( $t, $sep, $n ) = ( $1, $2, $3 );
1378 11 $t .= $sep;
1379 0 ▶ if ( $n =~ s/(\[.*\])$// ) { $t .= $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ s/(\[.*\])$//u) 0 11 11
1380 11 push @args, Affix::Wrap::Argument->new( type => Affix::Wrap::Type->parse($t), name => $n );
1381 }
1382 else {
1383 0 push @args, Affix::Wrap::Argument->new( type => Affix::Wrap::Type->parse($raw) );
1384 }
1385 }
1386 13 push @$acc,
1387 Affix::Wrap::Function->new(
1388 name => $func_name,
1389 mangled_name => $func_name,
1390 ret => $ret_obj,
1391 args => \@args,
1392 file => $f,
1393 line => $self->_ln( $c, $s ),
1394 end_line => $self->_ln( $c, $e ),
1395 doc => $self->_doc( $c, $s ),
1396 start_offset => $s,
1397 end_offset => $e
1398 );
1399 }
1400 }
1401
1402 5 ▶ method _mem($b) {
Subroutine _mem: called CC=11 SCAR=28.4
1403 5 my @m;
1404 5 my $pending_doc = '';
1405 10 ▶ my $clean = sub ($t) {
Subroutine __ANON__: called CC=2 SCAR=7.0
1406 10 $t =~ s/^\s*\/\*\*?//mg;
1407 10 $t =~ s/\s*\*\/$//mg;
1408 10 $t =~ s/^\s*\*\s?//mg;
1409 10 $t =~ s/^\s*\/\/\s?//mg;
1410 10 $t =~ s/^\s+|\s+$//g;
1411 10 ▶ return length($t) ? $t : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $t ? : 0 10 10
1412 5 };
1413 5 ▶ while ( length($b) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $b > 0) 25 5 30
1414 25 ▶ if ( $b =~ s/^(\s+)// ) { next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s/^(\s+)//u) 15 10 25
1415 0 ▶ if ( $b =~ s|^(\s*/\*(.*?)\*/)||s ) { $pending_doc .= $2; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s[^(\s*/\*(.*?)\*/)][]su) 0 10 10
1416 0 ▶ if ( $b =~ s|^(//(.*?)\n)|| ) { $pending_doc .= "$2\n"; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s[^(//(.*?)\n)][]u) 0 10 10
1417 10 ▶ if ( $b =~ s/^\s*(union|struct)\s*(\{(?:[^{}]++|(?2))*\})\s*(\w+)\s*;// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s/^\s*(union|struct)\s*(\{(?:[^{}]++|(?2))*\})\s*(\w+)\s*;//u) 1 9 10
1418 1 my $tag = $1;
1419 1 my $d = Affix::Wrap::Struct->new( name => '', tag => $tag, members => $self->_mem( substr( $2, 1, -1 ) ) );
1420 1 push @m, Affix::Wrap::Member->new( name => $3, definition => $d, doc => $clean->($pending_doc) );
1421 1 $pending_doc = '';
1422 1 next;
1423 }
1424
1425 # Function pointer: ret (*name)(args)
1426 9 ▶ if ( $b =~ s/^\s*([\w\s\*]+?)\s*\(\*\s*(\w+)\)\s*\((.*?)\)\s*;// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s/^\s*([\w\s\*]+?)\s*\(\*\s*(\w+)\)\s*\((.*?)\)\s*;//u) 0 9 9
1427 0 my ( $ret_str, $name, $args_str ) = ( $1, $2, $3 );
1428 0 my $ret = Affix::Wrap::Type->parse($ret_str);
1429 0 my @args;
1430 0 ▶ if ( $args_str ne '' && $args_str ne 'void' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args_str ne "" and $args_str ne "void") 0 0 0
Condition0%0/3
$args_str ne "" and $args_str ne "void"
!ll&&!rl&&r
000
MC/DC0%0/2
$args_str ne "" and $args_str ne "void"
$args_str ne "" $args_str ne "void"
Truth table0%0/3
A and B
A= $args_str ne ""B= $args_str ne "void"
ABresult
0X0
100
111
1431 0 @args = map { Affix::Wrap::Type->parse($_) } split( /\s*,\s*/, $args_str );
1432 }
1433 0 my $type_obj = Affix::Wrap::Type::CodeRef->new( ret => $ret, params => \@args );
1434 0 push @m, Affix::Wrap::Member->new( name => $name, type => $type_obj, doc => $clean->($pending_doc) );
1435 0 $pending_doc = '';
1436 0 next;
1437 }
1438 9 ▶ if ( $b =~ s/^\s*(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)\s*;// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s/^\s*(.+?)([\s\*]+)([a-zA-Z_]\w*(?:\[.*?\])?)\s*;//u) 9 0 9
1439 9 my ( $t, $sep, $n ) = ( $1, $2, $3 );
1440 9 $t .= $sep;
1441 9 $t =~ s/^\s+|\s+$//g;
1442 9 ▶ if ( $n =~ s/(\[.*\])$// ) { $t .= $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ s/(\[.*\])$//u) 2 7 9
1443 9 push @m, Affix::Wrap::Member->new( name => $n, type => Affix::Wrap::Type->parse($t), doc => $clean->($pending_doc) );
1444 9 $pending_doc = '';
1445 9 next;
1446 }
1447 0 substr( $b, 0, 1 ) = '';
1448 0 $pending_doc = '';
1449 }
1450 5 return \@m;
1451 }
1452 78 ▶ method _ln( $c, $o ) { ( substr( $c, 0, $o ) =~ tr/\n// ) + 1 }
Subroutine _ln: called CC=1 SCAR=0.0
1453
1454 35 ▶ method _doc( $c, $o ) {
Subroutine _doc: called CC=13 SCAR=30.0
1455 35 ▶ return undef if $o == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o == 0 13 22 35
1456 22 my @l = split /\n/, substr( $c, 0, $o );
1457 22 my @d;
1458 22 my $cap = 0;
1459 22 ▶ while ( my $l = pop @l ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = pop @l) 22 0 22
1460 22 ▶ next if !$cap && $l =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not $cap and $l =~ /^\s*$/u 0 22 22
Condition33%1/3
not $cap and $l =~ /^\s*$/u
!ll&&!rl&&r
0220
MC/DC0%0/2
not $cap and $l =~ /^\s*$/u
not $cap $l =~ /^\s*$/u
Truth table33%1/3
not(A) and B
A= not $capB= $l =~ /^\s*$/u
ABresult
0X0
100
111
1461 22 ▶ if ( $l =~ s/\s*\*\/\s*$// ) { $cap = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ s[\s*\*/\s*$][]u) { } 3 19 22
elsif ($l =~ m[^\s*//]u) { } 0 19 19
1462 0 elsif ( $l =~ m{^\s*//} ) { $cap = 1; }
1463 22 ▶ if ($cap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cap) { } 3 19 22
1464 3 unshift @d, $l;
1465 3 ▶ last if $l =~ /^\s*\/\*/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ m[^\s*/\*]u 3 0 3
1466 0 ▶ last if $l =~ m{^\s*//} && ( !@l || $l[-1] !~ m{^\s*//} );
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ m[^\s*//]u and not @l && $l[-1] =~ m[^\s*//]u 0 0 0
Condition0%0/6
$l =~ m[^\s*//]u and not @l && $l[-1] =~ m[^\s*//]u
!ll&&!rl&&r
000
@l && $l[-1] =~ m[^\s*//]u
!ll&&!rl&&r
000
MC/DC0%0/3
$l =~ m[^\s*//]u and not @l && $l[-1] =~ m[^\s*//]u
$l =~ m[^\s*//]u @l $l[-1] =~ m[^\s*//]u
Truth table0%0/4
A and not(B && C)
A= $l =~ m[^\s*//]uB= @lC= $l[-1] =~ m[^\s*//]u
ABCresult
0XX0
1110
10X1
1101
1467 }
1468 19 else {last}
1469 }
1470 22 ▶ return undef unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 19 3 22
1471 3 my $t = join "\n", @d;
1472 3 $t =~ s/^\s*(\/\*+|\*+\/|\*|\/\/)\s?//mg;
1473 3 $t =~ s/^\s+|\s+$//g;
1474 3 return $t;
1475 }
1476 }
1477
1478 2 class Affix::Wrap {
1479 2 field $driver : param //= ();
1480 2 field $project_files : param //= $driver->project_files;
1481 2 field $include_dirs : param //= [];
1482 2 field $types : param //= {};
1483 #
1484 4 ▶ ADJUST {
Subroutine __ANON__: called CC=11 SCAR=45.5
1485 4 ▶ if ( defined $driver && !builtin::blessed($driver) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $driver and not builtin::blessed($driver)) { } 0 4 4
elsif (not defined $driver) { } 0 4 4
Condition33%1/3
defined $driver and not builtin::blessed($driver)
!ll&&!rl&&r
040
MC/DC0%0/2
defined $driver and not builtin::blessed($driver)
defined $driver not builtin::blessed($driver)
Truth table33%1/3
A and not(B)
A= defined $driverB= not builtin::blessed($driver)
ABresult
0X0
100
111
1486 0 ▶ if ( $driver eq 'Clang' ) { $driver = Affix::Wrap::Driver::Clang->new( project_files => $project_files ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($driver eq 'Clang') { } 0 0 0
elsif ($driver eq 'Regex') { } 0 0 0
1487 0 elsif ( $driver eq 'Regex' ) { $driver = Affix::Wrap::Driver::Regex->new( project_files => $project_files ); }
1488 0 else { die "Unknown driver '$driver'"; }
1489 }
1490 elsif ( !defined $driver ) {
1491
1492 # Wrap in a localized warn-handler to suppress the internal "Can't spawn" error
1493 0 my $exit = do {
1494 0 local $SIG{__WARN__} = sub { };
1495 0 system( 'clang', '--version', '>', File::Spec->devnull, '2>&1' );
1496 };
1497 0 my $use_clang = ( $exit == 0 );
1498 0 ▶ if ( $use_clang && $^O eq 'cygwin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_clang and $^O eq "cygwin") 0 0 0
Condition0%0/3
$use_clang and $^O eq "cygwin"
!ll&&!rl&&r
000
MC/DC0%0/2
$use_clang and $^O eq "cygwin"
$use_clang $^O eq "cygwin"
Truth table0%0/3
A and B
A= $use_clangB= $^O eq "cygwin"
ABresult
0X0
100
111
1499 0 ▶ my $which = `which clang 2>/dev/null` // '';
Condition0%0/2
`which clang 2>/dev/null` // ""
l!l
00
MC/DC0%0/1
`which clang 2>/dev/null` // ""
`which clang 2>/dev/null`
Truth table0%0/2
A
A= `which clang 2>/dev/null`
Aresult
11
00
1500 0 ▶ $use_clang = 0 unless $which =~ m{^/(usr/)?bin/clang};
Branch: 1 branch
BranchTrueFalseTotal
unless $which =~ m[^/(usr/)?bin/clang]u 0 0 0
1501 }
1502 0 ▶ $driver = $use_clang ? Affix::Wrap::Driver::Clang->new( project_files => $project_files ) :
Branch: 1 branch
BranchTrueFalseTotal
$use_clang ? : 0 0 0
1503 Affix::Wrap::Driver::Regex->new( project_files => $project_files );
1504 }
1505 }
1506
1507 11 ▶ method parse( $entry_point //= () ) {
Subroutine parse: called CC=3 SCAR=11.4
Pod documented
1508 11 ▶ $entry_point //= $project_files->[0];
Condition33%1/3
$entry_point //= $project_files->[0]
l!l&&r!l&&!r
0110
MC/DC0%0/2
$entry_point //= $project_files->[0]
$entry_point $project_files->[0]
Truth table33%1/3
A //= B
A= $entry_pointB= $project_files->[0]
ABresult
1X1
011
000
1509 11 my @nodes = $driver->parse( $entry_point, $include_dirs );
1510 11 $self->_resolve_macros( \@nodes );
1511 11 return @nodes;
1512 }
1513
1514 11 ▶ method _resolve_macros ($nodes) {
Subroutine _resolve_macros: called CC=7 SCAR=19.6
1515 11 my %macros;
1516 11 for my $node (@$nodes) {
1517 18 ▶ if ( $node isa Affix::Wrap::Macro ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node isa "Affix::Wrap::Macro") 7 11 18
1518 7 ▶ my $val = $node->value // '';
Condition50%1/2
$node->value // ""
l!l
70
MC/DC0%0/1
$node->value // ""
$node->value
Truth table50%1/2
A
A= $node->value
Aresult
11
00
1519 7 $val =~ s/(?<=\d)[Uu][Ll]{0,2}//g; # Strip C suffixes like 100ULL
1520 7 $macros{ $node->name } = $val;
1521 }
1522 }
1523 11 my %cache;
1524 my $resolve;
1525 16 ▶ $resolve = sub($token) {
Subroutine __ANON__: called CC=11 SCAR=24.6
1526 16 ▶ return undef unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 16 16
1527 16 $token =~ s/^\s+|\s+$//g;
1528 16 ▶ return oct($token) if $token =~ /^0x[\da-fA-F]+$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /^0x[\da-fA-F]+$/iu 0 16 16
1529 16 ▶ return $token + 0 if $token =~ /^-?\d+(?:\.\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /^-?\d+(?:\.\d+)?$/u 6 10 16
1530 10 ▶ return $cache{$token} if exists $cache{$token};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache{$token} 0 10 10
1531 10 local $cache{$token} = undef;
1532 10 my $expr = $macros{$token};
1533 10 ▶ return undef unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 1 9 10
1534 9 ▶ 1 while $expr =~ s/^\((.*)\)$/$1/; # Strip outer parens
Branch: 1 branch
BranchTrueFalseTotal
$expr =~ s/^\((.*)\)$/$1/u and do { '???' } 2 9 11
1535
1536 # Resolve bitwise and arithmetic expressions
1537 9 ▶ if ( $expr =~ /[|&<>+\-*\/]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr =~ m[[|&<>+\-*/]]u) 2 7 9
1538 2 my $evaluable = $expr;
1539
1540 # Using {} delimiters so the // operator doesn't break the regex parser
1541 2 ▶ $evaluable =~ s{\b([a-zA-Z_]\w*)\b}{ $resolve->($1) // $1 }ge;
Condition33%1/3
&$resolve($1) // $1
l!l&&r!l&&!r
200
MC/DC0%0/2
&$resolve($1) // $1
&$resolve($1) $1
Truth table33%1/3
A // B
A= &$resolve($1)B= $1
ABresult
1X1
011
000
1542
1543 # Clean up any C-style suffixes that might have survived
1544 2 $evaluable =~ s/\b(\d+)L+\b/$1/g;
1545
1546 # If everything is now numeric/operators/whitespace, we can safely eval
1547 2 ▶ if ( $evaluable =~ /^[0-9\s|&<>\+\-\*\/\(\).xXa-fA-F]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($evaluable =~ m[^[0-9\s|&<>\+\-\*/\(\).xXa-fA-F]+$]u) 2 0 2
1548
1549 # Using a string eval here to let Perl's engine handle C-like precedence
1550 2 my $res = eval $evaluable;
1551 2 ▶ return $cache{$token} = $res if defined $res;
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 2 0 2
1552 }
1553 }
1554
1555 # Fallback: Treat as simple alias (A -> B)
1556 7 return $cache{$token} = $resolve->($expr);
1557 11 };
1558 11 for my $node (@$nodes) {
1559 18 ▶ if ( $node isa Affix::Wrap::Macro ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node isa "Affix::Wrap::Macro") 7 11 18
1560 7 my $val = $resolve->( $node->name );
1561 7 ▶ $node->set_value($val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 6 1 7
1562 }
1563 }
1564 }
1565
1566 25 ▶ method _generate_code( $lib, $pkg ) {
Subroutine _generate_code: called CC=25 SCAR=33.7
1567 25 ▶ Carp::croak("Affix::Wrap::generate/wrap requires a valid package name") unless defined $pkg && $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u 14 11 25
Condition66%2/3
defined $pkg and $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u
!ll&&!rl&&r
01411
MC/DC50%1/2
defined $pkg and $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u
defined $pkg $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u
Truth table66%2/3
A and B
A= defined $pkgB= $pkg =~ /^[a-zA-Z_]\w*(::\w+)*$/u
ABresult
0X0
100
111
1568 11 my @nodes = $self->parse;
1569 11 my %unique_types;
1570 my %referenced_names;
1571 11 for my $node (@nodes) {
1572 18 ▶ if ( $node->can('name') && $node->name && $node->name ne '(anonymous)' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->can("name") and $node->name and $node->name ne "(anonymous)") 18 0 18
Condition33%2/6
$node->can("name") and $node->name and $node->name ne "(anonymous)"
!ll&&!rl&&r
0018
$node->can("name") and $node->name
!ll&&!rl&&r
0018
MC/DC0%0/3
$node->can("name") and $node->name and $node->name ne "(anonymous)"
$node->can("name") $node->name $node->name ne "(anonymous)"
Truth table25%1/4
A and B and C
A= $node->can("name")B= $node->nameC= $node->name ne "(anonymous)"
ABCresult
0XX0
10X0
1100
1111
1573 18 ▶ next if $node isa Affix::Wrap::Macro || $node isa Affix::Wrap::Function || $node isa Affix::Wrap::Variable;
Branch: 1 branch
BranchTrueFalseTotal
if $node isa "Affix::Wrap::Macro" or $node isa "Affix::Wrap::Function" or $node isa "Affix::Wrap::Variable" 17 1 18
Condition83%5/6
$node isa "Affix::Wrap::Macro" or $node isa "Affix::Wrap::Function" or $node isa "Affix::Wrap::Variable"
l!l&&r!l&&!r
1701
$node isa "Affix::Wrap::Macro" or $node isa "Affix::Wrap::Function"
l!l&&r!l&&!r
7101
MC/DC66%2/3
$node isa "Affix::Wrap::Macro" or $node isa "Affix::Wrap::Function" or $node isa "Affix::Wrap::Variable"
$node isa "Affix::Wrap::Macro" $node isa "Affix::Wrap::Function" $node isa "Affix::Wrap::Variable"
Truth table75%3/4
A or B or C
A= $node isa "Affix::Wrap::Macro"B= $node isa "Affix::Wrap::Function"C= $node isa "Affix::Wrap::Variable"
ABCresult
1XX1
01X1
0011
0000
1574 1 $unique_types{ $node->name } = $node;
1575 }
1576
1577 # Collect dependencies from affix_type strings (e.g. '@sockaddr')
1578 1 ▶ my $sig = eval { $node->affix . "" } // '';
Condition50%1/2
eval { do { $node->affix . '' } } // ""
l!l
10
MC/DC0%0/1
eval { do { $node->affix . '' } } // ""
eval { do { $node->affix . '' } }
Truth table50%1/2
A
A= eval { do { $node->affix . '' } }
Aresult
11
00
1579 0 ▶ while ( $sig =~ /@([a-zA-Z_]\w*)/g ) { $referenced_names{$1} = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ /@([a-zA-Z_]\w*)/gu) 0 1 1
1580 }
1581
1582 # Atomic Engine Batch
1583 11 my @fwd = sort keys %{ { map { $_ => 1 } ( keys %unique_types, keys %referenced_names ) } };
1584 11 my @batch_lines;
1585 11 for my $name ( sort keys %unique_types ) {
1586 1 my $sig = $unique_types{$name}->affix_type;
1587 1 ▶ push @batch_lines, " typedef $name => $sig;" if $sig && $sig ne "$name()";
Branch: 1 branch
BranchTrueFalseTotal
if $sig and $sig ne "$name()" 1 0 1
Condition33%1/3
$sig and $sig ne "$name()"
!ll&&!rl&&r
001
MC/DC0%0/2
$sig and $sig ne "$name()"
$sig $sig ne "$name()"
Truth table33%1/3
A and B
A= $sigB= $sig ne "$name()"
ABresult
0X0
100
111
1588 }
1589 11 ▶ my $batch_str = @batch_lines ? join( "\n", @batch_lines ) . "\n" : "";
Branch: 1 branch
BranchTrueFalseTotal
@batch_lines ? : 1 10 11
1590
1591 # Perl Module Construction
1592 # Safely quote $lib: escape \ and ] within q[...] delimiters
1593 11 my $_lib = '';
1594 11 ▶ if ( defined $lib ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lib) 10 1 11
1595 10 my $safe_lib = $lib;
1596 10 $safe_lib =~ s/\\/\\\\/g;
1597 10 $safe_lib =~ s/\]/\\]/g;
1598 10 $_lib = "my \$lib = q[$safe_lib];";
1599 }
1600 11 my $out = <<~"PERL";
1601 package $pkg {
1602 use v5.40;
1603 use Affix qw[:all];
1604 #
1605 $_lib
1606 PERL
1607 11 for my $name (@fwd) {
1608 1 $out .= " typedef '$name';\n";
1609 }
1610 11 $out .= $batch_str;
1611 11 $out .= "\n #\n";
1612 11 for my $node (@nodes) {
1613 18 ▶ $out .= " " . $node->perl_constants . "\n" if $node isa Affix::Wrap::Enum;
Branch: 1 branch
BranchTrueFalseTotal
if $node isa "Affix::Wrap::Enum" 0 18 18
1614 }
1615 11 $out .= "\n #\n";
1616 11 for my $node (@nodes) {
1617 18 my $code = $node->affix_type;
1618 18 ▶ if ( $code && ( $node isa Affix::Wrap::Function || $node isa Affix::Wrap::Variable || $node isa Affix::Wrap::Macro ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code and $node isa "Affix::Wrap::Function" || $node isa "Affix::Wrap::Variable" || $node isa "Affix::Wrap::Macro") 17 1 18
Condition77%7/9
$code and $node isa "Affix::Wrap::Function" || $node isa "Affix::Wrap::Variable" || $node isa "Affix::Wrap::Macro"
!ll&&!rl&&r
0117
$node isa "Affix::Wrap::Function" or $node isa "Affix::Wrap::Variable" or $node isa "Affix::Wrap::Macro"
l!l&&r!l&&!r
1071
$node isa "Affix::Wrap::Function" or $node isa "Affix::Wrap::Variable"
l!l&&r!l&&!r
1008
MC/DC50%2/4
$code and $node isa "Affix::Wrap::Function" || $node isa "Affix::Wrap::Variable" || $node isa "Affix::Wrap::Macro"
$code $node isa "Affix::Wrap::Function" $node isa "Affix::Wrap::Variable" $node isa "Affix::Wrap::Macro"
Truth table60%3/5
A and B or C or D
A= $codeB= $node isa "Affix::Wrap::Function"C= $node isa "Affix::Wrap::Variable"D= $node isa "Affix::Wrap::Macro"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1619 17 $out .= " $code;\n";
1620 }
1621 }
1622 11 $out .= "};\n1;\n";
1623 11 return ( $out, \@nodes );
1624 }
1625
1626 20 ▶ method generate( $lib, $pkg, $file ) {
Subroutine generate: called CC=1 SCAR=0.0
Pod documented
1627 20 my ( $code, $nodes ) = $self->_generate_code( $lib, $pkg );
1628 7 Path::Tiny::path($file)->spew_utf8($code);
1629 }
1630
1631 3 ▶ method wrap ( $lib, $pkg //= [caller]->[0] ) {
Subroutine wrap: called CC=5 SCAR=16.1
Pod documented
1632 3 my ( $code, $nodes ) = $self->_generate_code( $lib, $pkg );
1633 1 ▶ eval $code;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
1634 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
1635 0 Carp::croak("Affix::Wrap wrap() compilation failed: $@\n\nCode:\n$code");
1636 }
1637 2 ▶ return grep { $_ isa Affix::Wrap::Function || $_ isa Affix::Wrap::Variable || $_ isa Affix::Wrap::Macro } @$nodes;
Condition66%4/6
$_ isa 'Affix::Wrap::Function' || $_ isa 'Affix::Wrap::Variable' || $_ isa 'Affix::Wrap::Macro'
l!l&&r!l&&!r
160
$_ isa "Affix::Wrap::Function" or $_ isa "Affix::Wrap::Variable"
l!l&&r!l&&!r
106
MC/DC0%0/3
$_ isa 'Affix::Wrap::Function' || $_ isa 'Affix::Wrap::Variable' || $_ isa 'Affix::Wrap::Macro'
$_ isa "Affix::Wrap::Function" $_ isa "Affix::Wrap::Variable" $_ isa 'Affix::Wrap::Macro'
Truth table50%2/4
A or B || C
A= $_ isa "Affix::Wrap::Function"B= $_ isa "Affix::Wrap::Variable"C= $_ isa 'Affix::Wrap::Macro'
ABCresult
1XX1
01X1
0011
0000
1638 }
1639
1640 0 ▶ method list_symbols ($lib_path) {
Subroutine list_symbols: not called CC=22 SCAR=62.3
Pod undocumented
1641 0 my $abs = path($lib_path)->absolute->stringify;
1642 0 ▶ return [] unless -e $abs;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $abs 0 0 0
1643 0 my @symbols;
1644 0 my ( $out, $err, $exit );
1645
1646 # llvm-nm
1647 # We use --extern-only to find the public API
1648 0 ▶ ( $out, $err, $exit ) = capture { system( 'llvm-nm', '--extern-only', '--defined-only', $abs ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1649 0 ▶ if ( $exit == 0 && $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit == 0 and $out) 0 0 0
Condition0%0/3
$exit == 0 and $out
!ll&&!rl&&r
000
MC/DC0%0/2
$exit == 0 and $out
$exit == 0 $out
Truth table0%0/3
A and B
A= $exit == 0B= $out
ABresult
0X0
100
111
1650 0 for ( split /\n/, $out ) {
1651 0 ▶ if (/ [TRG] (?:_)?(\w+)$/) { push @symbols, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if (/ [TRG] (?:_)?(\w+)$/u) 0 0 0
1652 }
1653 }
1654
1655 # objdump for Strawberry Perl
1656 0 ▶ if ( !@symbols ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@symbols) 0 0 0
1657 0 ▶ ( $out, $err, $exit ) = capture { system( 'objdump', '-p', $abs ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1658 0 ▶ if ( $exit == 0 && $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit == 0 and $out) 0 0 0
Condition0%0/3
$exit == 0 and $out
!ll&&!rl&&r
000
MC/DC0%0/2
$exit == 0 and $out
$exit == 0 $out
Truth table0%0/3
A and B
A= $exit == 0B= $out
ABresult
0X0
100
111
1659
1660 # objdump -p displays the "Export Address Table"
1661 # We look for the lines following the table header
1662 0 my $in_exports = 0;
1663 0 for ( split /\n/, $out ) {
1664 0 ▶ if (/^\[Ordinal\/Name Pointer\] Table$/) { $in_exports = 1; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (m(^\[Ordinal/Name Pointer\] Table$)u) 0 0 0
1665 0 ▶ if ($in_exports) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_exports) 0 0 0
1666 0 ▶ last if /^\s*$/; # End of table
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/u 0 0 0
1667
1668 # Format:[ 0] lsquic_engine_new
1669 0 ▶ if (/\[\s*\d+\]\s+(\w+)/) { push @symbols, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if (/\[\s*\d+\]\s+(\w+)/u) 0 0 0
1670 }
1671 }
1672 }
1673 }
1674
1675 # dumpbin for MSVC
1676 0 ▶ if ( !@symbols ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@symbols) 0 0 0
1677 0 ▶ ( $out, $err, $exit ) = capture { system( 'dumpbin', '/EXPORTS', $abs ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1678 0 ▶ if ( $exit == 0 && $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit == 0 and $out) 0 0 0
Condition0%0/3
$exit == 0 and $out
!ll&&!rl&&r
000
MC/DC0%0/2
$exit == 0 and $out
$exit == 0 $out
Truth table0%0/3
A and B
A= $exit == 0B= $out
ABresult
0X0
100
111
1679 0 my $in_exports = 0;
1680 0 for ( split /\n/, $out ) {
1681 0 ▶ if (/ordinal\s+hint\s+RVA\s+name/) { $in_exports = 1; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (/ordinal\s+hint\s+RVA\s+name/u) 0 0 0
1682 0 ▶ if ($in_exports) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_exports) 0 0 0
1683
1684 # Format: 1 0 00001234 lsquic_engine_new
1685 0 ▶ if (/^\s+\d+\s+[A-F0-9]+\s+[A-F0-9]+\s+(\w+)/) { push @symbols, $1; }
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+\d+\s+[A-F0-9]+\s+[A-F0-9]+\s+(\w+)/u) 0 0 0
1686 }
1687 }
1688 }
1689 }
1690 0 @symbols = sort @symbols;
1691 0 ▶ if ( !@symbols ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@symbols) 0 0 0
1692 0 warn "[!] list_symbols: No symbols found in $abs using llvm-nm, objdump, or dumpbin.\n";
1693 }
1694 0 return \@symbols;
1695 }
1696 }
1697 }
1698 2 1;
1699 __END__
« blib/lib/Affix/Platform/BSD.pm ↑ Summary blib/lib/Test2/Tools/Affix.pm »