lib/PDL/PP.pm

filter: Statementstmt 84.3% 990 / 1174 Branchbran 63.5% 380 / 598 Conditioncond 54.1% 230 / 425 MC/DCmcdc 24.3% 55 / 226 Subroutinesub 82.3% 200 / 243 Podpod 25.7% 18 / 70 totaltotal 68.4% 1873 / 2736 CC 470 SCAR 26.7
CC
470
Cov
73%
pp_def
66.1
__ANON__
57.4
__ANON__
33.7
CRAP 14.5
« blib/lib/PDL/Reduce.pm ↑ Summary lib/PDL/Primitive.pd »
1 # $PDL::PP::deftbl is an array-ref of
2 # PDL::PP::Rule->new("Name1", "Name2", $ref_to_sub)
3 # where Name1 represents the target of the rule, Name2 the condition,
4 # and the subroutine reference is the routine called when the rule is
5 # applied.
6 #
7 # If there is no condition, the argument can be left out of the call
8 # (unless there is a doc string), so
9 # PDL::PP::Rule->new("Name1", $ref_to_sub)
10 #
11 # The target and conditions can also be an array reference, so
12 # PDL::PP::Rule->new("Name1", ["Name2","Name3"], $ref_to_sub)
13 # PDL::PP::Rule->new(["Name1","Name2"], "Name3", $ref_to_sub)
14 # PDL::PP::Rule->new(["Name1","Name2"], ["Name3","Name4], $ref_to_sub)
15 #
16 # If a doc string exists then the condition must also
17 # be supplied, even if it is just [] (ie no condition).
18 #
19 # There are specialized rules for common situations. The rules for the
20 # target, condition, and doc arguments hold from the base class (ie
21 # whether scalar or array values are used, ...)
22 #
23 # Return a constant:
24 #
25 # PDL::PP::Rule::Returns->new($targets [,$conditions [,$doc]], $value)
26 # is used to return a constant. So
27 # PDL::PP::Rule::Returns->new("Name1", "foo")
28 #
29 # This class is specialized since there are some common return values:
30 # PDL::PP::Rule::Returns::Zero->new($targets [,$conditions [,$doc]])
31 # PDL::PP::Rule::Returns::One->new($targets [,$conditions [,$doc]])
32 # PDL::PP::Rule::Returns::EmptyString->new($targets [,$conditions [,$doc]])
33 # PDL::PP::Rule::Returns::NULL->new($targets [,$conditions [,$doc]])
34 # which return 0, 1, "", and "NULL" respectively
35 #
36 # The InsertName class exists to allow you to return something like
37 # "foo<routine name>bar"
38 # e.g.
39 # PDL::PP::Rule::InsertName->new("Foo", '_pdl_%s_bar')
40 # PDL::PP::Rule::InsertName->new("Foo", "Arg2", '_pdl_%s_bar')
41 # Note that the Name argument is automatically used as a condition, so
42 # it does not need to be supplied, and the return value should be
43 # given as a string and use a %s where the name goes
44 #
45 # The Substitute rule replaces dollar-signed macros ($P(), $ISBAD(), etc)
46 # with the low-level C code to perform the macro.
47 # PDL::PP::Rule::Substitute->new($target,$condition)
48 # $target and $condition must be scalars.
49  
50 package # hide from PAUSE/MetaCPAN
51 PDL::PP::Rule;
52  
53 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 3 ▶use overload ('""' => \&PDL::PP::Rule::stringify);
Subroutine BEGIN: called CC=1 SCAR=0.0
59 sub stringify {
60 247 ▶ my $self = shift;
Subroutine stringify: called CC=5 SCAR=16.1
61  
62 247 my $str = ref $self;
63 4260 ▶ if ("PDL::PP::Rule" eq $str) {
Branch: 1 branch
BranchTrueFalseTotal
if ('PDL::PP::Rule' eq $str) { } 2577 1930 4507
64 4260 $str = "Rule";
65 } else {
66 4260 $str =~ s/PDL::PP::Rule:://;
67 }
68 4260 $str = "($str) ";
69 4260 ▶ $str .= "[".join(",", @{$self->{targets}||[]})."]";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"targets"} or [] 0 4507 4507
70 1537 ▶ $str .= "<-[".join(",", @{$self->{conditions}||[]})."] ";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"conditions"} or [] 36 4471 4507
71 4507 ▶ $str .= $self->{doc} if exists $self->{doc};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"doc"} 1896 2611 4507
72 4507 return $str;
73 }
74  
75 # Takes two args: the calling object and the message, but we only care
76 # about the message:
77 4260 ▶sub report ($$) { print $_[1] if $::PP_VERBOSE; }
Subroutine report: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 12821 12821
78  
79 # Very limited error checking.
80 # Allow scalars for targets and conditions to be optional
81 #
82 # At present you have to have a conditions argument if you supply
83 # a doc string
84 my $rule_usage = "Usage: PDL::PP::Rule->new(\$targets[,\$conditions[,\$doc],] [,\$ref])\n";
85 sub new {
86 2723 ▶ die $rule_usage if @_ < 2 or @_ > 5;
Subroutine new: called CC=9 SCAR=22.2
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 5 0 339 339
Condition33%1/3
@_ < 2 or @_ > 5
l!l&&r!l&&!r
00339
MC/DC0%0/2
@_ < 2 or @_ > 5
@_ < 2 @_ > 5
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 5
ABresult
1X1
011
000
87 1849 my $class = shift;
88 1849 my $self = bless {}, $class;
89 6961 my $targets = shift;
90 6961 ▶ $targets = [$targets] unless ref $targets eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $targets eq "ARRAY" 294 45 339
91 1849 $self->{targets} = $targets;
92 3031 ▶ return $self if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 48 291 339
93 3031 ▶ $self->{ref} = pop if ref $_[-1] eq "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "CODE" 237 54 291
94 3031 ▶ my $conditions = shift // [];
Condition50%1/2
shift() // []
l!l
2910
MC/DC0%0/1
shift() // []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
95 3031 ▶ $conditions = [$conditions] unless ref $conditions eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $conditions eq "ARRAY" 60 231 291
96 3031 $self->{conditions} = $conditions;
97 3031 ▶ $self->{doc} = shift if defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 123 168 291
98 3031 $self;
99 }
100  
101 # $rule->any_targets_exist($pars);
102 #
103 # Returns 1 if any of the targets exist in $pars, 0 otherwise.
104 # A return value of 1 means that the rule should not be applied.
105 sub any_targets_exist {
106 3031 ▶ my $self = shift;
Subroutine any_targets_exist: called CC=3 SCAR=11.0
107 1849 my $pars = shift;
108  
109 1849 my $targets = $self->{targets};
110  
111 1834 foreach my $target (@$targets) {
112 1834 ▶ if (exists $pars->{$target}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pars->{$target}) 247 4496 4743
113 1834 $self->report("--skipping since TARGET $target exists\n");
114 1988 return 1;
115 }
116 }
117 1988 return 0;
118 }
119  
120 # $rule->all_conditions_exist($pars);
121 #
122 # Returns 1 if all of the required conditions exist in $pars, 0 otherwise.
123 # A return value of 0 means that the rule should not be applied.
124 sub all_conditions_exist {
125 1988 ▶ my $self = shift;
Subroutine all_conditions_exist: called CC=3 SCAR=11.0
126 1988 my $pars = shift;
127 0 ▶ return 1 unless my @nonexist = grep !/\?$/ && !exists $pars->{$_}, @{$self->{conditions}};
Branch: 1 branch
BranchTrueFalseTotal
unless my(@nonexist) = grep((!(/\?$/ || exists $pars->{$_})), @{$$self{"conditions"};}) 2723 1537 4260
Condition100%3/3
/\?$/ || exists $pars->{$_}
l!l&&r!l&&!r
143088511735
MC/DC100%2/2
/\?$/ || exists $pars->{$_}
/\?$/ exists $pars->{$_}
Truth table100%3/3
A || B
A= /\?$/B= exists $pars->{$_}
ABresult
1X1
011
000
128 1834 $self->report("--skipping since CONDITIONs (@nonexist) do not exist\n");
129 12 0;
130 }
131  
132 # $rule->should_apply($pars);
133 #
134 # Returns 1 if the rule should be applied (ie no targets already
135 # exist in $pars and all the required conditions exist in $pars),
136 # otherwise 0.
137 #
138 sub should_apply {
139 12 ▶ my $self = shift;
Subroutine should_apply: called CC=3 SCAR=11.0
140 196 my $pars = shift;
141 196 ▶ return 0 if $self->any_targets_exist($pars);
Branch: 1 branch
BranchTrueFalseTotal
if $self->any_targets_exist($pars) 247 4260 4507
142 196 ▶ return 0 unless $self->all_conditions_exist($pars);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->all_conditions_exist($pars) 1537 2723 4260
143 75 return 1;
144 }
145  
146 # my @args = $self->extract_args($pars);
147 sub extract_args {
148 75 ▶ my ($self, $pars) = @_;
Subroutine extract_args: called CC=1 SCAR=0.0
149 75 @$pars{ map {(my $r=$_)=~s/\?$//;$r} @{ $self->{conditions} } };
150 }
151  
152 # Apply the rule using the supplied $pars hash reference.
153 #
154 sub apply {
155 75 ▶ my $self = shift;
Subroutine apply: called CC=8 SCAR=21.1
156 1077 my $pars = shift;
157  
158 carp "Unable to apply rule $self as there is no subroutine reference!"
159 1077 ▶ unless exists $self->{ref};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"ref"} 0 3031 3031
160  
161 1077 my $targets = $self->{targets};
162 1077 my $conditions = $self->{conditions};
163 1077 my $ref = $self->{ref};
164  
165 1077 $self->report("Applying: $self\n");
166  
167 703 ▶ return unless $self->should_apply($pars);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->should_apply($pars) 1182 1849 3031
168  
169 # Create the argument array for the routine.
170 #
171 703 my @args = $self->extract_args($pars);
172  
173 # Run this rule's subroutine:
174 6 my @retval = $ref->(@args);
175  
176 # Check for any inconsistencies:
177 6 ▶ confess "Internal error: rule '$self' returned " . (1+$#retval)
Branch: 1 branch
BranchTrueFalseTotal
unless $#retval == $targets->$#* 0 1834 1834
178 . " items and expected " . (1+$#$targets)
179 unless $#retval == $#$targets;
180  
181 18 $self->report("--setting:");
182 9 foreach my $target (@$targets) {
183 15 $self->report(" $target");
184 confess "Cannot have multiple meanings for target $target!"
185 15 ▶ if exists $pars->{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $pars->{$target} 0 1988 1988
186 15 my $result = shift @retval;
187  
188 # The following test suggests that things could/should be
189 # improved in the code generation.
190 #
191 15 ▶ if (defined $result and $result eq 'DO NOT SET!!') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result and $result eq 'DO NOT SET!!') { } 0 1988 1988
Condition66%2/3
defined $result and $result eq "DO NOT SET!!"
!ll&&!rl&&r
11418740
MC/DC0%0/2
defined $result and $result eq "DO NOT SET!!"
defined $result $result eq "DO NOT SET!!"
Truth table66%2/3
A and B
A= defined $resultB= $result eq "DO NOT SET!!"
ABresult
0X0
100
111
192 15 $self->report (" is 'DO NOT SET!!'");
193 } else {
194 15 $pars->{$target} = $result;
195 }
196 }
197 15 $self->report("\n");
198 }
199  
200  
201 package # hide from PAUSE/MetaCPAN
202 PDL::PP::Rule::Croak;
203  
204 # Croaks if all of the input variables are defined. Use this to identify
205 # incompatible arguments.
206 our @ISA = qw(PDL::PP::Rule);
207 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
208  
209 sub new {
210 15 ▶ croak('Usage: PDL::PP::Rule::Croak->new(["incompatible", "arguments"], "Croaking message")')
Subroutine new: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 12 12
211 unless @_ == 3;
212 15 shift->SUPER::new([], @_);
213 }
214  
215 sub apply {
216 15 ▶ my ($self, $pars) = @_;
Subroutine apply: called CC=2 SCAR=7.1
217 15 $self->report("Applying: $self\n");
218 203 ▶ croak("$pars->{Name}: $self->{doc}") if $self->should_apply($pars);
Branch: 1 branch
BranchTrueFalseTotal
if $self->should_apply($pars) 0 196 196
219 }
220  
221 package # hide from PAUSE/MetaCPAN
222 PDL::PP::Rule::Returns;
223 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
224 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
225  
226 our @ISA = qw (PDL::PP::Rule);
227  
228 # This class does not treat return values of "DO NOT SET!!"
229 # as special.
230 #
231 sub new {
232 203 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.0
233 203 my $value = pop;
234 203 my $self = $class->SUPER::new(@_);
235 203 $self->{"returns.value"} = $value;
236 171 my $targets = $self->{targets};
237 171 ▶ croak "There can only be 1 target for a $self, not " . (1+$#$targets) . "!"
Branch: 1 branch
BranchTrueFalseTotal
unless $targets->$#* == 0 0 75 75
238 unless $#$targets == 0;
239 171 return $self;
240 }
241  
242 sub apply {
243 0 ▶ my $self = shift;
Subroutine apply: called CC=3 SCAR=11.1
244 234 my $pars = shift;
245  
246 carp "Unable to apply rule $self as there is no return value!"
247 234 ▶ unless exists $self->{"returns.value"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"returns.value"} 0 1077 1077
248  
249 234 my $target = $self->{targets}->[0];
250  
251 234 $self->report("Applying: $self\n");
252  
253 468 ▶ return unless $self->should_apply($pars);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->should_apply($pars) 374 703 1077
254  
255 # Set the value
256 #
257 468 $self->report ("--setting: $target\n");
258 468 $pars->{$target} = $self->{"returns.value"};
259 }
260  
261 package # hide from PAUSE/MetaCPAN
262 PDL::PP::Rule::Returns::Zero;
263  
264 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
265  
266 our @ISA = qw (PDL::PP::Rule::Returns);
267  
268 sub new {
269 234 ▶ shift->SUPER::new(@_,0);
Subroutine new: called CC=1 SCAR=0.0
270 }
271  
272 package # hide from PAUSE/MetaCPAN
273 PDL::PP::Rule::Returns::One;
274  
275 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
276  
277 our @ISA = qw (PDL::PP::Rule::Returns);
278  
279 sub new {
280 0 ▶ shift->SUPER::new(@_,1);
Subroutine new: called CC=1 SCAR=6.9
281 }
282  
283 package # hide from PAUSE/MetaCPAN
284 PDL::PP::Rule::Returns::EmptyString;
285  
286 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
287  
288 our @ISA = qw (PDL::PP::Rule::Returns);
289  
290 sub new {
291 234 ▶ shift->SUPER::new(@_,"");
Subroutine new: called CC=1 SCAR=0.0
292 }
293  
294 package # hide from PAUSE/MetaCPAN
295 PDL::PP::Rule::Returns::NULL;
296  
297 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
298  
299 our @ISA = qw (PDL::PP::Rule::Returns);
300  
301 sub new {
302 234 ▶ shift->SUPER::new(@_,"NULL");
Subroutine new: called CC=1 SCAR=0.0
303 }
304  
305 package # hide from PAUSE/MetaCPAN
306 PDL::PP::Rule::InsertName;
307  
308 4507 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
309 1930 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
310 our @ISA = qw (PDL::PP::Rule);
311  
312 # This class does not treat return values of "DO NOT SET!!"
313 # as special.
314 sub new {
315 177 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=12.0
316 177 my $value = pop;
317 234 my @args = @_;
318 0 my $self = $class->SUPER::new(@args);
319 137 $self->{"insertname.value"} = $value;
320 # Generate a default doc string
321 1 ▶ $self->{doc} ||= "Sets $self->{targets}->[0] to \"$value\"";
Condition50%1/2
$self->{"doc"} ||= qq[Sets $self->{"targets"}[0] to "$value"]
l!l
015
MC/DC0%0/1
$self->{"doc"} ||= qq[Sets $self->{"targets"}[0] to "$value"]
$self->{"doc"}
Truth table50%1/2
A
A= $self->{"doc"}
Aresult
11
00
322 1 my $targets = $self->{targets};
323 9 ▶ croak "There can only be 1 target for a $self, not " . (1+$#$targets) . "!"
Branch: 1 branch
BranchTrueFalseTotal
unless @$targets == 1 0 15 15
324 unless @$targets == 1;
325 9 unshift @{$self->{conditions}}, "Name"; # add "Name" as first condition
326 0 return $self;
327 }
328  
329 sub apply {
330 0 ▶ my $self = shift;
Subroutine apply: called CC=3 SCAR=14.2
331 0 my $pars = shift;
332 carp "Unable to apply rule $self as there is no return value!"
333 0 ▶ unless exists $self->{"insertname.value"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"insertname.value"} 0 203 203
334 0 $self->report("Applying: $self\n");
335 4 ▶ return unless $self->should_apply($pars);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->should_apply($pars) 32 171 203
336 # Set the value
337 4 my $target = $self->{targets}[0];
338 20 $self->report ("--setting: $target (name=$pars->{Name})\n");
339 0 $pars->{$target} = sprintf $self->{"insertname.value"}, $pars->{Name};
340 }
341  
342 # PDL::PP::Rule::Substitute->new($target,$condition)
343 # $target and $condition must be scalars.
344 package # hide from PAUSE/MetaCPAN
345 PDL::PP::Rule::Substitute;
346  
347 4507 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
348 4507 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
349 our @ISA = qw (PDL::PP::Rule);
350  
351 2 ▶sub badflag_isset { "($_[0]->state & PDL_BADVAL)" }
Subroutine badflag_isset: not called CC=1 SCAR=0.0
352  
353 # Probably want this directly in the apply routine but leave as is for now
354 sub dosubst_private {
355 2 ▶ my ($src,$sname,$pname,$name,$sig,$compobj,$privobj) = @_;
Subroutine dosubst_private: called CC=6 SCAR=20.4
356 2 ▶ my $ret = (ref $src ? $src->[0] : $src);
Branch: 1 branch
BranchTrueFalseTotal
ref $src ? : 0 234 234
357 215 my @pairs;
358 206 for ([$compobj,'COMP'], [$privobj,'PRIV']) {
359 188 my ($cobj, $which) = @$_;
360 188 my ($cn,$co) = map $cobj->$_, qw(othernames otherobjs);
361 push @pairs, 'DO'.$which.'ALLOC' => sub {
362 join '', map $$co{$_}->get_malloc("\$$which($_)"),
363 188 ▶ grep $$co{$_}->need_malloc, @$cn
Subroutine __ANON__: not called CC=1 SCAR=0.0
364 188 };
365 }
366 my %syms = (
367 @pairs,
368 215 ((ref $src) ? %{$src->[1]} : ()),
369 188 ▶ PRIV => sub {return "$sname->$_[0]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
370 422 ▶ COMP => sub {my $r="$pname->$_[0]";$sig->other_is_output($_[0])?"(*($r))":$r},
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$sig->other_is_output($_[0]) ? : 0 1 1
371 422 ▶ CROAK => sub {"return PDL->make_error(PDL_EUSERERROR, \"Error in $name:\" @{[join ',', @_]})"},
Subroutine __ANON__: called CC=1 SCAR=0.0
372 188 ▶ NAME => sub {return $name},
Subroutine __ANON__: not called CC=1 SCAR=0.0
373 188 ▶ MODULE => sub {return $::PDLMOD},
Subroutine __ANON__: not called CC=1 SCAR=0.0
374 188 ▶ PDLSTATESETBAD => sub { ($sig->objs->{$_[0]}//confess "Can't get PDLSTATESETBAD for unknown ndarray '$_[0]'")->do_pdlaccess."->state |= PDL_BADVAL" },
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/3
$sig->objs->{$_[0]} // confess("Can't get PDLSTATESETBAD for unknown ndarray '$_[0]'")
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig->objs->{$_[0]} // confess("Can't get PDLSTATESETBAD for unknown ndarray '$_[0]'")
$sig->objs->{$_[0]} confess("Can't get PDLSTATESETBAD for unknown ndarray '$_[0]'")
Truth table0%0/3
A // B
A= $sig->objs->{$_[0]}B= confess("Can't get PDLSTATESETBAD for unknown ndarray '$_[0]'")
ABresult
1X1
011
000
375 188 ▶ PDLSTATESETGOOD => sub { ($sig->objs->{$_[0]}->do_pdlaccess//confess "Can't get PDLSTATESETGOOD for unknown ndarray '$_[0]'")."->state &= ~PDL_BADVAL" },
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/3
$sig->objs->{$_[0]}->do_pdlaccess // confess("Can't get PDLSTATESETGOOD for unknown ndarray '$_[0]'")
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig->objs->{$_[0]}->do_pdlaccess // confess("Can't get PDLSTATESETGOOD for unknown ndarray '$_[0]'")
$sig->objs->{$_[0]}->do_pdlaccess confess("Can't get PDLSTATESETGOOD for unknown ndarray '$_[0]'")
Truth table0%0/3
A // B
A= $sig->objs->{$_[0]}->do_pdlaccessB= confess("Can't get PDLSTATESETGOOD for unknown ndarray '$_[0]'")
ABresult
1X1
011
000
376 39 ▶ PDLSTATEISBAD => sub {badflag_isset(($sig->objs->{$_[0]}//confess "Can't get PDLSTATEISBAD for unknown ndarray '$_[0]'")->do_pdlaccess)},
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/3
$sig->objs->{$_[0]} // confess("Can't get PDLSTATEISBAD for unknown ndarray '$_[0]'")
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig->objs->{$_[0]} // confess("Can't get PDLSTATEISBAD for unknown ndarray '$_[0]'")
$sig->objs->{$_[0]} confess("Can't get PDLSTATEISBAD for unknown ndarray '$_[0]'")
Truth table0%0/3
A // B
A= $sig->objs->{$_[0]}B= confess("Can't get PDLSTATEISBAD for unknown ndarray '$_[0]'")
ABresult
1X1
011
000
377 39 ▶ PDLSTATEISGOOD => sub {"!".badflag_isset(($sig->objs->{$_[0]}//confess "Can't get PDLSTATEISGOOD for unknown ndarray '$_[0]'")->do_pdlaccess)},
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/3
$sig->objs->{$_[0]} // confess("Can't get PDLSTATEISGOOD for unknown ndarray '$_[0]'")
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig->objs->{$_[0]} // confess("Can't get PDLSTATEISGOOD for unknown ndarray '$_[0]'")
$sig->objs->{$_[0]} confess("Can't get PDLSTATEISGOOD for unknown ndarray '$_[0]'")
Truth table0%0/3
A // B
A= $sig->objs->{$_[0]}B= confess("Can't get PDLSTATEISGOOD for unknown ndarray '$_[0]'")
ABresult
1X1
011
000
378 39 ▶ P => sub { (my $o = ($sig->objs->{$_[0]}//confess "Can't get P for unknown ndarray '$_[0]'"))->{FlagPhys} = 1; $o->do_pointeraccess; },
Subroutine __ANON__: called CC=2 SCAR=8.1
Condition33%1/3
$sig->objs->{$_[0]} // confess("Can't get P for unknown ndarray '$_[0]'")
l!l&&r!l&&!r
400
MC/DC0%0/2
$sig->objs->{$_[0]} // confess("Can't get P for unknown ndarray '$_[0]'")
$sig->objs->{$_[0]} confess("Can't get P for unknown ndarray '$_[0]'")
Truth table33%1/3
A // B
A= $sig->objs->{$_[0]}B= confess("Can't get P for unknown ndarray '$_[0]'")
ABresult
1X1
011
000
379 39 ▶ PDL => sub { ($sig->objs->{$_[0]}//confess "Can't get PDL for unknown ndarray '$_[0]'")->do_pdlaccess },
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$sig->objs->{$_[0]} // confess("Can't get PDL for unknown ndarray '$_[0]'")
l!l&&r!l&&!r
2000
MC/DC0%0/2
$sig->objs->{$_[0]} // confess("Can't get PDL for unknown ndarray '$_[0]'")
$sig->objs->{$_[0]} confess("Can't get PDL for unknown ndarray '$_[0]'")
Truth table33%1/3
A // B
A= $sig->objs->{$_[0]}B= confess("Can't get PDL for unknown ndarray '$_[0]'")
ABresult
1X1
011
000
380 2 ▶ SIZE => sub { ($sig->dims_obj->ind_obj($_[0])//confess "Can't get SIZE of unknown dim '$_[0]'")->get_size },
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/3
$sig->dims_obj->ind_obj($_[0]) // confess("Can't get SIZE of unknown dim '$_[0]'")
l!l&&r!l&&!r
000
MC/DC0%0/2
$sig->dims_obj->ind_obj($_[0]) // confess("Can't get SIZE of unknown dim '$_[0]'")
$sig->dims_obj->ind_obj($_[0]) confess("Can't get SIZE of unknown dim '$_[0]'")
Truth table0%0/3
A // B
A= $sig->dims_obj->ind_obj($_[0])B= confess("Can't get SIZE of unknown dim '$_[0]'")
ABresult
1X1
011
000
381 3 ▶ SETNDIMS => sub {"PDL_RETERROR(PDL_err, PDL->reallocdims(__it,$_[0]));"},
Subroutine __ANON__: called CC=1 SCAR=0.0
382 3 ▶ SETDIMS => sub {"PDL_RETERROR(PDL_err, PDL->setdims_careful(__it));"},
Subroutine __ANON__: called CC=1 SCAR=0.0
383 3 ▶ SETDELTABROADCASTIDS => sub {PDL::PP::pp_line_numbers(__LINE__, <<EOF)},
Subroutine __ANON__: called CC=1 SCAR=0.0
384 {int __ind; PDL_RETERROR(PDL_err, PDL->reallocbroadcastids(\$PDL(CHILD), \$PDL(PARENT)->nbroadcastids));
385 for(__ind=0; __ind<\$PDL(PARENT)->nbroadcastids; __ind++)
386 \$PDL(CHILD)->broadcastids[__ind] = \$PDL(PARENT)->broadcastids[__ind] + ($_[0]);
387 }
388 EOF
389 188 ▶ %PDL::PP::macros,
Branch: 1 branch
BranchTrueFalseTotal
ref $src ? : 0 234 234
390 );
391 11 my $known_pat = join '|', map quotemeta, sort keys %syms;
392 11 ▶ while (my ($before, $kw, $args, $other) = macro_extract($ret, $known_pat)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = macro_extract($ret, $known_pat)) 177 234 411
393 204 ▶ confess("$kw not defined in '$ret'!") if !$syms{$kw};
Branch: 1 branch
BranchTrueFalseTotal
unless $syms{$kw} 0 177 177
394 204 $ret = join '', $before, $syms{$kw}->(split_cpp($args)), $other;
395 }
396 188 $ret;
397 }
398  
399 # split like C pre-processor - on commas unless in "" or ()
400 my $extract_spec = [
401 3 ▶ sub {Text::Balanced::extract_delimited($_[0], '"')},
Subroutine __ANON__: called CC=1 SCAR=0.0
402 3 ▶ sub {Text::Balanced::extract_bracketed($_[0], '()')},
Subroutine __ANON__: called CC=1 SCAR=0.0
403 qr/\s+/,
404 qr/[^",\(\s]+/,
405 { COMMA => qr/,/ },
406 ];
407 sub split_cpp {
408 3 ▶ my ($text) = @_;
Subroutine split_cpp: called CC=7 SCAR=19.5
409 3 require Text::Balanced;
410 3 my ($thisstr, @parts);
411 3 ▶ while (defined(my $n = Text::Balanced::extract_multiple($text, $extract_spec, undef, 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $n = &Text::Balanced::extract_multiple($text, $extract_spec, undef, 1))) 215 188 403
412 3 ▶ if (ref $n) { push @parts, $thisstr // ''; $thisstr = ''; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n) { } 11 204 215
Condition50%1/2
$thisstr // ""
l!l
110
MC/DC0%0/1
$thisstr // ""
$thisstr
Truth table50%1/2
A
A= $thisstr
Aresult
11
00
413 3 ▶ else { $thisstr = '' if !defined $thisstr; $thisstr .= $n; }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thisstr 186 18 204
414 }
415 9 ▶ push @parts, $thisstr if defined $thisstr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $thisstr 186 2 188
416 3 s/^\s+//, s/\s+$// for @parts;
417 3 @parts;
418 }
419  
420 sub macro_extract {
421 3 ▶ require Text::Balanced;
Subroutine macro_extract: called CC=2 SCAR=7.0
422 3 my ($text, $pat) = @_;
423 3 ▶ return unless $text =~ /\$($pat)\s*(?=\()/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\$($pat)\s*(?=\()/ 234 188 422
424 3 my ($before, $kw, $other) = ($`, $1, $');
425 3 (my $bracketed, $other) = Text::Balanced::extract_bracketed($other, '(")');
426 3 $bracketed = substr $bracketed, 1, -1; # chop off brackets
427 3 $bracketed =~ s:^\s*(.*?)\s*$:$1:;
428 0 ($before, $kw, $bracketed, $other);
429 }
430  
431 sub new {
432 0 ▶ die "Usage: PDL::PP::Rule::Substitute->new(\$target,\$condition);"
Subroutine new: called CC=4 SCAR=23.2
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 39 39
433 unless @_ == 3;
434 0 my ($class, $target, $condition) = @_;
435 0 ▶ die "\$target must be a scalar for PDL::PP::Rule::Substitute" if ref $target;
Branch: 1 branch
BranchTrueFalseTotal
if ref $target 0 39 39
436 0 ▶ die "\$condition must be a scalar for PDL::PP::Rule::Substitute" if ref $condition;
Branch: 1 branch
BranchTrueFalseTotal
if ref $condition 0 39 39
437 0 $class->SUPER::new($target, [$condition, qw(StructName ParamStructName Name SignatureObj CompObj PrivObj)],
438 \&dosubst_private);
439 }
440  
441 package PDL::PP;
442  
443 339 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
444  
445 our $VERSION = "2.3";
446 $VERSION = eval $VERSION;
447  
448 our $macros_xs = pp_line_numbers(__LINE__, <<'EOF');
449 #include "pdlperl.h"
450 EOF
451  
452 our $header_c = pp_line_numbers(__LINE__, <<'EOF');
453 /*
454 * THIS FILE WAS GENERATED BY PDL::PP from %s! Do not modify!
455 */
456  
457 #define PDL_FREE_CODE(trans, destroy, comp_free_code, ntpriv_free_code) \
458 if (destroy) { \
459 comp_free_code \
460 } \
461 if ((trans)->dims_redone) { \
462 ntpriv_free_code \
463 }
464  
465 #include "EXTERN.h"
466 #include "perl.h"
467 #include "XSUB.h"
468 #include "pdl.h"
469 #include "pdlcore.h"
470 #define PDL %s
471 extern Core* PDL; /* Structure hold core C functions */
472 EOF
473 our $header_xs = <<'EOF';
474  
475 Core* PDL = NULL; /* Structure hold core C functions */
476  
477 MODULE = %1$s PACKAGE = %2$s PREFIX=pdl_run_
478  
479 PROTOTYPES: DISABLE
480  
481 EOF
482 our $header_xsboot = pp_line_numbers(__LINE__, <<'EOF');
483 BOOT:
484 /* Get pointer to structure of core shared C routines */
485 /* make sure PDL::Core is loaded */
486 EOF
487  
488 339 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
489 339 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
490 291 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
491  
492 our @ISA = qw(Exporter);
493  
494 our @EXPORT = qw/pp_addhdr pp_addpm pp_bless pp_def pp_done pp_add_boot
495 pp_add_exported pp_addxs pp_add_isa pp_export_nothing
496 pp_add_typemaps
497 pp_core_importList pp_beginwrap pp_setversion
498 pp_addbegin pp_line_numbers
499 pp_deprecate_module pp_add_macros/;
500  
501 $::PP_VERBOSE = 0;
502  
503 our $done = 0; # pp_done has not been called yet
504  
505 291 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
506  
507 0 ▶sub nopm { $::PDLPACK eq 'NONE' } # flag that we don't want to generate a PM
Subroutine nopm: called CC=1 SCAR=6.9
Pod undocumented
508  
509 sub import {
510 0 ▶ my ($mod,$modname, $packname, $base, $callpack, $multi_c, $deep) = @_;
Subroutine import: called CC=5 SCAR=25.5
511 # Allow for users to not specify the packname
512 0 ▶ ($packname, $base, $callpack) = ($modname, $packname, $base)
Branch: 1 branch
BranchTrueFalseTotal
if $packname =~ m[/] 0 3 3
513 if ($packname =~ m|/|);
514 0 $::PDLMOD=$modname; $::PDLPACK=$packname; $::PDLBASE=$base;
515 0 ▶ $::CALLPACK = $callpack || $::PDLMOD;
Condition33%1/3
$callpack || $main::PDLMOD
l!l&&r!l&&!r
030
MC/DC0%0/2
$callpack || $main::PDLMOD
$callpack $main::PDLMOD
Truth table33%1/3
A || B
A= $callpackB= $main::PDLMOD
ABresult
1X1
011
000
516 0 $::PDLMULTI_C = $multi_c; # one pp-*.c per function
517 0 ▶ $::PDLMULTI_C_PREFIX = $deep ? "$base-" : "";
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 0 3 3
518 0 $::PDLOBJ = "PDL"; # define pp-funcs in this package
519 0 $::PDLXS="";
520 0 $::PDLOVERLOAD="";
521 0 $::PDLBEGIN="";
522 0 $::PDLPMROUT="";
523 0 for ('Top','Bot','Middle') { $::PDLPM{$_}="" }
524 0 @::PDLPMISA=('PDL::Exporter', 'DynaLoader');
525 69 @::PDL_IFBEGINWRAP = ('','');
526 69 $::PDLVERSIONSET = '';
527 69 $::PDLMODVERSION = undef;
528 1 $::DOCUMENTED = 0;
529 1 $::PDLCOREIMPORT = ""; #import list from core, defaults to everything, i.e. use Core
530 # could be set to () for importing nothing from core. or qw/ barf / for
531 # importing barf only.
532 1 @::PDL_LVALUE_SUBS = ();
533 0 @_=("PDL::PP");
534 68 goto &Exporter::import;
535 }
536  
537 sub list_functions {
538 68 ▶ my ($file) = @_;
Subroutine list_functions: not called CC=4 SCAR=16.3
Pod undocumented
539 68 my @funcs;
540 1 undef &PDL::PP::pp_def;
541 1 ▶ local *PDL::PP::pp_def = sub { push @funcs, (_pp_parsename($_[0]))[0]};
Subroutine __ANON__: not called CC=1 SCAR=1.2
542 1 undef &PDL::PP::pp_done;
543 1 ▶ local *PDL::PP::pp_done = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
544 1 $::PDLMOD = $file;
545 1 ▶ $_ ||= '' for $::CALLPACK, $::PDLOBJ; # stop warnings
Condition0%0/2
$_ ||= ""
l!l
00
MC/DC0%0/1
$_ ||= ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
546 30 require File::Spec::Functions;
547 30 do ''.File::Spec::Functions::rel2abs($file);
548 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
549 0 @funcs;
550 }
551  
552 our %macros;
553  
554 sub pp_add_macros {
555 0 ▶ confess "Usage: pp_add_macros(name=>sub {},...)" if @_%2;
Subroutine pp_add_macros: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
556 0 %macros = (%macros, @_);
557 }
558  
559 sub pp_beginwrap {
560 0 ▶ @::PDL_IFBEGINWRAP = ('BEGIN {','}');
Subroutine pp_beginwrap: not called CC=1 SCAR=6.9
Pod documented
561 }
562  
563 sub pp_setversion {
564 0 ▶ my ($ver) = @_;
Subroutine pp_setversion: not called CC=2 SCAR=14.6
Pod documented
565 0 ▶ $ver = qq{'$ver'} if $ver !~ /['"]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ver =~ /['"]/ 0 0 0
566 0 $::PDLMODVERSION = '$VERSION';
567 1 $::PDLVERSIONSET = "our \$VERSION = $ver;";
568 }
569  
570 sub pp_addhdr {
571 1 ▶ my ($hdr) = @_;
Subroutine pp_addhdr: not called CC=2 SCAR=10.5
Pod documented
572 0 $::PDLXSC .= $hdr;
573 34 ▶ $::PDLXSC_header .= $hdr if $::PDLMULTI_C;
Branch: 1 branch
BranchTrueFalseTotal
if $main::PDLMULTI_C 0 0 0
574 }
575  
576 sub _pp_addpm_nolineno {
577 34 ▶ my $pm = shift;
Subroutine _pp_addpm_nolineno: called CC=4 SCAR=14.4
578 0 my $pos;
579 43 ▶ if (ref $pm) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pm) { } 1 68 69
580 44 my $opt = $pm;
581 44 $pm = shift;
582 confess "unknown option '$opt->{At}' (only Top|Bot|Middle)" unless defined $opt->{At} &&
583 44 ▶ $opt->{At} =~ /^(Top|Bot|Middle)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"At"} and $opt->{"At"} =~ /^(Top|Bot|Middle)$/ 1 0 1
Condition33%1/3
defined $opt->{"At"} and $opt->{"At"} =~ /^(Top|Bot|Middle)$/
!ll&&!rl&&r
010
MC/DC0%0/2
defined $opt->{"At"} and $opt->{"At"} =~ /^(Top|Bot|Middle)$/
defined $opt->{"At"} $opt->{"At"} =~ /^(Top|Bot|Middle)$/
Truth table33%1/3
A and B
A= defined $opt->{"At"}B= $opt->{"At"} =~ /^(Top|Bot|Middle)$/
ABresult
0X0
100
111
584 44 $pos = $opt->{At};
585 } else {
586 44 $pos = 'Middle';
587 }
588 44 $pm =~ s#\n{3,}#\n\n#g;
589 44 $::PDLPM{$pos} .= "\n$pm\n\n";
590 }
591  
592 sub pp_addpm {
593 221 ▶ my @args = @_;
Subroutine pp_addpm: called CC=2 SCAR=7.0
Pod documented
594 221 ▶ my $pmind = ref $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 0 1
595 221 my @c = caller;
596 4 $args[$pmind] = _pp_line_number_file($c[1], $c[2]-1, "\n$args[$pmind]");
597 4 $args[$pmind] =~ s#\n{3,}#\n\n#g;
598 44 _pp_addpm_nolineno(@args);
599 }
600  
601 sub pp_add_exported {
602 44 ▶ shift if !$_[0] or $_[0] eq __PACKAGE__;
Subroutine pp_add_exported: called CC=3 SCAR=13.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0] or $_[0] eq __PACKAGE__ 30 0 30
Condition33%1/3
not $_[0] or $_[0] eq __PACKAGE__
l!l&&r!l&&!r
0300
MC/DC0%0/2
not $_[0] or $_[0] eq __PACKAGE__
not $_[0] $_[0] eq __PACKAGE__
Truth table33%1/3
not(A) or B
A= not $_[0]B= $_[0] eq __PACKAGE__
ABresult
1X1
011
000
603 2 $::PDLPMROUT .= join ' ', @_, '';
604 }
605  
606 sub pp_addbegin {
607 2 ▶ my ($cmd) = @_;
Subroutine pp_addbegin: not called CC=2 SCAR=7.6
Pod documented
608 2 ▶ if ($cmd =~ /^\s*BOOT\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^\s*BOOT\s*$/) { } 0 0 0
609 2 pp_beginwrap;
610 } else {
611 2 $::PDLBEGIN .= $cmd."\n";
612 }
613 }
614  
615 # Sub to call to export nothing (i.e. for building OO package/object)
616 sub pp_export_nothing {
617 249 ▶ $::PDLPMROUT = ' ';
Subroutine pp_export_nothing: not called CC=1 SCAR=0.0
Pod documented
618 }
619  
620 sub pp_add_isa {
621 249 ▶ push @::PDLPMISA,@_;
Subroutine pp_add_isa: not called CC=1 SCAR=0.0
Pod documented
622 }
623  
624 sub pp_add_boot {
625 19 ▶ my ($boot) = @_;
Subroutine pp_add_boot: not called CC=1 SCAR=0.0
Pod documented
626 19 $boot =~ s/^\s*\n//gm; # XS doesn't like BOOT having blank lines
627 5 $::PDLXSBOOT .= $boot;
628 }
629  
630 sub pp_bless{
631 5 ▶ my($new_package)=@_;
Subroutine pp_bless: called CC=1 SCAR=0.0
Pod documented
632 5 $::PDLOBJ = $new_package;
633 }
634  
635 # sub to call to set the import list from core on the 'Use Core' line in the .pm file.
636 # set to '()' to not import anything from Core, or 'qw/ barf /' to import barf.
637 sub pp_core_importList{
638 5 ▶ $::PDLCOREIMPORT = $_[0];
Subroutine pp_core_importList: not called CC=1 SCAR=0.0
Pod documented
639 }
640  
641 sub printxs {
642 14 ▶ shift;
Subroutine printxs: called CC=1 SCAR=0.0
Pod undocumented
643 14 $::PDLXS .= join'',@_;
644 }
645  
646 sub pp_addxs {
647 14 ▶ PDL::PP->printxs("\nMODULE = $::PDLMOD PACKAGE = $::CALLPACK\n\n",
Subroutine pp_addxs: not called CC=1 SCAR=0.0
Pod documented
648 @_,
649 "\nMODULE = $::PDLMOD PACKAGE = $::PDLOBJ PREFIX=pdl_run_\n\n");
650 }
651  
652 # inserts #line directives into source text. Use like this:
653 # ...
654 # FirstKey => ...,
655 # Code => pp_line_numbers(__LINE__, $x . $y . $c),
656 # OtherKey => ...
657 sub pp_line_numbers {
658 25 ▶ _pp_line_number_file((caller)[1], @_);
Subroutine pp_line_numbers: called CC=1 SCAR=0.0
Pod documented
659 }
660 sub _pp_line_number_file {
661 25 ▶ my ($filename, $line, $string) = @_;
Subroutine _pp_line_number_file: called CC=6 SCAR=17.9
662 2 ▶ confess "pp_line_numbers called with undef" if !defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 44 44
663 # The line needs to be incremented by one for the bookkeeping to work
664 2 $line++;
665 2 ▶ $filename = 'lib/PDL/PP.pm' if $filename eq __FILE__;
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq __FILE__ 42 2 44
666 23 $filename =~ s/\\/\\\\/g; # Escape backslashes
667 9 my @to_return = "\nPDL_LINENO_START $line \"$filename\"\n";
668 # Look for broadcastloops and loops and add # line directives
669 9 foreach (split (/\n/, $string)) {
670 # Always add the current line.
671 9 push @to_return, "$_\n";
672 # If we need to add a # line directive, do so after incrementing
673 9 $line++;
674 14 ▶ if (/%\{/ or /%}/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/%\{/ or /%}/) 4 217 221
Condition100%3/3
/%\{/ or /%}/
l!l&&r!l&&!r
22217
MC/DC100%2/2
/%\{/ or /%}/
/%\{/ /%}/
Truth table100%3/3
A or B
A= /%\{/B= /%}/
ABresult
1X1
011
000
675 14 push @to_return, "PDL_LINENO_END\n";
676 14 push @to_return, "PDL_LINENO_START $line \"$filename\"\n";
677 }
678 }
679 14 push @to_return, "PDL_LINENO_END\n";
680 14 return join('', @to_return);
681 }
682 my $LINE_RE = qr/^(\s*)PDL_LINENO_(?:START (\S+) "(.*)"|(END))$/;
683 sub _pp_linenumber_fill {
684 2 ▶ local $_; # else get "Modification of a read-only value attempted"
Subroutine _pp_linenumber_fill: called CC=17 SCAR=30.2
685 0 my ($file, $text) = @_;
686 0 my (@stack, @to_return) = [1, $file];
687 0 my @lines = split /\n/, $text;
688 0 ▶ REALLINE: while (defined($_ = shift @lines)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = shift @lines)) 249 2 251
689 0 $_->[0]++ for @stack;
690 2 ▶ push(@to_return, $_), next if !/$LINE_RE/;
Branch: 1 branch
BranchTrueFalseTotal
unless /$LINE_RE/ 230 19 249
691 2 my ($ci, $new_line, $new_file, $is_end) = ($1, $2, $3, $4);
692 2 ▶ if (!$is_end) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_end) 5 14 19
693 2 push @stack, [$new_line-1, $new_file];
694 2 ▶ push @to_return, qq{$ci#line @{[$stack[-1][0]+1]} "$stack[-1][1]"} if @lines;
Branch: 1 branch
BranchTrueFalseTotal
if @lines 5 0 5
695 34 next REALLINE;
696 }
697 34 @stack = [$stack[0][0], $file]; # as soon as any block is left, line numbers for outer blocks become meaningless
698 34 my ($seen_empty, $empty_first, $last_ci, @last_dir) = (0, undef, $ci); # list=(line, file)
699 0 LINE: while (1) {
700 0 ▶ last REALLINE if !@lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 25 25
701 0 ▶ if (!length $lines[0] && $lines[1] !~ /^=/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $lines[0] or $lines[1] =~ /^=/) 2 23 25
Condition66%2/3
length $lines[0] or $lines[1] =~ /^=/
l!l&&r!l&&!r
2302
MC/DC50%1/2
length $lines[0] or $lines[1] =~ /^=/
length $lines[0] $lines[1] =~ /^=/
Truth table66%2/3
A or B
A= length $lines[0]B= $lines[1] =~ /^=/
ABresult
1X1
011
000
702 34 $seen_empty = 1;
703 1 shift @lines;
704 1 next LINE;
705 }
706 1 ▶ if ($lines[0] =~ /$LINE_RE/) { # directive
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[0] =~ /$LINE_RE/) { } 9 14 23
707 1 ▶ ($last_ci, @last_dir) = ($1, !$4 ? ($2, $3) : ());
Branch: 1 branch
BranchTrueFalseTotal
!$4 ? : 9 0 9
708 1 ▶ $empty_first //= $seen_empty;
Condition33%1/3
$empty_first //= $seen_empty
l!l&&r!l&&!r
090
MC/DC0%0/2
$empty_first //= $seen_empty
$empty_first $seen_empty
Truth table33%1/3
A //= B
A= $empty_firstB= $seen_empty
ABresult
1X1
011
000
709 1 shift @lines;
710 1 next LINE;
711 } else { # substantive
712 1 ▶ push @stack, \@last_dir if @last_dir;
Branch: 1 branch
BranchTrueFalseTotal
if @last_dir 9 5 14
713 1 ▶ push(@to_return, ''), $stack[0][0]++ if $seen_empty and $empty_first;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_empty and $empty_first 1 13 14
Condition100%3/3
$seen_empty and $empty_first
!ll&&!rl&&r
1211
MC/DC100%2/2
$seen_empty and $empty_first
$seen_empty $empty_first
Truth table100%3/3
A and B
A= $seen_emptyB= $empty_first
ABresult
0X0
100
111
714 0 push @to_return, qq{$last_ci#line $stack[-1][0] "$stack[-1][1]"};
715 1 ▶ push(@to_return, ''), $stack[0][0]++ if $seen_empty and !$empty_first;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_empty and not $empty_first 1 13 14
Condition100%3/3
$seen_empty and not $empty_first
!ll&&!rl&&r
1211
MC/DC100%2/2
$seen_empty and not $empty_first
$seen_empty not $empty_first
Truth table100%3/3
A and not(B)
A= $seen_emptyB= not $empty_first
ABresult
0X0
100
111
716 1 last LINE;
717 }
718 }
719 }
720 1 join '', map "$_\n", @to_return;
721 }
722  
723 sub _file_same {
724 1 ▶ my ($from_text, $to_file) = @_;
Subroutine _file_same: not called CC=2 SCAR=6.9
725 1 require File::Map;
726 1 File::Map::map_file(my $to_map, $to_file, '<');
727 1 s/^[^\n]*#line[^\n]*?\n//gm for $from_text, (my $to_text = $to_map);
728 1 $from_text eq $to_text;
729 }
730 sub _write_file {
731 1 ▶ my ($file, $text) = @_;
Subroutine _write_file: called CC=4 SCAR=18.7
732 49 $text = _pp_linenumber_fill($file, $text);
733 49 ▶ return if -f $file && _file_same($text, $file);
Branch: 1 branch
BranchTrueFalseTotal
if -f $file and _file_same($text, $file) 0 2 2
Condition33%1/3
-f $file and _file_same($text, $file)
!ll&&!rl&&r
200
MC/DC0%0/2
-f $file and _file_same($text, $file)
-f $file _file_same($text, $file)
Truth table33%1/3
A and B
A= -f $fileB= _file_same($text, $file)
ABresult
0X0
100
111
734 0 ▶ open my $fh, '>', $file or confess "open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or confess("open ${file}: $!") 0 2 2
735 0 binmode $fh; # to guarantee length will be same for same contents
736 0 print $fh $text;
737 }
738  
739 sub printxsc {
740 0 ▶ (undef, my $file) = (shift, shift);
Subroutine printxsc: called CC=3 SCAR=15.0
Pod undocumented
741 0 my $text = join '',@_;
742 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) { } 0 34 34
743 49 (my $mod_underscores = $::PDLMOD) =~ s#::#_#g;
744 49 ▶ $text = join '', sprintf($PDL::PP::header_c, $0, $mod_underscores), $::PDLXSC_header//'', $text;
Condition0%0/2
$main::PDLXSC_header // ""
l!l
00
MC/DC0%0/1
$main::PDLXSC_header // ""
$main::PDLXSC_header
Truth table0%0/2
A
A= $main::PDLXSC_header
Aresult
11
00
745 49 _write_file($file, $text);
746 } else {
747 49 $::PDLXSC .= $text;
748 }
749 }
750  
751 sub pp_done {
752 49 ▶ return if $PDL::PP::done; # do only once!
Subroutine pp_done: called CC=12 SCAR=28.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::PP::done 0 1 1
753 49 $PDL::PP::done = 1;
754 49 ▶ print "DONE!\n" if $::PP_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 1 1
755 49 ▶ print "Inline running PDL::PP version $PDL::PP::VERSION...\n" if nopm();
Branch: 1 branch
BranchTrueFalseTotal
if nopm() 0 1 1
756 49 require PDL::Core::Dev;
757 49 my $pdl_boot = PDL::Core::Dev::PDL_BOOT('PDL', $::PDLMOD);
758 49 ▶ my $user_boot = $::PDLXSBOOT//'';
Condition50%1/2
$main::PDLXSBOOT // ""
l!l
01
MC/DC0%0/1
$main::PDLXSBOOT // ""
$main::PDLXSBOOT
Truth table50%1/2
A
A= $main::PDLXSBOOT
Aresult
11
00
759 49 ▶ $user_boot =~ s/^\s*(.*?)\n*$/ $1\n/ if $user_boot;
Branch: 1 branch
BranchTrueFalseTotal
if $user_boot 0 1 1
760 49 ▶ $user_boot .= <<EOF if @::PDL_LVALUE_SUBS;
Branch: 1 branch
BranchTrueFalseTotal
if @main::PDL_LVALUE_SUBS 0 1 1
761 char *package = "$::PDLOBJ";
762 HV* stash = gv_stashpvn(package, strlen(package), TRUE);
763 49 char *meths[] = {@{[join ',', map qq{"$_"}, @::PDL_LVALUE_SUBS]},NULL}, **methsptr = meths;
764 for (; *methsptr; methsptr++) {
765 SV **meth = hv_fetch(stash, *methsptr, strlen(*methsptr), 0);
766 if (!meth) croak("No found method '%s' in '%s'", *methsptr, package);
767 CV *cv = GvCV(*meth);
768 if (!cv) croak("No found CV for '%s' in '%s'", *methsptr, package);
769 CvLVALUE_on(cv);
770 }
771 EOF
772 3 (my $mod_underscores = $::PDLMOD) =~ s#::#_#g;
773 49 ▶ my $text = join '',
Condition50%1/2
$main::PDLXSC // ""
l!l
10
MC/DC0%0/1
$main::PDLXSC // ""
$main::PDLXSC
Truth table50%1/2
A
A= $main::PDLXSC
Aresult
11
00
774 sprintf($PDL::PP::header_c, $0, $mod_underscores),
775 $::PDLXSC//'',
776 $PDL::PP::macros_xs,
777 sprintf($PDL::PP::header_xs, $::PDLMOD, $::PDLOBJ),
778 $::PDLXS, "\n",
779 $PDL::PP::header_xsboot, $pdl_boot, $user_boot;
780 4507 _write_file("$::PDLBASE.xs", $text);
781 34 ▶ return if nopm;
Branch: 1 branch
BranchTrueFalseTotal
if nopm() 0 1 1
782 34 $::PDLPMISA = "'".join("','",@::PDLPMISA)."'";
783 34 ▶ $::PDLBEGIN = "BEGIN {\n$::PDLBEGIN\n}"
Branch: 1 branch
BranchTrueFalseTotal
unless $main::PDLBEGIN =~ /^\s*$/ 0 1 1
784 unless $::PDLBEGIN =~ /^\s*$/;
785 34 ▶ $::PDLMODVERSION //= '';
Condition50%1/2
$main::PDLMODVERSION //= ""
l!l
01
MC/DC0%0/1
$main::PDLMODVERSION //= ""
$main::PDLMODVERSION
Truth table50%1/2
A
A= $main::PDLMODVERSION
Aresult
11
00
786 0 ▶ $::FUNCSPOD = $::DOCUMENTED ? "\n\n=head1 FUNCTIONS\n\n=cut\n\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$main::DOCUMENTED ? : 1 0 1
787 0 _write_file("$::PDLBASE.pm", join "\n\n", <<EOF, $::PDLBEGIN, $::PDLPM{Top}, $::FUNCSPOD, @::PDLPM{qw(Middle Bot)}, '# Exit with OK status', "1;\n");
788 #
789 # GENERATED WITH PDL::PP from $0! Don't modify!
790 #
791 package $::PDLPACK;
792  
793 our \@EXPORT_OK = qw($::PDLPMROUT);
794 our %EXPORT_TAGS = (Func=>\\\@EXPORT_OK);
795  
796 use PDL::Core$::PDLCOREIMPORT;
797 use PDL::Exporter;
798 use DynaLoader;
799  
800 $::PDL_IFBEGINWRAP[0]
801 $::PDLVERSIONSET
802 our \@ISA = ( $::PDLPMISA );
803 push \@PDL::Core::PP, __PACKAGE__;
804 bootstrap $::PDLMOD $::PDLMODVERSION;
805 $::PDL_IFBEGINWRAP[-1]
806 $::PDLOVERLOAD
807 EOF
808 } # end pp_done
809  
810 sub _pp_parsename {
811 34 ▶ my ($name) = @_;
Subroutine _pp_parsename: called CC=4 SCAR=15.5
812 # See if the 'name' is multiline, in which case we extract the
813 # name and add the FullDoc field
814 34 ▶ return ($name, undef) if $name !~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\n/ 49 0 49
815 34 my $fulldoc = $name;
816 # See if the very first thing is a word. That is going to be the
817 # name of the function under consideration
818 34 ▶ if ($fulldoc =~ s/^(\w+)//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fulldoc =~ s/^(\w+)//) { } 0 0 0
elsif ($fulldoc =~ /=head2 (\w+)/) { } 0 0 0
819 34 $name = $1;
820 } elsif ($fulldoc =~ /=head2 (\w+)/) {
821 34 $name = $1;
822 } else {
823 34 croak('Unable to extract name');
824 }
825 34 ($name, $fulldoc);
826 }
827  
828 sub pp_def {
829 34 ▶ require PDL::Core::Dev;
Subroutine pp_def: called CC=19 SCAR=41.9
Pod documented
830 0 require PDL::Types;
831 0 require PDL::PP::PdlParObj;
832 0 require PDL::PP::Signature;
833 0 require PDL::PP::Dims;
834 0 require PDL::PP::CType;
835 0 require PDL::PP::PDLCode;
836 0 ▶ PDL::PP::load_deftable() if !$PDL::PP::deftbl;
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::PP::deftbl 3 46 49
837 0 my($name,%obj) = @_;
838 0 ▶ print "*** Entering pp_def for $name\n" if $::PP_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 49 49
839 0 ($name, my $fulldoc) = _pp_parsename($name);
840 0 ▶ $obj{FullDoc} = $fulldoc if defined $fulldoc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fulldoc 0 49 49
841 0 $obj{Name} = $name;
842 croak("ERROR: pp_def=$name given empty GenericTypes!\n")
843 0 ▶ if exists $obj{GenericTypes} and !@{ $obj{GenericTypes} || [] };
Branch: 2 branches
BranchTrueFalseTotal
if exists $obj{"GenericTypes"} and not @{$obj{"GenericTypes"} or [];} 0 49 49
$obj{"GenericTypes"} or [] 0 3 3
Condition66%2/3
exists $obj{"GenericTypes"} and not @{$obj{"GenericTypes"} or [];}
!ll&&!rl&&r
4630
MC/DC0%0/2
exists $obj{"GenericTypes"} and not @{$obj{"GenericTypes"} or [];}
exists $obj{"GenericTypes"} not @{$obj{"GenericTypes"} or [];}
Truth table66%2/3
A and not(B)
A= exists $obj{"GenericTypes"}B= not @{$obj{"GenericTypes"} or [];}
ABresult
0X0
100
111
844 0 foreach my $rule (@$PDL::PP::deftbl) {
845 0 $rule->apply(\%obj);
846 }
847 print "Result of translate for $name:\n" . Dumper(\%obj) . "\n"
848 0 ▶ if exists $obj{Dump} and $obj{Dump} and $::PP_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if exists $obj{"Dump"} and $obj{"Dump"} and $main::PP_VERBOSE 0 34 34
Condition33%2/6
exists $obj{"Dump"} and $obj{"Dump"} and $main::PP_VERBOSE
!ll&&!rl&&r
3400
exists $obj{"Dump"} and $obj{"Dump"}
!ll&&!rl&&r
3400
MC/DC0%0/3
exists $obj{"Dump"} and $obj{"Dump"} and $main::PP_VERBOSE
exists $obj{"Dump"} $obj{"Dump"} $main::PP_VERBOSE
Truth table25%1/4
A and B and C
A= exists $obj{"Dump"}B= $obj{"Dump"}C= $main::PP_VERBOSE
ABCresult
0XX0
10X0
1100
1111
849  
850 croak("ERROR: No FreeFunc for pp_def=$name!\n")
851 0 ▶ unless exists $obj{FreeFunc};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj{"FreeFunc"} 0 34 34
852  
853 2 my $ctext = join("\n\n",grep $_, @obj{qw(
854 CHeader StructDecl RedoDimsFunc
855 ReadDataFunc WriteBackDataFunc
856 FreeFunc
857 VTableDef RunFunc
858 )});
859 2 ▶ if ($::PDLMULTI_C) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::PDLMULTI_C) { } 0 34 34
860 2 PDL::PP->printxsc(undef, "$obj{RunFuncHdr};\n");
861 2 PDL::PP->printxsc($::PDLMULTI_C_PREFIX."pp-$obj{Name}.c", $ctext);
862 } else {
863 2 PDL::PP->printxsc(undef, $ctext);
864 }
865 2 PDL::PP->printxs($obj{NewXSCode});
866 2 ▶ pp_add_boot($obj{BootSetNewXS}) if $obj{BootSetNewXS};
Branch: 1 branch
BranchTrueFalseTotal
if $obj{"BootSetNewXS"} 0 34 34
867 2 ▶ PDL::PP->pp_add_exported($name) unless $obj{NoExport};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj{"NoExport"} 30 4 34
868 2 ▶ PDL::PP::_pp_addpm_nolineno("\n".$obj{PdlDoc}."\n") if $obj{PdlDoc};
Branch: 1 branch
BranchTrueFalseTotal
if $obj{"PdlDoc"} 34 0 34
869 10 ▶ PDL::PP::_pp_addpm_nolineno($obj{PMCode}) if defined $obj{PMCode};
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj{"PMCode"} 0 34 34
870 10 ▶ PDL::PP::_pp_addpm_nolineno($obj{PMFunc}."\n") if defined $obj{PMFunc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj{"PMFunc"} 34 0 34
871  
872 10 ▶ print "*** Leaving pp_def for $name\n" if $::PP_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 34 34
873 10 \%obj;
874 }
875  
876 # marks this module as deprecated. This handles the user warnings, and adds a
877 # notice into the documentation. Can take a {infavor => "newmodule"} option
878 sub pp_deprecate_module
879 {
880 10 ▶ my $options;
Subroutine pp_deprecate_module: not called CC=6 SCAR=27.2
Pod documented
881 10 ▶ if( ref $_[0] eq 'HASH' ) { $options = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
882 10 else { $options = { @_ }; }
883  
884 10 my $infavor;
885  
886 10 ▶ if( $options && ref $options eq 'HASH' && $options->{infavor} )
Branch: 1 branch
BranchTrueFalseTotal
if ($options and ref $options eq "HASH" and $options->{"infavor"}) 0 0 0
Condition0%0/6
$options and ref $options eq "HASH" and $options->{"infavor"}
!ll&&!rl&&r
000
$options and ref $options eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
$options and ref $options eq "HASH" and $options->{"infavor"}
$options ref $options eq "HASH" $options->{"infavor"}
Truth table0%0/4
A and B and C
A= $optionsB= ref $options eq "HASH"C= $options->{"infavor"}
ABCresult
0XX0
10X0
1100
1111
887 {
888 10 $infavor = $options->{infavor};
889 }
890  
891 10 my $mod = $::PDLMOD;
892 0 my $envvar = 'PDL_SUPPRESS_DEPRECATION_WARNING__' . uc $mod;
893 0 $envvar =~ s/::/_/g;
894  
895 0 my $warning_main =
896 "$mod is deprecated.";
897 0 ▶ $warning_main .=
Branch: 1 branch
BranchTrueFalseTotal
if $infavor 0 0 0
898 " Please use $infavor instead." if $infavor;
899  
900 0 my $warning_suppression_runtime =
901 "This module will be removed in the future; please update your code.\n" .
902 "Set the environment variable $envvar\n" .
903 "to suppress this warning\n";
904  
905 34 my $warning_suppression_pod =
906 "A warning will be generated at runtime upon a C<use> of this module\n" .
907 "This warning can be suppressed by setting the $envvar\n" .
908 "environment variable\n";
909  
910 34 my $deprecation_notice = <<EOF ;
911 XXX=head1 DEPRECATION NOTICE
912  
913 $warning_main
914 $warning_suppression_pod
915  
916 XXX=cut
917  
918 EOF
919 34 $deprecation_notice =~ s/^XXX=/=/gms;
920 0 _pp_addpm_nolineno( {At => 'Top'}, $deprecation_notice );
921  
922 0 _pp_addpm_nolineno {At => 'Top'}, <<EOF;
923 warn "$warning_main\n$warning_suppression_runtime" unless \$ENV{$envvar};
924 EOF
925 }
926  
927 4507 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
928 ▶$SIG{__DIE__} = \&Carp::confess if $::PP_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 3 3
929  
930 my $typemap_obj;
931 sub _load_typemap {
932 0 ▶ require ExtUtils::Typemaps;
Subroutine _load_typemap: called CC=4 SCAR=14.2
933 34 require PDL::Core::Dev;
934 # according to MM_Unix 'privlibexp' is the right directory
935 # seems to work even on OS X (where installprivlib breaks things)
936 34 my $_rootdir = $Config{privlibexp}.'/ExtUtils/';
937 # First the system typemaps..
938 34 my @tm = ($_rootdir.'../../../../lib/ExtUtils/typemap',
939 $_rootdir.'../../../lib/ExtUtils/typemap',
940 $_rootdir.'../../lib/ExtUtils/typemap',
941 $_rootdir.'../../../typemap',
942 $_rootdir.'../../typemap', $_rootdir.'../typemap',
943 $_rootdir.'typemap');
944 34 push @tm, &PDL::Core::Dev::PDL_TYPEMAP, '../../typemap', '../typemap', 'typemap';
945 990 ▶ carp "**CRITICAL** PP found no typemaps in (@tm)"
Branch: 1 branch
BranchTrueFalseTotal
unless my(@typemaps) = grep((-f $_ && -T _), @tm) 0 2 2
Condition66%2/3
-f $_ && -T _
!ll&&!rl&&r
1804
MC/DC50%1/2
-f $_ && -T _
-f $_ -T _
Truth table66%2/3
A && B
A= -f $_B= -T _
ABresult
0X0
100
111
946 unless my @typemaps = grep -f $_ && -T _, @tm;
947 990 $typemap_obj = ExtUtils::Typemaps->new;
948 672 $typemap_obj->merge(file => $_, replace => 1) for @typemaps;
949 672 $typemap_obj;
950 }
951 sub typemap {
952 672 ▶ my ($type, $method) = @_;
Subroutine typemap: called CC=3 SCAR=11.2
Pod undocumented
953 20 ▶ $typemap_obj ||= _load_typemap();
Condition66%2/3
$typemap_obj ||= _load_typemap()
l!l&&r!l&&!r
820
MC/DC0%0/2
$typemap_obj ||= _load_typemap()
$typemap_obj _load_typemap()
Truth table66%2/3
A ||= B
A= $typemap_objB= _load_typemap()
ABresult
1X1
011
000
954 20 $type=ExtUtils::Typemaps::tidy_type($type);
955 20 my $inputmap = $typemap_obj->$method(ctype => $type);
956 10 ▶ die "The type =$type= does not have a typemap entry!\n" unless $inputmap;
Branch: 1 branch
BranchTrueFalseTotal
unless $inputmap 0 10 10
957 10 ($inputmap->code, $type);
958 }
959 sub typemap_eval { # lifted from ExtUtils::ParseXS::Eval, ignoring eg $ALIAS
960 10 ▶ my ($code, $varhash) = @_;
Subroutine typemap_eval: called CC=2 SCAR=7.0
Pod undocumented
961 my ($var, $type, $num, $init, $pname, $arg, $ntype, $argoff, $subtype)
962 10 = @$varhash{qw(var type num init pname arg ntype argoff subtype)};
963 10 my $ALIAS;
964 10 my $rv = eval qq(qq\a$code\a);
965 10 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
966 10 $rv;
967 }
968  
969 sub pp_add_typemaps {
970 0 ▶ confess "Usage: pp_add_typemaps([string|file|typemap]=>\$arg)" if @_ != 2;
Subroutine pp_add_typemaps: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 0 0
971 0 ▶ $typemap_obj ||= _load_typemap();
Condition0%0/3
$typemap_obj ||= _load_typemap()
l!l&&r!l&&!r
000
MC/DC0%0/2
$typemap_obj ||= _load_typemap()
$typemap_obj _load_typemap()
Truth table0%0/3
A ||= B
A= $typemap_objB= _load_typemap()
ABresult
1X1
011
000
972 0 ▶ my $new_obj = $_[0] eq 'typemap' ? $_[1] : ExtUtils::Typemaps->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq 'typemap' ? : 0 0 0
973 0 pp_addxs($new_obj->as_embedded_typemap);
974 0 $typemap_obj->merge(typemap => $new_obj, replace => 1);
975 }
976  
977 sub make_xs_code {
978 0 ▶ my($xscode_before,$xscode_after,$str,
Subroutine make_xs_code: called CC=2 SCAR=9.2
Pod undocumented
979 $xs_c_headers,
980 @bits) = @_;
981 0 my($boot,$prelude);
982 3 ▶ if($xs_c_headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xs_c_headers) { } 0 34 34
983 3 $prelude = join '', $xs_c_headers->[0], @bits, $xs_c_headers->[1];
984 3 $boot = $xs_c_headers->[2];
985 1 $str .= "\n";
986 } else {
987 49 my $xscode = join '', @bits;
988 0 $str .= "$xscode_before\n$xscode$xscode_after\n";
989 }
990 0 $str =~ s/(\s*\n)+/\n/g;
991 0 ($str,$boot,$prelude)
992 }
993  
994 sub indent($$) {
995 0 ▶ my ($ind, $text) = @_;
Subroutine indent: called CC=3 SCAR=14.2
Pod undocumented
996 0 ▶ return $text if !length $text or !$ind;
Branch: 1 branch
BranchTrueFalseTotal
unless length $text and $ind 318 672 990
Condition100%3/3
length $text and $ind
!ll&&!rl&&r
100218672
MC/DC100%2/2
length $text and $ind
length $text $ind
Truth table100%3/3
A and B
A= length $textB= $ind
ABresult
0X0
100
111
997 0 $ind = ' ' x $ind;
998 0 $text =~ s/^(.+)$/$ind$1/mg;
999 0 return $text;
1000 }
1001  
1002 # This subroutine generates the XS code needed to call the perl 'initialize'
1003 # routine in order to create new output PDLs
1004 sub callPerlInit {
1005 0 ▶ my ($sv) = @_;
Subroutine callPerlInit: called CC=2 SCAR=14.0
Pod undocumented
1006 0 ▶ confess "callPerlInit error: \$sv must be defined" if !defined $sv;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sv 0 20 20
1007 0 "PDL_XS_PERLINIT_initsv($sv)";
1008 }
1009  
1010 sub callTypemap {
1011 0 ▶ my ($x, $ptype, $pname) = @_;
Subroutine callTypemap: called CC=1 SCAR=6.9
Pod undocumented
1012 0 my ($setter, $type) = typemap($ptype, 'get_inputmap');
1013 0 (my $ntype = $type) =~ s:\s+::g; $ntype =~ s:\*:Ptr:g;
1014 0 my $ret = typemap_eval($setter, {var=>$x, type=>$type, arg=>("${x}_SV"),
1015 pname=>$pname, ntype=>$ntype});
1016 0 $ret =~ s/^\s*(.*?)\s*$/$1/g;
1017 0 $ret =~ s/\s*\n\s*/ /g;
1018 0 $ret;
1019 }
1020  
1021 ###########################################################
1022 # Name : extract_signature_from_fulldoc
1023 # Usage : $sig = extract_signature_from_fulldoc($fulldoc)
1024 # Purpose : pull out the signature from the fulldoc string
1025 # Returns : whatever is in parentheses in the signature, or undef
1026 # Parameters : $fulldoc
1027 # Throws : never
1028 # Notes : the signature must have the following form:
1029 # :
1030 # : =for sig
1031 # : <blank>
1032 # : Signature: (<signature can
1033 # : be multiline>)
1034 # : <blank>
1035 # :
1036 # : The two spaces before "Signature" are required, as are
1037 # : the parentheses.
1038 sub extract_signature_from_fulldoc {
1039 0 ▶ my $fulldoc = shift;
Subroutine extract_signature_from_fulldoc: not called CC=3 SCAR=16.7
Pod undocumented
1040 0 ▶ if ($fulldoc =~ /=for sig\n\n Signature: \(([^\n]*)\n/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fulldoc =~ /=for sig\n\n Signature: \(([^\n]*)\n/g) 0 0 0
1041 # Extract the signature and remove the final parenthesis
1042 0 my $sig = $1;
1043 49 ▶ $sig .= $1 while $fulldoc =~ /\G\h+([^\n]*)\n/g;
Branch: 1 branch
BranchTrueFalseTotal
$fulldoc =~ /\G\h+([^\n]*)\n/g and do { $sig .= $1 } 0 0 0
1044 49 $sig =~ s/\)\s*$//;
1045 49 return $sig;
1046 }
1047 46 return;
1048 }
1049  
1050 # function to be run by real pp_def so fake pp_def can do without other modules
1051 sub load_deftable {
1052 # Build the valid-types regex and valid Pars argument only once. These are
1053 # also used in PDL::PP::PdlParObj, which is why they are globally available.
1054 2 ▶my $pars_re = $PDL::PP::PdlParObj::pars_re;
Subroutine load_deftable: called CC=1 SCAR=0.1
Pod undocumented
1055  
1056 # Set up the rules for translating the pp_def contents.
1057 #
1058 $PDL::PP::deftbl =
1059 [
1060 PDL::PP::Rule->new(
1061 [qw(RedoDims EquivCPOffsCode HandleBad P2Child)],
1062 ["Identity"],
1063 "sets up identity PARENT->CHILD transform with dataflow",
1064 sub {
1065 0 ▶ (PDL::PP::pp_line_numbers(__LINE__-1, '
Subroutine __ANON__: called CC=1 SCAR=6.9
1066 int i;
1067 $SETNDIMS($PDL(PARENT)->ndims);
1068 for(i=0; i<$PDL(CHILD)->ndims; i++) {
1069 $PDL(CHILD)->dims[i] = $PDL(PARENT)->dims[i];
1070 }
1071 $SETDIMS();
1072 $SETDELTABROADCASTIDS(0);
1073 $PRIV(dims_redone) = 1;
1074 '),
1075 PDL::PP::pp_line_numbers(__LINE__,
1076 'PDL_Indx i;
1077 for(i=0; i<$PDL(CHILD)->nvals; i++) {
1078 $EQUIVCPOFFS(i,i);
1079 }'),
1080 1, 1);
1081 }),
1082  
1083 # used as a flag for many of the routines
1084 # ie should we bother with bad values for this routine?
1085 # 1 - yes,
1086 # 0 - no, maybe issue a warning
1087 PDL::PP::Rule->new("BadFlag", "HandleBad?",
1088 "Sets BadFlag based upon HandleBad key",
1089 1 ▶ sub { $_[0] }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1090  
1091 ####################
1092 # FullDoc Handling #
1093 ####################
1094  
1095 # Error processing: does FullDoc contain BadDoc, yet BadDoc specified?
1096 PDL::PP::Rule::Croak->new(['FullDoc', 'BadDoc'],
1097 'Cannot have both FullDoc and BadDoc defined'),
1098 PDL::PP::Rule::Croak->new(['FullDoc', 'Doc'],
1099 'Cannot have both FullDoc and Doc defined'),
1100 # Note: no error processing on Pars; it's OK for the docs to gloss over
1101 # the details.
1102  
1103 # Add the Pars section based on the signature of the FullDoc if the Pars
1104 # section doesn't already exist
1105 PDL::PP::Rule->new('Pars', 'FullDoc',
1106 'Sets the Pars from the FullDoc if Pars is not explicitly specified',
1107 # Purpose : extract the Pars from the signature from the fulldoc string,
1108 # : the part of the signature that specifies the ndarrays
1109 # Returns : a string appropriate for the Pars key
1110 # Parameters : $fulldoc
1111 # Throws : if there is no signature
1112 # : if there is no extractable Pars section
1113 # : if some PDL arguments come after the OtherPars arguments start
1114 # Notes : This is meant to be used directly in a Rule. Therefore, it
1115 # : is only called if the Pars key does not yet exist, so if it
1116 # : is not possible to extract the Pars section, it dies.
1117 sub {
1118 1 ▶ my $fulldoc = shift;
Subroutine __ANON__: not called CC=7 SCAR=30.2
1119 # Get the signature or die
1120 45 ▶ my $sig = extract_signature_from_fulldoc($fulldoc)
Branch: 1 branch
BranchTrueFalseTotal
my $sig = extract_signature_from_fulldoc($fulldoc) or confess("No Pars specified and none could be extracted from FullDoc") 0 0 0
1121 or confess('No Pars specified and none could be extracted from FullDoc');
1122 # Everything is semicolon-delimited
1123 0 my @args = split /\s*;\s*/, $sig;
1124 0 my @pars;
1125 0 my $switched_to_other_pars = 0;
1126 0 for my $arg (@args) {
1127 1 ▶ confess('All PDL args must come before other pars in FullDoc signature')
Branch: 1 branch
BranchTrueFalseTotal
if $switched_to_other_pars and $arg =~ /$pars_re/ 0 0 0
Condition0%0/3
$switched_to_other_pars and $arg =~ /$pars_re/
!ll&&!rl&&r
000
MC/DC0%0/2
$switched_to_other_pars and $arg =~ /$pars_re/
$switched_to_other_pars $arg =~ /$pars_re/
Truth table0%0/3
A and B
A= $switched_to_other_parsB= $arg =~ /$pars_re/
ABresult
0X0
100
111
1128 if $switched_to_other_pars and $arg =~ $pars_re;
1129 1 ▶ if ($arg =~ $pars_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /$pars_re/) { } 0 0 0
1130 1 push @pars, $arg;
1131 } else {
1132 1 $switched_to_other_pars = 1;
1133 }
1134 }
1135 # Make sure there's something there
1136 1 ▶ confess('FullDoc signature contains no PDL arguments') if @pars == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @pars == 0 0 0 0
1137 # All done!
1138 1 return join('; ', @pars);
1139 }
1140 ),
1141 PDL::PP::Rule->new('OtherPars', 'FullDoc',
1142 'Sets the OtherPars from the FullDoc if OtherPars is not explicitly specified',
1143 # Purpose : extract the OtherPars from the signature from the fulldoc
1144 # : string, the part of the signature that specifies non-ndarray
1145 # : arguments
1146 # Returns : a string appropriate for the OtherPars key
1147 # Parameters : $fulldoc
1148 # Throws : if some OtherPars arguments come before the last PDL argument
1149 # Notes : This is meant to be used directly in a Rule. Therefore, it
1150 # : is only called if the OtherPars key does not yet exist.
1151 sub {
1152 1 ▶ my $fulldoc = shift;
Subroutine __ANON__: not called CC=7 SCAR=26.4
1153 # Get the signature or do not set
1154 1 ▶ my $sig = extract_signature_from_fulldoc($fulldoc)
Branch: 1 branch
BranchTrueFalseTotal
my $sig = extract_signature_from_fulldoc($fulldoc) or return "DO NOT SET!!" 0 0 0
1155 or return 'DO NOT SET!!';
1156 # Everything is semicolon-delimited
1157 49 my @args = split /\s*;\s*/, $sig;
1158 49 my @otherpars;
1159 47 for my $arg (@args) {
1160 47 ▶ confess('All PDL args must come before other pars in FullDoc signature')
Branch: 1 branch
BranchTrueFalseTotal
if @otherpars > 0 and $arg =~ /$pars_re/ 0 0 0
Condition0%0/3
@otherpars > 0 and $arg =~ /$pars_re/
!ll&&!rl&&r
000
MC/DC0%0/2
@otherpars > 0 and $arg =~ /$pars_re/
@otherpars > 0 $arg =~ /$pars_re/
Truth table0%0/3
A and B
A= @otherpars > 0B= $arg =~ /$pars_re/
ABresult
0X0
100
111
1161 if @otherpars > 0 and $arg =~ $pars_re;
1162 17 ▶ if ($arg !~ $pars_re) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg =~ /$pars_re/) 0 0 0
1163 17 push @otherpars, $arg;
1164 }
1165 }
1166 # All done!
1167 17 ▶ return 'DO NOT SET!!'if @otherpars == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @otherpars == 0 0 0 0
1168 16 return join('; ', @otherpars);
1169 }
1170 ),
1171  
1172 ################################
1173 # Other Documentation Handling #
1174 ################################
1175  
1176 # no docs by default
1177 PDL::PP::Rule::Returns->new("Doc", [], 'Sets the default doc string',
1178 "\n=for ref\n\ninfo not available\n"),
1179  
1180 PDL::PP::Rule->new("BadDoc", [qw(BadFlag Name)],
1181 'Sets the default documentation for handling of bad values',
1182 sub {
1183 16 ▶ my ($bf, $name) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
1184 16 my $str;
1185 16 ▶ if ( not defined($bf) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bf) { } 46 3 49
elsif ($bf) { } 2 1 3
1186 16 $str = "C<$name> does not process bad values.\n";
1187 } elsif ( $bf ) {
1188 16 $str = "C<$name> processes bad values.\n";
1189 } else {
1190 11 $str = "C<$name> ignores the bad-value flag of the input ndarrays.\n";
1191 }
1192 11 $str .= "It will set the bad-value flag of all output ndarrays if " .
1193 "the flag is set for any of the input ndarrays.\n";
1194 }
1195 ),
1196  
1197 # Default: no otherpars
1198 PDL::PP::Rule::Returns::EmptyString->new("OtherPars"),
1199  
1200 # Notes
1201 # Suffix 'NS' means, "Needs Substitution". In other words, the string
1202 # associated with a key that has the suffix "NS" must be run through a
1203 # Substitute
1204 # The substituted version should then replace "NS" with "Subd"
1205 # So: FreeCodeNS -> FreeCodeSubd
1206  
1207 PDL::PP::Rule::Returns->new("StructName", "__privtrans"),
1208 PDL::PP::Rule::Returns->new("ParamStructName", "__params"),
1209  
1210 16 ▶ PDL::PP::Rule->new("HaveBroadcasting","HaveThreading", sub {@_}), # compat
Subroutine __ANON__: not called CC=1 SCAR=0.0
1211 PDL::PP::Rule::Croak->new([qw(P2Child GenericTypes)],
1212 'Cannot have both P2Child and GenericTypes defined'),
1213 PDL::PP::Rule::Croak->new([qw(P2Child Inplace)],
1214 'Cannot have both P2Child and Inplace defined'),
1215 PDL::PP::Rule::Returns::One->new('P2Child', 'AffinePriv', 'AffinePriv => P2Child'),
1216 PDL::PP::Rule->new([qw(Pars HaveBroadcasting GenericTypes DefaultFlow AllFuncHeader RedoDimsFuncHeader)],
1217 [qw(P2Child Name StructName)],
1218 sub {
1219 15 ▶ my (undef,$name,$sname) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
1220 14 ("PARENT(); [oca]CHILD();",0,[PDL::Types::ppdefs_all()],1,
1221 "pdl *__it = $sname->pdls[1]; (void) __it;\n",
1222 "PDL->hdr_childcopy($sname); $sname->dims_redone = 1;\n",
1223 );
1224 }),
1225  
1226 # Question: where is ppdefs defined?
1227 # Answer: lib/PDL/Types.pm
1228 PDL::PP::Rule->new("GenericTypes", [],
1229 'Sets GenericTypes flag to all real types known to PDL::Types',
1230 13 ▶ sub {[PDL::Types::ppdefs()]}),
Subroutine __ANON__: called CC=1 SCAR=0.0
1231  
1232 PDL::PP::Rule->new("ExtraGenericSwitches", "FTypes",
1233 'Makes ExtraGenericSwitches identical to FTypes if the latter exists and the former does not',
1234 13 ▶ sub {return $_[0]}),
Subroutine __ANON__: not called CC=1 SCAR=0.0
1235 PDL::PP::Rule::Returns->new("ExtraGenericSwitches", [],
1236 'Sets ExtraGenericSwitches to an empty hash if it does not already exist', {}),
1237  
1238 PDL::PP::Rule::InsertName->new("VTableName", 'pdl_%s_vtable'),
1239  
1240 PDL::PP::Rule::Returns->new("Priv", "AffinePriv", 'PDL_Indx incs[$PDL(CHILD)->ndims];PDL_Indx offs; '),
1241 PDL::PP::Rule::Returns->new("IsAffineFlag", "AffinePriv", "PDL_ITRANS_ISAFFINE"),
1242 PDL::PP::Rule::Returns::Zero->new("IsAffineFlag"),
1243  
1244 PDL::PP::Rule->new("RedoDims", [qw(EquivPDimExpr EquivDimCheck?)],
1245 sub {
1246 12 ▶ my($pdimexpr,$dimcheck) = @_;
Subroutine __ANON__: not called CC=1 SCAR=0.0
1247 12 $pdimexpr =~ s/\$CDIM\b/i/g;
1248 11 ' PDL_Indx i,cor;
1249 '.$dimcheck.'
1250 $SETNDIMS($PDL(PARENT)->ndims);
1251 $DOPRIVALLOC();
1252 $PRIV(offs) = 0;
1253 for(i=0; i<$PDL(CHILD)->ndims; i++) {
1254 cor = '.$pdimexpr.';
1255 $PDL(CHILD)->dims[i] = $PDL(PARENT)->dims[cor];
1256 $PRIV(incs)[i] = $PDL(PARENT)->dimincs[cor];
1257 }
1258 $SETDIMS();
1259 $SETDELTABROADCASTIDS(0);
1260 $PRIV(dims_redone) = 1;
1261 ';
1262 }),
1263  
1264 PDL::PP::Rule->new("Code", "EquivCPOffsCode",
1265 "create Code from EquivCPOffsCode",
1266 sub {
1267 10 ▶ my ($good) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
1268 10 $good =~ s/
1269 \$EQUIVCPOFFS\(([^()]+),([^()]+)\)
1270 /do { PDL_IF_BAD(if (\$PISBAD(PARENT,[$2]) ) { \$PSETBAD(CHILD,[$1]); } else,) { \$P(CHILD)[$1] = \$P(PARENT)[$2]; } } while (0)/gx;
1271 2 $good =~ s/
1272 \$EQUIVCPTRUNC\(([^()]+),([^()]+),([^()]+)\)
1273 /do { if (($3) PDL_IF_BAD(|| \$PISBAD(PARENT,[$2]),) ) { PDL_IF_BAD(\$PSETBAD(CHILD,[$1]),\$P(CHILD)[$1] = 0); } else {\$P(CHILD)[$1] = \$P(PARENT)[$2]; } } while (0)/gx;
1274 10 $good;
1275 }),
1276  
1277 PDL::PP::Rule->new("BackCode", "EquivCPOffsCode",
1278 "create BackCode from EquivCPOffsCode",
1279 # Since PARENT & CHILD need NOT be the same type we cannot just copy
1280 # values from one to the other - we have to check for the presence
1281 # of bad values, hence the expansion for the $bad code
1282 #
1283 # Some operators (notably range) also have an out-of-range flag; they use
1284 # the macro EQUIVCPTRUNC instead of EQUIVCPOFFS.
1285 # $EQUIVCPTRUNC does the same as EQUIVCPOFFS but accepts a
1286 # child-out-of-bounds flag. If the out-of-bounds flag is set, the
1287 # forward code puts BAD/0 into the child, and reverse code refrains
1288 # from copying.
1289 # --CED 27-Jan-2003
1290 sub {
1291 10 ▶ my ($good) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.2
1292 # parse 'good' code
1293 8 $good =~ s/
1294 \$EQUIVCPOFFS\(([^()]+),([^()]+)\)
1295 /do { PDL_IF_BAD(if( \$PISBAD(CHILD,[$1]) ) { \$PSETBAD(PARENT,[$2]); } else,) { \$P(PARENT)[$2] = \$P(CHILD)[$1]; } } while (0)/gx;
1296 8 $good =~ s/
1297 \$EQUIVCPTRUNC\(([^()]+),([^()]+),([^()]+)\)
1298 /do { if (!($3)) { PDL_IF_BAD(if (\$PISBAD(CHILD,[$1]) ) { \$PSETBAD(PARENT,[$2]); } else,) { \$P(PARENT)[$2] = \$P(CHILD)[$1]; } } } while (0)/gx;
1299 0 $good;
1300 }),
1301  
1302 PDL::PP::Rule::Returns::NULL->new("ReadDataFuncName", "AffinePriv"),
1303 PDL::PP::Rule::Returns::NULL->new("WriteBackDataFuncName", "AffinePriv"),
1304  
1305 PDL::PP::Rule::InsertName->new("NewXSName", '_%s_int'),
1306  
1307 PDL::PP::Rule::Returns::One->new("HaveBroadcasting"),
1308  
1309 PDL::PP::Rule::Returns::EmptyString->new("Priv"),
1310 PDL::PP::Rule->new("PrivObj", [qw(Name Priv)],
1311 0 ▶ sub { PDL::PP::Signature->new('', @_) }),
Subroutine __ANON__: called CC=1 SCAR=6.9
1312  
1313 # Parameters in the 'a(x,y); [o]b(y)' format, with
1314 # fixed nos of real, unbroadcast-over dims.
1315 # Also "Other pars", the parameters which are usually not pdls.
1316 PDL::PP::Rule->new("SignatureObj", [qw(Pars Name OtherPars OtherParsDefaults? ArgOrder?)],
1317 8 ▶ sub { PDL::PP::Signature->new(@_) }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1318  
1319 # Compiled representations i.e. what the RunFunc function leaves
1320 # in the params structure. By default, copies of the parameters
1321 # but in many cases (e.g. slice) a benefit can be obtained
1322 # by parsing the string in that function.
1323 # If the user wishes to specify their own MakeComp code and Comp content,
1324 # The next definitions allow this.
1325 PDL::PP::Rule->new("CompObj", [qw(Name OtherPars Comp?)],
1326 8 ▶ sub { PDL::PP::Signature->new('', $_[0], join(';', grep defined() && /[^\s;]/, @_[1..$#_])) }),
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
defined $_ && /[^\s;]/
!ll&&!rl&&r
47407
MC/DC100%2/2
defined $_ && /[^\s;]/
defined $_ /[^\s;]/
Truth table100%3/3
A && B
A= defined $_B= /[^\s;]/
ABresult
0X0
100
111
1327 8 ▶ PDL::PP::Rule->new("CompStruct", ["CompObj"], sub {$_[0]->getcomp}),
Subroutine __ANON__: called CC=1 SCAR=0.0
1328  
1329 PDL::PP::Rule->new("InplaceNormalised", [qw(Name SignatureObj Inplace)],
1330 'interpret Inplace and Signature to get input/output',
1331 # Inplace can be supplied several values
1332 # => 1
1333 # assumes fn has an input and output ndarray (eg 'a(); [o] b();')
1334 # => [ 'a' ]
1335 # assumes several input ndarrays in sig, so 'a' labels which
1336 # one is to be marked inplace
1337 # => [ 'a', 'b' ]
1338 # input ndarray is a(), output ndarray is 'b'
1339 # this will set InplaceNormalised to [input,output]
1340 sub {
1341 8 ▶ my ($name, $sig, $arg) = @_;
Subroutine __ANON__: called CC=24 SCAR=32.1
1342 30 ▶ confess 'Inplace given false value' if !$arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 0 17 17
1343 30 ▶ confess "Inplace array-ref (@$arg) > 2 elements" if ref($arg) eq "ARRAY" and @$arg > 2;
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "ARRAY" and @$arg > 2 1 16 17
Condition100%3/3
ref $arg eq "ARRAY" and @$arg > 2
!ll&&!rl&&r
5111
MC/DC100%2/2
ref $arg eq "ARRAY" and @$arg > 2
ref $arg eq "ARRAY" @$arg > 2
Truth table100%3/3
A and B
A= ref $arg eq "ARRAY"B= @$arg > 2
ABresult
0X0
100
111
1344 # find input and output ndarrays
1345 8 my %is_out = map +($_=>1), my @out = $sig->names_out;
1346 8 my @in = $sig->names_in;
1347 8 ▶ my $in = @in == 1 ? $in[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@in == 1 ? : 11 5 16
1348 8 ▶ my $out = @out == 1 ? $out[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@out == 1 ? : 14 2 16
1349 8 my $noutca = $sig->names_oca;
1350 8 ▶ if (ref($arg) eq "ARRAY" and @$arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq "ARRAY" and @$arg) 11 5 16
Condition66%2/3
ref $arg eq "ARRAY" and @$arg
!ll&&!rl&&r
5011
MC/DC50%1/2
ref $arg eq "ARRAY" and @$arg
ref $arg eq "ARRAY" @$arg
Truth table66%2/3
A and B
A= ref $arg eq "ARRAY"B= @$arg
ABresult
0X0
100
111
1351 8 $in = $$arg[0];
1352 2 ▶ $out = $$arg[1] if @$arg > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$arg > 1 6 5 11
1353 }
1354 8 ▶ confess "ERROR in pp_def($name): Inplace does not know name of input ndarray, options were (@in)"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 1 15 16
1355 unless defined $in;
1356 confess "ERROR in pp_def($name): Inplace input ndarray '$in' is actually output"
1357 8 ▶ if $is_out{$in};
Branch: 1 branch
BranchTrueFalseTotal
if $is_out{$in} 1 14 15
1358 2 ▶ confess "ERROR in pp_def($name): Inplace does not know name of output ndarray, options were (@out)"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 1 13 14
1359 unless defined $out;
1360 8 my ($in_obj, $out_obj) = map $sig->objs->{$_}, $in, $out;
1361 8 ▶ confess "ERROR in pp_def($name): Inplace output arg $out not [o]\n" if !$$out_obj{FlagW};
Branch: 1 branch
BranchTrueFalseTotal
unless $out_obj->{"FlagW"} 1 12 13
1362 6 my ($in_inds, $out_inds) = map $_->{IndObjs}, $in_obj, $out_obj;
1363 6 ▶ confess "ERROR in pp_def($name): Inplace args $in and $out different number of dims"
Branch: 1 branch
BranchTrueFalseTotal
if @$in_inds != @$out_inds 1 11 12
1364 if @$in_inds != @$out_inds;
1365 6 for my $i (0..$#$in_inds) {
1366 6 my ($in_ind, $out_ind) = map $_->[$i], $in_inds, $out_inds;
1367 6 ▶ next if grep !defined $_->{Value}, $in_ind, $out_ind;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_->{"Value"})), $in_ind, $out_ind) 8 2 10
1368 confess "ERROR in pp_def($name): Inplace Pars $in and $out inds ".join('=',@$in_ind{qw(Name Value)})." and ".join('=',@$out_ind{qw(Name Value)})." not compatible"
1369 6 ▶ if $in_ind->{Value} != $out_ind->{Value};
Branch: 1 branch
BranchTrueFalseTotal
if $in_ind->{"Value"} != $out_ind->{"Value"} 1 1 2
1370 }
1371 6 my ($in_flags, $out_flags) = map [sort grep /^FlagType/, keys %$_], $in_obj, $out_obj;
1372 6 ▶ confess "ERROR in pp_def($name): Inplace args $in and $out have different type specifications '@$in_flags' vs '@$out_flags'"
Branch: 1 branch
BranchTrueFalseTotal
if join($", @$in_flags) ne join($", @$out_flags) 2 8 10
1373 if "@$in_flags" ne "@$out_flags";
1374 6 ▶ confess "ERROR in pp_def($name): Inplace args $in and $out have different type specifications '@$in_obj{@$in_flags}' vs '@$out_obj{@$out_flags}"
Branch: 1 branch
BranchTrueFalseTotal
if join($", @$in_obj{@$in_flags}) ne join($", @$out_obj{@$out_flags}) 0 8 8
1375 if "@$in_obj{@$in_flags}" ne "@$out_obj{@$out_flags}";
1376 2 ▶ confess "ERROR in pp_def($name): Inplace args $in and $out have different type specifications '@{[($in_obj->{Type}//'NONE')]}' vs '@{[($out_obj->{Type}//'NONE')]}'"
Condition0%0/4
$in_obj->{"Type"} // "NONE"
l!l
00
$out_obj->{"Type"} // "NONE"
l!l
00
MC/DC0%0/1
$in_obj->{"Type"} // "NONE"
$in_obj->{"Type"}
MC/DC0%0/1
$out_obj->{"Type"} // "NONE"
$out_obj->{"Type"}
Truth table0%0/2
A
A= $in_obj->{"Type"}
Aresult
11
00
Truth table0%0/2
A
A= $out_obj->{"Type"}
Aresult
11
00
1377 6 ▶ if ($in_obj->{Type}//'NONE') ne ($out_obj->{Type}//'NONE');
Branch: 1 branch
BranchTrueFalseTotal
if ($in_obj->{"Type"} // "NONE") ne ($out_obj->{"Type"} // "NONE") 0 8 8
Condition100%4/4
$in_obj->{"Type"} // "NONE"
l!l
17
$out_obj->{"Type"} // "NONE"
l!l
17
MC/DC100%1/1
$in_obj->{"Type"} // "NONE"
$in_obj->{"Type"}
MC/DC100%1/1
$out_obj->{"Type"} // "NONE"
$out_obj->{"Type"}
Truth table100%2/2
A
A= $in_obj->{"Type"}
Aresult
11
00
Truth table100%2/2
A
A= $out_obj->{"Type"}
Aresult
11
00
1378 6 [$in, $out];
1379 }),
1380 PDL::PP::Rule->new(["InplaceCode"], [qw(InplaceNormalised)],
1381 'code to implement working inplace',
1382 # insert code, after the autogenerated xs argument processing code
1383 # produced by VarArgsXSHdr and AFTER any in HdrCode
1384 # - this code flags the routine as working inplace,
1385 sub {
1386 6 ▶ my ($arg) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
1387 6 my ($in, $out) = @$arg;
1388 6 " PDL_XS_INPLACE($in, $out)\n";
1389 }),
1390 PDL::PP::Rule->new("InplaceCode", [qw(Name SignatureObj)],
1391 'catch inplace flag on non-implementing ops',
1392 sub {
1393 6 ▶ my ($name, $sig) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
1394 6 join '', map qq{ if (PDL_IS_INPLACE($_)) PDL->pdl_barf("$name: $_->inplace but not supported");\n},
1395 $sig->names_in;
1396 }),
1397 PDL::PP::Rule->new("InplaceDocValues",
1398 [qw(Name SignatureObj InplaceNormalised NoExport?)],
1399 'doc describing usage inplace',
1400 sub {
1401 6 ▶ my ($name, $sig, $inplace, $noexport) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
1402 6 my @args = @{ $sig->args_callorder };
1403 6 my %inplace_involved = map +($_=>1), my ($in, $out) = @$inplace;
1404 6 my $meth_call = $args[0] eq $in;
1405 38 @args = grep !$inplace_involved{$_}, @args;
1406 38 ▶ my @vals = !$meth_call ? () : [
Branch: 2 branches
BranchTrueFalseTotal
!$meth_call ? : 0 8 8
!@args ? : 6 2 8
1407 "\$$in->inplace->$name".(
1408 37 !@args ? '' : "(@{[join ', ', map qq{\$$_}, @args]})"
1409 ).";", []
1410 ];
1411 37 ▶ my $prefix = $noexport ? "$::PDLOBJ\::" : "";
Branch: 1 branch
BranchTrueFalseTotal
$noexport ? : 2 6 8
1412 38 ▶ push @vals, [ "$prefix$name(\$$in->inplace".(
Branch: 1 branch
BranchTrueFalseTotal
!@args ? : 6 2 8
1413 38 !@args ? '' : ", @{[join ', ', map qq{\$$_}, @args]}"
1414 ).");", []];
1415 38 $vals[0][1] = ["can be used inplace"];
1416 38 \@vals;
1417 }),
1418 PDL::PP::Rule::Returns->new("InplaceDocValues", []),
1419  
1420 PDL::PP::Rule->new("OverloadDocValues",
1421 [qw(Name SignatureObj Overload Inplace?)],
1422 'implement and doc Perl overloaded operators',
1423 sub {
1424 38 ▶ my ($name, $sig, $ovl, $inplace) = @_;
Subroutine __ANON__: called CC=14 SCAR=31.1
1425 38 ▶ confess "$name Overload given false value" if !$ovl;
Branch: 1 branch
BranchTrueFalseTotal
unless $ovl 0 6 6
1426 38 ▶ $ovl = [$ovl] if !ref $ovl;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ovl 1 5 6
1427 38 my ($op, $mutator, $bitwise) = @$ovl;
1428 38 ▶ confess "$name Overload trying to define mutator but no inplace"
Branch: 1 branch
BranchTrueFalseTotal
if $mutator and not $inplace 0 6 6
Condition66%2/3
$mutator and not $inplace
!ll&&!rl&&r
330
MC/DC0%0/2
$mutator and not $inplace
$mutator not $inplace
Truth table66%2/3
A and not(B)
A= $mutatorB= not $inplace
ABresult
0X0
100
111
1429 if $mutator && !$inplace;
1430 38 my $one_arg = $sig->names_in == 1;
1431 38 my $ret = "{ package # hide from MetaCPAN\n $::PDLOBJ;\n";
1432 38 ▶ my $bitwise_passon = $bitwise ? '$_[2]?@_[1,0]:@_[0,1]' : '@_';
Branch: 1 branch
BranchTrueFalseTotal
$bitwise ? : 0 6 6
1433 38 my $fullname = $::PDLOBJ."::$name";
1434 38 ▶ if ($one_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($one_arg) { } 2 4 6
1435 38 $ret .= pp_line_numbers(__LINE__, <<EOF);
1436 sub overload_$name {
1437 4 ▶ Carp::confess("$fullname: overloaded '$op' given undef")
Subroutine overload_bitnot: called CC=2 SCAR=7.2
Subroutine overload_cos: called CC=2 SCAR=7.2
Subroutine overload_exp: called CC=2 SCAR=7.2
Subroutine overload_log: called CC=2 SCAR=7.2
Subroutine overload_not: called CC=2 SCAR=7.2
Subroutine overload_sin: called CC=2 SCAR=7.2
Subroutine overload_sqrt: called CC=2 SCAR=7.2
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 7 branches
BranchTrueFalseTotal
if grep((!defined($_)), $_[0]) 0 4 4
if grep((!defined($_)), $_[0]) 0 86 86
if grep((!defined($_)), $_[0]) 0 23 23
if grep((!defined($_)), $_[0]) 0 11 11
if grep((!defined($_)), $_[0]) 0 131 131
if grep((!defined($_)), $_[0]) 0 76 76
if grep((!defined($_)), $_[0]) 0 34 34
1438 if grep !defined, \$_[0];
1439 4 $fullname(\$_[0]);
1440 }
1441 70 ▶use overload '$op' => \\&overload_$name;
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
1442 EOF
1443 } else {
1444 38 $ret .= pp_line_numbers(__LINE__, <<EOF);
1445 {
1446 3 my (\$foo, \$overload_sub);
1447 sub overload_$name {
1448 35 ▶ Carp::confess("$fullname: overloaded '$op' given undef")
Subroutine overload_and2: called CC=7 SCAR=27.0
Subroutine overload_atan2: called CC=6 SCAR=24.6
Subroutine overload_divide: called CC=6 SCAR=24.6
Subroutine overload_eq: called CC=6 SCAR=24.6
Subroutine overload_ge: called CC=6 SCAR=24.6
Subroutine overload_gt: called CC=6 SCAR=24.6
Subroutine overload_le: called CC=6 SCAR=24.6
Subroutine overload_lt: called CC=6 SCAR=24.6
Subroutine overload_matmult: called CC=6 SCAR=24.6
Subroutine overload_minus: called CC=6 SCAR=24.6
Subroutine overload_modulo: called CC=6 SCAR=24.6
Subroutine overload_mult: called CC=6 SCAR=24.6
Subroutine overload_ne: called CC=6 SCAR=24.6
Subroutine overload_or2: called CC=7 SCAR=27.0
Subroutine overload_plus: called CC=6 SCAR=24.6
Subroutine overload_power: called CC=6 SCAR=24.6
Subroutine overload_shiftleft: called CC=6 SCAR=24.6
Subroutine overload_shiftright: not called CC=6 SCAR=24.6
Subroutine overload_spaceship: not called CC=6 SCAR=24.6
Subroutine overload_xor: called CC=7 SCAR=27.0
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 20 branches
BranchTrueFalseTotal
if grep((!defined($_)), @_[0, 1]) 0 35 35
if grep((!defined($_)), @_[0, 1]) 0 15 15
if grep((!defined($_)), @_[0, 1]) 0 272 272
if grep((!defined($_)), @_[0, 1]) 0 771 771
if grep((!defined($_)), @_[0, 1]) 0 16 16
if grep((!defined($_)), @_[0, 1]) 0 416 416
if grep((!defined($_)), @_[0, 1]) 0 21 21
if grep((!defined($_)), @_[0, 1]) 0 354 354
if grep((!defined($_)), @_[0, 1]) 0 193 193
if grep((!defined($_)), @_[0, 1]) 0 660 660
if grep((!defined($_)), @_[0, 1]) 0 50 50
if grep((!defined($_)), @_[0, 1]) 0 1609 1609
if grep((!defined($_)), @_[0, 1]) 0 246 246
if grep((!defined($_)), @_[0, 1]) 0 25 25
if grep((!defined($_)), @_[0, 1]) 2 718 720
if grep((!defined($_)), @_[0, 1]) 0 27 27
if grep((!defined($_)), @_[0, 1]) 0 9 9
if grep((!defined($_)), @_[0, 1]) 0 0 0
if grep((!defined($_)), @_[0, 1]) 0 0 0
if grep((!defined($_)), @_[0, 1]) 0 2 2
1449 if grep !defined, \@_[0,1];
1450 35 ▶ return $fullname($bitwise_passon) unless ref \$_[1]
Branch: 23 branches
BranchTrueFalseTotal
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "&")) and $foo != $overload_sub 0 0 0
$_[2] ? : 0 35 35
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "atan2")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "/")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "==")) and $foo != $overload_sub 1 0 1
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">=")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "x")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "-")) and $foo != $overload_sub 3 0 3
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "%")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "*")) and $foo != $overload_sub 37 0 37
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "!=")) and $foo != $overload_sub 1 0 1
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "|")) and $foo != $overload_sub 1 0 1
$_[2] ? : 0 25 25
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "+")) and $foo != $overload_sub 3 0 3
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "**")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<<")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">>")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=>")) and $foo != $overload_sub 0 0 0
unless ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "^")) and $foo != $overload_sub 0 0 0
$_[2] ? : 0 2 2
Condition47%85/180
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "&")) and $foo != $overload_sub
!ll&&!rl&&r
3500
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "&"))
!ll&&!rl&&r
3500
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
0350
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "atan2")) and $foo != $overload_sub
!ll&&!rl&&r
1500
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "atan2"))
!ll&&!rl&&r
1500
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
1140
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "/")) and $foo != $overload_sub
!ll&&!rl&&r
27200
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "/"))
!ll&&!rl&&r
27200
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
187850
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "==")) and $foo != $overload_sub
!ll&&!rl&&r
77010
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "=="))
!ll&&!rl&&r
77001
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
2884821
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">=")) and $foo != $overload_sub
!ll&&!rl&&r
1600
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">="))
!ll&&!rl&&r
1600
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
1510
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">")) and $foo != $overload_sub
!ll&&!rl&&r
41600
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">"))
!ll&&!rl&&r
41600
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
364520
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=")) and $foo != $overload_sub
!ll&&!rl&&r
2100
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<="))
!ll&&!rl&&r
2100
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
2010
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<")) and $foo != $overload_sub
!ll&&!rl&&r
35400
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<"))
!ll&&!rl&&r
35400
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
344100
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "x")) and $foo != $overload_sub
!ll&&!rl&&r
19300
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "x"))
!ll&&!rl&&r
19300
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
11920
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "-")) and $foo != $overload_sub
!ll&&!rl&&r
65730
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "-"))
!ll&&!rl&&r
65703
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
3263313
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "%")) and $foo != $overload_sub
!ll&&!rl&&r
5000
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "%"))
!ll&&!rl&&r
5000
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
34160
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "*")) and $foo != $overload_sub
!ll&&!rl&&r
1572370
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "*"))
!ll&&!rl&&r
1572037
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
64193137
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "!=")) and $foo != $overload_sub
!ll&&!rl&&r
24600
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "!="))
!ll&&!rl&&r
24510
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
1331121
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "|")) and $foo != $overload_sub
!ll&&!rl&&r
2410
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "|"))
!ll&&!rl&&r
2401
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
0241
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "+")) and $foo != $overload_sub
!ll&&!rl&&r
71530
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "+"))
!ll&&!rl&&r
71503
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
4222933
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "**")) and $foo != $overload_sub
!ll&&!rl&&r
2700
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "**"))
!ll&&!rl&&r
2700
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
2430
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<<")) and $foo != $overload_sub
!ll&&!rl&&r
900
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<<"))
!ll&&!rl&&r
900
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
900
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">>")) and $foo != $overload_sub
!ll&&!rl&&r
000
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">>"))
!ll&&!rl&&r
000
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
000
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=>")) and $foo != $overload_sub
!ll&&!rl&&r
000
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=>"))
!ll&&!rl&&r
000
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
000
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "^")) and $foo != $overload_sub
!ll&&!rl&&r
200
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "^"))
!ll&&!rl&&r
200
ref $_[1] and ref $_[1] ne "PDL"
!ll&&!rl&&r
020
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "&")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "&")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "atan2")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "atan2")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "/")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "/")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "==")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "==")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">=")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], ">=")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], ">")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "<=")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "<")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "x")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "x")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "-")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "-")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "%")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "%")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "*")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "*")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "!=")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "!=")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "|")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "|")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "+")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "+")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "**")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "**")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<<")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "<<")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], ">>")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], ">>")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "<=>")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "<=>")) $foo != $overload_sub
MC/DC0%0/4
ref $_[1] and ref $_[1] ne "PDL" and defined($foo = overload::Method($_[1], "^")) and $foo != $overload_sub
ref $_[1] ref $_[1] ne "PDL" defined($foo = overload::Method($_[1], "^")) $foo != $overload_sub
Truth table20%1/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "&"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "atan2"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "/"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table60%3/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "=="))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], ">="))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], ">"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "<="))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "<"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "x"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table60%3/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "-"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "%"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table60%3/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "*"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table60%3/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "!="))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "|"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table60%3/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "+"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table40%2/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "**"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table20%1/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "<<"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], ">>"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "<=>"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table20%1/5
A and B and C and D
A= ref $_[1]B= ref $_[1] ne "PDL"C= defined($foo = overload::Method($_[1], "^"))D= $foo != $overload_sub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1451 && (ref \$_[1] ne '$::PDLOBJ')
1452 && defined(\$foo = overload::Method(\$_[1], '$op'))
1453 && \$foo != \$overload_sub; # recursion guard
1454 0 goto &\$foo;
1455 }
1456 70 ▶ use overload '$op' => \$overload_sub = \\&overload_$name;
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
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
1457 }
1458 EOF
1459 }
1460 1 ▶ $ret .= pp_line_numbers(__LINE__, <<EOF) if $mutator;
Branch: 1 branch
BranchTrueFalseTotal
if $mutator 3 3 6
1461 # in1, in2, out, swap if true
1462 3 sub overload_${name}_mutate {
1463 5 ▶ Carp::confess("$fullname: overloaded '$op=' given undef")
Subroutine overload_and2_mutate: called CC=2 SCAR=8.1
Subroutine overload_divide_mutate: called CC=2 SCAR=8.1
Subroutine overload_minus_mutate: called CC=2 SCAR=8.1
Subroutine overload_modulo_mutate: called CC=2 SCAR=8.1
Subroutine overload_mult_mutate: called CC=2 SCAR=8.1
Subroutine overload_or2_mutate: called CC=2 SCAR=8.1
Subroutine overload_plus_mutate: called CC=2 SCAR=8.1
Subroutine overload_power_mutate: called CC=2 SCAR=8.1
Subroutine overload_shiftleft_mutate: not called CC=2 SCAR=8.1
Subroutine overload_shiftright_mutate: not called CC=2 SCAR=8.1
Subroutine overload_xor_mutate: not called CC=2 SCAR=8.1
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 11 branches
BranchTrueFalseTotal
if grep((!defined($_)), @_[0, 1]) 0 5 5
if grep((!defined($_)), @_[0, 1]) 0 469 469
if grep((!defined($_)), @_[0, 1]) 0 369 369
if grep((!defined($_)), @_[0, 1]) 0 170 170
if grep((!defined($_)), @_[0, 1]) 0 232 232
if grep((!defined($_)), @_[0, 1]) 0 52 52
if grep((!defined($_)), @_[0, 1]) 2 318 320
if grep((!defined($_)), @_[0, 1]) 0 62 62
if grep((!defined($_)), @_[0, 1]) 0 0 0
if grep((!defined($_)), @_[0, 1]) 0 0 0
if grep((!defined($_)), @_[0, 1]) 0 0 0
1464 if grep !defined, \@_[0,1];
1465 5 $fullname(\$_[0]->inplace, \$_[1]); \$_[0]
1466 }
1467 70 ▶use overload '$op=' => \\&overload_${name}_mutate;
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
Subroutine BEGIN: called CC=1 SCAR=0.0
1468 EOF
1469 2 $::PDLOVERLOAD .= "$ret}\n";
1470 2 my @args = @{ $sig->args_callorder };
1471 2 my @outs = $sig->names_out;
1472 0 ▶ confess "$name error in Overload doc: !=1 output (@outs)" if @outs != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @outs != 1 0 6 6
1473 35 my @ins = $sig->names_in;
1474 35 ▶ my $sp = $op !~ /^[a-z]/ ? '' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
!($op =~ /^[a-z]/) ? : 2 4 6
1475 35 ▶ my @vals = ["\$$outs[0] = ".(
Branch: 2 branches
BranchTrueFalseTotal
$one_arg ? : 2 4 6
$sp ? : 2 2 4
1476 $one_arg ? "$op$sp\$$ins[0]" :
1477 $sp ? "$op \$$ins[0], \$$ins[1]" :
1478 "\$$ins[0] $op \$$ins[1]"
1479 ).";",
1480 ["overloads the Perl '$op' operator"]
1481 ];
1482 38 ▶ push @vals, ["\$$ins[0] $op= \$$ins[1];", []] if $mutator && !$one_arg;
Branch: 1 branch
BranchTrueFalseTotal
if $mutator and not $one_arg 1 5 6
Condition100%3/3
$mutator and not $one_arg
!ll&&!rl&&r
321
MC/DC100%2/2
$mutator and not $one_arg
$mutator not $one_arg
Truth table100%3/3
A and not(B)
A= $mutatorB= not $one_arg
ABresult
0X0
100
111
1483 38 \@vals;
1484 }),
1485 PDL::PP::Rule::Returns->new("OverloadDocValues", []),
1486  
1487 PDL::PP::Rule->new("DefaultFlowFlag", [qw(DefaultFlow? BackCode? AffinePriv?)],
1488 'Set starting dataflow forward if DefaultFlow, back if (BackCode | AffinePriv)',
1489 sub {
1490 38 ▶ my ($df, $bc, $aff) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
1491 64 ▶ $bc || $aff ? "PDL_ITRANS_DO_DATAFLOW_ANY" :
Branch: 2 branches
BranchTrueFalseTotal
$bc || $aff ? : 2 36 38
$df ? : 1 35 36
Condition66%2/3
$bc or $aff
l!l&&r!l&&!r
2036
MC/DC50%1/2
$bc or $aff
$bc $aff
Truth table66%2/3
A or B
A= $bcB= $aff
ABresult
1X1
011
000
1492 $df ? "PDL_ITRANS_DO_DATAFLOW_F" :
1493 0;
1494 },
1495 ),
1496 PDL::PP::Rule->new('Lvalue', "DefaultFlowFlag",
1497 'Lvalue <= DefaultFlowFlag value',
1498 sub {
1499 27 ▶ my ($flowflag) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
1500 3 ▶ $flowflag =~ /ANY/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$flowflag =~ /ANY/ ? : 2 35 37
1501 },
1502 ),
1503 PDL::PP::Rule->new([qw(UsageDoc ParamDoc)],
1504 [qw(Name Doc? SignatureObj OtherParsDefaults? ArgOrder?
1505 OverloadDocValues InplaceDocValues ParamDesc? Lvalue NoExport?
1506 )],
1507 'generate "usage" section of doc',
1508 sub {
1509 64 ▶ my ($name, $doc, $sig, $otherdefaults, $argorder,
Subroutine __ANON__: called CC=31 SCAR=35.2
1510 $overloadvals, $inplacevals, $paramdesc, $lvalue, $noexport,
1511 ) = @_;
1512 64 ▶ $otherdefaults ||= {};
Condition100%2/2
$otherdefaults ||= {}
l!l
137
MC/DC100%1/1
$otherdefaults ||= {}
$otherdefaults
Truth table100%2/2
A
A= $otherdefaults
Aresult
11
00
1513 38 ▶ $paramdesc ||= {};
Condition50%1/2
$paramdesc ||= {}
l!l
038
MC/DC0%0/1
$paramdesc ||= {}
$paramdesc
Truth table50%1/2
A
A= $paramdesc
Aresult
11
00
1514 37 ▶ confess "pp_def($name): non-ref ParamDesc given" if !ref $paramdesc;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $paramdesc 0 38 38
1515 37 my @args = @{ $sig->args_callorder };
1516 my $paramdoc = !keys(%$paramdesc) ? '' : join('',
1517 "=head3 Parameters\n\n=over\n\n", (
1518 63 ▶ map "=item $_\n\n$paramdesc->{$_}\n\n", grep $paramdesc->{$_}, @args,
Branch: 1 branch
BranchTrueFalseTotal
!keys(%$paramdesc) ? : 38 0 38
1519 ), "=back\n\n");
1520 27 ▶ return ('',$paramdoc) if $doc && $doc =~ /^=for usage/m;
Branch: 1 branch
BranchTrueFalseTotal
if $doc and $doc =~ /^=for usage/m 0 38 38
Condition33%1/3
$doc and $doc =~ /^=for usage/m
!ll&&!rl&&r
0380
MC/DC0%0/2
$doc and $doc =~ /^=for usage/m
$doc $doc =~ /^=for usage/m
Truth table33%1/3
A and B
A= $docB= $doc =~ /^=for usage/m
ABresult
0X0
100
111
1521 3 my %any_out = map +($_=>1), $sig->names_out_nca, $sig->other_out;
1522 63 my %outca = map +($_=>1), $sig->names_oca;
1523 38 my @inargs = grep !$outca{$_}, @args;
1524 my $noptional = grep $any_out{$_} ||
1525 38 ▶ exists $otherdefaults->{$_}, @inargs;
Condition100%3/3
$any_out{$_} || exists $otherdefaults->{$_}
l!l&&r!l&&!r
28155
MC/DC100%2/2
$any_out{$_} || exists $otherdefaults->{$_}
$any_out{$_} exists $otherdefaults->{$_}
Truth table100%3/3
A || B
A= $any_out{$_}B= exists $otherdefaults->{$_}
ABresult
1X1
011
000
1526 63 my @argsets;
1527 63 ▶ my $plural = keys(%$otherdefaults) > 1 ? "s" : "";
Branch: 1 branch
BranchTrueFalseTotal
keys %$otherdefaults > 1 ? : 0 38 38
1528 38 ▶ my $override = !keys(%$otherdefaults) ? '' : " of ".join(", ", map "$_=$otherdefaults->{$_}", grep exists $otherdefaults->{$_}, @args);
Branch: 1 branch
BranchTrueFalseTotal
!keys(%$otherdefaults) ? : 37 1 38
1529 38 ▶ if (keys %outca) {
Branch: 2 branches
BranchTrueFalseTotal
if (keys %outca) { } 1 37 38
elsif ($argorder) { } 2 35 37
1530 3 push @argsets, [\@inargs, [ grep $outca{$_}, @args ], []];
1531 } elsif ($argorder) {
1532 5 ▶ my @allouts = grep $any_out{$_} || $outca{$_}, @args;
Condition66%2/3
$any_out{$_} || $outca{$_}
l!l&&r!l&&!r
306
MC/DC50%1/2
$any_out{$_} || $outca{$_}
$any_out{$_} $outca{$_}
Truth table66%2/3
A || B
A= $any_out{$_}B= $outca{$_}
ABresult
1X1
011
000
1533 3 push @argsets, map [[ @inargs[0..$_] ], \@allouts, []],
1534 ($#inargs-$noptional)..$#inargs-@allouts;
1535 3 push @argsets, [\@args, [], ['all arguments given']];
1536 0 ▶ unshift @{$argsets[0][2]}, "using default$plural$override" if $override;
Branch: 1 branch
BranchTrueFalseTotal
if $override 0 2 2
1537 } else {
1538 push @argsets, [
1539 [grep !($any_out{$_} || exists $otherdefaults->{$_}), @args],
1540 38 ▶ [grep $any_out{$_}, @args],
Branch: 1 branch
BranchTrueFalseTotal
if keys %any_out and keys %$otherdefaults 1 34 35
Condition100%6/6
keys %any_out and keys %$otherdefaults
!ll&&!rl&&r
12221
$any_out{$_} || exists $otherdefaults->{$_}
l!l&&r!l&&!r
112
MC/DC100%2/2
keys %any_out and keys %$otherdefaults
keys %any_out keys %$otherdefaults
MC/DC100%2/2
$any_out{$_} || exists $otherdefaults->{$_}
$any_out{$_} exists $otherdefaults->{$_}
Truth table100%3/3
A and B
A= keys %any_outB= keys %$otherdefaults
ABresult
0X0
100
111
Truth table100%3/3
A || B
A= $any_out{$_}B= exists $otherdefaults->{$_}
ABresult
1X1
011
000
1541 ["using default value$plural$override"],
1542 ]
1543 if keys %any_out && keys %$otherdefaults;
1544 push @argsets, [
1545 [grep !$any_out{$_},@args],
1546 38 ▶ [grep $any_out{$_},@args],
Branch: 2 branches
BranchTrueFalseTotal
if keys %any_out 23 12 35
keys %$otherdefaults ? : 1 22 23
1547 [keys %$otherdefaults ? "overriding default$plural" : ()],
1548 ]
1549 if keys %any_out;
1550 38 push @argsets, [\@args, [], ['all arguments given']];
1551 }
1552 153 my @invocs = @$overloadvals;
1553 93 ▶ my $prefix = $noexport ? "$::PDLOBJ\::" : "";
Branch: 1 branch
BranchTrueFalseTotal
$noexport ? : 4 34 38
1554 0 ▶ push @invocs, map [(!@{$_->[1]} ? '' :
Branch: 1 branch
BranchTrueFalseTotal
@{$_->[1];} == 1 ? : 24 3 27
1555 0 @{$_->[1]} == 1 ? "\$$_->[1][0] = " :
1556 0 "(".join(", ", map "\$$_", @{$_->[1]}).") = "
1557 38 )."$prefix$name(".join(", ", map "\$$_", @{$_->[0]}).");",
1558 0 ▶ [@{$_->[2]}]], @argsets;
Branch: 1 branch
BranchTrueFalseTotal
!@{$_->[1];} ? : 37 27 64
1559 38 ▶ if ($sig->names_in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig->names_in) 37 1 38
1560 38 $argsets[0][2] = ['method call'];
1561 38 $argsets[$_][2] = [] for 1..$#argsets; # they get the idea
1562 38 ▶ push @invocs, map [(!@{$_->[1]} ? '' :
Branch: 1 branch
BranchTrueFalseTotal
@{$_->[1];} == 1 ? : 24 3 27
1563 37 @{$_->[1]} == 1 ? "\$$_->[1][0] = " :
1564 37 ▶ "(".join(", ", map "\$$_", @{$_->[1]}).") = "
Branch: 1 branch
BranchTrueFalseTotal
@{$_->[0];} <= 1 ? : 25 38 63
1565 )."\$$_->[0][0]->$name".(
1566 37 @{$_->[0]} <= 1 ? '' :
1567 37 "(".join(", ", map "\$$_", @{$_->[0]}[1..$#{$_->[0]}]).")"
1568 ).";",
1569 38 ▶ [@{$_->[2]}]], grep @{$_->[0]}, @argsets;
Branch: 1 branch
BranchTrueFalseTotal
!@{$_->[1];} ? : 36 27 63
1570 }
1571 36 push @invocs, @$inplacevals;
1572 36 ▶ if ($lvalue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lvalue) 3 35 38
1573 36 my ($first_meth) = grep @{$_->[1]} == 1, @argsets;
1574 push @invocs, [
1575 "\$$first_meth->[0][0]->$name".(
1576 37 @{$first_meth->[0]} <= 1 ? '' :
1577 37 ▶ "(".join(", ", map "\$$_", @{$first_meth->[0]}[1..$#{$first_meth->[0]}]).")"
Branch: 2 branches
BranchTrueFalseTotal
if $first_meth 3 0 3
@{$first_meth->[0];} <= 1 ? : 3 0 3
1578 )." .= \$data;",
1579 ['usable as lvalue']] if $first_meth;
1580 }
1581 37 require List::Util;
1582 37 my $maxlen = List::Util::max(map length($_->[0]), @invocs);
1583 (join('', "\n=for usage\n\n",
1584 37 ▶ (map !@{$_->[1]} ? " $_->[0]\n" : sprintf(" %-${maxlen}s%s\n", $_->[0], " # ".join ", ", @{$_->[1]}), @invocs), "\n\n"),
Branch: 1 branch
BranchTrueFalseTotal
!@{$_->[1];} ? : 60 93 153
1585 $paramdoc,
1586 );
1587 }),
1588 PDL::PP::Rule::Returns::EmptyString->new("UsageDoc", []),
1589  
1590 # the docs
1591 PDL::PP::Rule->new("PdlDoc", "FullDoc", sub {
1592 37 ▶ my $fulldoc = shift;
Subroutine __ANON__: not called CC=2 SCAR=7.6
1593 # Append a final cut if it doesn't exist due to heredoc shenanigans
1594 37 ▶ $fulldoc .= "\n\n=cut\n" unless $fulldoc =~ /\n=cut\n*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $fulldoc =~ /\n=cut\n*$/ 0 0 0
1595 # Make sure the =head1 FUNCTIONS section gets added
1596 37 $::DOCUMENTED++;
1597 37 return $fulldoc;
1598 }
1599 ),
1600 PDL::PP::Rule::Returns::Zero->new("NoPthread"), # assume we can pthread, unless indicated otherwise
1601 PDL::PP::Rule::Returns->new("Synonyms", []),
1602 PDL::PP::Rule->new("PdlDoc", [qw(
1603 Name Pars OtherPars GenericTypes Doc UsageDoc BadDoc?
1604 HaveBroadcasting NoPthread IsAffineFlag DefaultFlowFlag ParamDoc
1605 InplaceNormalised? Synonyms
1606 )],
1607 sub {
1608 37 ▶ my ($name,$pars,$otherpars,$gentypes,$doc,$usagedoc,$baddoc,
Subroutine __ANON__: called CC=17 SCAR=28.5
1609 $havebroadcasting, $noPthreadFlag, $affflag, $flowflag, $paramdoc,
1610 $inplace, $synonyms,
1611 ) = @_;
1612 37 ▶ return '' if !defined $doc # Allow explicit non-doc using Doc=>undef
Branch: 1 branch
BranchTrueFalseTotal
if not defined $doc or $doc =~ /^\s*internal\s*$/i 0 38 38
Condition33%1/3
not defined $doc or $doc =~ /^\s*internal\s*$/i
l!l&&r!l&&!r
0038
MC/DC0%0/2
not defined $doc or $doc =~ /^\s*internal\s*$/i
not defined $doc $doc =~ /^\s*internal\s*$/i
Truth table33%1/3
not(A) or B
A= not defined $docB= $doc =~ /^\s*internal\s*$/i
ABresult
1X1
011
000
1613 or $doc =~ /^\s*internal\s*$/i;
1614 # If the doc string is one line let's have two for the
1615 # reference card information as well
1616 37 ▶ $doc = "=for ref\n\n".$doc if $doc !~ /\n/;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc =~ /\n/ 0 38 38
1617 37 $::DOCUMENTED++;
1618 37 $doc =~ s/\n(=cut\s*\n)+(\s*\n)*$/\n/m; # Strip extra =cut's
1619 37 my $sigdoc = '';
1620 37 ▶ if ($doc !~ /^=for\s+sig\b/m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc =~ /^=for\s+sig\b/m) 37 1 38
1621 # Strip leading whitespace and trailing semicolons and whitespace
1622 37 $pars =~ s/^\s*(.+[^;])[;\s]*$/$1/;
1623 37 ▶ $otherpars =~ s/^\s*(.+[^;])[;\s]*$/$1/ if $otherpars;
Branch: 1 branch
BranchTrueFalseTotal
if $otherpars 7 30 37
1624 37 my @typesigparts = '';
1625 37 my @typenames = map PDL::Type->new($_)->ioname, @$gentypes;
1626 37 ▶ while (@typenames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@typenames) 417 36 453
1627 37 ▶ push @typesigparts, '' if length $typesigparts[-1] > 50;
Branch: 1 branch
BranchTrueFalseTotal
if length $typesigparts[-1] > 50 34 383 417
1628 37 ▶ $typesigparts[-1] .= ($typesigparts[-1]&&' ') . shift @typenames;
Condition100%2/2
$typesigparts[-1] && ' '
!ll
70347
MC/DC100%1/1
$typesigparts[-1] && ' '
$typesigparts[-1]
Truth table100%2/2
A
A= $typesigparts[-1]
Aresult
00
11
1629 }
1630 37 my $typesig = join "\n ", @typesigparts;
1631 37 $sigdoc = <<"EOD" ;
1632 XXX=for sig
1633  
1634 37 ▶ Signature: ($pars@{[$otherpars ? "; $otherpars" : ""]})
Branch: 1 branch
BranchTrueFalseTotal
$otherpars ? : 7 29 36
1635 Types: ($typesig)
1636 EOD
1637 }
1638 37 ▶ if ( defined $baddoc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $baddoc) 37 0 37
1639 # Strip leading newlines and any =cut markings
1640 37 $baddoc =~ s/\n(=cut\s*\n)+(\s*\n)*$/\n/m;
1641 37 $baddoc =~ s/^\n+//;
1642 37 $baddoc = "\n=for bad\n\n$baddoc";
1643 }
1644 37 ▶ my @misc = $havebroadcasting ? "Broadcasts over its inputs.\n" : "Does not broadcast.\n";
Branch: 1 branch
BranchTrueFalseTotal
$havebroadcasting ? : 35 2 37
1645 37 ▶ unshift @misc, "Can operate inplace with C<$inplace->[0]> as output C<$inplace->[1]>.\n" if $inplace;
Branch: 1 branch
BranchTrueFalseTotal
if $inplace 8 29 37
1646 37 ▶ push @misc, "Can't use POSIX threads.\n" if $noPthreadFlag;
Branch: 1 branch
BranchTrueFalseTotal
if $noPthreadFlag 1 36 37
1647 37 ▶ push @misc, "Makes L<virtual affine|PDL::Indexing> ndarrays.\n" if $affflag;
Branch: 1 branch
BranchTrueFalseTotal
if $affflag 0 37 37
1648 37 ▶ push @misc, "Creates data-flow".($flowflag !~ /ANY/ ? "" : " back and forth").
Branch: 2 branches
BranchTrueFalseTotal
if $flowflag 3 34 37
!($flowflag =~ /ANY/) ? : 1 2 3
1649 " by default.\n" if $flowflag;
1650 76 my $miscdocs = join '', grep $_, $paramdoc, @misc, $baddoc;
1651 22 my $baddoc_function_pod = <<"EOD" ;
1652  
1653 18 XXX=head2 @{[join ', ', $name, @$synonyms]}
1654  
1655 $sigdoc$usagedoc
1656 $doc
1657  
1658 =pod
1659  
1660 $miscdocs
1661  
1662 XXX=cut
1663  
1664 EOD
1665 72 $baddoc_function_pod =~ s/^XXX=/=/gms;
1666 72 $baddoc_function_pod;
1667 }
1668 ),
1669  
1670 PDL::PP::Rule::Returns::EmptyString->new("HdrCode", [],
1671 'Code that will be inserted before the call to the RunFunc'),
1672 PDL::PP::Rule::Returns::EmptyString->new("FtrCode", [],
1673 'Code that will be inserted after the call to the RunFunc'),
1674  
1675 PDL::PP::Rule->new("VarArgsXSHdr",
1676 [qw(Name SignatureObj
1677 OtherParsDefaults? ArgOrder? InplaceNormalised?)],
1678 'XS code to process input arguments based on supplied Pars argument to pp_def; not done if GlobalNew or PMCode supplied',
1679 sub {
1680 72 ▶ my($name,$sig,
Subroutine __ANON__: called CC=50 SCAR=40.5
1681 $otherdefaults,$argorder,$inplace) = @_;
1682 72 my @args = @{ $sig->args_callorder };
1683 37 my %other = map +($_=>1), @{$sig->othernames(1, 1)};
1684 10 ▶ $otherdefaults ||= {};
Condition100%2/2
$otherdefaults ||= {}
l!l
136
MC/DC100%1/1
$otherdefaults ||= {}
$otherdefaults
Truth table100%2/2
A
A= $otherdefaults
Aresult
11
00
1685 10 my $ci = 2; # current indenting
1686 10 my $optypes = $sig->otherobjs;
1687 10 ▶ my %ptypes = map +($_=>$$optypes{$_} ? $$optypes{$_}->get_decl('', {VarArrays2Ptrs=>1}) : 'pdl *'), @args;
Branch: 1 branch
BranchTrueFalseTotal
$optypes->{$_} ? : 9 74 83
1688 10 my %out = map +($_=>1), $sig->names_out_nca;
1689 37 my %outca = map +($_=>1), $sig->names_oca;
1690 37 my @inargs = grep !$outca{$_}, @args;
1691 37 my %other_out = map +($_=>1), $sig->other_out;
1692 37 my $nout = keys(%out) + keys(%other_out);
1693 37 my $noutca = keys %outca;
1694 37 my $ntot = @args;
1695 37 my $nallout = $nout + $noutca;
1696 37 my $ndefault = keys %$otherdefaults;
1697 4 my %valid_itemcounts = ((my $nmaxonstack = $ntot - $noutca)=>1);
1698 4 $valid_itemcounts{my $nin = $nmaxonstack - $nout} = 1;
1699 37 ▶ $valid_itemcounts{my $nin_minus_default = "($nin-$ndefault)"} = 1 if $ndefault;
Branch: 1 branch
BranchTrueFalseTotal
if $ndefault 1 36 37
1700 25 my $only_one = keys(%valid_itemcounts) == 1;
1701 37 ▶ my $nretval = $argorder ? $nout :
Branch: 2 branches
BranchTrueFalseTotal
$argorder ? : 2 35 37
$only_one ? : 13 22 35
1702 $only_one ? $noutca :
1703 "(items == $nmaxonstack) ? $noutca : $nallout";
1704 37 my ($cnt, @preinit, @xsargs, %already_read, %name2cnts) = -1;
1705 37 ▶ my @inputdecls = map "PDL_Indx ${_}_count=0;", grep $other{$_} && $optypes->{$_}->is_array, @inargs;
Condition66%2/3
$other{$_} && $optypes->{$_}->is_array
!ll&&!rl&&r
7390
MC/DC0%0/2
$other{$_} && $optypes->{$_}->is_array
$other{$_} $optypes->{$_}->is_array
Truth table66%2/3
A && B
A= $other{$_}B= $optypes->{$_}->is_array
ABresult
0X0
100
111
1706 37 foreach my $x (@inargs) {
1707 37 ▶ if (!$argorder && ($out{$x} || $other_out{$x} || exists $otherdefaults->{$x})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $argorder and $out{$x} || $other_out{$x} || exists $otherdefaults->{$x}) 0 54 54
Condition66%6/9
not $argorder and $out{$x} || $other_out{$x} || exists $otherdefaults->{$x}
!ll&&!rl&&r
10660
$out{$x} or $other_out{$x} or exists $otherdefaults->{$x}
l!l&&r!l&&!r
22044
$out{$x} or $other_out{$x}
l!l&&r!l&&!r
22044
MC/DC0%0/4
not $argorder and $out{$x} || $other_out{$x} || exists $otherdefaults->{$x}
not $argorder $out{$x} $other_out{$x} exists $otherdefaults->{$x}
Truth table40%2/5
not(A) and B or C or D
A= not $argorderB= $out{$x}C= $other_out{$x}D= exists $otherdefaults->{$x}
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1708 37 ▶ last if @xsargs + keys(%out) + $noutca != $ntot;
Branch: 1 branch
BranchTrueFalseTotal
if @xsargs + keys(%out) + $noutca != $ntot 4 18 22
1709 37 $argorder = 1; # remaining all output ndarrays, engage
1710 }
1711 37 $cnt++;
1712 37 $name2cnts{$x} = [$cnt, $cnt];
1713 37 $already_read{$x} = 1;
1714 push @xsargs, $x.(!$argorder ? '' :
1715 exists $otherdefaults->{$x} ? "=$otherdefaults->{$x}" :
1716 37 ▶ !$out{$x} ? '' :
Branch: 4 branches
BranchTrueFalseTotal
!$argorder ? : 44 28 72
exists $otherdefaults->{$x} ? : 0 28 28
!$out{$x} ? : 6 22 28
$inplace && $x eq $inplace->[1] ? : 8 14 22
Condition66%2/3
$inplace and $x eq $inplace->[1]
!ll&&!rl&&r
1408
MC/DC50%1/2
$inplace and $x eq $inplace->[1]
$inplace $x eq $inplace->[1]
Truth table66%2/3
A and B
A= $inplaceB= $x eq $inplace->[1]
ABresult
0X0
100
111
1717 $inplace && $x eq $inplace->[1] ? "=$x" :
1718 "=".callPerlInit($x."_SV")
1719 );
1720 37 ▶ push @inputdecls, "$ptypes{$x}$x".($inplace && $x eq $inplace->[1] ? "=NO_INIT" : '');
Branch: 1 branch
BranchTrueFalseTotal
$inplace && $x eq $inplace->[1] ? : 8 64 72
Condition100%3/3
$inplace and $x eq $inplace->[1]
!ll&&!rl&&r
54108
MC/DC100%2/2
$inplace and $x eq $inplace->[1]
$inplace $x eq $inplace->[1]
Truth table100%3/3
A and B
A= $inplaceB= $x eq $inplace->[1]
ABresult
0X0
100
111
1721 }
1722 37 my $shortcnt = my $xs_arg_cnt = $cnt;
1723 82 foreach my $x (@inargs[$cnt+1..$nmaxonstack-1]) {
1724 82 $cnt++;
1725 37 $name2cnts{$x} = [$cnt, undef];
1726 37 ▶ $name2cnts{$x}[1] = ++$shortcnt if !($out{$x} || $other_out{$x});
Branch: 1 branch
BranchTrueFalseTotal
unless $out{$x} or $other_out{$x} 5 5 10
Condition66%2/3
$out{$x} or $other_out{$x}
l!l&&r!l&&!r
505
MC/DC50%1/2
$out{$x} or $other_out{$x}
$out{$x} $other_out{$x}
Truth table66%2/3
A or B
A= $out{$x}B= $other_out{$x}
ABresult
1X1
011
000
1727 37 push @xsargs, "$x=$x";
1728 37 ▶ push @inputdecls, "$ptypes{$x}$x".($other{$x} && !exists $otherdefaults->{$x} ? "; { ".callTypemap($x, $ptypes{$x}, $name)."; }" : "=NO_INIT");
Branch: 1 branch
BranchTrueFalseTotal
$other{$x} && !exists $otherdefaults->{$x} ? : 4 6 10
Condition100%3/3
$other{$x} and not exists $otherdefaults->{$x}
!ll&&!rl&&r
514
MC/DC100%2/2
$other{$x} and not exists $otherdefaults->{$x}
$other{$x} not exists $otherdefaults->{$x}
Truth table100%3/3
A and not(B)
A= $other{$x}B= not exists $otherdefaults->{$x}
ABresult
0X0
100
111
1729 }
1730 37 push @inputdecls, map "$ptypes{$_}$_=".callPerlInit($_."_SV").";", grep $outca{$_}, @args;
1731 37 ▶ my $defaults_rawcond = $ndefault ? "items == $nin_minus_default" : '';
Branch: 1 branch
BranchTrueFalseTotal
$ndefault ? : 1 36 37
1732 my $svdecls = join '', map "\n $_",
1733 (map "SV *${_}_SV = ".(
1734 !$name2cnts{$_} ? 'NULL' :
1735 ($argorder || (defined $otherdefaults->{$_} && !$nout)) ? "items > $name2cnts{$_}[1] ? ST($name2cnts{$_}[1]) : ".($other_out{$_} ? "sv_newmortal()" : "NULL") :
1736 $name2cnts{$_}[0] == ($name2cnts{$_}[1]//-1) ? "ST($name2cnts{$_}[0])" :
1737 "(items == $nmaxonstack) ? ST($name2cnts{$_}[0]) : ".
1738 (!defined $name2cnts{$_}[1] ? ($other_out{$_} ? "sv_newmortal()" : "NULL") :
1739 defined $otherdefaults->{$_} ? "!($defaults_rawcond) ? ST($name2cnts{$_}[1]) : ".($other_out{$_} ? "sv_newmortal()" : "NULL") :
1740 "ST($name2cnts{$_}[1])"
1741 )
1742 37 ▶ ).";", (grep !$already_read{$_}, $sig->names_in), $sig->names_out, @{$sig->othernames(1, 1, \%already_read)}),
Branch: 8 branches
BranchTrueFalseTotal
!$name2cnts{$_} ? : 1 32 33
$argorder || defined $otherdefaults->{$_} && !$nout ? : 22 10 32
$other_out{$_} ? : 0 22 22
$name2cnts{$_}[0] == ($name2cnts{$_}[1] // -1) ? : 0 10 10
!defined($name2cnts{$_}[1]) ? : 5 5 10
$other_out{$_} ? : 0 5 5
defined $otherdefaults->{$_} ? : 1 4 5
$other_out{$_} ? : 0 1 1
Condition75%6/8
$argorder or defined $otherdefaults->{$_} and not $nout
l!l&&r!l&&!r
22010
defined $otherdefaults->{$_} and not $nout
!ll&&!rl&&r
910
$name2cnts{$_}[1] // -1
l!l
55
MC/DC33%1/3
$argorder or defined $otherdefaults->{$_} and not $nout
$argorder defined $otherdefaults->{$_} not $nout
MC/DC100%1/1
$name2cnts{$_}[1] // -1
$name2cnts{$_}[1]
Truth table75%3/4
A or B and not(C)
A= $argorderB= defined $otherdefaults->{$_}C= not $nout
ABCresult
1XX1
0111
00X0
0100
Truth table100%2/2
A
A= $name2cnts{$_}[1]
Aresult
11
00
1743 ;
1744 my $argcode =
1745 indent(2, join '',
1746 (map
1747 "if (!${_}_SV) { $_ = ($otherdefaults->{$_}); } else ".
1748 "{ ".callTypemap($_, $ptypes{$_}, $name)."; }\n",
1749 0 ▶ grep !$argorder && exists $otherdefaults->{$_}, @{$sig->othernames(1, 1)}),
Branch: 1 branch
BranchTrueFalseTotal
$argorder ? : 0 5 5
Condition66%6/9
$out{$_} && !$already_read{$_} && !($inplace && $_ eq $inplace->[1])
!ll&&!rl&&r
7805
$out{$_} and not $already_read{$_}
!ll&&!rl&&r
56225
$inplace && $_ eq $inplace->[1]
!ll&&!rl&&r
500
MC/DC50%2/4
$out{$_} && !$already_read{$_} && !($inplace && $_ eq $inplace->[1])
$out{$_} not $already_read{$_} $inplace $_ eq $inplace->[1]
Truth table60%3/5
A and not(B) && not(C && D)
A= $out{$_}B= not $already_read{$_}C= $inplaceD= $_ eq $inplace->[1]
ABCDresult
0XXX0
10XX0
11110
110X1
11101
1750 (map callTypemap($_, $ptypes{$_}, $name).";\n", grep !$already_read{$_}, $sig->names_in),
1751 0 ▶ (map +("if (${_}_SV) { ".($argorder ? '' : callTypemap($_, $ptypes{$_}, $name))."; } else ")."$_ = ".callPerlInit($_."_SV").";\n", grep $out{$_} && !$already_read{$_} && !($inplace && $_ eq $inplace->[1]), @args)
Condition100%3/3
!$argorder && exists $otherdefaults->{$_}
!ll&&!rl&&r
261
MC/DC100%2/2
!$argorder && exists $otherdefaults->{$_}
!$argorder exists $otherdefaults->{$_}
Truth table100%3/3
not(A) && B
A= !$argorderB= exists $otherdefaults->{$_}
ABresult
0X0
100
111
1752 );
1753 37 ▶ push @preinit, qq[PDL_XS_PREAMBLE($nretval);] if $nallout;
Branch: 1 branch
BranchTrueFalseTotal
if $nallout 25 12 37
1754 37 ▶ push @preinit, qq{if (!(@{[join ' || ', map "(items == $_)", sort keys %valid_itemcounts]}))
Branch: 1 branch
BranchTrueFalseTotal
unless $only_one or $argorder or $nmaxonstack == keys(%valid_itemcounts) + $xs_arg_cnt 4 33 37
Condition83%5/6
$only_one or $argorder or $nmaxonstack == keys(%valid_itemcounts) + $xs_arg_cnt
l!l&&r!l&&!r
3304
$only_one or $argorder
l!l&&r!l&&!r
13204
MC/DC66%2/3
$only_one or $argorder or $nmaxonstack == keys(%valid_itemcounts) + $xs_arg_cnt
$only_one $argorder $nmaxonstack == keys(%valid_itemcounts) + $xs_arg_cnt
Truth table75%3/4
A or B or C
A= $only_oneB= $argorderC= $nmaxonstack == keys(%valid_itemcounts) + $xs_arg_cnt
ABCresult
1XX1
01X1
0011
0000
1755 croak("Usage: ${main::PDLOBJ}::$name(@{[
1756 join ",", map exists $otherdefaults->{$_} ? "$_=$otherdefaults->{$_}" :
1757 37 ▶ $out{$_} || $other_out{$_} ? "[$_]" : $_, @inargs
Branch: 2 branches
BranchTrueFalseTotal
exists $otherdefaults->{$_} ? : 1 15 16
$out{$_} || $other_out{$_} ? : 5 10 15
Condition66%2/3
$out{$_} or $other_out{$_}
l!l&&r!l&&!r
5010
MC/DC50%1/2
$out{$_} or $other_out{$_}
$out{$_} $other_out{$_}
Truth table66%2/3
A or B
A= $out{$_}B= $other_out{$_}
ABresult
1X1
011
000
1758 ]}) (you may leave [outputs] and values with =defaults out of list)");}
1759 unless $only_one || $argorder || ($nmaxonstack == keys(%valid_itemcounts) + $xs_arg_cnt);
1760 37 ▶ my $preamble = @preinit ? qq[\n PREINIT:@{[join "\n ", "", @preinit]}\n INPUT:\n] : '';
Branch: 1 branch
BranchTrueFalseTotal
@preinit ? : 25 12 37
1761 37 join '', qq[
1762 \nvoid
1763 37 pdl_run_$name(@{[join ', ', @xsargs]})$svdecls
1764 37 $preamble@{[join "\n ", "", @inputdecls]}
1765 PPCODE:
1766 ], map "$_\n", $argcode;
1767 }),
1768  
1769 # globalnew implies internal usage, not XS
1770 PDL::PP::Rule::Returns->new("VarArgsXSReturn","GlobalNew",undef),
1771 PDL::PP::Rule->new("FixArgsXSOtherOutDeclSV",
1772 ["SignatureObj"],
1773 "Generate XS to declare SVs for output OtherPars",
1774 sub {
1775 37 ▶ my ($sig) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.7
1776 37 my $optypes = $sig->otherobjs;
1777 37 my @args = @{ $sig->allnames(1, 1) };
1778 37 my %outca = map +($_=>1), $sig->names_oca;
1779 37 my %other_output = map +($_=>1), my @other_output = ($sig->other_io, $sig->other_out);
1780 0 my $ci = 2;
1781 0 my $cnt = 0; my %outother2cnt;
1782 0 foreach my $x (grep !$outca{$_}, @args) {
1783 0 ▶ $outother2cnt{$x} = $cnt if $other_output{$x};
Branch: 1 branch
BranchTrueFalseTotal
if $other_output{$x} 0 82 82
1784 37 $cnt++;
1785 }
1786 37 join "\n", map indent($ci,qq{SV *${_}_SV = ST($outother2cnt{$_});}), @other_output;
1787 }),
1788 PDL::PP::Rule->new("XSOtherOutSet",
1789 [qw(Name SignatureObj)],
1790 "Generate XS to set SVs to output values for OtherPars",
1791 sub {
1792 37 ▶ my ($name, $sig) = @_;
Subroutine __ANON__: called CC=2 SCAR=8.1
1793 37 my $clause1 = '';
1794 37 my @other_output = ($sig->other_io, $sig->other_out);
1795 0 my $optypes = $sig->otherobjs;
1796 0 my %ptypes = map +($_=>$$optypes{$_}->get_decl('', {VarArrays2Ptrs=>1})), @other_output;
1797 0 for my $x (@other_output) {
1798 0 my ($setter, $type) = typemap($ptypes{$x}, 'get_outputmap');
1799 37 $setter = typemap_eval($setter, {var=>$x, type=>$type, arg=>"tsv",
1800 pname=>$name});
1801 37 $clause1 .= <<EOF;
1802 if (!${x}_SV)
1803 PDL->pdl_barf("Internal error in $name: tried to output to NULL ${x}_SV");
1804 {\n SV *tsv = sv_newmortal();
1805 $setter
1806 sv_setsv(${x}_SV, tsv);\n}
1807 EOF
1808 }
1809 37 indent(2, $clause1);
1810 }),
1811 PDL::PP::Rule->new("VarArgsXSReturn",
1812 ["SignatureObj"],
1813 "Generate XS trailer to return output variables or leave them as modified input variables",
1814 sub {
1815 37 ▶ my ($sig) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
1816 37 my $oc = my @outs = $sig->names_out; # output ndarrays in calling order
1817 7 my @other_outputs = ($sig->other_io, $sig->other_out); # output OtherPars
1818 7 my $clause1 = join ';', (map "ST($_) = $outs[$_]_SV", 0 .. $#outs),
1819 13 (map "ST(@{[$_+$oc]}) = $other_outputs[$_]_SV", 0 .. $#other_outputs);
1820 13 ▶ $clause1 ? indent(2,"PDL_XS_RETURN($clause1)\n") : '';
Branch: 1 branch
BranchTrueFalseTotal
$clause1 ? : 25 12 37
1821 }),
1822  
1823 PDL::PP::Rule->new("NewXSHdr", ["NewXSName","SignatureObj"],
1824 sub {
1825 12 ▶ my($name,$sig) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
1826 12 my $shortpars = join ',', @{ $sig->allnames(1, 1) };
1827 37 my $optypes = $sig->otherobjs;
1828 37 my @counts = map "PDL_Indx ${_}_count=0;", grep $optypes->{$_}->is_array, @{ $sig->othernames(1, 1) };
1829 37 my $longpars = join "\n", map " $_", @counts, $sig->alldecls(1, 0, 1);
1830 37 return<<END;
1831 \nvoid
1832 $name($shortpars)
1833 $longpars
1834 END
1835 }),
1836 PDL::PP::Rule::InsertName->new("RunFuncName", 'pdl_run_%s'),
1837 PDL::PP::Rule->new("NewXSCHdrs", ["RunFuncName","SignatureObj","GlobalNew"],
1838 sub {
1839 37 ▶ my($name,$sig,$gname) = @_;
Subroutine __ANON__: not called CC=1 SCAR=0.0
1840 11 my $longpars = join ",", $sig->alldecls(0, 1);
1841 2 my $opening = ' pdl_error PDL_err = {0, NULL, 0};';
1842 34 my $closing = ' return PDL_err;';
1843 34 return ["pdl_error $name($longpars) {$opening","$closing}",
1844 " PDL->$gname = $name;"];
1845 }),
1846 PDL::PP::Rule->new(["RunFuncCall","RunFuncHdr"],["RunFuncName","SignatureObj"], sub {
1847 34 ▶ my ($func_name,$sig) = @_;
Subroutine __ANON__: called CC=2 SCAR=8.4
1848 34 ▶ my $shortpars = join ',', map $sig->other_is_output($_)?"&$_":$_, @{ $sig->allnames(0) };
Branch: 1 branch
BranchTrueFalseTotal
$sig->other_is_output($_) ? : 0 83 83
1849 0 my $longpars = join ",", $sig->alldecls(0, 1);
1850 33 (indent(2,"PDL->barf_if_error($func_name($shortpars));\n"),
1851 "pdl_error $func_name($longpars)");
1852 }),
1853  
1854 PDL::PP::Rule->new("IgnoreTypesOf", ["FTypes","SignatureObj"], sub {
1855 34 ▶ my ($ftypes, $sig) = @_;
Subroutine __ANON__: not called CC=2 SCAR=6.9
1856 34 my ($pnames, $pobjs) = ($sig->names_sorted, $sig->objs);
1857 34 $_->{FlagIgnore} = 1 for grep $ftypes->{$_->{Name}}, @$pobjs{@$pnames};
1858 34 +{map +($_,1), keys %$ftypes};
1859 }),
1860 PDL::PP::Rule::Returns->new("IgnoreTypesOf", {}),
1861  
1862 PDL::PP::Rule->new("NewXSTypeCoerceNS", ["StructName"],
1863 0 ▶ sub { " PDL_RETERROR(PDL_err, PDL->type_coerce($_[0]));\n" }),
Subroutine __ANON__: called CC=1 SCAR=6.9
1864 PDL::PP::Rule::Substitute->new("NewXSTypeCoerceSubd", "NewXSTypeCoerceNS"),
1865  
1866 PDL::PP::Rule->new("NewXSRunTrans", ["StructName"], sub {
1867 0 ▶ my($trans) = @_;
Subroutine __ANON__: called CC=1 SCAR=1.2
1868 34 " PDL_RETERROR(PDL_err, PDL->make_trans_mutual($trans));\n";
1869 }),
1870  
1871 PDL::PP::Rule->new(["StructDecl","ParamStructType"],
1872 ["CompStruct","Name"],
1873 sub {
1874 34 ▶ my($comp,$name) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
1875 34 ▶ return ('', '') if !$comp;
Branch: 1 branch
BranchTrueFalseTotal
unless $comp 30 7 37
1876 34 my $ptype = "pdl_params_$name";
1877 34 (PDL::PP::pp_line_numbers(__LINE__-1, qq[typedef struct $ptype {\n]).qq[$comp\n} $ptype;],
1878 $ptype);
1879 }),
1880  
1881 do {
1882 sub wrap_vfn {
1883 my (
1884 34 ▶ $code,$rout,$func_header,
Subroutine wrap_vfn: called CC=2 SCAR=7.2
Pod undocumented
1885 $all_func_header,$sname,$pname,$ptype,$extra_args,
1886 ) = @_;
1887 0 ▶ join "", PDL::PP::pp_line_numbers(__LINE__,
Branch: 1 branch
BranchTrueFalseTotal
$ptype ? : 2 11 13
1888 qq[pdl_error $rout(pdl_trans *$sname$extra_args) {
1889 pdl_error PDL_err = {0, NULL, 0};]),
1890 ($ptype ? " $ptype *$pname = $sname->params; (void)$pname;\n" : ''),
1891 indent(2, join '', grep $_, $all_func_header, $func_header, $code),
1892 " return PDL_err;\n}";
1893 }
1894 sub make_vfn_args {
1895 0 ▶ my ($which, $extra_args) = @_;
Subroutine make_vfn_args: called CC=1 SCAR=0.2
Pod undocumented
1896 ("${which}Func",
1897 ["${which}CodeSubd","${which}FuncName","${which}FuncHeader?",
1898 qw(AllFuncHeader? StructName ParamStructName ParamStructType),
1899 ],
1900 9 ▶ sub {$_[1] eq 'NULL' ? '' : wrap_vfn(@_,$extra_args//'')}
Subroutine __ANON__: called CC=3 SCAR=11.2
Branch: 1 branch
BranchTrueFalseTotal
$_[1] eq 'NULL' ? : 65 13 78
Condition50%1/2
$extra_args // ""
l!l
013
MC/DC0%0/1
$extra_args // ""
$extra_args
Truth table50%1/2
A
A= $extra_args
Aresult
11
00
1901 34 );
1902 }
1903 49 ()},
1904  
1905 9 ▶ PDL::PP::Rule->new("MakeCompOther", [qw(SignatureObj ParamStructName)], sub { $_[0]->getcopy("$_[1]->%s") }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1906 9 ▶ PDL::PP::Rule->new("MakeCompTotal", [qw(MakeCompOther MakeComp?)], sub { join "\n", grep $_, @_ }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1907 PDL::PP::Rule::Substitute->new("MakeCompiledReprSubd", "MakeCompTotal"),
1908  
1909 PDL::PP::Rule->new("NewXSSetTransPDLs", ["SignatureObj","StructName"], sub {
1910 9 ▶ my($sig,$trans) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
1911 9 join '',
1912 map " $trans->pdls[$_->[0]] = $_->[2];\n",
1913 grep !$_->[1], $sig->names_sorted_tuples;
1914 }),
1915 PDL::PP::Rule->new("NewXSExtractTransPDLs", [qw(SignatureObj StructName MakeComp?)], sub {
1916 9 ▶ my($sig,$trans,$makecomp) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
1917 9 ▶ !$makecomp ? '' : join '',
Branch: 1 branch
BranchTrueFalseTotal
!$makecomp ? : 37 0 37
1918 map " $_->[2] = $trans->pdls[$_->[0]];\n",
1919 grep !$_->[1], $sig->names_sorted_tuples;
1920 }),
1921  
1922 (map PDL::PP::Rule::Substitute->new("${_}ReadDataCodeUnparsed", "${_}Code"), '', 'Bad'),
1923 PDL::PP::Rule->new(PDL::PP::Code::make_args(qw(ReadData)),
1924 9 ▶ sub { PDL::PP::Code->new(@_, undef, undef, 1); }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1925 PDL::PP::Rule::Substitute->new("ReadDataCodeSubd", "ReadDataCodeParsed"),
1926 PDL::PP::Rule::InsertName->new("ReadDataFuncName", 'pdl_%s_readdata'),
1927 PDL::PP::Rule->new(make_vfn_args("ReadData")),
1928  
1929 (map PDL::PP::Rule::Substitute->new("${_}WriteBackDataCodeUnparsed", "${_}BackCode"), '', 'Bad'),
1930 PDL::PP::Rule->new(PDL::PP::Code::make_args(qw(WriteBackData)),
1931 9 ▶ sub { PDL::PP::Code->new(@_, undef, 1, 1); }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1932 PDL::PP::Rule::Substitute->new("WriteBackDataCodeSubd", "WriteBackDataCodeParsed"),
1933 PDL::PP::Rule::InsertName->new("WriteBackDataFuncName", "BackCode", 'pdl_%s_writebackdata'),
1934 PDL::PP::Rule::Returns::NULL->new("WriteBackDataFuncName", "Code"),
1935 PDL::PP::Rule->new(make_vfn_args("WriteBackData")),
1936  
1937 # CORE21 move this into pdlapi so RedoDims without Code can broadcast
1938 PDL::PP::Rule->new("DefaultRedoDims",
1939 ["StructName"],
1940 9 ▶ sub { "PDL_RETERROR(PDL_err, PDL->redodims_default($_[0]));\n" }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1941 PDL::PP::Rule->new("DimsSetters",
1942 ["SignatureObj"],
1943 9 ▶ sub { $_[0]->dims_init }),
Subroutine __ANON__: called CC=1 SCAR=0.0
1944 PDL::PP::Rule->new("RedoDimsFuncName", [qw(Name RedoDims? RedoDimsCode? DimsSetters)],
1945 9 ▶ sub { (scalar grep $_ && /\S/, @_[1..$#_]) ? "pdl_$_[0]_redodims" : 'NULL'}),
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
scalar grep(($_ && /\S/), @_[1 .. $#_]) ? : 3 31 34
Condition66%2/3
$_ && /\S/
!ll&&!rl&&r
9903
MC/DC50%1/2
$_ && /\S/
$_ /\S/
Truth table66%2/3
A && B
A= $_B= /\S/
ABresult
0X0
100
111
1946 PDL::PP::Rule::Returns->new("RedoDimsCode", [],
1947 'Code that can be inserted to set the size of output ndarrays dynamically based on input ndarrays; is parsed',
1948 ''),
1949 (map PDL::PP::Rule::Substitute->new("RedoDims${_}Unparsed", "RedoDims$_"), '', 'Code'),
1950 PDL::PP::Rule->new(PDL::PP::Code::make_args(qw(RedoDims)),
1951 'makes the parsed representation from the supplied RedoDimsCode',
1952 9 ▶ sub { return '' if !$_[0]; PDL::PP::Code->new(@_, 1, undef, 0); }),
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 34 0 34
1953 16 ▶ PDL::PP::Rule->new("RedoDimsCodeParsed","RedoDimsUnparsed", sub {@_}),
Subroutine __ANON__: not called CC=1 SCAR=0.0
1954 PDL::PP::Rule->new("RedoDims",
1955 ["DimsSetters","RedoDimsCodeParsed","DefaultRedoDims"],
1956 'makes the redodims function from the various bits and pieces',
1957 9 ▶ sub { join "\n", grep $_ && /\S/, @_ }),
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition66%2/3
$_ && /\S/
!ll&&!rl&&r
64035
MC/DC50%1/2
$_ && /\S/
$_ /\S/
Truth table66%2/3
A && B
A= $_B= /\S/
ABresult
0X0
100
111
1958 PDL::PP::Rule::Substitute->new("RedoDimsCodeSubd", "RedoDims"),
1959 PDL::PP::Rule->new(make_vfn_args("RedoDims")),
1960  
1961 PDL::PP::Rule->new("CompFreeCode", [qw(CompObj CompFreeCodeComp?)],
1962 "Free any OtherPars/Comp stuff, including user-supplied code (which is probably paired with own MakeComp)",
1963 9 ▶ sub {join '', grep defined() && length, $_[0]->getfree("COMP"), @_[1..$#_]},
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
34340
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1964 ),
1965 9 ▶ PDL::PP::Rule->new("NTPrivFreeCode", "PrivObj", sub {$_[0]->getfree("PRIV")}),
Subroutine __ANON__: called CC=1 SCAR=0.0
1966 PDL::PP::Rule->new("FreeCodeNS",
1967 ["StructName","CompFreeCode","NTPrivFreeCode"],
1968 sub {
1969 9 ▶ (grep $_, @_[1..$#_]) ? "PDL_FREE_CODE($_[0], destroy, $_[1], $_[2])" : ''}),
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
grep($_, @_[1 .. $#_]) ? : 0 34 34
1970 PDL::PP::Rule::Substitute->new("FreeCodeSubd", "FreeCodeNS"),
1971 PDL::PP::Rule->new("FreeFuncName",
1972 ["FreeCodeSubd","Name"],
1973 9 ▶ sub {$_[0] ? "pdl_$_[1]_free" : 'NULL'}),
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 34 34
1974 PDL::PP::Rule->new(make_vfn_args("Free", ", char destroy")),
1975  
1976 PDL::PP::Rule->new("NewXSCoerceMustNS", "FTypes",
1977 sub {
1978 9 ▶ my($ftypes) = @_;
Subroutine __ANON__: not called CC=1 SCAR=0.0
1979 16 join '', map
1980 PDL::PP::pp_line_numbers(__LINE__, "$_->datatype = $ftypes->{$_};"),
1981 sort keys %$ftypes;
1982 }),
1983 PDL::PP::Rule::Returns::EmptyString->new("NewXSCoerceMustNS"),
1984 PDL::PP::Rule::Substitute->new("NewXSCoerceMustCompSubd", "NewXSCoerceMustNS"),
1985  
1986 PDL::PP::Rule->new("NewXSStructInit0",
1987 ["StructName","VTableName","ParamStructName","ParamStructType"],
1988 "Rule to create and initialise the private trans structure",
1989 sub {
1990 16 ▶ my( $sname, $vtable, $pname, $ptype ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
1991 16 ▶ indent(2, <<EOF . ($ptype ? "$ptype *$pname = $sname->params;\n" : ""));
Branch: 1 branch
BranchTrueFalseTotal
$ptype ? : 7 27 34
1992 if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
1993 pdl_trans *$sname = PDL->create_trans(&$vtable);
1994 if (!$sname) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
1995 EOF
1996 }),
1997  
1998 PDL::PP::Rule->new(["RunFunc"],
1999 ["RunFuncHdr",
2000 "NewXSStructInit0",
2001 "NewXSSetTransPDLs",
2002 "NewXSTypeCoerceSubd",
2003 "NewXSExtractTransPDLs",
2004 "MakeCompiledReprSubd",
2005 "NewXSCoerceMustCompSubd",
2006 "NewXSRunTrans",
2007 ],
2008 "Generate C function with idiomatic arg list to maybe call from XS",
2009 sub {
2010 9 ▶ my ($xs_c_header, @bits) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
2011 9 my $opening = ' pdl_error PDL_err = {0, NULL, 0};';
2012 16 my $closing = ' return PDL_err;';
2013 9 join '', "$xs_c_header {\n$opening\n", @bits, "$closing\n}\n";
2014 }),
2015  
2016 # internal usage, not XS - NewXSCHdrs only set if GlobalNew
2017 PDL::PP::Rule->new(["NewXSCode","BootSetNewXS","NewXSInPrelude"],
2018 ["NewXSHdr", "NewXSCHdrs", "RunFuncCall"],
2019 "Non-varargs XS code when GlobalNew given",
2020 9 ▶ sub {(undef,(make_xs_code(' CODE:','',@_))[1..2])}),
Subroutine __ANON__: not called CC=1 SCAR=0.0
2021 # if PMCode supplied, no var-args stuff
2022 PDL::PP::Rule->new(["NewXSCode","BootSetNewXS","NewXSInPrelude"],
2023 [qw(PMCode NewXSHdr NewXSCHdrs? FixArgsXSOtherOutDeclSV HdrCode RunFuncCall FtrCode XSOtherOutSet)],
2024 "Non-varargs XS code when PMCode given",
2025 9 ▶ sub {make_xs_code(' CODE:','',@_[1..$#_])}),
Subroutine __ANON__: not called CC=1 SCAR=0.0
2026 PDL::PP::Rule->new(["NewXSCode","BootSetNewXS","NewXSInPrelude"],
2027 [qw(VarArgsXSHdr NewXSCHdrs? HdrCode InplaceCode RunFuncCall FtrCode XSOtherOutSet VarArgsXSReturn)],
2028 "Rule to print out XS code when variable argument list XS processing is enabled",
2029 9 ▶ sub {make_xs_code('','',@_)}),
Subroutine __ANON__: called CC=1 SCAR=0.0
2030  
2031 PDL::PP::Rule->new("VTableDef",
2032 [qw(VTableName ParamStructType
2033 RedoDimsFuncName ReadDataFuncName WriteBackDataFuncName FreeFuncName
2034 SignatureObj HaveBroadcasting NoPthread Name
2035 GenericTypes IsAffineFlag DefaultFlowFlag
2036 BadFlag)],
2037 sub {
2038 9 ▶ my($vname,$ptype,$rdname,$rfname,$wfname,$ffname,
Subroutine __ANON__: called CC=19 SCAR=29.7
2039 $sig,$havebroadcasting, $noPthreadFlag, $name, $gentypes,
2040 $affflag, $flowflag, $badflag) = @_;
2041 9 my ($pnames, $pobjs) = ($sig->names_sorted, $sig->objs);
2042 9 my $nparents = 0 + grep !$pobjs->{$_}->{FlagW}, @$pnames;
2043 34 my $npdls = scalar @$pnames;
2044 34 my @op_flags;
2045 34 ▶ push @op_flags, 'PDL_TRANS_DO_BROADCAST' if $havebroadcasting;
Branch: 1 branch
BranchTrueFalseTotal
if $havebroadcasting 8 1 9
2046 34 ▶ push @op_flags, 'PDL_TRANS_BADPROCESS' if $badflag;
Branch: 1 branch
BranchTrueFalseTotal
if $badflag 1 8 9
2047 34 ▶ push @op_flags, 'PDL_TRANS_BADIGNORE' if defined $badflag and !$badflag;
Branch: 1 branch
BranchTrueFalseTotal
if defined $badflag and not $badflag 0 9 9
Condition66%2/3
defined $badflag and not $badflag
!ll&&!rl&&r
810
MC/DC0%0/2
defined $badflag and not $badflag
defined $badflag not $badflag
Truth table66%2/3
A and not(B)
A= defined $badflagB= not $badflag
ABresult
0X0
100
111
2048 3 ▶ push @op_flags, 'PDL_TRANS_NO_PARALLEL' if $noPthreadFlag;
Branch: 1 branch
BranchTrueFalseTotal
if $noPthreadFlag 0 9 9
2049 3 ▶ push @op_flags, 'PDL_TRANS_OUTPUT_OTHERPAR' if $sig->other_any_out;
Branch: 1 branch
BranchTrueFalseTotal
if $sig->other_any_out 0 9 9
2050 3 ▶ my $op_flags = join('|', @op_flags) || '0';
Condition50%1/2
join('|', @op_flags) || '0'
l!l
90
MC/DC0%0/1
join('|', @op_flags) || '0'
join('|', @op_flags)
Truth table50%1/2
A
A= join('|', @op_flags)
Aresult
11
00
2051 3 ▶ my $iflags = join('|', grep $_, $affflag, $flowflag) || '0';
Condition100%2/2
join('|', grep($_, $affflag, $flowflag)) || '0'
l!l
27
MC/DC100%1/1
join('|', grep($_, $affflag, $flowflag)) || '0'
join('|', grep($_, $affflag, $flowflag))
Truth table100%2/2
A
A= join('|', grep($_, $affflag, $flowflag))
Aresult
11
00
2052 3 my $gentypes_txt = join(", ", (map PDL::Type->new($_)->sym, @$gentypes), '-1');
2053 3 my @realdims = map 0+@{$_->{IndObjs}}, @$pobjs{@$pnames};
2054 3 ▶ my $realdims = join(", ", @realdims) || '0';
Condition50%1/2
join(', ', @realdims) || '0'
l!l
90
MC/DC0%0/1
join(', ', @realdims) || '0'
join(', ', @realdims)
Truth table50%1/2
A
A= join(', ', @realdims)
Aresult
11
00
2055 3 ▶ my $parnames = join(",",map qq|"$_"|, @$pnames) || '""';
Condition50%1/2
join(',', map((qq["$_"]), @$pnames)) || '""'
l!l
90
MC/DC0%0/1
join(',', map((qq["$_"]), @$pnames)) || '""'
join(',', map((qq["$_"]), @$pnames))
Truth table50%1/2
A
A= join(',', map((qq["$_"]), @$pnames))
Aresult
11
00
2056 3 ▶ my $parflags = join(",\n ",map join('|', $_->cflags)||'0', @$pobjs{@$pnames}) || '0';
Condition100%4/4
join(",\n ", map((join('|', $_->cflags) || '0'), @$pobjs{@$pnames})) || '0'
l!l
72
join('|', $_->cflags) || '0'
l!l
97
MC/DC100%1/1
join(",\n ", map((join('|', $_->cflags) || '0'), @$pobjs{@$pnames})) || '0'
join(",\n ", map((join('|', $_->cflags) || '0'), @$pobjs{@$pnames}))
MC/DC100%1/1
join('|', $_->cflags) || '0'
join('|', $_->cflags)
Truth table100%2/2
A
A= join(",\n ", map((join('|', $_->cflags) || '0'), @$pobjs{@$pnames}))
Aresult
11
00
Truth table100%2/2
A
A= join('|', $_->cflags)
Aresult
11
00
2057 3 ▶ my $partypes = join(", ", map defined()?$_->sym:-1, map $_->{Type}, @$pobjs{@$pnames}) || '-1';
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 2 14 16
Condition50%1/2
join(', ', map((defined $_ ? $_->sym : -1), map($_->{'Type'}, @$pobjs{@$pnames}))) || '-1'
l!l
90
MC/DC0%0/1
join(', ', map((defined $_ ? $_->sym : -1), map($_->{'Type'}, @$pobjs{@$pnames}))) || '-1'
join(', ', map((defined $_ ? $_->sym : -1), map($_->{'Type'}, @$pobjs{@$pnames})))
Truth table50%1/2
A
A= join(', ', map((defined $_ ? $_->sym : -1), map($_->{'Type'}, @$pobjs{@$pnames})))
Aresult
11
00
2058 3 my $i = 0; my @starts = map { my $ci = $i; $i += $_; $ci } @realdims;
2059 3 ▶ my $realdim_ind_start = join(", ", @starts) || '0';
Condition100%2/2
join(', ', @starts) || '0'
l!l
72
MC/DC100%1/1
join(', ', @starts) || '0'
join(', ', @starts)
Truth table100%2/2
A
A= join(', ', @starts)
Aresult
11
00
2060 3 my @rd_inds = map $_->get_index, map @{$_->{IndObjs}}, @$pobjs{@$pnames};
2061 3 ▶ my $realdim_inds = join(", ", @rd_inds) || '0';
Condition100%2/2
join(', ', @rd_inds) || '0'
l!l
54
MC/DC100%1/1
join(', ', @rd_inds) || '0'
join(', ', @rd_inds)
Truth table100%2/2
A
A= join(', ', @rd_inds)
Aresult
11
00
2062 3 my @indnames = sort $sig->dims_obj->ind_names;
2063 3 ▶ my $indnames = join(",", map qq|"$_"|, @indnames) || '""';
Condition100%2/2
join(',', map((qq["$_"]), @indnames)) || '""'
l!l
72
MC/DC100%1/1
join(',', map((qq["$_"]), @indnames)) || '""'
join(',', map((qq["$_"]), @indnames))
Truth table100%2/2
A
A= join(',', map((qq["$_"]), @indnames))
Aresult
11
00
2064 3 ▶ my $sizeof = $ptype ? "sizeof($ptype)" : '0';
Branch: 1 branch
BranchTrueFalseTotal
$ptype ? : 1 8 9
2065 3 <<EOF;
2066 static pdl_datatypes ${vname}_gentypes[] = { $gentypes_txt };
2067 static PDL_Indx ${vname}_realdims[] = { $realdims };
2068 static char *${vname}_parnames[] = { $parnames };
2069 static short ${vname}_parflags[] = {
2070 $parflags
2071 };
2072 static pdl_datatypes ${vname}_partypes[] = { $partypes };
2073 static PDL_Indx ${vname}_realdims_starts[] = { $realdim_ind_start };
2074 static PDL_Indx ${vname}_realdims_ind_ids[] = { $realdim_inds };
2075 static char *${vname}_indnames[] = { $indnames };
2076 pdl_transvtable $vname = {
2077 $op_flags, $iflags, ${vname}_gentypes, $nparents, $npdls, NULL /*CORE21*/,
2078 ${vname}_realdims, ${vname}_parnames,
2079 ${vname}_parflags, ${vname}_partypes,
2080 3 ${vname}_realdims_starts, ${vname}_realdims_ind_ids, @{[scalar @rd_inds]},
2081 @{[scalar @indnames]}, ${vname}_indnames,
2082 $rdname, $rfname, $wfname,
2083 $ffname,
2084 $sizeof,"$::PDLMOD\::$name"
2085 };
2086 EOF
2087 }),
2088  
2089 PDL::PP::Rule->new('PMFunc', [qw(Name Synonyms)],
2090 'Sets PMFunc to default symbol table manipulations',
2091 sub {
2092 ▶ my ($name, $synonyms) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
2093 ▶ join '', $::PDL_IFBEGINWRAP[0],
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $name ? : 34 1 35
2094 (map +($_ eq $name ? '' : "*$::PDLOBJ\::$_ = ").
2095 "*$_ = \\&$::PDLOBJ\::$name;\n", $name, @$synonyms),
2096 $::PDL_IFBEGINWRAP[1]
2097 }
2098 ),
2099  
2100 PDL::PP::Rule->new([], [qw(Lvalue Name)],
2101 'If Lvalue key, make the XS routine be lvalue with CvLVALUE_on',
2102 sub {
2103 ▶ my ($lvalue, $name) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
2104 ▶ push @::PDL_LVALUE_SUBS, $name if $lvalue;
Branch: 1 branch
BranchTrueFalseTotal
if $lvalue 3 31 34
2105 ();
2106 }
2107 1 ),
2108  
2109 ];
2110 }
2111  
2112 1;
« blib/lib/PDL/Reduce.pm ↑ Summary lib/PDL/Primitive.pd »