blib/lib/PMLTQ/BtredEvaluator.pm

filter: Statementstmt 4.3% 66 / 1532 Branchbran 0.0% 0 / 1086 Conditioncond 0.0% 0 / 725 MC/DCmcdc 0.0% 0 / 416 Subroutinesub 22.3% 17 / 76 Podpod 0.0% 0 / 41 totaltotal 2.1% 83 / 3876 CC 817 SCAR 98.1
CC
817
Cov
2%
serialize_expression_pt
55460.0
serialize_element
15252.0
serialize_filter
6812.5
CRAP 18266.6
« blib/lib/PMLTQ/SQLEvaluator.pm ↑ Summary blib/lib/PMLTQ/_Parser.pm »
1 package PMLTQ::BtredEvaluator;
2 1 our $AUTHORITY = 'cpan:MATY';
3 1 $PMLTQ::BtredEvaluator::VERSION = '1.2.2';
4 # ABSTRACT: Pure perl evaluator of PML-TQ queries based on headless implementation of TrEd called Btred
5  
6 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Treex::PML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Treex::PML::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use POSIX qw(ceil floor);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use PMLTQ::Relation;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use UNIVERSAL::DOES;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use PMLTQ::Common qw(:constants first min max uniq ListV AltV SeqV compute_column_data_type compute_expression_data_type compute_expression_data_type_pt);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 our $STOP;
21 1 our $PROGRESS;
22 1 our $DEBUG = $ENV{PMLTQ_DEBUG};
23 1 our $DEBUGGER = $ENV{IN_DEBUGGER}; # set when using a debugger, this will save subroutines as files
24 1 our $ALL_SUBQUERIES_LAST=0;
25  
26 1 PMLTQ::Relation->load();
27  
28 sub round {
29 0 ▶ my ($num, $digits)=@_;
Subroutine round: not called CC=1 SCAR=6.9
Pod undocumented
30 0 $digits = int $digits;
31 0 return sprintf("%.${digits}f", $num);
32 }
33 sub trunc {
34 0 ▶ my ($self, $num, $digits) = @_;
Subroutine trunc: not called CC=2 SCAR=17.9
Pod undocumented
35 0 $digits = int $digits;
36 0 my $decimalscale = 10**abs($digits);
37 0 ▶ if ($digits >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($digits >= 0) { } 0 0 0
38 0 return int($num * $decimalscale) / $decimalscale;
39 } else {
40 0 return int($num / $decimalscale) * $decimalscale;
41 }
42 }
43  
44 1 my %test_relation = (
45 'parent' => q($start->parent == $end),
46 'child' => q($end->parent == $start),
47 'same-tree-as' => q($start->root==$end->root), # not very efficient !!
48 'same-document-as' => q(1), # FIXME: not correct !!
49 );
50  
51 sub _compute_bounds {
52 0 ▶ my ($direction, $min, $max) = @_;
Subroutine _compute_bounds: not called CC=15 SCAR=54.8
53 0 my ($lmin,$lmax,$rmin,$rmax);
54  
55 # return no bounds if the bounds are the default bounds:
56 # none, {1,}, or {0,} (which also means {1,})
57 0 ▶ return if !defined($max) and (!defined($min) or $min==0 or $min==1);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max and !defined($min) || $min == 0 || $min == 1 0 0 0
Condition0%0/9
not defined $max and !defined($min) || $min == 0 || $min == 1
!ll&&!rl&&r
000
not defined $min or $min == 0 or $min == 1
l!l&&r!l&&!r
000
not defined $min or $min == 0
l!l&&r!l&&!r
000
MC/DC0%0/4
not defined $max and !defined($min) || $min == 0 || $min == 1
not defined $max not defined $min $min == 0 $min == 1
Truth table0%0/5
not(A) and not(B) or C or D
A= not defined $maxB= not defined $minC= $min == 0D= $min == 1
ABCDresult
0XXX0
10000
11XX1
101X1
10011
58  
59 0 ▶ $min = 1 if !defined($min);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 0 0 0
60 0 ▶ if ($min<0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min < 0) 0 0 0
61 0 ▶ $lmin = (defined($max) and ($max<0)) ? $max : -1;
Branch: 1 branch
BranchTrueFalseTotal
defined $max && $max < 0 ? : 0 0 0
Condition0%0/3
defined $max and $max < 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max and $max < 0
defined $max $max < 0
Truth table0%0/3
A and B
A= defined $maxB= $max < 0
ABresult
0X0
100
111
62 0 $lmax = $min;
63 }
64 0 ▶ if (!defined($max) or $max>0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $max or $max > 0) 0 0 0
Condition0%0/3
not defined $max or $max > 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $max or $max > 0
not defined $max $max > 0
Truth table0%0/3
not(A) or B
A= not defined $maxB= $max > 0
ABresult
1X1
011
000
65 0 ▶ $rmin = (defined($min) and ($min>0)) ? $min : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $min && $min > 0 ? : 0 0 0
Condition0%0/3
defined $min and $min > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and $min > 0
defined $min $min > 0
Truth table0%0/3
A and B
A= defined $minB= $min > 0
ABresult
0X0
100
111
66 0 $rmax = $max;
67 }
68 0 ▶ if ($direction>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction > 0) { } 0 0 0
69 0 return ($lmin,$lmax,$rmin,$rmax);
70 } else {
71 # swap left and right and change signs
72 return map {
73 0 ▶ defined($_) ? -$_ : undef
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
74 } ($rmin,$rmax, $lmin,$lmax);
75 }
76 }
77  
78 sub test_depth_first_order {
79 0 ▶ my ($start,$end,$dir,$lmin,$lmax,$rmin,$rmax)=@_;
Subroutine test_depth_first_order: not called CC=46 SCAR=76.8
Pod undocumented
80  
81 # see DepthFirstRangeIterator for interpretation of bounds
82  
83 # we first find a nearest common ancestor and check the
84 # nodes belong to the same tree
85  
86 # compute roots and level for each node
87 0 ▶ my $with_bounds = (defined($rmin) or defined($lmin)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $rmin || defined $lmin ? : 0 0 0
Condition0%0/3
defined $rmin or defined $lmin
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $rmin or defined $lmin
defined $rmin defined $lmin
Truth table0%0/3
A or B
A= defined $rminB= defined $lmin
ABresult
1X1
011
000
88  
89 0 my ($sl,$el)=(0,0);
90 0 my ($sr,$er)=($start,$end);
91 0 my $aux;
92 0 ▶ while ($aux = $sr->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux = $sr->parent) 0 0 0
93 0 $sr=$aux; $sl++;
94 }
95 0 ▶ while ($aux = $er->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux = $er->parent) 0 0 0
96 0 $er=$aux; $el++;
97 }
98 0 ▶ return 0 if $sr != $er;
Branch: 1 branch
BranchTrueFalseTotal
if $sr != $er 0 0 0
99 0 ▶ return 0 if $start == $end;
Branch: 1 branch
BranchTrueFalseTotal
if $start == $end 0 0 0
100  
101 # make the nodes be on the same level
102 0 ($sr,$er)=($start,$end);
103 0 ▶ if ($sl > $el) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sl > $el) { } 0 0 0
elsif ($el > $sl) { } 0 0 0
104 0 ▶ do { $sr=$sr->parent; } while --$sl > $el;
Branch: 1 branch
BranchTrueFalseTotal
--$sl > $el and do { do { $sr = $sr->parent } } 0 0 0
105 } elsif ($el > $sl) {
106 0 ▶ do { $er=$er->parent; } while --$el > $sl;
Branch: 1 branch
BranchTrueFalseTotal
--$el > $sl and do { do { $er = $er->parent } } 0 0 0
107 }
108  
109 0 my $dist = 0;
110  
111 # move the nodes up until their parent is their nearest common ancestor
112 0 ▶ while ($sr->parent != $er->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sr->parent != $er->parent) 0 0 0
113 0 $sr = $sr->parent;
114 0 $er = $er->parent;
115 0 $dist++;
116 }
117  
118 # now at least dist levels must be travelled downwards
119 # before we reach one of the nodes from the other
120 # still, both maximum bounds must be violated
121 0 ▶ if ($with_bounds) { # early check
Branch: 1 branch
BranchTrueFalseTotal
if ($with_bounds) 0 0 0
122 0 ▶ if ((!defined($rmin) or defined($rmax) and $dist>$rmax)
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($rmin) || defined $rmax && $dist > $rmax and !defined($lmin) || defined $lmax && $dist > -$lmax) 0 0 0
Condition0%0/15
!defined($rmin) || defined $rmax && $dist > $rmax and !defined($lmin) || defined $lmax && $dist > -$lmax
!ll&&!rl&&r
000
not defined $rmin or defined $rmax and $dist > $rmax
l!l&&r!l&&!r
000
defined $rmax and $dist > $rmax
!ll&&!rl&&r
000
not defined $lmin or defined $lmax and $dist > -$lmax
l!l&&r!l&&!r
000
defined $lmax and $dist > -$lmax
!ll&&!rl&&r
000
MC/DC0%0/6
!defined($rmin) || defined $rmax && $dist > $rmax and !defined($lmin) || defined $lmax && $dist > -$lmax
not defined $rmin defined $rmax $dist > $rmax not defined $lmin defined $lmax $dist > -$lmax
Truth table0%0/10
not(A) or B and C and not(D) or E and F
A= not defined $rminB= defined $rmaxC= $dist > $rmaxD= not defined $lminE= defined $lmaxF= $dist > -$lmax
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
123 and
124 (!defined($lmin) or defined($lmax) and $dist>-$lmax)) {
125 0 return 0;
126 }
127 }
128  
129 # check if $start precedes $end as a sibling
130 0 ▶ if ($dir>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir > 0) { } 0 0 0
131 0 ▶ while ($sr and $sr!=$er) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sr and $sr != $er) 0 0 0
Condition0%0/3
$sr and $sr != $er
!ll&&!rl&&r
000
MC/DC0%0/2
$sr and $sr != $er
$sr $sr != $er
Truth table0%0/3
A and B
A= $srB= $sr != $er
ABresult
0X0
100
111
132 0 $sr = $sr->rbrother;
133 0 $dist++;
134 }
135 } else {
136 0 ▶ while ($sr and $sr!=$er) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sr and $sr != $er) 0 0 0
Condition0%0/3
$sr and $sr != $er
!ll&&!rl&&r
000
MC/DC0%0/2
$sr and $sr != $er
$sr $sr != $er
Truth table0%0/3
A and B
A= $srB= $sr != $er
ABresult
0X0
100
111
137 0 $sr = $sr->lbrother;
138 0 $dist++;
139 }
140 }
141  
142 0 ▶ if (!$with_bounds) { # we are done
Branch: 1 branch
BranchTrueFalseTotal
if (not $with_bounds) { } 0 0 0
143 0 ▶ return $sr ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sr ? : 0 0 0
144 } else {
145 # early check
146 0 ▶ if ((!defined($rmin) or defined($rmax) and $dist>$rmax)
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($rmin) || defined $rmax && $dist > $rmax and !defined($lmin) || defined $lmax && $dist > -$lmax) 0 0 0
Condition0%0/15
!defined($rmin) || defined $rmax && $dist > $rmax and !defined($lmin) || defined $lmax && $dist > -$lmax
!ll&&!rl&&r
000
not defined $rmin or defined $rmax and $dist > $rmax
l!l&&r!l&&!r
000
defined $rmax and $dist > $rmax
!ll&&!rl&&r
000
not defined $lmin or defined $lmax and $dist > -$lmax
l!l&&r!l&&!r
000
defined $lmax and $dist > -$lmax
!ll&&!rl&&r
000
MC/DC0%0/6
!defined($rmin) || defined $rmax && $dist > $rmax and !defined($lmin) || defined $lmax && $dist > -$lmax
not defined $rmin defined $rmax $dist > $rmax not defined $lmin defined $lmax $dist > -$lmax
Truth table0%0/10
not(A) or B and C and not(D) or E and F
A= not defined $rminB= defined $rmaxC= $dist > $rmaxD= not defined $lminE= defined $lmaxF= $dist > -$lmax
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
147 and
148 (!defined($lmin) or defined($lmax) and $dist>-$lmax)) {
149 0 return 0;
150 }
151 0 ▶ if (($dir>0) xor !$sr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir > 0 xor not $sr) { } 0 0 0
Condition0%0/4
$dir > 0 xor not $sr
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$dir > 0 xor not $sr
$dir > 0 not $sr
Truth table0%0/4
A xor not(B)
A= $dir > 0B= not $sr
ABresult
110
101
011
000
152 0 ▶ return 0 unless defined $rmin; # no right range, but $end is right of $start
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rmin 0 0 0
153 0 $dist = 0;
154 0 $aux = $start;
155 0 ▶ while ($aux) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux) 0 0 0
156 0 $aux= $aux->following;
157 0 $dist++;
158 0 ▶ return 0 if defined($rmax) and $dist>$rmax;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rmax and $dist > $rmax 0 0 0
Condition0%0/3
defined $rmax and $dist > $rmax
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rmax and $dist > $rmax
defined $rmax $dist > $rmax
Truth table0%0/3
A and B
A= defined $rmaxB= $dist > $rmax
ABresult
0X0
100
111
159 0 ▶ if ($aux == $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux == $end) 0 0 0
160 0 ▶ return (($dist>=$rmin) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$dist >= $rmin ? : 0 0 0
161 }
162 }
163 0 warn("test_depth_first_precedes: This should never happen: expected end node on the following axes, but did not reach it!");
164 } else {
165 0 ▶ return 0 unless defined $lmin; # no left range, but $end is left of $start
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lmin 0 0 0
166 0 $dist = 0;
167 0 $aux = $start;
168 0 ▶ while ($aux) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux) 0 0 0
169 0 $aux = $aux->previous;
170 0 $dist--;
171 0 ▶ return 0 if defined($lmax) and $dist<$lmax;
Branch: 1 branch
BranchTrueFalseTotal
if defined $lmax and $dist < $lmax 0 0 0
Condition0%0/3
defined $lmax and $dist < $lmax
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lmax and $dist < $lmax
defined $lmax $dist < $lmax
Truth table0%0/3
A and B
A= defined $lmaxB= $dist < $lmax
ABresult
0X0
100
111
172 0 ▶ if ($aux == $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aux == $end) 0 0 0
173 0 ▶ return(($dist<=$lmin) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$dist <= $lmin ? : 0 0 0
174 }
175 }
176 0 warn("test_depth_first_precedes: This should never happen: expected end node on the preceding axes, but did not reach it!");
177 }
178 0 return 0; # should not happen
179 }
180 }
181  
182 #
183 # The order span of a node N is a pair of numbers [ m(N) , M(N) ], where:
184 # m(N)=M(N)=N.ord if N has an ordering attribute named 'ord';
185 # otherwise
186 # m(N)=min{m(C); C is a child of N}
187 # M(N)=min{M(C); C is a child of N}
188 #
189 # We say that A order-precedes{x,y} B iff x <= m(B)-M(A) <= y
190 # and A order-precedes B if m(B)>M(A)
191 #
192 # Implementation:
193 # We assume that the tree does not change during the life-time of this
194 # query evaluator.
195 #
196 # We compute the spans as needed and cache them in the hidden
197 # attribute '.#order_span' of each node as [m(N),M(N),SELF], where
198 # SELF is a weak reference to the evaluator, indicating whether the
199 # precomputed span is to be assumed up-to-date. See
200 # _compute_order_span() for details.
201  
202  
203 sub get_cached_order_span_min {
204 0 ▶ my ($self,$node)=@_;
Subroutine get_cached_order_span_min: not called CC=1 SCAR=6.9
Pod undocumented
205 0 my $span = $self->_compute_order_span($node);
206 0 return $span->[0];
207 }
208 sub get_cached_order_span_max {
209 0 ▶ my ($self,$node)=@_;
Subroutine get_cached_order_span_max: not called CC=1 SCAR=6.9
Pod undocumented
210 0 my $span = $self->_compute_order_span($node);
211 0 return $span->[1];
212 }
213  
214 # return a cached order_span, if valid for this evaluator
215 sub _get_order_span {
216 0 ▶ my ($self,$node)=@_;
Subroutine _get_order_span: not called CC=5 SCAR=34.0
217 0 ▶ return unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 0 0
218 0 my $span = $node->{'.#order_span'};
219 0 ▶ if (defined($span) and defined($span->[2]) and $span->[2]==$self) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $span and defined $span->[2] and $span->[2] == $self) 0 0 0
Condition0%0/6
defined $span and defined $span->[2] and $span->[2] == $self
!ll&&!rl&&r
000
defined $span and defined $span->[2]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $span and defined $span->[2] and $span->[2] == $self
defined $span defined $span->[2] $span->[2] == $self
Truth table0%0/4
A and B and C
A= defined $spanB= defined $span->[2]C= $span->[2] == $self
ABCresult
0XX0
10X0
1100
1111
220 0 return $span;
221 }
222 0 return;
223 }
224  
225  
226 # Usage: $self->_compute_order_span($node)
227 #
228 # return the order span of a given node, updating cache where needed
229 # for unordered nodes, this means traversing at least some part of the subtree
230 # and computing (and caching) the spans there too
231 # Worst case of this algorithm is O(n) where n is the number of nodes
232 # in the subtree of the given node, however when run over all nodes in a tree,
233 # the running time is O(n) for n=the number of nodes in the tree
234  
235 sub _compute_order_span {
236 0 ▶ my ($self,$node)=@_;
Subroutine _compute_order_span: not called CC=17 SCAR=57.2
237 0 for ($self->_get_order_span($node)) {
238 0 ▶ return($_) if defined;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 0 0 0
239 }
240 0 my %order_attributes; # used to cache the name of an ordering attribute for a particular type
241  
242 # helper closure that computes the ordering attribute of a given
243 # node using the cache:
244 my $get_order = sub {
245 0 ▶ my ($n)=@_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
246 0 my $type = $n->type;
247 0 ▶ $type = $type->get_content_decl if $type->get_decl_type == PML_ELEMENT_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if $type->get_decl_type == 13 0 0 0
248 0 my $attr = $order_attributes{ $type };
249 0 ▶ unless (defined($attr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr) 0 0 0
250 0 my ($attr) = $type->find_members_by_role('#ORDER');
251 0 ▶ $order_attributes{ $type } = ( $attr ? $attr->get_name : '' );
Branch: 1 branch
BranchTrueFalseTotal
$attr ? : 0 0 0
252 }
253 0 return $attr;
254 0 };
255  
256 #
257 # The following is a simple DFS with updating parent's span on the way up
258 # we do not enter subtrees of ordered nodes, since the spans of
259 # those nodes have no effect on the span of any node higher in the
260 # tree
261 #
262 0 my $top = $node;
263 0 my $span;
264 0 ▶ NODE: while ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
265 0 my $attr = $get_order->($node);
266 0 $span = undef;
267 0 ▶ if (length($attr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $attr) { } 0 0 0
268 0 my $ord = $node->{$attr};
269 0 $span = [$ord,$ord,$self];
270 0 weaken($span->[2]);
271 0 ▶ return $span if $node==$top;
Branch: 1 branch
BranchTrueFalseTotal
if $node == $top 0 0 0
272 } else {
273 0 $span=$node->{'.#order_span'}=[undef,undef,$self];
274 0 weaken($span->[2]);
275 0 my $son = $node->firstson;
276 0 ▶ if ($son) {
Branch: 1 branch
BranchTrueFalseTotal
if ($son) 0 0 0
277 0 $node=$son;
278 0 next NODE;
279 }
280 }
281 0 ▶ while ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
282 0 ▶ return $span if $node==$top;
Branch: 1 branch
BranchTrueFalseTotal
if $node == $top 0 0 0
283 0 my $rb = $node->rbrother;
284 0 ▶ if ($rb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rb) 0 0 0
285 0 $node = $rb;
286 0 next NODE;
287 }
288 0 my $p = $node->parent;
289 0 my $p_span = $self->_get_order_span($p);
290 0 ▶ if ($p_span and $span and defined($span->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p_span and $span and defined $span->[0]) 0 0 0
Condition0%0/6
$p_span and $span and defined $span->[0]
!ll&&!rl&&r
000
$p_span and $span
!ll&&!rl&&r
000
MC/DC0%0/3
$p_span and $span and defined $span->[0]
$p_span $span defined $span->[0]
Truth table0%0/4
A and B and C
A= $p_spanB= $spanC= defined $span->[0]
ABCresult
0XX0
10X0
1100
1111
291 0 ▶ $p_span->[0] = $span->[0] if !defined($p_span->[0]) or $span->[0]<$p_span->[0];
Branch: 1 branch
BranchTrueFalseTotal
if not defined $p_span->[0] or $span->[0] < $p_span->[0] 0 0 0
Condition0%0/3
not defined $p_span->[0] or $span->[0] < $p_span->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $p_span->[0] or $span->[0] < $p_span->[0]
not defined $p_span->[0] $span->[0] < $p_span->[0]
Truth table0%0/3
not(A) or B
A= not defined $p_span->[0]B= $span->[0] < $p_span->[0]
ABresult
1X1
011
000
292 0 ▶ $p_span->[1] = $span->[1] if !defined($p_span->[1]) or $span->[1]>$p_span->[1];
Branch: 1 branch
BranchTrueFalseTotal
if not defined $p_span->[1] or $span->[1] > $p_span->[1] 0 0 0
Condition0%0/3
not defined $p_span->[1] or $span->[1] > $p_span->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $p_span->[1] or $span->[1] > $p_span->[1]
not defined $p_span->[1] $span->[1] > $p_span->[1]
Truth table0%0/3
not(A) or B
A= not defined $p_span->[1]B= $span->[1] > $p_span->[1]
ABresult
1X1
011
000
293 }
294 0 $node = $p;
295 0 $span = $p_span;
296 }
297 }
298 0 warn(__PACKAGE__."_compute_order_span: This should never happen\n");
299 0 return $self->_get_order_span($top);
300 }
301  
302 sub stop {
303 0 ▶ $STOP=1;
Subroutine stop: not called CC=1 SCAR=6.9
Pod undocumented
304 }
305  
306 sub new {
307 0 ▶ my ($class,$query_tree,$opts)=@_;
Subroutine new: not called CC=70 SCAR=84.8
Pod undocumented
308 0 ▶ $opts ||= {};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
309 #######################
310 # The following lexical variables may be used directly by the
311 # condition subroutines
312 0 my @conditions;
313 my @iterators;
314 0 my @aux_iterators; # iterators used by transitive 'ref' relations
315 0 my @sub_queries;
316 0 my $parent_query=$opts->{parent_query};
317 0 ▶ my $matched_nodes = $parent_query ? $parent_query->{matched_nodes} : [];
Branch: 1 branch
BranchTrueFalseTotal
$parent_query ? : 0 0 0
318 0 ▶ my $all_iterators = $parent_query ? $parent_query->{all_iterators} : [];
Branch: 1 branch
BranchTrueFalseTotal
$parent_query ? : 0 0 0
319 0 my %have;
320 my $query_pos;
321 #######################
322  
323  
324 0 my @debug;
325 0 my %name2pos;
326 0 my %name2type;
327 # maps node position in a (sub)query to a position of the matching node in $matched_nodes
328 # we avoid using hashes for efficiency
329 my $self = bless {
330  
331 query_pos => 0,
332 iterators => \@iterators,
333 is_overlapping => [],
334 aux_iterators => \@aux_iterators,
335 filter => undef,
336 conditions => \@conditions,
337 have => \%have,
338  
339 debug => \@debug,
340  
341 sub_queries => \@sub_queries,
342 parent_query => $parent_query,
343 parent_query_pos => $opts->{parent_query_pos},
344 parent_query_match_pos => $opts->{parent_query_match_pos},
345  
346 matched_nodes => $matched_nodes, # nodes matched so far (incl. nodes in subqueries; used for evaluation of cross-query relations)
347 all_iterators => $all_iterators, # nodes matched so far (incl. nodes in subqueries; used for evaluation of cross-query relations)
348  
349 type_mapper => $opts->{type_mapper},
350  
351 0 name2pos => \%name2pos,
352 name2type => \%name2type,
353 parent_pos => undef,
354 pos2match_pos => undef,
355 name2match_pos => undef,
356 # query_nodes => [],
357 results => [],
358 }, $class;
359 0 ▶ unless ($self->{type_mapper}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type_mapper"}) 0 0 0
360 0 ▶ if ($opts->{fsfile}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($opts->{'fsfile'}) { } 0 0 0
elsif ($opts->{'current_filelist'} or $opts->{'current_filelist_trees'}) { } 0 0 0
elsif ($opts->{'tree'} or $opts->{'iterator'}) { } 0 0 0
361 0 $self->{type_mapper}=PMLTQ::TypeMapper->new({fsfile=>$opts->{fsfile}});
362 ▶ } elsif ($opts->{current_filelist} or $opts->{current_filelist_trees}) {
Condition0%0/3
$opts->{"current_filelist"} or $opts->{"current_filelist_trees"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"current_filelist"} or $opts->{"current_filelist_trees"}
$opts->{"current_filelist"} $opts->{"current_filelist_trees"}
Truth table0%0/3
A or B
A= $opts->{"current_filelist"}B= $opts->{"current_filelist_trees"}
ABresult
1X1
011
000
363 0 $self->{type_mapper}=PMLTQ::TypeMapper->new({filelist=>TredMacro::GetCurrentFileList()});
364 ▶ } elsif ($opts->{tree} or $opts->{iterator}) {
Condition0%0/3
$opts->{"tree"} or $opts->{"iterator"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"tree"} or $opts->{"iterator"}
$opts->{"tree"} $opts->{"iterator"}
Truth table0%0/3
A or B
A= $opts->{"tree"}B= $opts->{"iterator"}
ABresult
1X1
011
000
365 0 croak(__PACKAGE__."->new: missing required option: type_mapper");
366 } else {
367 0 $self->{type_mapper}=PMLTQ::TypeMapper->new({fsfile=>TredMacro::CurrentFile()})
368 }
369 }
370 0 ▶ weaken($self->{parent_query}) if $self->{parent_query};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parent_query"} 0 0 0
371 0 $query_pos = \$self->{query_pos};
372  
373 0 my $clone_before_plan = 0;
374 0 ▶ if (ref($query_tree)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $query_tree) { } 0 0 0
375 0 $clone_before_plan = 1;
376 } else {
377 $query_tree = PMLTQ::Common::parse_query($query_tree,{
378 user_defined_relations => $self->{type_mapper}->get_user_defined_relations(),
379 0 pmlrf_relations => $self->{type_mapper}->get_pmlrf_relations(),
380 });
381 0 PMLTQ::Common::DetermineNodeType($_) for $query_tree->descendants;
382 }
383  
384 0 my $type = $query_tree->type->get_base_type_name;
385 0 ▶ unless ($type eq 'q-query.type' or
Branch: 1 branch
BranchTrueFalseTotal
unless ($type eq "q-query.type" or $type eq "q-subquery.type") 0 0 0
Condition0%0/3
$type eq "q-query.type" or $type eq "q-subquery.type"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "q-query.type" or $type eq "q-subquery.type"
$type eq "q-query.type" $type eq "q-subquery.type"
Truth table0%0/3
A or B
A= $type eq "q-query.type"B= $type eq "q-subquery.type"
ABresult
1X1
011
000
386 $type eq 'q-subquery.type') {
387 0 die "Not a query tree: $type!\n";
388 }
389 0 my $roots;
390 0 my @orig_nodes=PMLTQ::Common::FilterQueryNodes($query_tree);
391 0 my @query_nodes;
392 my %orig2query;
393 0 ▶ if ($opts->{no_plan}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'no_plan'}) { } 0 0 0
elsif ($self->{'parent_query'}) { } 0 0 0
394 0 ▶ $roots = ($type eq 'q-query.type') ? [ $query_tree->children ] : [$query_tree];
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'q-query.type' ? : 0 0 0
395 0 @query_nodes=@orig_nodes;
396 0 %orig2query = map { $_ => $_ } @orig_nodes;
397 } elsif ($self->{parent_query}) {
398 0 %orig2query = map { $_ => $_ } @orig_nodes;
399 0 @query_nodes=PMLTQ::Common::FilterQueryNodes($query_tree); # reordered
400 0 $roots = [$query_tree];
401 } else {
402 0 require PMLTQ::Planner;
403 0 @query_nodes=PMLTQ::Common::FilterQueryNodes($query_tree); # same order as @orig_nodes
404 0 %orig2query = map { $orig_nodes[$_] => $query_nodes[$_] } 0..$#orig_nodes;
405 0 PMLTQ::Planner::name_all_query_nodes($query_tree); # need for planning
406 0 $roots = PMLTQ::Planner::plan($self->{type_mapper},\@query_nodes,$query_tree);
407 0 for my $subquery (grep { $_->{'#name'} eq 'subtree' } $query_tree->root->descendants) {
408 my $subquery_roots = PMLTQ::Planner::plan(
409 $self->{type_mapper},
410 0 [PMLTQ::Common::FilterQueryNodes($subquery)],
411 $subquery->parent,
412 $subquery
413 );
414 0 ▶ if (@$subquery_roots>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$subquery_roots > 1) 0 0 0
415 0 die "A subquery is not connected: the sub-graph has more than one root node: ".PMLTQ::Commmon::as_text($subquery)."\n";
416 }
417 }
418 0 @query_nodes=PMLTQ::Common::FilterQueryNodes($query_tree); # reordered
419 }
420 0 my $query_node;
421 0 ▶ if (@$roots==0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$roots == 0) { } 0 0 0
elsif (@$roots > 1) { } 0 0 0
422 0 die "No query node!\n";
423 } elsif (@$roots>1) {
424 0 die "The query is not connected: the graph has more than one root node (@$roots)!\n";
425 } else {
426 0 ($query_node)=@$roots;
427 }
428 # @{$self->{query_nodes}}=@orig_nodes;
429 %name2pos = map {
430 0 my $name = $query_nodes[$_]->{name};
431 0 ▶ (defined($name) and length($name)) ? ($name=>$_) : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $name && length $name ? : 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
432 } 0..$#query_nodes;
433 {
434 0 my %node2pos = map { $query_nodes[$_] => $_ } 0..$#query_nodes;
435 0 $self->{query_node2pos} = { map { $_=>$node2pos{$orig2query{$_}} } @orig_nodes };
436 0 $self->{parent_pos} = [ map { $node2pos{ $_->parent } } @query_nodes ];
437 }
438  
439 {
440 0 my @all_query_nodes = grep {$_->{'#name'} =~ /^(node|subquery)$/ } ($query_node->root->descendants);
441 0 ▶ print STDERR map { "$all_query_nodes[$_]{name} => $_\n" } 0..$#all_query_nodes if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
442 {
443 0 my %node2match_pos = map { $all_query_nodes[$_] => $_ } 0..$#all_query_nodes;
444 $self->{pos2match_pos} = [
445 0 map { $node2match_pos{ $query_nodes[$_] } } 0..$#query_nodes
446 ];
447 }
448 # we only allow refferrences to nodes in this query or some super-query
449 $self->{name2match_pos} = {
450 0 ($self->{parent_query} ? (%{$self->{parent_query}{name2match_pos}}) : ()),
451 0 ▶ map { $_ => $self->{pos2match_pos}[$name2pos{$_}] } keys %name2pos
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parent_query'} ? : 0 0 0
452 };
453  
454 0 ▶ if ($DEBUG > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 3) 0 0 0
455 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
456 print STDERR Dumper({
457 parent_query_map =>
458 ($self->{parent_query} ? $self->{parent_query}{name2match_pos} : undef),
459 our_map => $self->{name2match_pos},
460 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parent_query'} ? : 0 0 0
461 }
462  
463 0 my %node_types = map { $_=> 1 } @{$self->{type_mapper}->get_node_types};
464 0 my %schema_names = map { $_=> 1 } @{$self->{type_mapper}->get_schema_names};
465 0 my $default_type = $query_node->root->{'node-type'};
466 0 ▶ if ($default_type and !$node_types{$default_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default_type and not $node_types{$default_type}) 0 0 0
Condition0%0/3
$default_type and not $node_types{$default_type}
!ll&&!rl&&r
000
MC/DC0%0/2
$default_type and not $node_types{$default_type}
$default_type not $node_types{$default_type}
Truth table0%0/3
A and not(B)
A= $default_typeB= not $node_types{$default_type}
ABresult
0X0
100
111
467 0 die "The query specifies an invalid type '$default_type' as default node type!";
468 }
469 0 for my $node (@all_query_nodes) {
470 0 ▶ if (PMLTQ::Common::IsMemberNode($node)) {
Branch: 4 branches
BranchTrueFalseTotal
if (PMLTQ::Common::IsMemberNode($node)) { } 0 0 0
elsif ($node->{'node-type'} eq '*') { } 0 0 0
elsif ($node->{'node-type'} =~ m[^([^/]+):\*$]) { } 0 0 0
elsif ($node->{'node-type'}) { } 0 0 0
471 0 ▶ if ($node->{'node-type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{'node-type'}) { } 0 0 0
472 0 my $type = PMLTQ::Common::GetMemberNodeType($node,$self->{type_mapper});
473 0 ▶ if ($self->{type_mapper}->get_decl_for($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'type_mapper'}->get_decl_for($type)) { } 0 0 0
474 # ok
475 0 my $name = $node->{name};
476 0 ▶ if (defined($name) and length($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
477 0 $name2type{$name} = $type;
478 }
479 } else {
480 0 die "Invalid member path '$type' for ".PMLTQ::Common::as_text($node)."\n";
481 }
482 } else {
483 0 die "Member must specify attribute name: ".PMLTQ::Common::as_text($node)."\n";
484 }
485 0 next;
486 } elsif ($node->{'node-type'} eq '*') {
487 0 ▶ if (keys(%schema_names)>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %schema_names > 1) 0 0 0
488 0 die "Node-type wildcard '*' cannot be used for data with mutliple layers: ".PMLTQ::Common::as_text($node)."\n".
489 "\nHint: try one of ".join(" ",map "$_:*", sort keys(%schema_names))."\n";
490 }
491 } elsif ($node->{'node-type'} =~ m{^([^/]+):\*$}) {
492 0 my $schema_name = $1;
493 0 ▶ if (!$schema_names{$schema_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schema_names{$schema_name}) 0 0 0
494 0 die "The query specifies an invalid schema name '$schema_name' for node: ".PMLTQ::Common::as_text($node)."\n";
495 }
496 } elsif ($node->{'node-type'}) {
497 0 ▶ if (!$node_types{$node->{'node-type'}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node_types{$node->{"node-type"}}) 0 0 0
498 0 die "The query specifies an invalid type '$node->{'node-type'}' for node: ".PMLTQ::Common::as_text($node)."\n";
499 }
500 } else {
501 0 my $parent = $node->parent;
502 my @types =
503 $parent ?
504 (PMLTQ::Common::GetRelativeQueryNodeType(
505 $parent->{'node-type'},
506 $self->{type_mapper},
507 PMLTQ::BtredEvaluator::SeqV($node->{relation}))
508 0 ▶ ) : @{$self->{type_mapper}->get_node_types};
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
509 0 ▶ if (@types == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@types == 1) { } 0 0 0
elsif ($default_type) { } 0 0 0
510 0 $node->{'node-type'} = $types[0];
511 } elsif ($default_type) {
512 0 $node->{'node-type'} = $default_type;
513 } else {
514 0 die "Could not determine node type of node "
515 .PMLTQ::Common::as_text($node)."\n"
516 ."Possible types are: ".join(',',@types)." !\n";
517 }
518 }
519 0 my $name = $node->{name};
520 0 ▶ if (defined($name) and length($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
521 0 $name2type{$name} = $node->{'node-type'}
522 }
523 }
524 }
525  
526 # compile condition testing functions and create iterators
527 0 my (@r1,@r2,@r3);
528 0 for my $i (0..$#query_nodes) {
529 0 my $qn = $query_nodes[$i];
530 0 my $sub = $self->serialize_conditions($qn,{
531 query_pos => $i,
532 recompute_condition => \@r1, # appended in recursion
533 recompute_subquery => \@r2, # appended in recursion
534 reverted_relations => \@r3, # appended in recursion
535 });
536 0 ▶ my $conditions = eval $sub; die $@ if $@; # use the above-mentioned lexical context
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
537 0 push @debug, $sub;
538 0 push @conditions, $conditions;
539 0 my $iterator;
540 0 ▶ if (!$self->{parent_query} and $qn==$query_node) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'parent_query'} and $qn == $query_node) { } 0 0 0
Condition0%0/3
not $self->{"parent_query"} and $qn == $query_node
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"parent_query"} and $qn == $query_node
not $self->{"parent_query"} $qn == $query_node
Truth table0%0/3
not(A) and B
A= not $self->{"parent_query"}B= $qn == $query_node
ABresult
0X0
100
111
541 # top-level node iterates throguh all nodes
542 0 my $type = $qn->{'node-type'};
543 0 ▶ my $schema = $type && $self->{type_mapper}->get_schema_for_type($type);
Condition0%0/3
$type && $self->{'type_mapper'}->get_schema_for_type($type)
!ll&&!rl&&r
000
MC/DC0%0/2
$type && $self->{'type_mapper'}->get_schema_for_type($type)
$type $self->{'type_mapper'}->get_schema_for_type($type)
Truth table0%0/3
A && B
A= $typeB= $self->{'type_mapper'}->get_schema_for_type($type)
ABresult
0X0
100
111
544 0 ▶ my $schema_root_name = $schema && $schema->get_root_name;
Condition0%0/3
$schema && $schema->get_root_name
!ll&&!rl&&r
000
MC/DC0%0/2
$schema && $schema->get_root_name
$schema $schema->get_root_name
Truth table0%0/3
A && B
A= $schemaB= $schema->get_root_name
ABresult
0X0
100
111
545 0 ▶ if (ref $opts->{iterator}) {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $opts->{'iterator'}) { } 0 0 0
elsif ($opts->{'iterator'}) { } 0 0 0
elsif ($opts->{'tree'}) { } 0 0 0
elsif ($opts->{'fsfile'}) { } 0 0 0
elsif ($opts->{'current_filelist'}) { } 0 0 0
546 0 $iterator = $opts->{iterator};
547 0 $iterator->set_conditions($conditions);
548 } elsif ($opts->{iterator}) {
549 0 $iterator = $opts->{iterator}->new($conditions);
550 } elsif ($opts->{tree}) {
551 0 $iterator = PMLTQ::Relation::TreeIterator->new($conditions,$opts->{tree},$opts->{fsfile});
552 } elsif ($opts->{fsfile}) {
553 0 $iterator = PMLTQ::Relation::FSFileIterator->new($conditions,$opts->{fsfile});
554 } elsif ($opts->{current_filelist}) {
555 0 ▶ if ($opts->{particular_trees}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'particular_trees'}) { } 0 0 0
elsif ($schema_root_name eq 'treex_document') { } 0 0 0
556 0 $iterator = PMLTQ::Relation::CurrentFilelistTreesIterator->new($conditions);
557 ## TODO: think of better way of recognizing treex documents
558 } elsif ($schema_root_name eq 'treex_document') {
559 0 $iterator = PMLTQ::Relation::TreexFilelistIterator->new($conditions,$schema_root_name);
560 } else {
561 0 $iterator = PMLTQ::Relation::CurrentFilelistIterator->new($conditions,$schema_root_name);
562 }
563 } else {
564 0 ▶ if ($opts->{particular_trees}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'particular_trees'}) { } 0 0 0
elsif ($schema_root_name eq 'treex_document') { } 0 0 0
565 0 $iterator = PMLTQ::Relation::CurrentTreeIterator->new($conditions);
566 }
567 elsif ($schema_root_name eq 'treex_document') {
568 0 $iterator = PMLTQ::Relation::TreexFileIterator->new($conditions,$schema_root_name);
569 } else {
570 0 $iterator = PMLTQ::Relation::CurrentFileIterator->new($conditions,$schema_root_name);
571 }
572 }
573 } else {
574 0 $iterator = $self->create_iterator($qn,$conditions);
575 }
576 0 push @iterators, $iterator;
577 0 ▶ push @{$self->{is_overlapping}}, ($qn->{overlapping} ? 1 : undef);
Branch: 1 branch
BranchTrueFalseTotal
$qn->{'overlapping'} ? : 0 0 0
578 0 $all_iterators->[$self->{pos2match_pos}[$i]]=$iterator;
579 }
580 0 ▶ unless ($self->{parent_query} or ($opts->{no_filters} and !$opts->{count})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"parent_query"} or $opts->{"no_filters"} and not $opts->{"count"}) 0 0 0
Condition0%0/6
$self->{"parent_query"} or $opts->{"no_filters"} and not $opts->{"count"}
l!l&&r!l&&!r
000
$opts->{"no_filters"} and not $opts->{"count"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"parent_query"} or $opts->{"no_filters"} and not $opts->{"count"}
$self->{"parent_query"} $opts->{"no_filters"} not $opts->{"count"}
Truth table0%0/4
A or B and not(C)
A= $self->{"parent_query"}B= $opts->{"no_filters"}C= not $opts->{"count"}
ABCresult
1XX1
0111
00X0
0100
581 0 ▶ my $first = first { $_->{'#name'} eq 'node' and $_->{name} } $query_tree->children;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_->{"#name"} eq "node" and $_->{"name"} 0 0 0
582 my $output_opts = {
583 id => $first->{name},
584 0 };
585 my ($init_code,$filters) = $self->serialize_filters(
586 ($opts->{count}
587 ? Treex::PML::Factory
588 ->createList([{'return'
589 => Treex::PML::Factory->createList(['count()']) }],1)
590 0 ▶ : $query_tree->{'output-filters'}),
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'count'} ? : 0 0 0
591 $output_opts,
592 );
593 0 ▶ if ($init_code and @$filters) {
Branch: 1 branch
BranchTrueFalseTotal
if ($init_code and @$filters) 0 0 0
Condition0%0/3
$init_code and @$filters
!ll&&!rl&&r
000
MC/DC0%0/2
$init_code and @$filters
$init_code @$filters
Truth table0%0/3
A and B
A= $init_codeB= @$filters
ABresult
0X0
100
111
594 0 my $first_filter = $filters->[0];
595 0 ▶ $self->{filter} = eval $init_code; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
596 0 $self->{filters} = $filters;
597 }
598 }
599 0 return $self;
600 }
601  
602 sub type_mapper {
603 0 ▶ my ($self)=@_;
Subroutine type_mapper: not called CC=1 SCAR=6.9
Pod undocumented
604 0 return $self->{type_mapper};
605 }
606  
607 sub get_type_of_node {
608 0 ▶ my ($self,$name)=@_;
Subroutine get_type_of_node: not called CC=1 SCAR=6.9
Pod undocumented
609 0 return $self->{name2type}{$name};
610 }
611  
612 sub get_type_decl_for_node {
613 0 ▶ my ($self,$name)=@_;
Subroutine get_type_decl_for_node: not called CC=2 SCAR=17.9
Pod undocumented
614 0 my $node_type = $self->{name2type}{$name};
615 0 ▶ return $node_type && $self->{type_mapper}->get_decl_for($node_type);
Condition0%0/3
$node_type && $self->{'type_mapper'}->get_decl_for($node_type)
!ll&&!rl&&r
000
MC/DC0%0/2
$node_type && $self->{'type_mapper'}->get_decl_for($node_type)
$node_type $self->{'type_mapper'}->get_decl_for($node_type)
Truth table0%0/3
A && B
A= $node_typeB= $self->{'type_mapper'}->get_decl_for($node_type)
ABresult
0X0
100
111
616 }
617  
618 sub get_results {
619 0 ▶ my $self = shift;
Subroutine get_results: not called CC=1 SCAR=6.9
Pod undocumented
620 return $self->{results}
621 0 }
622 sub get_result_files {
623 0 ▶ my $self = shift;
Subroutine get_result_files: not called CC=1 SCAR=6.9
Pod undocumented
624 return $self->{result_files}
625 0 }
626 sub run_filters {
627 0 ▶ my $self = shift;
Subroutine run_filters: not called CC=2 SCAR=17.9
Pod undocumented
628 0 ▶ if ($self->{filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'filter'}) { } 0 0 0
629 0 $self->{filter}->($self);
630 0 return 1;
631 } else {
632 0 return 0;
633 }
634 }
635 sub flush_filters {
636 0 ▶ my $self = shift;
Subroutine flush_filters: not called CC=3 SCAR=24.8
Pod undocumented
637 0 ▶ if (!$STOP and $self->{filters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $PMLTQ::BtredEvaluator::STOP and $self->{"filters"}) 0 0 0
Condition0%0/3
not $PMLTQ::BtredEvaluator::STOP and $self->{"filters"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $PMLTQ::BtredEvaluator::STOP and $self->{"filters"}
not $PMLTQ::BtredEvaluator::STOP $self->{"filters"}
Truth table0%0/3
not(A) and B
A= not $PMLTQ::BtredEvaluator::STOPB= $self->{"filters"}
ABresult
0X0
100
111
638 0 return $self->{filters}[0]->{finish}($self->{filters}[0]);
639 }
640 0 return;
641 }
642 sub set_default_output_filter {
643 0 ▶ my ($self,$output) = @_;
Subroutine set_default_output_filter: not called CC=1 SCAR=6.9
Pod undocumented
644 0 $self->{default_output_filter}=$output;
645 }
646 sub get_default_output_filter {
647 0 ▶ my ($self) = @_;
Subroutine get_default_output_filter: not called CC=2 SCAR=17.9
Pod undocumented
648 0 ▶ return $self->{default_output_filter} || $self->std_out_filter;
Condition0%0/3
$self->{'default_output_filter'} || $self->std_out_filter
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'default_output_filter'} || $self->std_out_filter
$self->{'default_output_filter'} $self->std_out_filter
Truth table0%0/3
A || B
A= $self->{'default_output_filter'}B= $self->std_out_filter
ABresult
1X1
011
000
649 }
650  
651 sub init_filters {
652 0 ▶ my ($self,$output) = @_;
Subroutine init_filters: not called CC=4 SCAR=30.0
Pod undocumented
653 0 $STOP = 0;
654 0 ▶ if ($self->{filters} and @{$self->{filters}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"filters"} and @{$self->{"filters"};}) 0 0 0
Condition0%0/3
$self->{"filters"} and @{$self->{"filters"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"filters"} and @{$self->{"filters"};}
$self->{"filters"} @{$self->{"filters"};}
Truth table0%0/3
A and B
A= $self->{"filters"}B= @{$self->{"filters"};}
ABresult
0X0
100
111
655 0 ▶ $output ||= $self->get_default_output_filter;
Condition0%0/3
$output ||= $self->get_default_output_filter
l!l&&r!l&&!r
000
MC/DC0%0/2
$output ||= $self->get_default_output_filter
$output $self->get_default_output_filter
Truth table0%0/3
A ||= B
A= $outputB= $self->get_default_output_filter
ABresult
1X1
011
000
656 0 $self->{filters}[-1]->{output}=$output;
657 0 return $self->{filters}[0]->{init}->($self->{filters}[0]);
658 }
659 0 return;
660 }
661 sub get_filters {
662 0 ▶ my ($self) = @_;
Subroutine get_filters: not called CC=1 SCAR=6.9
Pod undocumented
663 0 return $self->{filters};
664 }
665  
666 sub r {
667 0 ▶ my ($self,$name)=@_;
Subroutine r: not called CC=4 SCAR=30.0
Pod undocumented
668 0 ▶ return unless $self->{results};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"results"} 0 0 0
669 0 my $pos = $self->{name2pos}{$name};
670 0 ▶ return unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 0 0
671 0 ▶ return wantarray ? ($self->{results}[$pos],$self->{result_files}[$pos]) : $self->{results}[$pos];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
672 }
673 1 *get_result_node = \&r;
674  
675 # sub get_query_nodes {
676 # my $self = shift;
677 # return $self->{query_nodes};
678 # }
679  
680 sub get_first_iterator {
681 0 ▶ return $_[0]->{iterators}[0];
Subroutine get_first_iterator: not called CC=1 SCAR=6.9
Pod undocumented
682 }
683  
684 sub reset {
685 0 ▶ my ($self)=@_;
Subroutine reset: not called CC=2 SCAR=17.9
Pod undocumented
686 0 $self->{query_pos} = 0;
687 0 %{$self->{have}}= (); #$self->{parent_query} ? %{$self->{parent_query}{have}} : ();
688 0 $_->reset for @{$self->{iterators}};
689 }
690  
691  
692 sub create_iterator {
693 0 ▶ my ($self,$qn,$conditions)=@_;
Subroutine create_iterator: not called CC=63 SCAR=83.0
Pod undocumented
694 # TODO: deal with negative relations, etc.
695  
696 0 my ($rel) = PMLTQ::BtredEvaluator::SeqV($qn->{relation});
697 0 ▶ my $relation = $rel && $rel->name;
Condition0%0/3
$rel && $rel->name
!ll&&!rl&&r
000
MC/DC0%0/2
$rel && $rel->name
$rel $rel->name
Truth table0%0/3
A && B
A= $relB= $rel->name
ABresult
0X0
100
111
698 0 ▶ $relation||='child';
Condition0%0/2
$relation ||= "child"
l!l
00
MC/DC0%0/1
$relation ||= "child"
$relation
Truth table0%0/2
A
A= $relation
Aresult
11
00
699 0 my ($start_node,$target,$target_type);
700 0 ▶ if ($qn->{'#name'} eq 'ref') {
Branch: 1 branch
BranchTrueFalseTotal
if ($qn->{'#name'} eq 'ref') { } 0 0 0
701 0 $start_node = $qn;
702 0 $target = $qn->{target};
703 0 $target_type = $self->{name2type}{$target};
704 } else {
705 0 $target = $qn->{'id'};
706 0 $target_type = $qn->{'node-type'};
707 0 $start_node = $qn->parent;
708 }
709 0 ▶ $start_node=$start_node->parent while $start_node && $start_node->{'#name'} !~ /^(node|subquery)$/;
Branch: 1 branch
BranchTrueFalseTotal
$start_node and not $start_node->{"#name"} =~ /^(node|subquery)$/ and do { $start_node = $start_node->parent } 0 0 0
Condition0%0/3
$start_node and not $start_node->{"#name"} =~ /^(node|subquery)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$start_node and not $start_node->{"#name"} =~ /^(node|subquery)$/
$start_node not $start_node->{"#name"} =~ /^(node|subquery)$/
Truth table0%0/3
A and not(B)
A= $start_nodeB= not $start_node->{"#name"} =~ /^(node|subquery)$/
ABresult
0X0
100
111
710 0 my $iterator;
711  
712 # fix foo/content()/bar and foo/[]/bar
713 0 ▶ $target_type = join '/',map { ($_ eq '[]' or $_ eq 'content()') ? '#content' : $_ } split /\//, $target_type;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '[]' || $_ eq 'content()' ? : 0 0 0
Condition0%0/3
$_ eq "[]" or $_ eq "content()"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "[]" or $_ eq "content()"
$_ eq "[]" $_ eq "content()"
Truth table0%0/3
A or B
A= $_ eq "[]"B= $_ eq "content()"
ABresult
1X1
011
000
714  
715 0 ▶ if ($relation eq 'child') {
Branch: 12 branches
BranchTrueFalseTotal
if ($relation eq 'child') { } 0 0 0
elsif ($relation eq 'member') { } 0 0 0
elsif ($relation eq 'descendant') { } 0 0 0
elsif ($relation eq 'parent') { } 0 0 0
elsif ($relation eq 'same-tree-as') { } 0 0 0
elsif ($relation eq 'same-document-as') { } 0 0 0
elsif ($relation eq 'order-precedes' or $relation eq 'order-follows') { } 0 0 0
elsif ($relation eq 'depth-first-follows') { } 0 0 0
elsif ($relation eq 'depth-first-precedes') { } 0 0 0
elsif ($relation eq 'ancestor') { } 0 0 0
elsif ($relation eq 'sibling') { } 0 0 0
elsif ($relation eq 'user-defined') { } 0 0 0
716 0 $iterator = PMLTQ::Relation::ChildnodeIterator->new($conditions);
717 } elsif ($relation eq 'member') {
718 0 $iterator = PMLTQ::Relation::MemberIterator->new($conditions,$target_type);
719 } elsif ($relation eq 'descendant') {
720 my ($min,$max)=
721 0 ▶ map { (defined($_) and length($_)) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
722 0 map { $rel->value->{$_} }
723 qw(min_length max_length);
724 0 ▶ if (defined($min) or defined($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min or defined $max) { } 0 0 0
Condition0%0/3
defined $min or defined $max
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $min or defined $max
defined $min defined $max
Truth table0%0/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
725 0 $iterator = PMLTQ::Relation::DescendantIteratorWithBoundedDepth->new($conditions,$min,$max);
726 } else {
727 0 $iterator = PMLTQ::Relation::DescendantIterator->new($conditions);
728 }
729 } elsif ($relation eq 'parent') {
730 0 $iterator = PMLTQ::Relation::ParentIterator->new($conditions);
731 } elsif ($relation eq 'same-tree-as') {
732 0 $iterator = PMLTQ::Relation::SameTreeIterator->new($conditions);
733 } elsif ($relation eq 'same-document-as') {
734 0 $iterator = PMLTQ::Relation::FSFileIterator->new($conditions);
735 ▶ } elsif ($relation eq 'order-precedes' or $relation eq 'order-follows') {
Condition0%0/3
$relation eq "order-precedes" or $relation eq "order-follows"
l!l&&r!l&&!r
000
MC/DC0%0/2
$relation eq "order-precedes" or $relation eq "order-follows"
$relation eq "order-precedes" $relation eq "order-follows"
Truth table0%0/3
A or B
A= $relation eq "order-precedes"B= $relation eq "order-follows"
ABresult
1X1
011
000
736 my ($attr1,$attr2) =
737 map {
738 0 ▶ if (defined) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 0 0 0
739 0 my $decl = $self->{type_mapper}->get_decl_for($_);
740 0 ▶ if ($decl->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 13) 0 0 0
741 0 $decl = $decl->get_content_decl;
742 }
743 0 my ($m)=$decl->find_members_by_role('#ORDER');
744 0 ▶ defined($m) && $m->get_name
Branch: 1 branch
BranchTrueFalseTotal
defined $m and $m->get_name 0 0 0
745 } else {
746 0 undef;
747 }
748 0 } ($start_node->{'node-type'},$target_type);
749 my ($min,$max)=
750 0 ▶ map { (defined($_) and $_) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && $_ ? : 0 0 0
Condition0%0/3
defined $_ and $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and $_
defined $_ $_
Truth table0%0/3
A and B
A= defined $_B= $_
ABresult
0X0
100
111
751 0 map { $rel->value->{$_} }
752 qw(min_length max_length);
753 0 weaken( my $weak_self = $self );
754 $iterator = PMLTQ::Relation::OrderIterator->new($conditions,$attr1,$attr2,
755 (($relation eq 'order-follows') ? -1 : 1),
756 $min,$max,
757 0 ▶ sub { $weak_self->_compute_order_span($_[0]) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
758 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$relation eq 'order-follows' ? : 0 0 0
759 } elsif ($relation eq 'depth-first-follows') {
760 my ($min,$max)=
761 0 ▶ map { (defined($_) and $_) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && $_ ? : 0 0 0
Condition0%0/3
defined $_ and $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and $_
defined $_ $_
Truth table0%0/3
A and B
A= defined $_B= $_
ABresult
0X0
100
111
762 0 map { $rel->value->{$_} } qw(min_length max_length);
763 0 my @bounds = _compute_bounds(-1, $min,$max );
764 0 ▶ if (@bounds) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bounds) { } 0 0 0
765 0 $iterator = PMLTQ::Relation::DepthFirstRangeIterator->new($conditions,@bounds);
766 } else {
767 0 $iterator = PMLTQ::Relation::DepthFirstFollowsIterator->new($conditions);
768 }
769 } elsif ($relation eq 'depth-first-precedes') {
770 my ($min,$max)=
771 0 ▶ map { (defined($_) and $_) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && $_ ? : 0 0 0
Condition0%0/3
defined $_ and $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and $_
defined $_ $_
Truth table0%0/3
A and B
A= defined $_B= $_
ABresult
0X0
100
111
772 0 map { $rel->value->{$_} } qw(min_length max_length);
773 0 my @bounds = _compute_bounds(1, $min,$max );
774 0 ▶ if (@bounds) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bounds) { } 0 0 0
775 0 $iterator = PMLTQ::Relation::DepthFirstRangeIterator->new($conditions,@bounds);
776 } else {
777 0 $iterator = PMLTQ::Relation::DepthFirstPrecedesIterator->new($conditions);
778 }
779 } elsif ($relation eq 'ancestor') {
780 my ($min,$max)=
781 0 ▶ map { (defined($_) and $_) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && $_ ? : 0 0 0
Condition0%0/3
defined $_ and $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and $_
defined $_ $_
Truth table0%0/3
A and B
A= defined $_B= $_
ABresult
0X0
100
111
782 0 map { $rel->value->{$_} }
783 qw(min_length max_length);
784 0 ▶ if (defined($min) or defined($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min or defined $max) { } 0 0 0
Condition0%0/3
defined $min or defined $max
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $min or defined $max
defined $min defined $max
Truth table0%0/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
785 0 $iterator = PMLTQ::Relation::AncestorIteratorWithBoundedDepth->new($conditions,$min,$max);
786 } else {
787 0 $iterator = PMLTQ::Relation::AncestorIterator->new($conditions);
788 }
789 } elsif ($relation eq 'sibling') {
790 my ($min,$max)=
791 0 ▶ map { (defined($_) and $_) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && $_ ? : 0 0 0
Condition0%0/3
defined $_ and $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and $_
defined $_ $_
Truth table0%0/3
A and B
A= defined $_B= $_
ABresult
0X0
100
111
792 0 map { $rel->value->{$_} }
793 qw(min_length max_length);
794 0 ▶ if (defined($min) or defined($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min or defined $max) { } 0 0 0
Condition0%0/3
defined $min or defined $max
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $min or defined $max
defined $min defined $max
Truth table0%0/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
795 0 $iterator = PMLTQ::Relation::SiblingIteratorWithDistance->new($conditions,$min,$max);
796 } else {
797 0 $iterator = PMLTQ::Relation::SiblingIterator->new($conditions);
798 }
799 } elsif ($relation eq 'user-defined') {
800 0 my $label = $rel->value->{label};
801 0 my ($min,$max)=($rel->value->{min_length},$rel->value->{max_length});
802 0 ▶ my $transitive = ((!(defined($min) && length($min))
Branch: 1 branch
BranchTrueFalseTotal
!(defined $min && length $min || defined $max && length $max) || defined $max && $max == 1 ? : 0 0 0
Condition0%0/15
not defined $min && length $min || defined $max && length $max or defined $max and $max == 1
l!l&&r!l&&!r
000
defined $min && length $min || defined $max && length $max
l!l&&r!l&&!r
000
defined $min and length $min
!ll&&!rl&&r
000
defined $max and length $max
!ll&&!rl&&r
000
defined $max and $max == 1
!ll&&!rl&&r
000
MC/DC0%0/6
not defined $min && length $min || defined $max && length $max or defined $max and $max == 1
defined $min length $min defined $max length $max defined $max $max == 1
Truth table0%0/13
not(A and B || C and D) or E and F
A= defined $minB= length $minC= defined $maxD= length $maxE= defined $maxF= $max == 1
ABCDEFresult
0X0XXX1
0X10XX1
100XXX1
1010XX1
11XX111
0X11111
1011111
11XX0X0
11XX100
0X110X0
0X11100
10110X0
1011100
803 && !(defined($max) && length($max))) || (defined($max) && $max==1)) ? 0 : 1;
804 0 ▶ if (defined($min) && defined($max) && ($min>$max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max and $min > $max) 0 0 0
Condition0%0/6
defined $min and defined $max and $min > $max
!ll&&!rl&&r
000
defined $min and defined $max
!ll&&!rl&&r
000
MC/DC0%0/3
defined $min and defined $max and $min > $max
defined $min defined $max $min > $max
Truth table0%0/4
A and B and C
A= defined $minB= defined $maxC= $min > $max
ABCresult
0XX0
10X0
1100
1111
805 0 die "Invalid bounds for transitive relation '$label\{$min,$max}'\n";
806 }
807  
808 0 my $schema = $self->{type_mapper}->get_schema_for_type($start_node->{'node-type'});
809 0 $iterator = PMLTQ::Relation->create_iterator($schema->get_root_name, $start_node->{'node-type'}, $label, $conditions);
810 0 ▶ unless (defined $iterator) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $iterator) 0 0 0
811 0 ▶ if (first { $_ eq $label }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { $_ eq $label; } , @{$self->{'type_mapper'}->get_pmlrf_relations($start_node);})) { } 0 0 0
812 0 @{$self->{type_mapper}->get_pmlrf_relations($start_node)}) {
813 0 $iterator = PMLTQ::Relation::PMLREFIterator->new($conditions,$label);
814 } else {
815 0 die "user-defined relation '".$label."' unknown or not implemented in BTrEd Search\n"
816 }
817 }
818  
819 0 ▶ if ($transitive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transitive) 0 0 0
820 0 ▶ if ($start_node->{'node-type'} ne $target_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_node->{"node-type"} ne $target_type) 0 0 0
821 0 die "Cannot create transitive closure for relation with different start-node and end-node types: '$start_node->{q(node-type)}' -> '$target_type'\n";
822 }
823 0 $iterator = PMLTQ::Relation::TransitiveIterator->new($iterator,$min,$max);
824 }
825 } else {
826 0 die "relation ".$relation." not valid for this node or not yet implemented \n"
827 }
828 0 ▶ print STDERR "iterator: ".ref($iterator)."\n" if defined($DEBUG) and $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $PMLTQ::BtredEvaluator::DEBUG and $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
Condition0%0/3
defined $PMLTQ::BtredEvaluator::DEBUG and $PMLTQ::BtredEvaluator::DEBUG > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $PMLTQ::BtredEvaluator::DEBUG and $PMLTQ::BtredEvaluator::DEBUG > 1
defined $PMLTQ::BtredEvaluator::DEBUG $PMLTQ::BtredEvaluator::DEBUG > 1
Truth table0%0/3
A and B
A= defined $PMLTQ::BtredEvaluator::DEBUGB= $PMLTQ::BtredEvaluator::DEBUG > 1
ABresult
0X0
100
111
829  
830 0 ▶ if ($qn->{optional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qn->{'optional'}) { } 0 0 0
831 0 ▶ print STDERR "iterator: [OPTIONAL]\n" if defined($DEBUG) and $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $PMLTQ::BtredEvaluator::DEBUG and $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
Condition0%0/3
defined $PMLTQ::BtredEvaluator::DEBUG and $PMLTQ::BtredEvaluator::DEBUG > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $PMLTQ::BtredEvaluator::DEBUG and $PMLTQ::BtredEvaluator::DEBUG > 1
defined $PMLTQ::BtredEvaluator::DEBUG $PMLTQ::BtredEvaluator::DEBUG > 1
Truth table0%0/3
A and B
A= defined $PMLTQ::BtredEvaluator::DEBUGB= $PMLTQ::BtredEvaluator::DEBUG > 1
ABresult
0X0
100
111
832 0 return PMLTQ::Relation::OptionalIterator->new($iterator);
833 } else {
834 0 return $iterator;
835 }
836 }
837  
838 sub serialize_filters {
839 0 ▶ my ($self,$filters,$opts)=@_;
Subroutine serialize_filters: not called CC=12 SCAR=50.5
Pod undocumented
840 0 ▶ return unless ref $filters;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $filters 0 0 0
841 0 ▶ $opts ||= {};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
842 # first filter is special, it can refer to nodes
843 0 my $prev;
844 my @filters;
845 0 for my $f (PMLTQ::Common::merge_filters_2($filters)) {
846 0 $opts->{filter_id} = "filter_".scalar(@filters);
847 0 push @filters, $self->serialize_filter($f,$opts); # can return multiple filters
848 }
849 0 for my $filter (@filters) {
850 0 ▶ if ($prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 0 0 0
851 0 $prev->{output}=$filter;
852 }
853 0 $prev = $filter;
854 }
855 0 ▶ if ($DEBUG > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 2) 0 0 0
856 0 my $j=0;
857 0 for my $f (@filters) {
858 0 my $i = -1;
859 0 print STDERR "##### RESULT FILTER ", $j++,"\n";
860 0 print STDERR sprintf("%3s\t%s",$i++,$_."\n") for split /\n/,$f->{code};
861 0 my $k=0;
862 0 for my $s (@{$f->{local_filters_code}}) {
863 0 print STDERR "\t##### LOCAL GROUPING FILTER ", $k++," OF FILTER $j\n";
864 0 $i = -1;
865 0 print STDERR sprintf("\t%3s\t%s",$i++,$_."\n") for split /\n/,$s;
866 }
867 }
868 {
869 0 my $i = -1;
870 0 print STDERR "\t##### INIT_CODE\n";
871 0 print STDERR sprintf("\t%3s\t%s",$i++,$_."\n") for split /\n/,$opts->{filter_init};
872 }
873 }
874 0 return ($opts->{filter_init},\@filters);
875 }
876  
877 sub std_out_filter {
878 0 ▶ my ($self)=@_;
Subroutine std_out_filter: not called CC=1 SCAR=6.9
Pod undocumented
879 return {
880 ▶ init => sub {
Subroutine __ANON__: not called CC=1 SCAR=0.0
881 # print("-" x 60, "\n");
882 },
883 process_row => sub {
884 0 ▶ my ($self,$row)=@_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
885 0 print(join("\t",@$row)."\n");
886 },
887 ▶ finish => sub {
Subroutine __ANON__: not called CC=1 SCAR=0.0
888 # print("-" x 60, "\n");
889 }
890 0 };
891 }
892  
893 sub buffer_all_filter {
894 0 ▶ my ($self)=@_;
Subroutine buffer_all_filter: not called CC=1 SCAR=6.9
Pod undocumented
895 return {
896 init => sub {
897 0 ▶ my ($self)=@_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
898 0 $self->{saved_rows}=[];
899 },
900 process_row => sub {
901 0 ▶ my ($self,$row)=@_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
902 0 push @{$self->{saved_rows}}, $row;
903 },
904 finish => sub {
905 0 ▶ my ($self)=@_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
906 0 return $self->{saved_rows};
907 }
908 0 };
909 }
910  
911 1 my %aggregation_template = (
912 count => q`
913 sub {
914 my ($self, $i)=@_;
915 $self->{aggregated}[$i]++;
916 }`,
917 _DEFAULT_ => q`
918 sub {
919 my ($self, $i, $row)=@_;
920 #<IF_LEN _FUNC_VARLIST_>
921 my (_FUNC_VARLIST_) = @$row[_FUNC_COLNUMS_];
922 #</IF_LEN>
923 #<IF_LEN _FUNC_DEFINED_>
924 if (_FUNC_DEFINED_) {
925 #</IF_LEN>
926 _FUNC_OP_
927 #<IF_LEN _FUNC_DEFINED_>
928 }
929 #</IF_LEN>
930 }`
931 );
932 1 my %aggregation_init = (
933 sum => '0',
934 max => 'undef',
935 min => 'undef',
936 count => '0',
937 avg => '[undef,0]',
938 concat => '[]',
939  
940 row_number => '[]',
941 rank => '[]',
942 dense_rank => '[]',
943 );
944 1 my %aggregation_op = (
945 sum => q`$self->{aggregated}[$i] += _ARG_;`,
946 max => q`my $max = $self->{aggregated}[$i];
947 my $val = _ARG_;
948 $self->{aggregated}[$i] = $val if !defined($max) or $max<$val`,
949 min => q`my $min = $self->{aggregated}[$i];
950 my $val = _ARG_;
951 $self->{aggregated}[$i] = $val if !defined($min) or $val<$min`,
952 avg => q`my $avg = $self->{aggregated}[$i];
953 $self->{aggregated}[$i][0] += _ARG_;
954 $self->{aggregated}[$i][1] ++;`, # shell we count null values as 0 ?
955 concat => q`push @{$self->{aggregated}[$i]}, [_ARG_,_SORT_ARGS_];`,
956  
957 row_number => q`push @{$self->{aggregated}[$i]}, [$row,_SORT_ARGS_];`,
958 rank => q`push @{$self->{aggregated}[$i]}, [$row,_SORT_ARGS_];`,
959 dense_rank => q`push @{$self->{aggregated}[$i]}, [$row,_SORT_ARGS_];`,
960 );
961 1 my %aggregation_final = (
962 avg => q`_RESULT_ = (_RESULT_->[0] / _RESULT_->[1]);`,
963 concat => q`_RESULT_ = do{ use locale; join(_ARG1_, map $_->[0], _SORT_CMP_ @{_RESULT_}) };`,
964  
965 row_number => q`use locale; my @sorted = _SORT_CMP_ @{_RESULT_}; _RESULT_ = { map { $sorted[$_][0] => $_+1 } 0..$#sorted };`,
966  
967 rank => q`use locale;
968 my @sorted = _SORT_CMP_ @{_RESULT_};
969 my ($rank,$rowno)=(1,1);
970 _RESULT_ =
971 @sorted ?
972 {
973 ((($a=shift(@sorted))->[0] => 1),
974 map {
975 $b=$_;
976 $rank=$rowno if _CMP_;
977 $rowno++;
978 $a = $b;
979 $a->[0] => $rank
980 } @sorted)
981 } : {};`,
982  
983 dense_rank => q`use locale;
984 my @sorted = _SORT_CMP_ @{_RESULT_};
985 my $rank=1;
986 _RESULT_ =
987 @sorted ?
988 {
989 ((($a=shift(@sorted))->[0] => 1),
990 map {
991 $b=$_;
992 $rank++ if _CMP_;
993 $a = $b;
994 $a->[0] => $rank;
995 } @sorted)
996 } : {};`,
997 );
998  
999 1 my %code_template = (
1000 PLAIN => q`
1001 {
1002 type => 'PLAIN',
1003 init => sub {
1004 my ($self)=@_;
1005 #<IF_DISTINCT>
1006 $self->{seen} = {};
1007 #</IF_DISTINCT>
1008 my $out = $self->{output};
1009 $out->{init}->($out);
1010 },
1011 process_row => sub {
1012 my ($self,$row)= @_;
1013 #<IF_LEN _RET_VARLIST_>
1014 my (_RET_VARLIST_) = @$row[_RET_COLNUMS_];
1015 #</IF_LEN>
1016 my $out = $self->{output};
1017 my @out_row = (
1018 _RET_COLS_
1019 );
1020 #<IF_DISTINCT>
1021 my $key = join "\x0",map { defined $_ ? $_ : '' } @out_row;
1022 unless (exists $self->{seen}{$key}) {
1023 $self->{seen}{$key}=undef;
1024 $out->{process_row}->($out,\@out_row)_IF_FILTER_;
1025 }
1026 #</IF_DISTINCT>
1027 #<IF_NOT_DISTINCT>
1028 $out->{process_row}->($out,\@out_row)_IF_FILTER_;
1029 #</IF_NOT_DISTINCT>
1030 },
1031 finish => sub {
1032 my ($self)= @_;
1033 my $out = $self->{output};
1034 $out->{finish}($out);
1035 }
1036 }`,
1037  
1038 # Example: >> $1, $2, 2+sum($2 over $1)*max($1 over $2)
1039 AGGREGATE => q`
1040 {
1041 type => 'AGGREGATE',
1042 init => sub {
1043 my ($self)= @_;
1044 #<IF_NOT_RETURN>
1045 my $out = $self->{output};
1046 $out->{init}->($out);
1047 #</IF_NOT_RETURN>
1048 _INIT_AGG_
1049 },
1050 process_row => sub {
1051 my ($self,$row)= @_;
1052 my $agg=0;
1053 $_->($self,$agg++,$row) for @{$self->{aggregation}};
1054 },
1055 aggregation => [
1056 _AGGREGATIONS_
1057 ],
1058 is_windowing => [
1059 _IS_WINDOWING_
1060 ],
1061 finish => sub {
1062 my ($self)=@_;
1063 #<IF_LEN _RET_VARLIST_>
1064 my (_RET_VARLIST_) = @{$self->{group_columns}}[_RET_COLNUMS_];
1065 #</IF_LEN>
1066 _AGG_FINALIZE_
1067 #<IF_RETURN>
1068 my @out_row = (
1069 _RET_COLS_
1070 );
1071 return($self->{result} = \@out_row) _IF_FILTER_;
1072 return; # in case a filter is present and fails
1073 #</IF_RETURN>
1074 #<IF_NOT_RETURN>
1075 my $out = $self->{output};
1076 my @out_row = (
1077 _RET_COLS_
1078 );
1079 $out->{process_row}->($out, \@out_row)_IF_FILTER_;
1080 $out->{finish}($out);
1081 #</IF_NOT_RETURN>
1082 }
1083 }`,
1084  
1085 GROUP => q`
1086 {
1087 type => 'GROUP',
1088 init => sub {
1089 my ($self)= @_;
1090 $self->{group} = {};
1091 },
1092 process_row => sub {
1093 my ($self,$row)= @_;
1094 #<IF_LEN _GROUP_VARLIST_>
1095 my (_GROUP_VARLIST_) = @$row[_GROUP_COLNUMS_];
1096 #</IF_LEN>
1097 my $g = [
1098 _GROUP_COLS_
1099 ];
1100 my $key = join "\x0",map { defined $_ ? $_ : '' } @$g;
1101 my $new;
1102 my $group = $self->{group}{$key} ||= ($new = {
1103 key => $key,
1104 group_columns => $g,
1105 %{$self->{grouping}}
1106 });
1107 $group->{init}->($group) if $new;
1108 $group->{process_row}->($group,$row);
1109 },
1110 finish => sub {
1111 my ($self)=@_;
1112 #<IF_NOT_RETURN>
1113 my $out = $self->{output};
1114 $out->{init}->($out);
1115 #</IF_NOT_RETURN>
1116 #<IF_RETURN>
1117 my %return;
1118 #</IF_RETURN>
1119 for my $group (values %{$self->{group}}) {
1120 my $r = $group->{finish}->($group);
1121 #<IF_RETURN>
1122 my $key = $group->{key};
1123 $return{$key}=$r;
1124 #</IF_RETURN>
1125 %$group=(); # immediatelly cleanup group data
1126 #<IF_NOT_RETURN>
1127 $out->{process_row}($out,$r) if defined $r;
1128 #</IF_NOT_RETURN>
1129 }
1130 #<IF_NOT_RETURN>
1131 $out->{finish}($out);
1132 #</IF_NOT_RETURN>
1133 #<IF_RETURN>
1134 return \%return;
1135 #</IF_RETURN>
1136 },
1137 grouping => _TEMPLATE_AGGREGATE_,
1138 };
1139 `,
1140 # Example: >> $1, $2, 2+sum($2 over $1)*max($1 over $2)
1141 INNER_AGGREGATE => q`
1142 {
1143 type => 'INNNER_AGGREGATE',
1144 init => sub {
1145 my ($self)= @_;
1146 $_->{init}->($_) for @{$self->{local_group}};
1147 $self->{saved_rows} = [];
1148  
1149 #<IF_NOT_RETURN>
1150 my $out = $self->{output};
1151 $out->{init}->($out);
1152 #</IF_NOT_RETURN>
1153 },
1154 local_group => \@local_filters,
1155 process_row => sub {
1156 my ($self,$row)= @_;
1157 push @{$self->{saved_rows}}, $row; # note: we could only save the columns we need
1158 $_->{process_row}->($_, $row) for @{$self->{local_group}};
1159 },
1160 finish => sub {
1161 my ($self)=@_;
1162 my $saved_rows = $self->{saved_rows};
1163 my $row;
1164 my $out = $self->{output};
1165 my @l = map $_->{finish}->($_), @{$self->{local_group}};
1166 my @is_windowing = map $_->{grouping}{is_windowing}[0], @{$self->{local_group}};
1167 #<IF_DISTINCT>
1168 my %seen;
1169 #</IF_DISTINCT>
1170 while ($row = shift @$saved_rows) {
1171 #<IF_LEN _RET_VARLIST_>
1172 my (_RET_VARLIST_) = @$row[_RET_COLNUMS_];
1173 #</IF_LEN>
1174 my @keys = (_LOCAL_GROUP_KEYS_); # group-expression of n-th filter
1175  
1176 my (_LOCAL_VARLIST_) =
1177 map {
1178 my $group_result = $l[$_]{ $keys[$_] }[0];
1179 $is_windowing[$_] ? $group_result->{ $row } : $group_result
1180 } 0..$#l;
1181 my @out_row = (
1182 _RET_COLS_
1183 );
1184 #<IF_DISTINCT>
1185 my $key = join "\x0",map { defined $_ ? $_ : '' } @out_row;
1186 next if exists $seen{$key};
1187 $seen{$key}=undef;
1188 #</IF_DISTINCT>
1189 $out->{process_row}->($out, \@out_row)_IF_FILTER_;
1190 }
1191 $out->{finish}($out);
1192 }
1193 }`,
1194 SORT => q`
1195 {
1196 type => 'SORT',
1197 init => sub {
1198 my ($self)= @_;
1199 $self->{saved_rows} = [];
1200 my $out = $self->{output};
1201 $out->{init}->($out);
1202 },
1203 process_row => sub {
1204 my ($self,$row)= @_;
1205 push @{$self->{saved_rows}}, $row;
1206 },
1207 finish => sub {
1208 my ($self)=@_;
1209 my $saved_rows = $self->{saved_rows};
1210 use locale;
1211 @$saved_rows = _SORT_CMP_ @$saved_rows;
1212 my $row;
1213 my $out = $self->{output};
1214 while ($row = shift @$saved_rows) {
1215 $out->{process_row}->($out, $row);
1216 }
1217 $out->{finish}($out);
1218 }
1219 }`,
1220 );
1221  
1222 # do several substitutions at once
1223 sub _code_substitute {
1224 0 ▶ my (undef, $map)=@_;
Subroutine _code_substitute: not called CC=3 SCAR=24.8
1225 0 my $what = join('|',reverse sort keys %$map);
1226 0 $_[0] =~ s{[ \t]*#<IF_LEN ($what)>\s*?\n(.*?)[ \t]*#</IF_LEN>\s*?\n}{
1227 0 ▶ defined($map->{$1}) and length($map->{$1}) ? $2 : ''
Branch: 2 branches
BranchTrueFalseTotal
defined $map->{$1} and length $map->{$1} ? $2 : "" 0 0 0
length $map->{$1} ? : 0 0 0
1228 }seg;
1229 0 $_[0] =~ s{($what)}{ $map->{$1} }eg;
1230 }
1231  
1232 sub _code_template_substitute {
1233 0 ▶ my (undef, $map,$id)=@_;
Subroutine _code_template_substitute: not called CC=4 SCAR=30.0
1234 0 $_[0] =~ s{\b_TEMPLATE_([A-Z_]+)_\b}{
1235 0 _code_from_template($1, $map->{_MAP_},'sub_'.$id)
1236 }eg;
1237 0 ▶ if ($map) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map) 0 0 0
1238 0 my $what = join('|',reverse sort keys %$map);
1239 0 $_[0] =~ s{[ \t]*#<IF_((NOT_)?($what))>\s*?\n(.*?)[ \t]*#</IF_\1>\s*?\n}{
1240 0 ▶ (($2 ? !$map->{$3} : $map->{$3}) ? $4 : '')
Branch: 2 branches
BranchTrueFalseTotal
($2 ? !$map->{$3} : $map->{$3}) ? : 0 0 0
$2 ? : 0 0 0
1241 }seg;
1242 }
1243 }
1244  
1245 sub _code_from_template {
1246 0 ▶ my ($name,$map,$id)=@_;
Subroutine _code_from_template: not called CC=2 SCAR=17.9
1247 0 ▶ $map ||= {};
Condition0%0/2
$map ||= {}
l!l
00
MC/DC0%0/1
$map ||= {}
$map
Truth table0%0/2
A
A= $map
Aresult
11
00
1248 0 my $code = $code_template{$name};
1249 0 _code_template_substitute($code, $map,$id);
1250 0 return "\n#line 1 ${name}_${id}\n".$code;
1251 }
1252  
1253 sub serialize_filter {
1254 0 ▶ my ($self, $filter, $opts)=@_;
Subroutine serialize_filter: not called CC=85 SCAR=88.3
Pod undocumented
1255 # $filter->{group-by}
1256 # $filter->{distinct}
1257 # $filter->{return}
1258 # $filter->{sort-by}
1259  
1260 0 ▶ my @group_by = @{ $filter->{'group-by'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$filter->{"group-by"} or [] 0 0 0
1261 0 ▶ my @where = @{ $filter->{where} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$filter->{"where"} or [] 0 0 0
1262 0 ▶ my @return = @{ $filter->{return} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$filter->{"return"} or [] 0 0 0
1263 0 ▶ my @sort_by = @{ $filter->{'sort-by'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$filter->{"sort-by"} or [] 0 0 0
1264 0 my $having = $filter->{'having'};
1265  
1266 0 ▶ if ($DEBUG > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 3) 0 0 0
1267 0 print STDERR "----------------\n";
1268 0 print STDERR "Serializing: g: @group_by, r: @return, s: @sort_by\n";
1269 0 print STDERR "Column count: $opts->{column_count}\n";
1270 }
1271  
1272 0 ▶ my $is_first_filter = defined($opts->{column_count}) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'column_count'} ? : 0 0 0
1273 0 ▶ my $distinct = $filter->{distinct} || 0;
Condition0%0/2
$filter->{'distinct'} || 0
l!l
00
MC/DC0%0/1
$filter->{'distinct'} || 0
$filter->{'distinct'}
Truth table0%0/2
A
A= $filter->{'distinct'}
Aresult
11
00
1274  
1275 0 ▶ my $Foreach = $opts->{foreach} || [];
Condition0%0/2
$opts->{'foreach'} || []
l!l
00
MC/DC0%0/1
$opts->{'foreach'} || []
$opts->{'foreach'}
Truth table0%0/2
A
A= $opts->{'foreach'}
Aresult
11
00
1276 0 my $foreach_idx = 0;
1277 0 ▶ my $input_columns = $opts->{input_columns} || [];
Condition0%0/2
$opts->{'input_columns'} || []
l!l
00
MC/DC0%0/1
$opts->{'input_columns'} || []
$opts->{'input_columns'}
Truth table0%0/2
A
A= $opts->{'input_columns'}
Aresult
11
00
1278 0 ▶ my $return_columns = $opts->{columns_used} || {};
Condition0%0/2
$opts->{'columns_used'} || {}
l!l
00
MC/DC0%0/1
$opts->{'columns_used'} || {}
$opts->{'columns_used'}
Truth table0%0/2
A
A= $opts->{'columns_used'}
Aresult
11
00
1279  
1280 0 my %aggregations;
1281 my %return_aggregations;
1282 0 my @return_vars;
1283 0 my @return_exp = do {
1284 0 my $i = 0;
1285 map $self->serialize_column($_, {
1286 %$opts,
1287 var_prefix => 'v',
1288 foreach => ($is_first_filter && !@group_by ? $Foreach : undef),
1289 input_columns => ($is_first_filter && !@group_by ? $input_columns : undef),
1290 columns_used => $return_columns,
1291 vars_used => ($return_vars[$i++]={}),
1292 local_aggregations => \%return_aggregations,
1293 old_aggregations => $opts->{aggregations},
1294 old_aggregations_first_column => $opts->{old_aggregations_column},
1295 aggregations => \%aggregations,
1296 column_count => scalar(@group_by) || $opts->{column_count},
1297 0 ▶ is_first_filter => $is_first_filter,
Branch: 2 branches
BranchTrueFalseTotal
$is_first_filter && !@group_by ? : 0 0 0
$is_first_filter && !@group_by ? : 0 0 0
Condition0%0/9
$is_first_filter and not @group_by
!ll&&!rl&&r
000
$is_first_filter and not @group_by
!ll&&!rl&&r
000
scalar @group_by || $opts->{'column_count'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_first_filter and not @group_by
$is_first_filter not @group_by
MC/DC0%0/2
$is_first_filter and not @group_by
$is_first_filter not @group_by
MC/DC0%0/2
scalar @group_by || $opts->{'column_count'}
scalar @group_by $opts->{'column_count'}
Truth table0%0/3
A and not(B)
A= $is_first_filterB= not @group_by
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $is_first_filterB= not @group_by
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= scalar @group_byB= $opts->{'column_count'}
ABresult
1X1
011
000
1298 }), @return
1299 };
1300  
1301 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
1302 # print STDERR Dumper({having=>$having});
1303  
1304 0 ▶ my $having_exp = ref($having) && $self->serialize_element({
Condition0%0/3
ref $having && $self->serialize_element({%$opts, 'name', 'and', 'columns_used', {}, 'is_first_filter', 0, 'condition', $having, 'is_positive_conjunct', 1, 'output_filter', 1, 'output_filter_where_clause', 1, 'column_count', scalar @return, 'var_prefix', 'out_row[', 'var_suffix', ' - 1]'})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $having && $self->serialize_element({%$opts, 'name', 'and', 'columns_used', {}, 'is_first_filter', 0, 'condition', $having, 'is_positive_conjunct', 1, 'output_filter', 1, 'output_filter_where_clause', 1, 'column_count', scalar @return, 'var_prefix', 'out_row[', 'var_suffix', ' - 1]'})
ref $having $self->serialize_element({%$opts, 'name', 'and', 'columns_used', {}, 'is_first_filter', 0, 'condition', $having, 'is_positive_conjunct', 1, 'output_filter', 1, 'output_filter_where_clause', 1, 'column_count', scalar @return, 'var_prefix', 'out_row[', 'var_suffix', ' - 1]'})
Truth table0%0/3
A && B
A= ref $havingB= $self->serialize_element({%$opts, 'name', 'and', 'columns_used', {}, 'is_first_filter', 0, 'condition', $having, 'is_positive_conjunct', 1, 'output_filter', 1, 'output_filter_where_clause', 1, 'column_count', scalar @return, 'var_prefix', 'out_row[', 'var_suffix', ' - 1]'})
ABresult
0X0
100
111
1305 %$opts,
1306 name=>'and',
1307 columns_used => {},
1308 is_first_filter => 0,
1309 condition => $having,
1310 is_positive_conjunct => 1,
1311 output_filter => 1,
1312 output_filter_where_clause => 1,
1313 column_count => scalar(@return),
1314 var_prefix => 'out_row[',
1315 var_suffix => ' - 1]',
1316 });
1317 #print STDERR Dumper({having_exp=>$having_exp});
1318  
1319 0 my @compiled_filters;
1320 my %old_aggregations;
1321  
1322 my $prev_types = @group_by
1323 ? [map $self->compute_column_data_type($_,$opts), @group_by]
1324 0 ▶ : $opts->{column_types};
Branch: 1 branch
BranchTrueFalseTotal
@group_by ? : 0 0 0
1325  
1326 0 ▶ if (keys(%return_aggregations) and keys(%aggregations)) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %return_aggregations and keys %aggregations) 0 0 0
Condition0%0/3
keys %return_aggregations and keys %aggregations
!ll&&!rl&&r
000
MC/DC0%0/2
keys %return_aggregations and keys %aggregations
keys %return_aggregations keys %aggregations
Truth table0%0/3
A and B
A= keys %return_aggregationsB= keys %aggregations
ABresult
0X0
100
111
1327 # here we should split to two filters:
1328 # filter one is
1329 #
1330 # >> [ for <group> ]
1331 # [ give ] <cols_used>, <aggregations>
1332  
1333 # for this filter, we
1334 # use cols_used and also all occurrences of
1335 # aggregation functions as original parse trees
1336 # the first parse of local aggregations content_decl
1337 # is used to collect these, if embedded into local aggregations
1338 #
1339 # we run serialize_filter using only group_by
1340 # and the faked return
1341  
1342 0 my @aggregations = sort { $a->[0] <=> $b->[0] } values %aggregations;
1343  
1344 0 ▶ if ($DEBUG > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 3) 0 0 0
1345 0 print STDERR "========================\n";
1346 0 print STDERR "PART ONE:\n";
1347 }
1348  
1349 my $agg_filter = {
1350 0 'group-by' => $filter->{'group-by'},
1351 'return' => Treex::PML::Factory->createList([
1352 (map '$'.$_, sort keys(%$return_columns)),
1353 # these we pass in parsed
1354 (map [ 'ANALYTIC_FUNC',
1355 $_->[1], # name
1356 Treex::PML::CloneValue($_->[2]), # args
1357 undef, # over
1358 Treex::PML::CloneValue($_->[4]), # sort by
1359 ], @aggregations),
1360 ]),
1361 };
1362 0 push @compiled_filters, $self->serialize_filter($agg_filter,$opts);
1363  
1364 $prev_types = [
1365 map $self->compute_column_data_type($_,{
1366 %$opts,
1367 column_types => $prev_types,
1368 0 }), @{$agg_filter->{return}}
1369 ];
1370  
1371  
1372 0 $is_first_filter=0;
1373  
1374 0 ▶ if ($DEBUG > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 3) 0 0 0
1375 0 print STDERR "========================\n",
1376 "PART TWO:\n";
1377 }
1378  
1379 # the second filter is obtained as follows:
1380  
1381 # >> [distinct ] <return_cols_remapping_cols_to_cols_used_and_aggregations_to_extra_cols>
1382 # [ sort by <sort_cols> ]
1383  
1384 # so, we clear group_by, aggregations, preserve sort_by, and
1385  
1386 0 $opts->{column_count} = scalar @group_by;
1387 0 @group_by = ();
1388 0 %old_aggregations = %aggregations;
1389 0 %aggregations = ();
1390  
1391 0 ▶ print STDERR Data::Dumper::Dumper( \%old_aggregations ) if $DEBUG > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 3 0 0 0
1392  
1393 # we make sure that
1394 # _RET_VARLIST_ is serialized as the usual _RET_VARLIST_
1395 # appended by aggregation variables
1396 # and _RET_COLNUMS_ is serialized as 0..$#cols_used + @aggregations
1397 }
1398  
1399 0 my %group_columns;
1400 my @group_vars;
1401 0 my @group_by_exp = do {
1402 0 my $i = 0;
1403 0 map { $self->serialize_column($_, {
1404 %$opts,
1405 var_prefix => 'g',
1406 columns_used => \%group_columns,
1407 foreach => ($is_first_filter ? $Foreach : undef),
1408 input_columns => ($is_first_filter ? $input_columns : undef),
1409 vars_used => ($group_vars[$i++]={}),
1410 local_aggregations => undef, # not applicable
1411 aggregations => undef, # not applicable
1412 column_count => $opts->{column_count},
1413 0 ▶ is_first_filter => $is_first_filter,
Branch: 2 branches
BranchTrueFalseTotal
$is_first_filter ? : 0 0 0
$is_first_filter ? : 0 0 0
1414 }) } @group_by
1415 };
1416  
1417 0 my @local_filters;
1418 my @local_group_keys;
1419 0 for my $agg (values %return_aggregations) {
1420 0 my ($num, $name, $args, $over, $sort_by, $over_exp, $vars_used) = @$agg;
1421 # below we pass in something
1422 # that looks like a filter
1423 # but contains parse-trees instead of strings
1424 0 ▶ my $column_count = (@group_by || $opts->{column_count});
Condition0%0/3
@group_by || $opts->{'column_count'}
l!l&&r!l&&!r
000
MC/DC0%0/2
@group_by || $opts->{'column_count'}
@group_by $opts->{'column_count'}
Truth table0%0/3
A || B
A= @group_byB= $opts->{'column_count'}
ABresult
1X1
011
000
1425  
1426 0 ▶ if ($DEBUG > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 3) 0 0 0
1427 0 print STDERR "SUBFILTER\n";
1428 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
1429 0 print STDERR Dumper({
1430 name => $name,
1431 args => $args,
1432 over => $over,
1433 over_exp => $over_exp,
1434 vars_used => $vars_used,
1435 column_count => $column_count,
1436 input_columns => $input_columns,
1437 });
1438 }
1439 0 ▶ print STDERR Data::Dumper::Dumper( \%old_aggregations ) if $DEBUG > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 3 0 0 0
1440  
1441 my @f =
1442 $self->serialize_filter(
1443 {
1444 'group-by' => Treex::PML::Factory->createList(
1445 [@$over]
1446 ),
1447 'return' => Treex::PML::Factory->createList(
1448 [[
1449 'ANALYTIC_FUNC',
1450 $name,
1451 $args,
1452 undef,
1453 $sort_by,
1454 ]]
1455 ),
1456 },
1457 {
1458 column_types => $opts->{column_types},
1459 0 ▶ filter_id => $opts->{filter_id}.'_local_'.$num,
Branch: 2 branches
BranchTrueFalseTotal
$is_first_filter ? : 0 0 0
$is_first_filter ? : 0 0 0
1460 is_local_filter => 1,
1461 is_first_filter => $is_first_filter,
1462 input_columns => ($is_first_filter ? $input_columns : undef),
1463 foreach => ($is_first_filter ? $Foreach : undef),
1464 old_aggregations => \%old_aggregations,
1465 old_aggregations_first_column => scalar(keys(%$return_columns)),
1466 column_count => $column_count,
1467 code_map_flags => {
1468 RETURN => 1,
1469 },
1470 }
1471 );
1472 0 ▶ if (@f>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@f > 1) 0 0 0
1473 0 die "Internal error: serialize_filter on a local filter returned more than one filter:\n @f!";
1474 }
1475 0 $local_filters[$num] = $f[0];
1476 0 my $exp = do {
1477 0 my $i = 0;
1478 join(",\n ",
1479 map {
1480 0 my @vars_used = sort keys %{$vars_used->[$i]};
1481 0 ▶ if (@vars_used) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vars_used) { } 0 0 0
1482 0 '(('.join(' && ',map qq{defined($_)}, @vars_used).') ? ('.$_.') : undef)'
1483 } else {
1484 0 $_
1485 }
1486 } @$over_exp)
1487 };
1488 0 ▶ $local_group_keys[$num] =
Branch: 1 branch
BranchTrueFalseTotal
@$over_exp > 1 ? : 0 0 0
1489 @$over_exp > 1 ? 'join("\x0",'.$exp.')' : $exp;
1490 }
1491  
1492 0 my @aggregations_exp;
1493 my @aggregations_columns;
1494 0 my @aggregations_vars;
1495 0 my @aggregations = sort { $a->[0] <=> $b->[0] } values %aggregations;
1496 0 ▶ if (@aggregations) {
Branch: 1 branch
BranchTrueFalseTotal
if (@aggregations) 0 0 0
1497 @aggregations_exp = map {
1498 0 my $agg_no = $_->[0]; #no
1499 0 my $col_no = 0;
1500 [$_->[1], #name
1501 [ # columns
1502 map $self->serialize_column($_, {
1503 %$opts,
1504 var_prefix => 'v',
1505 columns_used => ($aggregations_columns[$agg_no]||={}),
1506 foreach => ($is_first_filter ? $Foreach : undef),
1507 input_columns => ($is_first_filter ? $input_columns : undef),
1508 vars_used => ($aggregations_vars[$agg_no][$col_no++]={}),
1509 local_aggregations => undef,
1510 aggregations => $opts->{aggregations}, # not applicable
1511 column_count => $opts->{column_count},
1512 is_first_filter => $is_first_filter,
1513 0 }), @{$_->[2]} # args
1514 ],
1515 [ # sort_by columns and types
1516 map {
1517 0 my $type = $self->compute_column_data_type($_->[0],$opts);
1518 [
1519 $self->serialize_column($_->[0], {
1520 %$opts,
1521 var_prefix => 'v',
1522 columns_used => ($aggregations_columns[$agg_no]||={}),
1523 foreach => ($is_first_filter ? $Foreach : undef),
1524 input_columns => ($is_first_filter ? $input_columns : undef),
1525 vars_used => ($aggregations_vars[$agg_no][$col_no++]={}),
1526 local_aggregations => undef,
1527 aggregations => $opts->{aggregations}, # not applicable
1528 column_count => $opts->{column_count},
1529 0 ▶ is_first_filter => $is_first_filter,
Branch: 2 branches
BranchTrueFalseTotal
$is_first_filter ? : 0 0 0
$is_first_filter ? : 0 0 0
Condition0%0/2
$aggregations_columns[$agg_no] ||= {}
l!l
00
MC/DC0%0/1
$aggregations_columns[$agg_no] ||= {}
$aggregations_columns[$agg_no]
Truth table0%0/2
A
A= $aggregations_columns[$agg_no]
Aresult
11
00
1530 }), # sort_column
1531 $type, # sort_column_type
1532 $_->[1] # sort direction (asc,desc)
1533 0 ▶ ]} @{$_->[4]} # sort_by
Branch: 2 branches
BranchTrueFalseTotal
$is_first_filter ? : 0 0 0
$is_first_filter ? : 0 0 0
Condition0%0/2
$aggregations_columns[$agg_no] ||= {}
l!l
00
MC/DC0%0/1
$aggregations_columns[$agg_no] ||= {}
$aggregations_columns[$agg_no]
Truth table0%0/2
A
A= $aggregations_columns[$agg_no]
Aresult
11
00
1534 ],
1535 ]
1536 } @aggregations;
1537 }
1538  
1539 $opts->{column_types} = [
1540 0 map $self->compute_column_data_type($_,{
1541 %$opts,
1542 column_types => $prev_types,
1543 }), @return
1544 ];
1545  
1546 0 my @sort_by_exp = do {
1547 0 my $i = 0;
1548 map {
1549 0 ▶ if (/^\$(\d+)(?:\s+(asc|desc))?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^\$(\d+)(?:\s+(asc|desc))?$/) { } 0 0 0
elsif (defined $_ and length $_) { } 0 0 0
1550 0 my ($col,$dir) = ($1,$2);
1551 0 my $max_col_no = scalar @return;
1552 0 ▶ if ($col > $max_col_no) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col > $max_col_no) 0 0 0
1553 0 die "Invalid number $col in sort by clause (there are only $max_col_no output columns)!\n";
1554 }
1555 0 [$col,$self->compute_column_data_type('$'.$col,$opts),$dir]
1556 ▶ } elsif (defined and length) {
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
1557 0 die "Invalid sort column: $_\n";
1558 } else {
1559 ()
1560 0 }
1561 } @sort_by
1562 };
1563  
1564 0 $opts->{column_count} = scalar @return;
1565  
1566 0 ▶ if ($DEBUG > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUG > 3) 0 0 0
1567 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
1568 print STDERR Dumper({
1569 foreach => $Foreach,
1570 aggregations => \@aggregations_exp,
1571 return_exp => \@return_exp,
1572 return_agg => \%return_aggregations,
1573 group_by_exp => \@group_by_exp,
1574 sort_by_exp => \@sort_by_exp,
1575 colum_types => $opts->{column_types},
1576 0 input_columns => $input_columns,
1577 });
1578 }
1579  
1580 0 my @columns_used = uniq(sort keys(%$return_columns));
1581 0 my @g_columns_used = uniq(sort keys(%group_columns));
1582  
1583 # In case we moved aggregations to a separate filter
1584 # that precedes this one, we want
1585 # _RET_VARLIST_ to be serialized as the usual _RET_VARLIST
1586 # but appended by aggregation variables \$a0..\$a$old_aggregation_count
1587 # and we want _RET_COLNUMS_ to be 0..(@cols_used + $old_aggregation_count - 1)
1588  
1589 0 my $old_aggregation_count = scalar keys %old_aggregations;
1590  
1591 0 my $varlist = join(',', (map '$v'.$_, @columns_used),
1592 (map '$a'.$_, 0..($old_aggregation_count-1))
1593 );
1594 0 ▶ my $colnums =
Branch: 1 branch
BranchTrueFalseTotal
$old_aggregation_count ? : 0 0 0
1595 $old_aggregation_count
1596 ? join(',', 0..($#columns_used+$old_aggregation_count))
1597 : join(',', map $_-1, @columns_used);
1598  
1599 0 my $g_varlist = join(',', map '$g'.$_, @g_columns_used);
1600 0 my $g_colnums = join(',', map $_-1, @g_columns_used);
1601 0 my $agg_varlist = join(',', map '$a'.$_, 0..$#aggregations_exp);
1602 0 my $local_varlist = join(',',map '$l'.$_,0..$#local_filters);
1603  
1604 0 my ($agg_final,$all_agg_code,$init_agg,$is_windowing);
1605 {
1606 0 $init_agg = do {
1607 0 my $i = 0;
1608 join("; \n",
1609 map {
1610 0 '$self->{aggregated}['.($i++).'] = '.$aggregation_init{ $_->[0] }."; # init $_->[0](...)"
1611 } @aggregations_exp)
1612 };
1613  
1614 {
1615 0 my (@agg_code, @agg_final,@is_windowing);
1616 0 my $i = 0;
1617 0 for my $aggr (@aggregations_exp) {
1618 0 my $funcname = $aggr->[0];
1619 0 my $args = $aggr->[1];
1620 0 my $sort_by_columns_and_types = $aggr->[2];
1621 0 ▶ my $agg_code = $aggregation_template{$funcname} || $aggregation_template{_DEFAULT_} ;
Condition0%0/3
$aggregation_template{$funcname} || $aggregation_template{'_DEFAULT_'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$aggregation_template{$funcname} || $aggregation_template{'_DEFAULT_'}
$aggregation_template{$funcname} $aggregation_template{'_DEFAULT_'}
Truth table0%0/3
A || B
A= $aggregation_template{$funcname}B= $aggregation_template{'_DEFAULT_'}
ABresult
1X1
011
000
1622 0 my @columns_used = uniq(sort keys(%{$aggregations_columns[$i]}));
1623 0 my $varlist = join(',', map '$v'.$_, @columns_used);
1624 0 my $colnums = join(',', map $_-1, @columns_used);
1625 0 my $defined = join(' && ', map 'defined($v'.$_.')', @columns_used);
1626 0 my $op = $aggregation_op{$funcname};
1627 0 ▶ if (defined $op) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $op) 0 0 0
1628 0 _code_substitute($op,
1629 {
1630 _ARG_ => $args->[0],
1631 _SORT_ARGS_ => join(',',map $_->[0], @$sort_by_columns_and_types),
1632 }
1633 )
1634 }
1635  
1636 # no substitutions on $agg_code past this point:
1637 0 _code_substitute($agg_code,
1638 {
1639 _FUNC_VARLIST_ => $varlist,
1640 _FUNC_COLNUMS_ => $colnums,
1641 _FUNC_DEFINED_ => $defined,
1642 _FUNC_OP_ => $op,
1643 });
1644  
1645 0 push @agg_code, " # $funcname(...)\n".$agg_code;
1646 0 ▶ push @is_windowing,($funcname =~ /^(?:rank|dense_rank|row_number)$/ ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$funcname =~ /^(?:rank|dense_rank|row_number)$/ ? : 0 0 0
1647  
1648 0 push @agg_final, 'my $a'.$i.' = $self->{aggregated}['.$i.'];';
1649 0 ▶ if (exists $aggregation_final{$funcname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $aggregation_final{$funcname}) 0 0 0
1650 0 my $final_code = $aggregation_final{$funcname};
1651 0 my $arg1;
1652 my $sort_cmp;
1653 0 ▶ if ($funcname =~ /^(concat|rank|dense_rank|row_number)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($funcname =~ /^(concat|rank|dense_rank|row_number)$/) 0 0 0
1654 0 $arg1 = $aggr->[1][1];
1655 0 ▶ $arg1 = defined($arg1) && length($arg1) ? $arg1 : q('');
Branch: 1 branch
BranchTrueFalseTotal
defined $arg1 && length $arg1 ? : 0 0 0
Condition0%0/3
defined $arg1 and length $arg1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $arg1 and length $arg1
defined $arg1 length $arg1
Truth table0%0/3
A and B
A= defined $arg1B= length $arg1
ABresult
0X0
100
111
1656 0 ▶ my @op = map { $_->[1]==COL_NUMERIC ? '<=>' : 'cmp' } @$sort_by_columns_and_types;
Branch: 1 branch
BranchTrueFalseTotal
$_->[1] == 2 ? : 0 0 0
1657 0 ▶ my @dir = map { $_->[2] && $_->[2] eq 'desc' ? '-' : '' } @$sort_by_columns_and_types;
Branch: 1 branch
BranchTrueFalseTotal
$_->[2] && $_->[2] eq 'desc' ? : 0 0 0
Condition0%0/3
$_->[2] and $_->[2] eq "desc"
!ll&&!rl&&r
000
MC/DC0%0/2
$_->[2] and $_->[2] eq "desc"
$_->[2] $_->[2] eq "desc"
Truth table0%0/3
A and B
A= $_->[2]B= $_->[2] eq "desc"
ABresult
0X0
100
111
1658 0 $sort_cmp = join(' or ',
1659 map $dir[$_].'( $a->['.($_+1).'] '.$op[$_].' $b->['.($_+1).'])',
1660 0..$#$sort_by_columns_and_types
1661 );
1662 }
1663 0 ▶ _code_substitute($final_code,
Branch: 1 branch
BranchTrueFalseTotal
$sort_cmp ? : 0 0 0
Condition0%0/2
$sort_cmp || '1'
l!l
00
MC/DC0%0/1
$sort_cmp || '1'
$sort_cmp
Truth table0%0/2
A
A= $sort_cmp
Aresult
11
00
1664 {
1665 _RESULT_ => '$a'.$i,
1666 _ARG1_ => $arg1,
1667 _CMP_ => ($sort_cmp || '1'),
1668 _SORT_CMP_ => ($sort_cmp ? 'sort {'.$sort_cmp.'}' : '')
1669 });
1670 0 push @agg_final,$final_code;
1671 }
1672 0 $i++;
1673 }
1674 0 $agg_final = join('',map { "\n ".$_ } @agg_final);
1675 0 $all_agg_code = join(',',@agg_code);
1676 0 $is_windowing = join(',',@is_windowing);
1677 }
1678 }
1679  
1680 0 my $cols = $self->serialize_col_expressions(\@return_exp, \@return_vars);
1681 0 my $group_cols = $self->serialize_col_expressions(\@group_by_exp, \@group_vars);
1682 0 my $local_group_keys = join (",\n ",@local_group_keys);
1683  
1684 0 my $output_filter;
1685 # first without any inner aggregations
1686 my $code;
1687 0 my $filter_id = $opts->{filter_id};
1688  
1689 0 ▶ if (@group_by) {
Branch: 4 branches
BranchTrueFalseTotal
if (@group_by) { } 0 0 0
elsif (@aggregations_exp and not keys %return_aggregations) { } 0 0 0
elsif (not @aggregations_exp and keys %return_aggregations) { } 0 0 0
elsif (@aggregations_exp and keys %return_aggregations) { } 0 0 0
1690 # use group_by template
1691 0 ▶ if (!@local_filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @local_filters) { } 0 0 0
1692 $code = _code_from_template('GROUP', {
1693 _MAP_ => { RETURN => 1 },
1694 RETURN => 0,
1695 DISTINCT => $distinct,
1696 0 ▶ %{$opts->{code_map_flags}||{}},
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"code_map_flags"} or {} 0 0 0
1697 0 },$opts->{filter_id});
1698 } else {
1699 0 die "TODO";
1700 }
1701 ▶ } elsif (@aggregations_exp and !keys(%return_aggregations)) {
Condition0%0/3
@aggregations_exp and not keys %return_aggregations
!ll&&!rl&&r
000
MC/DC0%0/2
@aggregations_exp and not keys %return_aggregations
@aggregations_exp not keys %return_aggregations
Truth table0%0/3
A and not(B)
A= @aggregations_expB= not keys %return_aggregations
ABresult
0X0
100
111
1702 # use the direct template
1703 $code = _code_from_template('AGGREGATE', {
1704 RETURN => 0,
1705 DISTINCT => $distinct,
1706 0 ▶ %{$opts->{code_map_flags}||{}},
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"code_map_flags"} or {} 0 0 0
1707 0 },$opts->{filter_id});
1708 ▶ } elsif (!@aggregations_exp and keys(%return_aggregations)) {
Condition0%0/3
not @aggregations_exp and keys %return_aggregations
!ll&&!rl&&r
000
MC/DC0%0/2
not @aggregations_exp and keys %return_aggregations
not @aggregations_exp keys %return_aggregations
Truth table0%0/3
not(A) and B
A= not @aggregations_expB= keys %return_aggregations
ABresult
0X0
100
111
1709 $code = _code_from_template('INNER_AGGREGATE', {
1710 RETURN => 0,
1711 DISTINCT => $distinct,
1712 0 ▶ %{$opts->{code_map_flags}||{}},
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"code_map_flags"} or {} 0 0 0
1713 0 },$opts->{filter_id});
1714 ▶ } elsif (@aggregations_exp and keys(%return_aggregations)) {
Condition0%0/3
@aggregations_exp and keys %return_aggregations
!ll&&!rl&&r
000
MC/DC0%0/2
@aggregations_exp and keys %return_aggregations
@aggregations_exp keys %return_aggregations
Truth table0%0/3
A and B
A= @aggregations_expB= keys %return_aggregations
ABresult
0X0
100
111
1715 0 die "TODO";
1716 } else {
1717 # no aggregations at all
1718 $code = _code_from_template('PLAIN', {
1719 RETURN => 0,
1720 DISTINCT => $distinct,
1721 0 ▶ %{$opts->{code_map_flags}||{}},
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"code_map_flags"} or {} 0 0 0
1722 0 },$opts->{filter_id});
1723 }
1724  
1725 # below, user-data may be involved, we must do a one step-substitution
1726 0 ▶ _code_substitute($code,
Branch: 1 branch
BranchTrueFalseTotal
defined $having_exp && length $having_exp ? : 0 0 0
Condition0%0/3
defined $having_exp and length $having_exp
!ll&&!rl&&r
000
MC/DC0%0/2
defined $having_exp and length $having_exp
defined $having_exp length $having_exp
Truth table0%0/3
A and B
A= defined $having_expB= length $having_exp
ABresult
0X0
100
111
1727 {
1728 _IS_WINDOWING_ => $is_windowing,
1729 _AGGREGATIONS_ => $all_agg_code,
1730 _RET_VARLIST_ => $varlist,
1731 _GROUP_VARLIST_ => $g_varlist,
1732 _RET_COLNUMS_ => $colnums,
1733 _GROUP_COLNUMS_ => $g_colnums,
1734 _AGG_FINALIZE_ => $agg_final,
1735 _INIT_AGG_ => $init_agg,
1736 _GROUP_COLS_ => $group_cols,
1737 _RET_COLS_ => $cols,
1738 _IF_FILTER_ => (defined($having_exp) && length($having_exp) ? (' if '.$having_exp) : ''),
1739 _LOCAL_VARLIST_ => $local_varlist,
1740 _LOCAL_GROUP_KEYS_ => $local_group_keys,
1741 }
1742 );
1743 0 ▶ $output_filter = eval $code; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1744 0 $output_filter->{local_filters_code} = [ map $_->{code}, @local_filters ];
1745 0 $output_filter->{code}=$code;
1746  
1747 # filter_init:
1748 0 ▶ if ($is_first_filter and !$opts->{is_local_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_first_filter and not $opts->{"is_local_filter"}) 0 0 0
Condition0%0/3
$is_first_filter and not $opts->{"is_local_filter"}
!ll&&!rl&&r
000
MC/DC0%0/2
$is_first_filter and not $opts->{"is_local_filter"}
$is_first_filter not $opts->{"is_local_filter"}
Truth table0%0/3
A and not(B)
A= $is_first_filterB= not $opts->{"is_local_filter"}
ABresult
0X0
100
111
1749 0 my $code = q`
1750 $first_filter->{process_row}->($first_filter, [
1751 _RET_COLS_
1752 ]);
1753 `;
1754  
1755 # no substitutions past this point!
1756 0 _code_substitute($code,
1757 {
1758 _RET_COLS_ => join (",\n ",@$input_columns),
1759 }
1760 );
1761 # now we simulate a left join
1762 {
1763 0 $code = $self->foreach_wrap($Foreach,$code,
1764 [[0,'sub {'],
1765 [1,'my ($self)=@_;'],
1766 [1,'my $first_filter = $self->{filters}[0];']],
1767 [[0,'}']]);
1768 }
1769 0 $opts->{filter_init} = $code;
1770 }
1771 0 push @compiled_filters, $output_filter;
1772  
1773 0 ▶ if (@sort_by_exp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sort_by_exp) 0 0 0
1774 my $sort_code = _code_from_template('SORT', {
1775 RETURN => 0,
1776 DISTINCT => 0,
1777 0 },'sort_'.$opts->{filter_id});
1778 # my $sort_varlist = join(',', map '$v'.$_, @sort_columns_used);
1779 # my $sort_colnums = join(',', map $_-1, @sort_columns_used);
1780 # my $sort_cols = $self->serialize_col_expressions(\@sort_by_exp, \@sort_vars);
1781 0 ▶ my @op = map { $_->[1]==COL_NUMERIC ? '<=>' : 'cmp' } @sort_by_exp;
Branch: 1 branch
BranchTrueFalseTotal
$_->[1] == 2 ? : 0 0 0
1782 my $sort_cmp = join(' or ',
1783 map {
1784 0 ▶ (($_->[2] and $_->[2] eq 'desc') ? '-' : '')
Branch: 2 branches
BranchTrueFalseTotal
$_->[2] && $_->[2] eq 'desc' ? : 0 0 0
$_->[1] == 2 ? : 0 0 0
Condition0%0/3
$_->[2] and $_->[2] eq "desc"
!ll&&!rl&&r
000
MC/DC0%0/2
$_->[2] and $_->[2] eq "desc"
$_->[2] $_->[2] eq "desc"
Truth table0%0/3
A and B
A= $_->[2]B= $_->[2] eq "desc"
ABresult
0X0
100
111
1785 .'( $a->['.($_->[0]-1).'] '
1786 .($_->[1]==COL_NUMERIC ? '<=>' : 'cmp')
1787 .' $b->['.($_->[0]-1).'])'
1788 } @sort_by_exp);
1789 0 ▶ _code_substitute($sort_code,
Branch: 1 branch
BranchTrueFalseTotal
$sort_cmp ? : 0 0 0
Condition0%0/2
$sort_cmp || '1'
l!l
00
MC/DC0%0/1
$sort_cmp || '1'
$sort_cmp
Truth table0%0/2
A
A= $sort_cmp
Aresult
11
00
1790 {
1791 _CMP_ => ($sort_cmp || '1'),
1792 _SORT_CMP_ => ($sort_cmp ? 'sort {'.$sort_cmp.'}' : '')
1793 }
1794 );
1795  
1796 0 ▶ $output_filter = eval $sort_code; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1797 0 $output_filter->{code}=$sort_code;
1798 0 push @compiled_filters, $output_filter;
1799 }
1800 0 return @compiled_filters;
1801 }
1802  
1803 sub foreach_wrap {
1804 0 ▶ my ($self,$Foreach,$code,$init_wrap_l,$init_wrap_r)=@_;
Subroutine foreach_wrap: not called CC=16 SCAR=56.1
Pod undocumented
1805 # now we simulate a left join
1806 0 ▶ my @wrap_l=$init_wrap_l ? @$init_wrap_l : ();
Branch: 1 branch
BranchTrueFalseTotal
$init_wrap_l ? : 0 0 0
1807 0 ▶ my @wrap_r=$init_wrap_r ? @$init_wrap_r : ();
Branch: 1 branch
BranchTrueFalseTotal
$init_wrap_r ? : 0 0 0
1808  
1809 0 my $i=0;
1810 0 my $indent=1;
1811 0 foreach my $f (@$Foreach) { # he?
1812 0 my $prev_var='$var'.($i-1);
1813 0 ▶ if ($f->[0]==1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f->[0] == 1) { } 0 0 0
elsif ($f->[0] == 0) { } 0 0 0
1814 push @wrap_l,
1815 [$indent,
1816 ($i && !$f->[2] && $f->[1]=~/\Q$prev_var\E/)
1817 ? qq`my \@var$i = defined(\$var`.($i-1).qq`) ? $f->[1] : ();`
1818 0 : ref($f->[2]) && @{$f->[2]}
1819 0 ▶ ? qq`my \@var$i = `.join(' && ', map qq`defined($_)`,@{$f->[2]}).qq` ? $f->[1] : (); # return_vars\n`
Branch: 2 branches
BranchTrueFalseTotal
$i && !$f->[2] && $f->[1] =~ /\Q$prev_var\E/ ? : 0 0 0
ref $f->[2] && @{$f->[2];} ? : 0 0 0
Condition0%0/9
$i and not $f->[2] and $f->[1] =~ /\Q$prev_var\E/
!ll&&!rl&&r
000
$i and not $f->[2]
!ll&&!rl&&r
000
ref $f->[2] and @{$f->[2];}
!ll&&!rl&&r
000
MC/DC0%0/3
$i and not $f->[2] and $f->[1] =~ /\Q$prev_var\E/
$i not $f->[2] $f->[1] =~ /\Q$prev_var\E/
MC/DC0%0/2
ref $f->[2] and @{$f->[2];}
ref $f->[2] @{$f->[2];}
Truth table0%0/4
A and not(B) and C
A= $iB= not $f->[2]C= $f->[1] =~ /\Q$prev_var\E/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A and B
A= ref $f->[2]B= @{$f->[2];}
ABresult
0X0
100
111
1820 : qq`my \@var$i = $f->[1]; # no defined test\n`
1821 ],
1822 [$indent,qq`foreach my \$var$i (\@var$i ? \@var$i : (undef)) {`];
1823 0 unshift @wrap_r, [$i,qq`}`];
1824 0 $indent++;
1825 } elsif ($f->[0]==0) {
1826 push @wrap_l, [$indent,
1827 ($i && !$f->[2] && $f->[1]=~/\Q$prev_var\E/)
1828 ? qq`my \$var$i = defined(\$var`.($i-1).qq`) ? $f->[1] : undef;`
1829 0 : ref($f->[2]) && @{$f->[2]}
1830 0 ▶ ? qq`my \$var$i = `.join(' && ', map qq`defined($_)`,@{$f->[2]}).qq` ? $f->[1] : undef; # return_vars\n`
Branch: 2 branches
BranchTrueFalseTotal
$i && !$f->[2] && $f->[1] =~ /\Q$prev_var\E/ ? : 0 0 0
ref $f->[2] && @{$f->[2];} ? : 0 0 0
Condition0%0/9
$i and not $f->[2] and $f->[1] =~ /\Q$prev_var\E/
!ll&&!rl&&r
000
$i and not $f->[2]
!ll&&!rl&&r
000
ref $f->[2] and @{$f->[2];}
!ll&&!rl&&r
000
MC/DC0%0/3
$i and not $f->[2] and $f->[1] =~ /\Q$prev_var\E/
$i not $f->[2] $f->[1] =~ /\Q$prev_var\E/
MC/DC0%0/2
ref $f->[2] and @{$f->[2];}
ref $f->[2] @{$f->[2];}
Truth table0%0/4
A and not(B) and C
A= $iB= not $f->[2]C= $f->[1] =~ /\Q$prev_var\E/
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A and B
A= ref $f->[2]B= @{$f->[2];}
ABresult
0X0
100
111
1831 : qq`my \$var$i = $f->[1]; # no defined test`];
1832 }
1833 0 $i ++;
1834 }
1835 return join('',
1836 0 map { (' ' x ($_->[0]+10)).$_->[1]."\n" }
1837 (
1838 @wrap_l,
1839 [$indent,$code],
1840 @wrap_r,
1841 )
1842 );
1843 }
1844  
1845  
1846 sub serialize_col_expressions {
1847 0 ▶ my ($self, $expressions, $vars)=@_;
Subroutine serialize_col_expressions: not called CC=3 SCAR=24.8
Pod undocumented
1848 0 my $i = 0;
1849 return
1850 join (",\n ",
1851 map {
1852 0 my @vars_used = sort keys %{$vars->[$i++]};
1853 0 ▶ if (@vars_used and !/^\$[a-z][0-9]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vars_used and not /^\$[a-z][0-9]+$/) { } 0 0 0
Condition0%0/3
@vars_used and not /^\$[a-z][0-9]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
@vars_used and not /^\$[a-z][0-9]+$/
@vars_used not /^\$[a-z][0-9]+$/
Truth table0%0/3
A and not(B)
A= @vars_usedB= not /^\$[a-z][0-9]+$/
ABresult
0X0
100
111
1854 0 '(('.join(' && ',map qq{defined($_)}, @vars_used).') ? ('.$_.') : undef)'
1855 } else {
1856 0 $_
1857 }
1858 } @$expressions);
1859 }
1860  
1861 sub serialize_column {
1862 0 ▶ my ($self,$column,$opts)=@_;
Subroutine serialize_column: not called CC=4 SCAR=30.0
Pod undocumented
1863 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1864 0 my $pt;
1865 0 ▶ if (ref($column)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $column) { } 0 0 0
1866 0 $pt = $column;
1867 } else {
1868 # column is a PT:
1869 0 $pt = PMLTQ::Common::parse_column_expression($column); # $pt stands for parse tree
1870 0 ▶ die "Invalid column expression '$column'" unless defined $pt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pt 0 0 0
1871 }
1872 0 return $self->serialize_expression_pt($pt,{
1873 %$opts,
1874 output_filter => 1,
1875 expression=>$column,
1876 });
1877 }
1878  
1879 sub serialize_conditions {
1880 0 ▶ my ($self,$qnode,$opts)=@_;
Subroutine serialize_conditions: not called CC=22 SCAR=61.2
Pod undocumented
1881 my $conditions = $self->serialize_element({
1882 %$opts,
1883 id => $qnode->{name},
1884 0 type => PMLTQ::Common::GetQueryNodeType($qnode,$self->{type_mapper}),
1885 name => 'and',
1886 condition => $qnode,
1887 });
1888  
1889 0 my $pos = $opts->{query_pos};
1890 0 my $match_pos = $self->{pos2match_pos}[$pos];
1891 0 my $optional;
1892 0 ▶ if ($qnode->{optional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qnode->{"optional"}) 0 0 0
1893 0 my $parent_pos = $self->{parent_pos}[$pos];
1894 0 ▶ if (!defined $parent_pos) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent_pos) 0 0 0
1895 0 die "Optional node cannot at the same time be the head of a subquery!";
1896 }
1897 0 $optional = '$matched_nodes->['.$self->{pos2match_pos}[$parent_pos].']';
1898 }
1899 0 ▶ if ($conditions and $conditions=~/\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conditions and $conditions =~ /\S/) { } 0 0 0
Condition0%0/3
$conditions and $conditions =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$conditions and $conditions =~ /\S/
$conditions $conditions =~ /\S/
Truth table0%0/3
A and B
A= $conditionsB= $conditions =~ /\S/
ABresult
0X0
100
111
1900 0 ▶ if (defined $optional) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $optional) 0 0 0
1901 0 $conditions='('.$optional.'==$node or '.$conditions.')';
1902 }
1903 } else {
1904 0 $conditions=undef
1905 }
1906  
1907 0 ▶ print STDERR "CONDITIONS[$pos/$match_pos]: $conditions\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
1908 0 my $check_preceding = '';
1909  
1910 0 my $recompute_cond = $opts->{recompute_condition}[$match_pos];
1911 0 ▶ if (defined $recompute_cond) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $recompute_cond) 0 0 0
1912 $check_preceding = join('', map {"\n and ".
1913 0 '$conditions['.$_.']->($matched_nodes->['.$self->{pos2match_pos}[$_].'],'
1914 .'$iterators['.$_.']->file,'
1915 .'1) '
1916 0 } sort { $a<=>$b } keys %$recompute_cond);
1917 }
1918 0 ▶ if (length $check_preceding) { # will check preceding nodes in chain
Branch: 1 branch
BranchTrueFalseTotal
if (length $check_preceding) 0 0 0
1919 0 $check_preceding = "\n".
1920 ' and ($backref or '.
1921 '($matched_nodes->['.$match_pos.']=$node) # a trick: make it appear as if this node already matched!'."\n".
1922 $check_preceding.
1923 ')';
1924 }
1925 my $nodetest =
1926 0 ▶ $qnode->{overlapping} ? '$node' :
Branch: 2 branches
BranchTrueFalseTotal
$qnode->{'overlapping'} ? : 0 0 0
defined $optional ? : 0 0 0
1927 '$node and ($backref or '
1928 .(defined($optional) ? $optional.'==$node or ' : '')
1929 .'!exists($have{$node}))';
1930 0 ▶ my $type_name = (PMLTQ::Common::IsMemberNode($qnode) or $qnode->{'node-type'} eq '*') ? undef : quotemeta($qnode->{'node-type'});
Branch: 1 branch
BranchTrueFalseTotal
PMLTQ::Common::IsMemberNode($qnode) || $qnode->{'node-type'} eq '*' ? : 0 0 0
Condition0%0/3
PMLTQ::Common::IsMemberNode($qnode) or $qnode->{"node-type"} eq "*"
l!l&&r!l&&!r
000
MC/DC0%0/2
PMLTQ::Common::IsMemberNode($qnode) or $qnode->{"node-type"} eq "*"
PMLTQ::Common::IsMemberNode($qnode) $qnode->{"node-type"} eq "*"
Truth table0%0/3
A or B
A= PMLTQ::Common::IsMemberNode($qnode)B= $qnode->{"node-type"} eq "*"
ABresult
1X1
011
000
1931 0 ▶ my $id=$qnode->{'name'} || '';
Condition0%0/2
$qnode->{'name'} || ''
l!l
00
MC/DC0%0/1
$qnode->{'name'} || ''
$qnode->{'name'}
Truth table0%0/2
A
A= $qnode->{'name'}
Aresult
11
00
1932 my $sub = qq(#line 1 "query-node/${match_pos}/$id"\n)
1933 . 'sub { my ($node,$fsfile,$backref)=@_; '."\n "
1934 #. 'print STDERR "node_ref: ".ref($node)."\n";' . "\n"
1935 #. 'print STDERR "backref: $backref\n";' . "\n"
1936 #. 'print STDERR "have: ($have{$node})\n";' . "\n"
1937 .$nodetest
1938 .(defined($type_name) && length($type_name) ? "\n and ".
1939 0 ▶ ($qnode->{'node-type'} =~ m{^(?:([^/]+):)?\*$}
Branch: 3 branches
BranchTrueFalseTotal
defined $type_name && length $type_name ? : 0 0 0
$qnode->{'node-type'} =~ m[^(?:([^/]+):)?\*$] ? : 0 0 0
defined $conditions ? : 0 0 0
Condition0%0/3
defined $type_name and length $type_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type_name and length $type_name
defined $type_name length $type_name
Truth table0%0/3
A and B
A= defined $type_nameB= length $type_name
ABresult
0X0
100
111
1940 ? q[$node->type->get_schema->get_root_name eq qq(].quotemeta($1).q[)]
1941 : q[$node->type->get_decl_path =~ m{^\!].$type_name.q[(?:\.type)?$}]) : ())
1942 .(defined($conditions) ? "\n and ".$conditions : '')
1943 . $check_preceding
1944 ."\n}";
1945 0 ▶ print STDERR "SUB: $sub\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
1946 # save sub to file
1947 0 my $path = "query-node/${match_pos}";
1948  
1949 # save subs as files for debugger
1950 0 ▶ if ($DEBUGGER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::BtredEvaluator::DEBUGGER) 0 0 0
1951 1 ▶ use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
1952 0 File::Path::make_path($path);
1953 0 ▶ open my $SUB, '>', "$path/$id"
Branch: 1 branch
BranchTrueFalseTotal
open my $SUB, ">", "$path/$id" or die "Cannot open debugger output\n" 0 0 0
1954 or die "Cannot open debugger output\n";
1955 0 print {$SUB} $sub;
1956 0 ▶ close $SUB or die "Cannot close debugger output\n";
Branch: 1 branch
BranchTrueFalseTotal
close $SUB or die "Cannot close debugger output\n" 0 0 0
1957 }
1958 0 return $sub;
1959 }
1960  
1961 sub serialize_test {
1962 0 ▶ my ($self, $left, $operator, $right, $left_type, $right_type)=@_;
Subroutine serialize_test: not called CC=37 SCAR=72.5
Pod undocumented
1963 0 ▶ my $negate = $operator=~s/^!// ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$operator =~ s/^!// ? : 0 0 0
1964 0 ▶ $left_type ||= 0;
Condition0%0/2
$left_type ||= 0
l!l
00
MC/DC0%0/1
$left_type ||= 0
$left_type
Truth table0%0/2
A
A= $left_type
Aresult
11
00
1965 0 ▶ $right_type ||= 0;
Condition0%0/2
$right_type ||= 0
l!l
00
MC/DC0%0/1
$right_type ||= 0
$right_type
Truth table0%0/2
A
A= $right_type
Aresult
11
00
1966  
1967 # fix empty variables
1968 0 ▶ $left = "($left||0)" if ($left_type == COL_NUMERIC && $left =~ /^\$/);
Branch: 1 branch
BranchTrueFalseTotal
if $left_type == 2 and $left =~ /^\$/ 0 0 0
Condition0%0/3
$left_type == 2 and $left =~ /^\$/
!ll&&!rl&&r
000
MC/DC0%0/2
$left_type == 2 and $left =~ /^\$/
$left_type == 2 $left =~ /^\$/
Truth table0%0/3
A and B
A= $left_type == 2B= $left =~ /^\$/
ABresult
0X0
100
111
1969 0 ▶ $right = "($right||0)" if ($right_type == COL_NUMERIC && $right =~ /^\$/);
Branch: 1 branch
BranchTrueFalseTotal
if $right_type == 2 and $right =~ /^\$/ 0 0 0
Condition0%0/3
$right_type == 2 and $right =~ /^\$/
!ll&&!rl&&r
000
MC/DC0%0/2
$right_type == 2 and $right =~ /^\$/
$right_type == 2 $right =~ /^\$/
Truth table0%0/3
A and B
A= $right_type == 2B= $right =~ /^\$/
ABresult
0X0
100
111
1970  
1971 0 ▶ if ($operator eq '=') {
Branch: 6 branches
BranchTrueFalseTotal
if ($operator eq '=') { } 0 0 0
elsif ($operator eq '<') { } 0 0 0
elsif ($operator eq '>') { } 0 0 0
elsif ($operator eq '<=') { } 0 0 0
elsif ($operator eq '>=') { } 0 0 0
elsif ($operator eq '~') { } 0 0 0
1972 0 ▶ if ($left_type == COL_NUMERIC && $right_type == COL_NUMERIC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_type == 2 and $right_type == 2) { } 0 0 0
Condition0%0/3
$left_type == 2 and $right_type == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$left_type == 2 and $right_type == 2
$left_type == 2 $right_type == 2
Truth table0%0/3
A and B
A= $left_type == 2B= $right_type == 2
ABresult
0X0
100
111
1973 0 ▶ $operator = $negate ? '!=' : '==';
Branch: 1 branch
BranchTrueFalseTotal
$negate ? : 0 0 0
1974 } else {
1975 0 ▶ $operator = $negate ? 'ne' : 'eq';
Branch: 1 branch
BranchTrueFalseTotal
$negate ? : 0 0 0
1976 }
1977 } elsif ($operator eq '<') {
1978 0 ▶ $operator = 'lt' unless ($left_type == COL_NUMERIC && $right_type == COL_NUMERIC);
Branch: 1 branch
BranchTrueFalseTotal
unless $left_type == 2 and $right_type == 2 0 0 0
Condition0%0/3
$left_type == 2 and $right_type == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$left_type == 2 and $right_type == 2
$left_type == 2 $right_type == 2
Truth table0%0/3
A and B
A= $left_type == 2B= $right_type == 2
ABresult
0X0
100
111
1979 } elsif ($operator eq '>') {
1980 0 ▶ $operator = 'gt' unless ($left_type == COL_NUMERIC && $right_type == COL_NUMERIC);
Branch: 1 branch
BranchTrueFalseTotal
unless $left_type == 2 and $right_type == 2 0 0 0
Condition0%0/3
$left_type == 2 and $right_type == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$left_type == 2 and $right_type == 2
$left_type == 2 $right_type == 2
Truth table0%0/3
A and B
A= $left_type == 2B= $right_type == 2
ABresult
0X0
100
111
1981 } elsif ($operator eq '<=') {
1982 0 ▶ $operator = 'le' unless ($left_type == COL_NUMERIC && $right_type == COL_NUMERIC);
Branch: 1 branch
BranchTrueFalseTotal
unless $left_type == 2 and $right_type == 2 0 0 0
Condition0%0/3
$left_type == 2 and $right_type == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$left_type == 2 and $right_type == 2
$left_type == 2 $right_type == 2
Truth table0%0/3
A and B
A= $left_type == 2B= $right_type == 2
ABresult
0X0
100
111
1983 } elsif ($operator eq '>=') {
1984 0 ▶ $operator = 'ge' unless ($left_type == COL_NUMERIC && $right_type == COL_NUMERIC);
Branch: 1 branch
BranchTrueFalseTotal
unless $left_type == 2 and $right_type == 2 0 0 0
Condition0%0/3
$left_type == 2 and $right_type == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$left_type == 2 and $right_type == 2
$left_type == 2 $right_type == 2
Truth table0%0/3
A and B
A= $left_type == 2B= $right_type == 2
ABresult
0X0
100
111
1985 } elsif ($operator eq '~') {
1986 0 ▶ $operator = $negate ? '!~' : '=~';
Branch: 1 branch
BranchTrueFalseTotal
$negate ? : 0 0 0
1987 }
1988 0 my $condition;
1989 0 ▶ if ($operator eq '~*') {
Branch: 4 branches
BranchTrueFalseTotal
if ($operator eq '~*') { } 0 0 0
elsif ($operator eq 'in') { } 0 0 0
elsif ($operator eq '->') { } 0 0 0
elsif ($operator =~ /^<(.*),(.*)>$/) { } 0 0 0
1990 0 ▶ $condition='do{ my $regexp='.$right.'; '.$left.($negate ? '!~' : '=~').' /$regexp/i}';
Branch: 1 branch
BranchTrueFalseTotal
$negate ? : 0 0 0
1991 } elsif ($operator eq 'in') {
1992 # TODO: 'first' is actually pretty slow, we should use a disjunction
1993 # but splitting may be somewhat non-trivial in such a case
1994 # - postponing till we know exactly how a tree-query term may look like
1995 0 ▶ $condition='do{ my $node='.$left.'; '.($negate ? '!' : '').'grep $_ eq '.$left.', '.$right.'}';
Branch: 1 branch
BranchTrueFalseTotal
$negate ? : 0 0 0
1996 # #$condition=$left.' =~ m{^(?:'.join('|',eval $right).')$}';
1997 # $right=~s/^\s*\(//;
1998 # $right=~s/\)\s*$//;
1999 # my @right = split /,/,$right;
2000 # $condition='do { my $node='.$left.'; ('.join(' or ',map { '$node eq '.$_ } @right).')}';
2001 } elsif ($operator eq '->') {
2002 # this is a special faked operator for PMLREF/ID comparison
2003 0 $condition='('.$left.' =~ /^(.*#)?\Q'.$right.'\E$/)';
2004 } elsif ($operator=~/^<(.*),(.*)>$/) { # special "fake is-between operator"
2005 0 my $exp = qq{($left - $right)};
2006 0 ▶ $condition =
Branch: 3 branches
BranchTrueFalseTotal
length $1 && length $2 ? : 0 0 0
length $1 ? : 0 0 0
length $2 ? : 0 0 0
Condition0%0/3
length $1 and length $2
!ll&&!rl&&r
000
MC/DC0%0/2
length $1 and length $2
length $1 length $2
Truth table0%0/3
A and B
A= length $1B= length $2
ABresult
0X0
100
111
2007 (length($1) and length($2)) ? qq{($exp>=$1 and $exp<=$2)} :
2008 length($1) ? qq{$exp >= $1} :
2009 length($2) ? qq{$exp <= $2} : die "Internal error: cannot serialize operator $operator\n";
2010 } else {
2011 0 $condition='('.$left.' '.$operator.' '.$right.')';
2012 }
2013 0 return $condition;
2014 }
2015  
2016 sub serialize_element {
2017 0 ▶ my ($self,$opts)=@_;
Subroutine serialize_element: not called CC=123 SCAR=96.3
Pod undocumented
2018  
2019 0 my ($name,$node)=map {$opts->{$_}} qw(name condition);
2020 0 ▶ my $pos = $opts->{query_pos} || 0;
Condition0%0/2
$opts->{'query_pos'} || 0
l!l
00
MC/DC0%0/1
$opts->{'query_pos'} || 0
$opts->{'query_pos'}
Truth table0%0/2
A
A= $opts->{'query_pos'}
Aresult
11
00
2021 0 my $match_pos = $self->{pos2match_pos}[$pos]; #WARN Use of uninitialized value $pos in array element (same bug is in original implementation)
2022 0 ▶ if ($name eq 'test') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'test') { } 0 0 0
elsif ($name =~ /^(?:and|or|not)$/) { } 0 0 0
elsif ($name eq 'subquery') { } 0 0 0
elsif ($name eq 'ref') { } 0 0 0
2023 0 my %depends_on;
2024 0 my $foreach = [];
2025 0 my ($left,$right,$left_type,$right_type);
2026 0 my $condition;
2027 0 ▶ if ($opts->{output_filter}) { # and $opts->{output_filter_where_clause}
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
2028 0 my ($left_pt, $right_pt) = map PMLTQ::Common::parse_column_expression($node->{$_}), qw(a b);
2029 0 ($left_type,$right_type)=map $self->compute_expression_data_type_pt($_,$opts), ($left_pt,$right_pt);
2030 $left = $self->serialize_expression_pt($left_pt,
2031 {%$opts,
2032 foreach => $opts->{foreach} || $foreach,
2033 expression=>$node->{a}
2034 0 ▶ });
Condition0%0/3
$opts->{'foreach'} || $foreach
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'foreach'} || $foreach
$opts->{'foreach'} $foreach
Truth table0%0/3
A || B
A= $opts->{'foreach'}B= $foreach
ABresult
1X1
011
000
2035 $right = $self->serialize_expression_pt($right_pt,
2036 {%$opts,
2037 foreach => $opts->{foreach} || $foreach,
2038 expression=>$node->{b}
2039 0 ▶ });
Condition0%0/3
$opts->{'foreach'} || $foreach
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'foreach'} || $foreach
$opts->{'foreach'} $foreach
Truth table0%0/3
A || B
A= $opts->{'foreach'}B= $foreach
ABresult
1X1
011
000
2040 } else {
2041 0 my ($left_pt, $right_pt) = map PMLTQ::Common::parse_expression($node->{$_}), qw(a b);
2042 0 ($left_type,$right_type)=map $self->compute_expression_data_type_pt($_,$opts), ($left_pt,$right_pt);
2043 $left = $self->serialize_expression_pt($left_pt,{%$opts,
2044 foreach => $foreach,
2045 depends_on => \%depends_on,
2046 expression=>$node->{a}
2047 0 });
2048 $right = $self->serialize_expression_pt($right_pt, {%$opts,
2049 foreach => $foreach,
2050 depends_on => \%depends_on,
2051 expression=>$node->{b}
2052 0 });
2053 }
2054 0 $condition = $self->serialize_test($left, $node->{operator},$right, $left_type,$right_type);
2055 0 my @wrap_l = ([0,q`do {`],[0,q` my $reslt;`]);
2056 0 my @wrap_r = ([0,q` $reslt`],[0,q`}`]);
2057 0 my $negate = 0;
2058 0 ▶ unless ($opts->{output_filter} and $opts->{foreach}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"output_filter"} and $opts->{"foreach"}) 0 0 0
Condition0%0/3
$opts->{"output_filter"} and $opts->{"foreach"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"output_filter"} and $opts->{"foreach"}
$opts->{"output_filter"} $opts->{"foreach"}
Truth table0%0/3
A and B
A= $opts->{"output_filter"}B= $opts->{"foreach"}
ABresult
0X0
100
111
2059 0 for my $i (0..$#$foreach) {
2060 0 ▶ if ($foreach->[$i][0]==2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($foreach->[$i][0] == 2) { } 0 0 0
elsif ($foreach->[$i][0] == 1) { } 0 0 0
2061 0 $negate=!$negate;
2062 0 unshift @wrap_r, [$i,q`$reslt = !$reslt;`];
2063 } elsif ($foreach->[$i][0]==1) {
2064 0 push @wrap_l, [$i,qq`foreach my \$var$i ($foreach->[$i][1]) {`],
2065 [$i,qq` if (defined \$var$i) {`] # although we might probably assume that list values are defined
2066 ;
2067 0 unshift @wrap_r, [$i,qq` last if \$reslt;`],
2068 [$i,qq` }`],
2069 [$i,qq`}`];
2070 } else {
2071 #my $tmp = $foreach->[$i][1];
2072 #$tmp =~ s/->.*//;
2073  
2074 0 push @wrap_l, [$i,qq`my \$var$i = $foreach->[$i][1];`],
2075 #[$i,qq`use Data::Dumper;`],
2076 #[$i,qq`print STDERR Dumper(\$var$i);`],
2077 [$i,qq`if (defined \$var$i) {`];
2078 0 unshift @wrap_r, [$i,qq`}`];
2079 }
2080 }
2081 }
2082 $condition = join('',
2083 0 ▶ map { (' ' x ($_->[0]+10)).$_->[1]."\n" }
Branch: 1 branch
BranchTrueFalseTotal
$negate ? : 0 0 0
2084 (
2085 @wrap_l,
2086 [$#$foreach,qq` \$reslt = ($condition) ? `.($negate ? '0:1;' : '1:0;')],
2087 @wrap_r
2088 )
2089 );
2090  
2091 0 my $target_match_pos = max($match_pos,keys %depends_on);
2092 0 my $target_pos = Treex::PML::Index($self->{pos2match_pos},$target_match_pos);
2093 0 ▶ if (defined $target_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_pos) { } 0 0 0
2094 # target node in the same sub-query
2095 0 ▶ if ($target_pos<=$pos) { #WARN Use of uninitialized value $pos in numeric le (<=)
Branch: 2 branches
BranchTrueFalseTotal
if ($target_pos <= $pos) { } 0 0 0
elsif ($target_pos > $pos) { } 0 0 0
2096 0 return $condition;
2097 } elsif ($target_pos>$pos) {
2098 0 $opts->{recompute_condition}[$target_match_pos]{$pos}=1;
2099 0 return ('( $$query_pos < '.$target_pos.' ? '.int(!$opts->{negative}).' : '.$condition.')');
2100 }
2101 } else {
2102 # this node is referred to from some super-query
2103 0 ▶ if ($target_match_pos > $self->{parent_query_match_pos}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_match_pos > $self->{"parent_query_match_pos"}) 0 0 0
2104 # we need to postpone the evaluation of the whole sub-query up-till $matched_nodes->[$target_match_pos] is known
2105 0 ▶ $self->{postpone_subquery_till}=$target_match_pos if ($self->{postpone_subquery_till}||0)<$target_match_pos;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"postpone_subquery_till"} || 0) < $target_match_pos 0 0 0
Condition0%0/2
$self->{'postpone_subquery_till'} || 0
l!l
00
MC/DC0%0/1
$self->{'postpone_subquery_till'} || 0
$self->{'postpone_subquery_till'}
Truth table0%0/2
A
A= $self->{'postpone_subquery_till'}
Aresult
11
00
2106 }
2107 0 return $condition;
2108 }
2109 } elsif ($name =~ /^(?:and|or|not)$/) {
2110 0 ▶ my $negative = $opts->{negative} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'negative'} ? : 0 0 0
2111 0 ▶ if ($name eq 'not') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "not") 0 0 0
2112 0 $negative=!$negative;
2113 }
2114 0 my %order = (
2115 test => 1,
2116 not => 2,
2117 or => 3,
2118 ref => 4,
2119 subquery => 5,
2120 );
2121 0 ▶ my @c =grep {defined and length}
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ 0 0 0
2122 map {
2123 $self->serialize_element({
2124 %$opts,
2125 negative => $negative,
2126 0 name => $_->{'#name'},
2127 # id => $node->{name},
2128 # type => $node->{'node-type'},
2129 condition => $_,
2130 })
2131 }
2132 0 ▶ sort { ($order{$a->{'#name'}}||100)<=>($order{$b->{'#name'}}||100) }
Condition0%0/4
$order{$PMLTQ::BtredEvaluator::a->{'#name'}} || 100
l!l
00
$order{$PMLTQ::BtredEvaluator::b->{'#name'}} || 100
l!l
00
MC/DC0%0/1
$order{$PMLTQ::BtredEvaluator::a->{'#name'}} || 100
$order{$PMLTQ::BtredEvaluator::a->{'#name'}}
MC/DC0%0/1
$order{$PMLTQ::BtredEvaluator::b->{'#name'}} || 100
$order{$PMLTQ::BtredEvaluator::b->{'#name'}}
Truth table0%0/2
A
A= $order{$PMLTQ::BtredEvaluator::a->{'#name'}}
Aresult
11
00
Truth table0%0/2
A
A= $order{$PMLTQ::BtredEvaluator::b->{'#name'}}
Aresult
11
00
2133 0 grep { $_->{'#name'} ne 'node' } $node->children;
2134 0 ▶ return () unless @c;
Branch: 1 branch
BranchTrueFalseTotal
unless @c 0 0 0
2135 0 ▶ if ($name eq 'not') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'not') { } 0 0 0
2136 0 return 'not('.join("\n and ",@c).')';
2137 } else {
2138 0 return '('.join("\n $name ",@c).')';
2139 }
2140 } elsif ($name eq 'subquery') {
2141 my $subquery = ref($self)->new($node, {
2142 type_mapper => $self->{type_mapper},
2143 0 parent_query => $self,
2144 parent_query_pos => $pos,
2145 parent_query_match_pos => $match_pos,
2146 });
2147 0 push @{$self->{sub_queries}}, $subquery;
2148 0 my $sq_pos = $#{$self->{sub_queries}};
2149 my @occ = map {
2150 (length($_->{min}) || length($_->{max})) ?
2151 ((length($_->{min}) ? $_->{min} : undef),
2152 0 ▶ (length($_->{max}) ? $_->{max}+1 : undef)) : (1,undef)
Branch: 3 branches
BranchTrueFalseTotal
length $_->{'min'} || length $_->{'max'} ? : 0 0 0
length $_->{'min'} ? : 0 0 0
length $_->{'max'} ? : 0 0 0
Condition0%0/3
length $_->{"min"} or length $_->{"max"}
l!l&&r!l&&!r
000
MC/DC0%0/2
length $_->{"min"} or length $_->{"max"}
length $_->{"min"} length $_->{"max"}
Truth table0%0/3
A or B
A= length $_->{"min"}B= length $_->{"max"}
ABresult
1X1
011
000
2153 0 } AltV($node->{occurrences});
2154 my $occ_list =
2155 0 ▶ max(map {int($_||0)} @occ)
Condition0%0/2
$_ || 0
l!l
00
MC/DC0%0/1
$_ || 0
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
2156 0 ▶ .','.join(',',(map { defined($_) ? $_ : 'undef' } @occ));
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
2157 0 my $condition = q`(($backref or $matched_nodes->[`.$match_pos.q`]=$node) and `. # trick: the subquery may ask about the current node
2158 qq/\$sub_queries[$sq_pos]->test_occurrences(\$node,\$fsfile,$occ_list))/;
2159 0 my $postpone_subquery_till = $subquery->{postpone_subquery_till};
2160 0 ▶ if (!defined $postpone_subquery_till or $ALL_SUBQUERIES_LAST) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $postpone_subquery_till or $PMLTQ::BtredEvaluator::ALL_SUBQUERIES_LAST) 0 0 0
Condition0%0/3
not defined $postpone_subquery_till or $PMLTQ::BtredEvaluator::ALL_SUBQUERIES_LAST
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $postpone_subquery_till or $PMLTQ::BtredEvaluator::ALL_SUBQUERIES_LAST
not defined $postpone_subquery_till $PMLTQ::BtredEvaluator::ALL_SUBQUERIES_LAST
Truth table0%0/3
not(A) or B
A= not defined $postpone_subquery_tillB= $PMLTQ::BtredEvaluator::ALL_SUBQUERIES_LAST
ABresult
1X1
011
000
2161 0 $postpone_subquery_till = $self->{pos2match_pos}[-1];
2162 0 ▶ print STDERR "ALL_SUBQUERIES_LAST used\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
2163 }
2164 0 ▶ if (defined $postpone_subquery_till) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $postpone_subquery_till) { } 0 0 0
2165 0 ▶ print STDERR "postponing subquery till: $postpone_subquery_till\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
2166 0 my $target_pos = Treex::PML::Index($self->{pos2match_pos},$postpone_subquery_till);
2167 0 ▶ if (defined $target_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_pos) { } 0 0 0
2168 # same subquery, simply postpone, just like when recomputing conditions
2169 # my $postpone_pos = $postpone_subquery_till;
2170 0 $opts->{recompute_condition}[$postpone_subquery_till]{$pos}=1;
2171 0 return ('( $$query_pos < '.$target_pos.' ? '.int(!$opts->{negative}).' : '.$condition.')');
2172 } else {
2173 0 ▶ print STDERR "other subquery\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 1 0 0 0
2174 # otherwise postpone this subquery as well
2175 0 ▶ $self->{postpone_subquery_till}=$postpone_subquery_till if $postpone_subquery_till>($self->{postpone_subquery_till}||0);
Branch: 1 branch
BranchTrueFalseTotal
if $postpone_subquery_till > ($self->{"postpone_subquery_till"} || 0) 0 0 0
Condition0%0/2
$self->{'postpone_subquery_till'} || 0
l!l
00
MC/DC0%0/1
$self->{'postpone_subquery_till'} || 0
$self->{'postpone_subquery_till'}
Truth table0%0/2
A
A= $self->{'postpone_subquery_till'}
Aresult
11
00
2176 0 return $condition;
2177 }
2178 } else {
2179 0 return $condition;
2180 }
2181 } elsif ($name eq 'ref') {
2182 0 my ($rel) = PMLTQ::BtredEvaluator::SeqV($node->{relation});
2183 0 ▶ return unless $rel;
Branch: 1 branch
BranchTrueFalseTotal
unless $rel 0 0 0
2184 0 my $target = $node->{target};
2185 0 my $relation = $rel->name;
2186 0 my $expression;
2187 0 my $label='';
2188 0 ▶ if ($relation eq 'user-defined') {
Branch: 1 branch
BranchTrueFalseTotal
if ($relation eq 'user-defined') { } 0 0 0
2189 0 $label = $rel->value->{label};
2190 0 my ($min,$max)=($rel->value->{min_length},$rel->value->{max_length});
2191 0 ▶ my $transitive = (defined($min) && ($min>1) or defined($max) && ($max>1)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $min && $min > 1 || defined $max && $max > 1 ? : 0 0 0
Condition0%0/9
defined $min and $min > 1 or defined $max and $max > 1
l!l&&r!l&&!r
000
defined $min and $min > 1
!ll&&!rl&&r
000
defined $max and $max > 1
!ll&&!rl&&r
000
MC/DC0%0/4
defined $min and $min > 1 or defined $max and $max > 1
defined $min $min > 1 defined $max $max > 1
Truth table0%0/7
A and B or C and D
A= defined $minB= $min > 1C= defined $maxD= $max > 1
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2192 0 ▶ if (defined($min) && defined($max) && ($min>$max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max and $min > $max) 0 0 0
Condition0%0/6
defined $min and defined $max and $min > $max
!ll&&!rl&&r
000
defined $min and defined $max
!ll&&!rl&&r
000
MC/DC0%0/3
defined $min and defined $max and $min > $max
defined $min defined $max $min > $max
Truth table0%0/4
A and B and C
A= defined $minB= defined $maxC= $min > $max
ABCresult
0XX0
10X0
1100
1111
2193 0 die "Invalid bounds for transitive relation '$label\{$min,$max}'\n";
2194 }
2195 0 my $target_type = $self->{name2type}{$target};
2196 0 ▶ if ($transitive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transitive) { } 0 0 0
2197 0 ▶ if ($opts->{'type'} ne $target_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"type"} ne $target_type) 0 0 0
2198 0 die "Cannot create transitive closure for relation with different start-node and end-node types: '$opts->{type}' -> '$target_type'\n";
2199 }
2200 0 ▶ push @{$self->{aux_iterators}}, $self->create_iterator($node,sub{1});
Subroutine __ANON__: not called CC=1 SCAR=6.9
2201 $expression =
2202 0 q(do{ my $it = $aux_iterators[).$#{$self->{aux_iterators}}.q(];
2203 my $aux = $it->start($start,$start_fsfile);
2204 $aux = $it->next while ($aux && $aux!=$end);
2205 $it->reset;
2206 $aux ? 1 : 0 });
2207 } else {
2208 0 my $start_node = $node->parent;
2209 0 ▶ $start_node = $start_node->parent while $start_node && $start_node->{'#name'} !~ /^(node|subquery)$/;
Branch: 1 branch
BranchTrueFalseTotal
$start_node and not $start_node->{"#name"} =~ /^(node|subquery)$/ and do { $start_node = $start_node->parent } 0 0 0
Condition0%0/3
$start_node and not $start_node->{"#name"} =~ /^(node|subquery)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$start_node and not $start_node->{"#name"} =~ /^(node|subquery)$/
$start_node not $start_node->{"#name"} =~ /^(node|subquery)$/
Truth table0%0/3
A and not(B)
A= $start_nodeB= not $start_node->{"#name"} =~ /^(node|subquery)$/
ABresult
0X0
100
111
2210 0 ▶ if ($start_node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_node) 0 0 0
2211 0 my $schema = $self->{type_mapper}->get_schema_for_type($start_node->{'node-type'});
2212 0 $expression = PMLTQ::Relation->test_code($schema->get_root_name,$start_node->{'node-type'},$label);
2213 }
2214 0 ▶ if (!defined $expression) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expression) 0 0 0
2215 0 ▶ if (first { $_ eq $label } @{$self->{type_mapper}->get_pmlrf_relations($node)}) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { $_ eq $label; } , @{$self->{'type_mapper'}->get_pmlrf_relations($node);})) { } 0 0 0
2216 0 return $self->serialize_element(
2217 {
2218 %$opts,
2219 name => 'test',
2220 condition => {
2221 '#name' => 'test',
2222 a => $label,
2223 b => 'id($'.$target.')',
2224 operator => '->',
2225 },
2226 });
2227 } else {
2228 0 die "User-defined relation '$label' not supported as a test on this node!\n";
2229 }
2230 }
2231 }
2232 } else {
2233 0 ▶ if ($relation eq 'descendant' or $relation eq 'ancestor') {
Branch: 4 branches
BranchTrueFalseTotal
if ($relation eq 'descendant' or $relation eq 'ancestor') { } 0 0 0
elsif ($relation eq 'sibling') { } 0 0 0
elsif ($relation =~ /^depth-first-(precedes|follows)/) { } 0 0 0
elsif ($relation eq 'order-precedes' or $relation eq 'order-follows') { } 0 0 0
Condition0%0/3
$relation eq "descendant" or $relation eq "ancestor"
l!l&&r!l&&!r
000
MC/DC0%0/2
$relation eq "descendant" or $relation eq "ancestor"
$relation eq "descendant" $relation eq "ancestor"
Truth table0%0/3
A or B
A= $relation eq "descendant"B= $relation eq "ancestor"
ABresult
1X1
011
000
2234 my ($min,$max)=
2235 0 ▶ map { (defined($_) and length($_)) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
2236 0 map { $rel->value->{$_} }
2237 qw(min_length max_length);
2238 0 ▶ my ($START,$END)=($relation eq 'ancestor') ? ('$start','$end') : ('$end','$start');
Branch: 1 branch
BranchTrueFalseTotal
$relation eq 'ancestor' ? : 0 0 0
2239 0 ▶ $expression = 'do { my $n='.$START.'; '.
Branch: 4 branches
BranchTrueFalseTotal
defined $min || defined $max ? : 0 0 0
defined $max ? : 0 0 0
defined $min || defined $max ? : 0 0 0
defined $min ? : 0 0 0
Condition0%0/6
defined $min or defined $max
l!l&&r!l&&!r
000
defined $min or defined $max
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $min or defined $max
defined $min defined $max
MC/DC0%0/2
defined $min or defined $max
defined $min defined $max
Truth table0%0/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
2240 ((defined($min) or defined($max)) ? 'my $l=0; ' : '').
2241 'while ($n and $n!='.$END.(defined($max) ? ' and $l<'.$max : ''). ') { $n=$n->parent; '.
2242 ((defined($min) or defined($max)) ? '$l++;' : '').
2243 ' }'.
2244 ' ($n and $n!='.$START.' and $n=='.$END.(defined($min) ? ' and '.$min.'<=$l' : '').') ? 1 : 0}';
2245 } elsif ($relation eq 'sibling') {
2246 my ($min,$max)=
2247 0 ▶ map { (defined($_) and length($_)) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
2248 0 map { $rel->value->{$_} }
2249 qw(min_length max_length);
2250 0 $expression = 'do { if ($start->parent == $end->parent) { my ($ret,$n);';
2251 0 ▶ if (defined($min) or defined($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min or defined $max) 0 0 0
Condition0%0/3
defined $min or defined $max
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $min or defined $max
defined $min defined $max
Truth table0%0/3
A or B
A= defined $minB= defined $max
ABresult
1X1
011
000
2252 0 $expression .= 'my $l;';
2253 }
2254 0 my $went_right;
2255 0 ▶ unless (defined($max) and $max<=0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $max and $max <= 0) 0 0 0
Condition0%0/3
defined $max and $max <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max and $max <= 0
defined $max $max <= 0
Truth table0%0/3
A and B
A= defined $maxB= $max <= 0
ABresult
0X0
100
111
2256 0 $went_right = 1;
2257 0 ▶ if ((defined($min) and $min>=0) or defined($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and $min >= 0 or defined $max) 0 0 0
Condition0%0/6
defined $min and $min >= 0 or defined $max
l!l&&r!l&&!r
000
defined $min and $min >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $min and $min >= 0 or defined $max
defined $min $min >= 0 defined $max
Truth table0%0/5
A and B or C
A= defined $minB= $min >= 0C= defined $max
ABCresult
11X1
0X11
1011
0X00
1000
2258 0 $expression .= ' $l=1; ';
2259 }
2260 0 $expression .= '$n=$start->rbrother; while ($n';
2261 0 ▶ if (defined($max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max) 0 0 0
2262 0 $expression .= ' and $l<='.$max;
2263 }
2264 0 $expression .= ') { if ($n==$end) { ';
2265 0 ▶ if (defined($min) and $min>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and $min > 1) { } 0 0 0
Condition0%0/3
defined $min and $min > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and $min > 1
defined $min $min > 1
Truth table0%0/3
A and B
A= defined $minB= $min > 1
ABresult
0X0
100
111
2266 0 $expression .= '$ret = ($l>='.$min.' ? 1 : 0);';
2267 } else {
2268 0 $expression .= '$ret = 1;';
2269 }
2270 0 $expression .= ' last; }; $n=$n->rbrother;';
2271 0 ▶ if ((defined($max) and $max<0) or defined($min)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max < 0 or defined $min) 0 0 0
Condition0%0/6
defined $max and $max < 0 or defined $min
l!l&&r!l&&!r
000
defined $max and $max < 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $max and $max < 0 or defined $min
defined $max $max < 0 defined $min
Truth table0%0/5
A and B or C
A= defined $maxB= $max < 0C= defined $min
ABCresult
11X1
0X11
1011
0X00
1000
2272 0 $expression .= ' $l++';
2273 }
2274 0 $expression .= '}';
2275 }
2276 0 ▶ unless (defined($min) and $min>=0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $min and $min >= 0) 0 0 0
Condition0%0/3
defined $min and $min >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and $min >= 0
defined $min $min >= 0
Truth table0%0/3
A and B
A= defined $minB= $min >= 0
ABresult
0X0
100
111
2277 0 ▶ $expression .= ' unless (defined($ret)) { ' if $went_right;
Branch: 1 branch
BranchTrueFalseTotal
if $went_right 0 0 0
2278  
2279 0 ▶ if ((defined($max) and $max<0) or defined($min)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max < 0 or defined $min) 0 0 0
Condition0%0/6
defined $max and $max < 0 or defined $min
l!l&&r!l&&!r
000
defined $max and $max < 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $max and $max < 0 or defined $min
defined $max $max < 0 defined $min
Truth table0%0/5
A and B or C
A= defined $maxB= $max < 0C= defined $min
ABCresult
11X1
0X11
1011
0X00
1000
2280 0 $expression .= ' $l=-1; ';
2281 }
2282 0 $expression .= '$n=$start->lbrother; while ($n';
2283 0 ▶ if (defined($min)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min) 0 0 0
2284 0 $expression .= ' and $l>='.$min;
2285 }
2286 0 $expression .= ') { if ($n==$end) { ';
2287 0 ▶ if (defined($max) and $max<-1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max < -1) { } 0 0 0
Condition0%0/3
defined $max and $max < -1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max and $max < -1
defined $max $max < -1
Truth table0%0/3
A and B
A= defined $maxB= $max < -1
ABresult
0X0
100
111
2288 0 $expression .= '$ret = ($l<='.$max.' ? 1 : 0);';
2289 } else {
2290 0 $expression .= '$ret = 1;';
2291 }
2292 0 $expression .= ' last; }; $n=$n->lbrother;';
2293 0 ▶ if ((defined($max) and $max<0) or defined($min)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $max < 0 or defined $min) 0 0 0
Condition0%0/6
defined $max and $max < 0 or defined $min
l!l&&r!l&&!r
000
defined $max and $max < 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $max and $max < 0 or defined $min
defined $max $max < 0 defined $min
Truth table0%0/5
A and B or C
A= defined $maxB= $max < 0C= defined $min
ABCresult
11X1
0X11
1011
0X00
1000
2294 0 $expression .= ' $l--';
2295 }
2296 0 $expression .= '}';
2297 0 ▶ $expression .= ' } ' if $went_right;
Branch: 1 branch
BranchTrueFalseTotal
if $went_right 0 0 0
2298 }
2299 0 $expression.= ' $ret ? 1 : 0 } else { 0 } }';
2300 } elsif ($relation =~ '^depth-first-(precedes|follows)') {
2301 0 ▶ my $dir = $1 eq 'precedes' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'precedes' ? : 0 0 0
2302 my ($min,$max)=
2303 0 ▶ map { (defined($_) and length($_)) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
2304 0 map { $rel->value->{$_} }
2305 qw(min_length max_length);
2306 0 my @bounds = _compute_bounds($dir, $min, $max);
2307 $expression =
2308 q{ PMLTQ::BtredEvaluator::test_depth_first_order($start, $end}
2309 .qq{, $dir}
2310 0 ▶ .join('',map { defined($_) ? ", $_" : ', undef' } @bounds)
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
2311 .q{ ) };
2312 ▶ } elsif ($relation eq 'order-precedes' or
Condition0%0/3
$relation eq "order-precedes" or $relation eq "order-follows"
l!l&&r!l&&!r
000
MC/DC0%0/2
$relation eq "order-precedes" or $relation eq "order-follows"
$relation eq "order-precedes" $relation eq "order-follows"
Truth table0%0/3
A or B
A= $relation eq "order-precedes"B= $relation eq "order-follows"
ABresult
1X1
011
000
2313 $relation eq 'order-follows') {
2314 my ($min,$max)=
2315 0 ▶ map { (defined($_) and length($_)) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
2316 0 map { $rel->value->{$_} }
2317 qw(min_length max_length);
2318 0 my $operator;
2319 0 ▶ my ($L,$R) = ($relation eq 'order-follows') ?
Branch: 1 branch
BranchTrueFalseTotal
$relation eq 'order-follows' ? : 0 0 0
2320 ('order_span_max()','order_span_min($'.$target.')')
2321 :
2322 ('order_span_max($'.$target.')','order_span_min()');
2323 0 ▶ if (defined($min) and defined($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $min and defined $max) { } 0 0 0
elsif (defined $min) { } 0 0 0
elsif (defined $max) { } 0 0 0
Condition0%0/3
defined $min and defined $max
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and defined $max
defined $min defined $max
Truth table0%0/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
2324 0 $operator = qq{<$min,$max>};
2325 } elsif (defined($min)) {
2326 0 $operator = qq{<$min,>};
2327 } elsif (defined($max)) {
2328 0 $operator = qq{<,$max>};
2329 } else {
2330 0 $operator = '<';
2331 }
2332 0 return $self->serialize_element(
2333 {
2334 %$opts,
2335 name => 'test',
2336 condition => {
2337 '#name' => 'test',
2338 a=>$L,
2339 b=>$R,
2340 operator => $operator,
2341 },
2342 });
2343 } else {
2344 0 $expression = $test_relation{$relation};
2345 }
2346 0 ▶ die "Relation '$relation' not supported test!\n" unless defined $expression;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expression 0 0 0
2347 }
2348 0 my $target_pos = $self->{name2pos}{$target};
2349 0 my $target_match_pos = $self->{name2match_pos}{$target};
2350 0 ▶ my $condition = q/ do{
Branch: 2 branches
BranchTrueFalseTotal
defined $target_pos ? : 0 0 0
defined $target_match_pos ? : 0 0 0
2351 my ($start,$end,$start_fsfile)=($node,$matched_nodes->[/.$target_match_pos.q/],$fsfile); # /.
2352 qq{$target (p:}. (defined $target_pos ? $target_pos : 'undef') .
2353 qq{/m:} . (defined $target_match_pos ? $target_match_pos : 'undef') . qq{)} .q/
2354 /.$expression.q/ } /;
2355 0 ▶ if (defined $target_pos) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $target_pos) { } 0 0 0
elsif (defined $target_match_pos) { } 0 0 0
2356 # target node in the same sub-query
2357 0 ▶ if ($target_pos<$pos) {
Branch: 2 branches
BranchTrueFalseTotal
if ($target_pos < $pos) { } 0 0 0
elsif ($target_pos > $pos) { } 0 0 0
2358 0 return $condition;
2359 } elsif ($target_pos>$pos) {
2360 0 $opts->{recompute_condition}[$target_match_pos]{$pos}=1;
2361 0 return ('( $$query_pos < '.$target_pos.' ? '.int(!$opts->{negative}).' : '.$condition.')');
2362 } else {
2363 # huh, really?
2364 0 return q/ do{ my ($start,$end,$start_fsfile)=($node,$node,$fsfile); /.$expression.q/ } /;
2365 }
2366 } elsif (defined $target_match_pos) {
2367 # this node is matched by some super-query
2368 0 ▶ if ($target_match_pos > $self->{parent_query_match_pos}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_match_pos > $self->{"parent_query_match_pos"}) 0 0 0
2369 # we need to postpone the evaluation of the whole sub-query up-till $matched_nodes->[$target_pos] is known
2370 0 ▶ $self->{postpone_subquery_till}=$target_match_pos if ($self->{postpone_subquery_till}||0)<$target_match_pos;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"postpone_subquery_till"} || 0) < $target_match_pos 0 0 0
Condition0%0/2
$self->{'postpone_subquery_till'} || 0
l!l
00
MC/DC0%0/1
$self->{'postpone_subquery_till'} || 0
$self->{'postpone_subquery_till'}
Truth table0%0/2
A
A= $self->{'postpone_subquery_till'}
Aresult
11
00
2371 }
2372 0 return $condition;
2373 } else {
2374 0 die "Node '$target' does not exist or belongs to a sub-query and cannot be referred from relation $relation $label at node no. $match_pos!\n";
2375 }
2376 } else {
2377 0 die "Unknown element $name ";
2378 }
2379 }
2380  
2381 sub serialize_target {
2382 0 ▶ my ($self,$target,$opts)=@_;
Subroutine serialize_target: not called CC=1 SCAR=6.9
Pod undocumented
2383 0 my ($node)=$self->serialize_target2($target,$opts);
2384 0 return $node;
2385 }
2386 # returns the target node + file
2387 sub serialize_target2 {
2388 0 ▶ my ($self,$target,$opts)=@_;
Subroutine serialize_target2: not called CC=7 SCAR=40.3
Pod undocumented
2389 0 my $target_match_pos = $self->{name2match_pos}{$target};
2390 0 my $this_pos = $opts->{query_pos};
2391 0 ▶ if (defined $opts->{id} and $target eq $opts->{id} and !$opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"id"} and $target eq $opts->{"id"} and not $opts->{"output_filter"}) 0 0 0
Condition0%0/6
defined $opts->{"id"} and $target eq $opts->{"id"} and not $opts->{"output_filter"}
!ll&&!rl&&r
000
defined $opts->{"id"} and $target eq $opts->{"id"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opts->{"id"} and $target eq $opts->{"id"} and not $opts->{"output_filter"}
defined $opts->{"id"} $target eq $opts->{"id"} not $opts->{"output_filter"}
Truth table0%0/4
A and B and not(C)
A= defined $opts->{"id"}B= $target eq $opts->{"id"}C= not $opts->{"output_filter"}
ABCresult
0XX0
10X0
1100
1111
2392 0 return ('$node',qq{\$iterators[$this_pos]->file});
2393 }
2394 0 ▶ if (defined $target_match_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_match_pos) { } 0 0 0
2395 0 $opts->{depends_on}{$target_match_pos}=1;
2396 return (
2397 0 ▶ ($opts->{output_filter} ? '$all_iterators->['.$target_match_pos.']->node' : '$matched_nodes->['.$target_match_pos.']'),
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'output_filter'} ? : 0 0 0
2398 '$all_iterators->['.$target_match_pos.']->file',
2399 );
2400 } else {
2401 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
2402 0 die "Node '$target' does not exist or belongs to a sub-query and cannot be referred from an output filter!\n";
2403 } else {
2404 0 my $match_pos = $self->{pos2match_pos}[$this_pos];
2405 0 die "Node '$target' does not exist or belongs to a sub-query and cannot be referred from expression $opts->{expression} of node no. $match_pos!\n";
2406 }
2407 }
2408 }
2409  
2410 sub serialize_expression_pt { # pt stands for parse tree
2411 0 ▶ my ($self,$pt,$opts)=@_;
Subroutine serialize_expression_pt: not called CC=235 SCAR=109.2
Pod undocumented
2412 #use Data::Dumper;
2413 #print STDERR "parse tree: " . Dumper($pt) if $DEBUG > 1;
2414 0 my $this_node_id = $opts->{id};
2415 0 ▶ if (ref($pt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pt) { } 0 0 0
2416 0 my $type = shift @$pt;
2417 0 ▶ if ($type eq 'EVERY') {
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'EVERY') { } 0 0 0
elsif ($type eq 'ATTR' or $type eq 'REF_ATTR') { } 0 0 0
elsif ($type eq 'IF') { } 0 0 0
elsif ($type eq 'ANALYTIC_FUNC') { } 0 0 0
elsif ($type eq 'FUNC') { } 0 0 0
elsif ($type eq 'EXP') { } 0 0 0
elsif ($type eq 'SET') { } 0 0 0
2418 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"output_filter"}) 0 0 0
2419 0 die "Cannot use quantifier '*' in output filter: '$opts->{expression}'"
2420 }
2421 0 push @{$opts->{foreach}}, [2];
2422 0 return $self->serialize_expression_pt($pt->[0],$opts);
2423 ▶ } elsif ($type eq 'ATTR' or $type eq 'REF_ATTR') {
Condition0%0/3
$type eq "ATTR" or $type eq "REF_ATTR"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "ATTR" or $type eq "REF_ATTR"
$type eq "ATTR" $type eq "REF_ATTR"
Truth table0%0/3
A or B
A= $type eq "ATTR"B= $type eq "REF_ATTR"
ABresult
1X1
011
000
2424 0 my ($node,$node_type);
2425 0 ▶ if ($opts->{output_filter} and defined($opts->{column_count})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"output_filter"} and defined $opts->{"column_count"}) 0 0 0
Condition0%0/3
$opts->{"output_filter"} and defined $opts->{"column_count"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"output_filter"} and defined $opts->{"column_count"}
$opts->{"output_filter"} defined $opts->{"column_count"}
Truth table0%0/3
A and B
A= $opts->{"output_filter"}B= defined $opts->{"column_count"}
ABresult
0X0
100
111
2426 0 die "Attribute reference cannot be used in output filter columns whose input is not the body of the query: '$opts->{expression}'"
2427 }
2428 0 ▶ if ($type eq 'REF_ATTR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'REF_ATTR') { } 0 0 0
2429 0 my $target = $pt->[0];
2430 0 $pt=$pt->[1];
2431 0 ▶ die "Error in attribute reference of node $target in expression $opts->{expression} of node '$this_node_id'"
Branch: 1 branch
BranchTrueFalseTotal
unless shift @$pt eq "ATTR" 0 0 0
2432 unless shift(@$pt) eq 'ATTR'; # not likely
2433 0 ▶ if ($target eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq '$') { } 0 0 0
2434 0 $node='$node';
2435 0 $node_type = $opts->{type};
2436 } else {
2437 0 $node=$self->serialize_target($target,$opts);
2438 0 $node_type = $self->{name2type}{$target};
2439 }
2440 } else {
2441 0 $node='$node';
2442 0 $node_type = $opts->{type};
2443 }
2444 # Below we resolve the attribute path according to the PML schema
2445 # we use $opts->{foreach} array to store information
2446 # about wrapper loops to be generated; elements of the foreach array are of the form:
2447 # [type, expression]
2448 # where type==2 and expressoin is undef for the primitive FORALL quantificator '*' (see 'EVERY')
2449 # type==1 if expression produces a list (to be wrapped with a foreach + if defined)
2450 # type==0 if expression produces at most one value (to be wrapped with an if defined)
2451 0 my $cast;
2452 0 ▶ if($pt->[0] =~ /^(.+)\?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pt->[0] =~ /^(.+)\?$/) { } 0 0 0
elsif ($node_type =~ m[^(?:([^/]+):)?\*$]) { } 0 0 0
2453 0 $cast = $1; shift @$pt;
2454 } elsif ($node_type=~m{^(?:([^/]+):)?\*$}) {
2455 0 my $node_types = $self->{type_mapper}->get_node_types($1);
2456 0 my @possibilities;
2457 0 ▶ my $path = join '/',map { ($_ eq '[]' or $_ eq 'content()') ? '#content' : $_ } @$pt;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '[]' || $_ eq 'content()' ? : 0 0 0
Condition0%0/3
$_ eq "[]" or $_ eq "content()"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "[]" or $_ eq "content()"
$_ eq "[]" $_ eq "content()"
Truth table0%0/3
A or B
A= $_ eq "[]"B= $_ eq "content()"
ABresult
1X1
011
000
2458 0 for my $nt (@$node_types) {
2459 0 my $decl = $self->{type_mapper}->get_decl_for($nt);
2460 0 ▶ my $attr_decl = $decl && $decl->find($path);
Condition0%0/3
$decl && $decl->find($path)
!ll&&!rl&&r
000
MC/DC0%0/2
$decl && $decl->find($path)
$decl $decl->find($path)
Truth table0%0/3
A && B
A= $declB= $decl->find($path)
ABresult
0X0
100
111
2461 0 ▶ $attr_decl=$attr_decl->get_content_decl
Branch: 1 branch
BranchTrueFalseTotal
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7 and do { $attr_decl = $attr_decl->get_content_decl } 0 0 0
Condition0%0/6
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7
!ll&&!rl&&r
000
$attr_decl->get_decl_type == 6 or $attr_decl->get_decl_type == 7
l!l&&r!l&&!r
000
MC/DC0%0/3
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7
$attr_decl $attr_decl->get_decl_type == 6 $attr_decl->get_decl_type == 7
Truth table0%0/4
A and B or C
A= $attr_declB= $attr_decl->get_decl_type == 6C= $attr_decl->get_decl_type == 7
ABCresult
0XX0
1000
11X1
1011
2462 while ($attr_decl and ($attr_decl->get_decl_type == PML_LIST_DECL or
2463 $attr_decl->get_decl_type == PML_ALT_DECL));
2464 0 ▶ push @possibilities,$nt if ($attr_decl and $attr_decl->is_atomic);
Branch: 1 branch
BranchTrueFalseTotal
if $attr_decl and $attr_decl->is_atomic 0 0 0
Condition0%0/3
$attr_decl and $attr_decl->is_atomic
!ll&&!rl&&r
000
MC/DC0%0/2
$attr_decl and $attr_decl->is_atomic
$attr_decl $attr_decl->is_atomic
Truth table0%0/3
A and B
A= $attr_declB= $attr_decl->is_atomic
ABresult
0X0
100
111
2465 }
2466 0 ▶ if (!@possibilities) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @possibilities) { } 0 0 0
2467 0 die "The attribute path '$path' is not valid for any node type matched by the '$node_type' wildcard: @$node_types\n";
2468 } else {
2469 0 $cast = '(?:'.join('|',@possibilities).')';
2470 }
2471 }
2472 0 ▶ my $attr=join '/',map { ($_ eq '[]' or $_ eq 'content()') ? '#content' : $_ } @$pt; # translate from PML-TQ notation to PML notation
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '[]' || $_ eq 'content()' ? : 0 0 0
Condition0%0/3
$_ eq "[]" or $_ eq "content()"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "[]" or $_ eq "content()"
$_ eq "[]" $_ eq "content()"
Truth table0%0/3
A or B
A= $_ eq "[]"B= $_ eq "content()"
ABresult
1X1
011
000
2473 0 ▶ my $type_decl = $cast ? undef : $self->{type_mapper}->get_decl_for($node_type);
Branch: 1 branch
BranchTrueFalseTotal
$cast ? : 0 0 0
2474 0 my $ret;
2475 0 ▶ if ($cast) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cast) { } 0 0 0
elsif (not $type_decl) { } 0 0 0
2476 # simplified implementation using Treex::PML::Node->all() method
2477 0 ▶ my $foreach = $opts->{foreach} ||= [];
Condition0%0/2
$opts->{"foreach"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"foreach"} ||= []
$opts->{"foreach"}
Truth table0%0/2
A
A= $opts->{"foreach"}
Aresult
11
00
2478 0 push @$foreach,
2479 [1, qq[(($node->type->get_decl_path =~ m{^\!].$cast.q[(?:\.type)?$}) ? ].
2480 $node.q[->all(qq(].quotemeta($attr).qq[)) : ())]
2481 ];
2482 0 $ret = '$var'.$#$foreach;
2483 } elsif (!$type_decl) {
2484 0 die "Cannot resolve attribute path $attr on an unknown node type '$node_type'\n";
2485 } else {
2486 0 my $decl = $type_decl;
2487 0 ▶ my $foreach = $opts->{foreach} ||= [];
Condition0%0/2
$opts->{"foreach"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"foreach"} ||= []
$opts->{"foreach"}
Truth table0%0/2
A
A= $opts->{"foreach"}
Aresult
11
00
2488 0 my $pexp=$node;
2489 0 my @steps = @$pt;
2490 0 my $step;
2491 0 my $decl_is = $decl->get_decl_type;
2492 0 ▶ while ($step = shift @steps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step = shift @steps) 0 0 0
2493 0 ▶ if ($decl_is == PML_CONTAINER_DECL and ($step eq '[]' or $step eq 'content()') ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($decl_is == 4 and $step eq '[]' || $step eq 'content()') { } 0 0 0
elsif ($decl_is == 3 or $decl_is == 4) { } 0 0 0
elsif ($decl_is == 5) { } 0 0 0
elsif ($decl_is == 6) { } 0 0 0
elsif ($decl_is == 7) { } 0 0 0
Condition0%0/6
$decl_is == 4 and $step eq "[]" || $step eq "content()"
!ll&&!rl&&r
000
$step eq "[]" or $step eq "content()"
l!l&&r!l&&!r
000
MC/DC0%0/3
$decl_is == 4 and $step eq "[]" || $step eq "content()"
$decl_is == 4 $step eq "[]" $step eq "content()"
Truth table0%0/4
A and B or C
A= $decl_is == 4B= $step eq "[]"C= $step eq "content()"
ABCresult
0XX0
1000
11X1
1011
2494 0 $decl=$decl->get_content_decl;
2495 0 push @$foreach, [0,$pexp.'->{qq(#content)}'];
2496 0 $pexp = '$var'.$#$foreach;
2497 ▶ } elsif ($decl_is == PML_STRUCTURE_DECL or $decl_is == PML_CONTAINER_DECL) {
Condition0%0/3
$decl_is == 3 or $decl_is == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 3 or $decl_is == 4
$decl_is == 3 $decl_is == 4
Truth table0%0/3
A or B
A= $decl_is == 3B= $decl_is == 4
ABresult
1X1
011
000
2498 0 my $m = $decl->get_member_by_name($step);
2499 0 ▶ if (defined $m) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m) { } 0 0 0
2500 0 $decl=$m->get_content_decl;
2501 } else {
2502 0 $m = $decl->get_member_by_name($step.'.rf');
2503 0 ▶ if ($m and ($m->get_role||'') eq '#KNIT') {
Branch: 2 branches
BranchTrueFalseTotal
if ($m and ($m->get_role || '') eq '#KNIT') { } 0 0 0
elsif ($m and ($m->get_content_decl->get_role || '') eq '#KNIT') { } 0 0 0
Condition0%0/5
$m and ($m->get_role || "") eq "#KNIT"
!ll&&!rl&&r
000
$m->get_role || ''
l!l
00
MC/DC0%0/2
$m and ($m->get_role || "") eq "#KNIT"
$m $m->get_role
Truth table0%0/3
A and B
A= $mB= $m->get_role
ABresult
0X0
100
111
2504 0 $decl=$m->get_knit_content_decl;
2505 ▶ } elsif ($m and ($m->get_content_decl->get_role||'') eq '#KNIT') {
Condition0%0/5
$m and ($m->get_content_decl->get_role || "") eq "#KNIT"
!ll&&!rl&&r
000
$m->get_content_decl->get_role || ''
l!l
00
MC/DC0%0/2
$m and ($m->get_content_decl->get_role || "") eq "#KNIT"
$m $m->get_content_decl->get_role
Truth table0%0/3
A and B
A= $mB= $m->get_content_decl->get_role
ABresult
0X0
100
111
2506 0 $decl=$m->get_content_decl;
2507 } else {
2508 0 ▶ die "Error while compiling attribute path $attr for objects of type '$node_type': didn't find member '$step'\n" unless defined($m);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 0 0 0
2509 }
2510 }
2511 #
2512 # value
2513 #
2514 0 push @$foreach, [0,$pexp.'->{qq('.quotemeta($step).')}'];
2515 0 $pexp = '$var'.$#$foreach;
2516 0 undef $step;
2517 } elsif ($decl_is == PML_SEQUENCE_DECL) {
2518 0 my $element = $step;
2519 0 my $pos;
2520 my $el_pos;
2521 0 ▶ if ($element=~s/^\[(\d+)\]//g) {
Branch: 2 branches
BranchTrueFalseTotal
if ($element =~ s/^\[(\d+)\]//g) { } 0 0 0
elsif ($element =~ s/\[\s*(\d+)\s*\]$//g) { } 0 0 0
2522 0 $pos = $1 - 1;
2523 } elsif ($element=~s/\[\s*(\d+)\s*\]$//g) {
2524 0 $el_pos = $1 - 1;
2525 }
2526 0 ▶ my $e = $decl->get_element_by_name($element) || die "Error while compiling attribute path $attr for objects of type '$node_type': didn't find element '$element'\n";
Condition0%0/2
$decl->get_element_by_name($element) || die("Error while compiling attribute path $attr for objects of type '${node_type}': didn't find element '${element}'\n")
l!l
00
MC/DC0%0/1
$decl->get_element_by_name($element) || die("Error while compiling attribute path $attr for objects of type '${node_type}': didn't find element '${element}'\n")
$decl->get_element_by_name($element)
Truth table0%0/2
A
A= $decl->get_element_by_name($element)
Aresult
11
00
2527 0 $decl = $e->get_content_decl;
2528 0 ▶ if (defined $pos) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pos) { } 0 0 0
elsif (defined $el_pos) { } 0 0 0
2529 0 push @$foreach, [0,$pexp.'->value_at('.$pos.')'];
2530 } elsif (defined $el_pos) {
2531 0 push @$foreach, [0,$pexp.'->values(qq('.quotemeta($element).'))->value_at('.$el_pos.')'];
2532 } else {
2533 0 push @$foreach, [1,$pexp.'->values(qq('.quotemeta($element).'))'];
2534 }
2535 0 $pexp = '$var'.$#$foreach;
2536 0 undef $step;
2537 } elsif ($decl_is == PML_LIST_DECL) {
2538 0 $decl = $decl->get_knit_content_decl;
2539 0 ▶ if (defined($step) and $step =~ /^\[([0-9]+)\]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $step and $step =~ /^\[([0-9]+)\]$/) { } 0 0 0
Condition0%0/3
defined $step and $step =~ /^\[([0-9]+)\]$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $step and $step =~ /^\[([0-9]+)\]$/
defined $step $step =~ /^\[([0-9]+)\]$/
Truth table0%0/3
A and B
A= defined $stepB= $step =~ /^\[([0-9]+)\]$/
ABresult
0X0
100
111
2540 0 push @$foreach, [0,$pexp.'->['.($1-1).']'];
2541 0 $pexp = '$var'.$#$foreach;
2542 0 undef $step;
2543 } else {
2544 0 push @$foreach, [1,'@{'.$pexp.'}'];
2545 0 $pexp = '$var'.$#$foreach;
2546 0 ▶ if (defined($step) and $step eq 'LM') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $step and $step eq 'LM') { } 0 0 0
Condition0%0/3
defined $step and $step eq "LM"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $step and $step eq "LM"
defined $step $step eq "LM"
Truth table0%0/3
A and B
A= defined $stepB= $step eq "LM"
ABresult
0X0
100
111
2547 0 undef $step;
2548 } else {
2549 0 $decl_is = $decl->get_decl_type;
2550 0 ▶ redo if defined($step);
Branch: 1 branch
BranchTrueFalseTotal
if defined $step 0 0 0
2551 }
2552 }
2553 } elsif ($decl_is == PML_ALT_DECL) {
2554 0 $decl = $decl->get_content_decl;
2555 0 push @$foreach, [1,'PMLTQ::BtredEvaluator::AltV('.$pexp.')'];
2556 0 $pexp = '$var'.$#$foreach;
2557 0 ▶ if (defined($step) and $step eq 'AM') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $step and $step eq 'AM') { } 0 0 0
Condition0%0/3
defined $step and $step eq "AM"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $step and $step eq "AM"
defined $step $step eq "AM"
Truth table0%0/3
A and B
A= defined $stepB= $step eq "AM"
ABresult
0X0
100
111
2558 0 undef $step;
2559 } else {
2560 0 $decl_is = $decl->get_decl_type;
2561 0 ▶ redo if defined($step);
Branch: 1 branch
BranchTrueFalseTotal
if defined $step 0 0 0
2562 }
2563 # } elsif ($decl->is_atomic and $step eq '#content') {
2564 # $pexp = '$var'.$#$foreach;
2565 } else {
2566 0 die "Error while compiling attribute path $attr for objects of type '$node_type': Cannot apply location step '$step' to an atomic type '".$decl->get_decl_path."' ($decl_is)!\n";
2567 }
2568 0 $decl_is = $decl->get_decl_type;
2569 0 ▶ redo if (!@steps and (($decl_is == PML_ALT_DECL) or ($decl_is == PML_LIST_DECL)));
Branch: 1 branch
BranchTrueFalseTotal
if not @steps and $decl_is == 7 || $decl_is == 6 0 0 0
Condition0%0/6
not @steps and $decl_is == 7 || $decl_is == 6
!ll&&!rl&&r
000
$decl_is == 7 or $decl_is == 6
l!l&&r!l&&!r
000
MC/DC0%0/3
not @steps and $decl_is == 7 || $decl_is == 6
not @steps $decl_is == 7 $decl_is == 6
Truth table0%0/4
not(A) and B or C
A= not @stepsB= $decl_is == 7C= $decl_is == 6
ABCresult
0XX0
1000
11X1
1011
2570 }
2571 0 $ret = $pexp; #'$var'.$#$foreach;
2572 }
2573 0 ▶ push @{$opts->{return_vars}||=[]},$ret;
Condition0%0/2
$opts->{"return_vars"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"return_vars"} ||= []
$opts->{"return_vars"}
Truth table0%0/2
A
A= $opts->{"return_vars"}
Aresult
11
00
2574 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"output_filter"}) 0 0 0
2575 0 $ret =$self->serialize_column_node_ref($ret,$opts);
2576 }
2577 0 return $ret;
2578 } elsif ($type eq 'IF') {
2579 0 ▶ if ($opts->{is_first_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'is_first_filter'}) { } 0 0 0
2580 0 my ($condition,$if_true,$if_false) = @$pt;
2581 my $test = $self->serialize_element({
2582 %$opts,
2583 foreach =>undef,
2584 0 name=>$condition->{'#name'},
2585 condition => $condition,
2586 is_positive_conjunct => 1,
2587 no_node_ref => 1,
2588 });
2589 0 ▶ my $foreach = $opts->{foreach} ||= [];
Condition0%0/2
$opts->{"foreach"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"foreach"} ||= []
$opts->{"foreach"}
Truth table0%0/2
A
A= $opts->{"foreach"}
Aresult
11
00
2590 0 my ($vars1,$vars2,$if_true_foreach, $if_false_foreach)=([],[],[],[]);
2591 0 my $if_true_exp = $self->serialize_expression_pt($if_true,{%$opts, no_node_ref => 1, foreach=> $if_true_foreach, return_vars => $vars1});
2592 0 my $if_false_exp = $self->serialize_expression_pt($if_false,{%$opts, no_node_ref => 1, foreach=> $if_false_foreach, return_vars => $vars2});
2593 0 ▶ $if_true_exp = $self->foreach_wrap($if_true_foreach,
Branch: 1 branch
BranchTrueFalseTotal
@$vars1 ? : 0 0 0
2594 q{ push @if_ret, }.
2595 (@$vars1 ?
2596 '('.join(' && ',map "defined($_)", @$vars1).') ? ('.$if_true_exp.') : ()'
2597 : $if_true_exp)
2598 );
2599 0 ▶ $if_false_exp = $self->foreach_wrap($if_false_foreach,
Branch: 1 branch
BranchTrueFalseTotal
@$vars2 ? : 0 0 0
2600 q{ push @if_ret, }.
2601 (@$vars2 ?
2602 '('.join(' && ',map "defined($_)", @$vars2).') ? ('.$if_false_exp.') : ()'
2603 : $if_false_exp)
2604 );
2605 0 push @$foreach,
2606 [1,
2607 qq[do { # IF
2608 my \@if_ret;
2609 if ($test) {
2610 # IF_TRUE
2611 $if_true_exp
2612 } else {
2613 # IF_FALSE
2614 $if_false_exp
2615 }
2616 \@if_ret
2617 }],
2618 [], # no defined() test
2619 ];
2620 0 my $ret = '$var'.$#$foreach;
2621 0 ▶ push @{$opts->{return_vars}||=[]},$ret;
Condition0%0/2
$opts->{"return_vars"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"return_vars"} ||= []
$opts->{"return_vars"}
Truth table0%0/2
A
A= $opts->{"return_vars"}
Aresult
11
00
2622 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"output_filter"}) 0 0 0
2623 0 $ret =$self->serialize_column_node_ref($ret,$opts);
2624 }
2625 0 return $ret;
2626 } else {
2627 0 my ($condition,$if_true,$if_false) = @$pt;
2628 my $test = $self->serialize_element({
2629 %$opts,
2630 0 name=>$condition->{'#name'},
2631 condition => $condition,
2632 is_positive_conjunct => 1,
2633 });
2634 0 my $if_true_exp = $self->serialize_expression_pt($if_true,$opts);
2635 0 my $if_false_exp = $self->serialize_expression_pt($if_false,$opts);
2636 0 return qq{($test ? $if_true_exp : $if_false_exp)};
2637 }
2638 } elsif ($type eq 'ANALYTIC_FUNC') {
2639 0 my $name = shift @$pt;
2640 die "The analytic function ${name}() can only be used in an output filter expression!\n"
2641 0 ▶ unless $opts->{'output_filter'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"output_filter"} 0 0 0
2642 die "The analytic function ${name}() cannot be used in the 'filter' clause!\n"
2643 0 ▶ if $opts->{'output_filter_where_clause'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"output_filter_where_clause"} 0 0 0
2644 0 my ($args,$over,$sort) = @$pt;
2645 0 ▶ $args||=[];
Condition0%0/2
$args ||= []
l!l
00
MC/DC0%0/1
$args ||= []
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
2646 0 ▶ if (($over and @$over==1 and $over->[0] eq 'ALL') or
Branch: 1 branch
BranchTrueFalseTotal
if ($over and @$over == 1 and $over->[0] eq "ALL" or not $opts->{"is_local_filter"} || $over && @$over and $name =~ /^(rank|dense_rank|row_number)/) 0 0 0
Condition0%0/18
$over and @$over == 1 and $over->[0] eq "ALL" or not $opts->{"is_local_filter"} || $over && @$over and $name =~ /^(rank|dense_rank|row_number)/
l!l&&r!l&&!r
000
$over and @$over == 1 and $over->[0] eq "ALL"
!ll&&!rl&&r
000
$over and @$over == 1
!ll&&!rl&&r
000
not $opts->{"is_local_filter"} || $over && @$over and $name =~ /^(rank|dense_rank|row_number)/
!ll&&!rl&&r
000
$opts->{'is_local_filter'} || $over && @$over
l!l&&r!l&&!r
000
$over and @$over
!ll&&!rl&&r
000
MC/DC0%0/7
$over and @$over == 1 and $over->[0] eq "ALL" or not $opts->{"is_local_filter"} || $over && @$over and $name =~ /^(rank|dense_rank|row_number)/
$over @$over == 1 $over->[0] eq "ALL" $opts->{'is_local_filter'} $over @$over $name =~ /^(rank|dense_rank|row_number)/
Truth table0%0/19
A and B and C or not(D || E and F) and G
A= $overB= @$over == 1C= $over->[0] eq "ALL"D= $opts->{'is_local_filter'}E= $overF= @$overG= $name =~ /^(rank|dense_rank|row_number)/
ABCDEFGresult
111XXXX1
0XX00X11
0XX01011
10X00X11
10X01011
11000X11
11001011
0XX1XXX0
0XX011X0
0XX00X00
0XX01000
10X1XXX0
10X011X0
10X00X00
10X01000
1101XXX0
110011X0
11000X00
11001000
2647 (!$opts->{is_local_filter} # to avoid infinitely deep recursion
2648 and !($over and @$over) and ($name =~ /^(rank|dense_rank|row_number)/))) {
2649 0 $over = ['0']; # the key can be arbitrary constant scalar
2650 }
2651  
2652 0 my $key = $name.'('.Data::Dumper->new([$args,$over,$sort],[qw(args over sort)])->Indent(0)->Dump.')';
2653 0 ▶ if ($name eq 'concat') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'concat') { } 0 0 0
elsif (@$args > 1) { } 0 0 0
elsif ($name =~ /^(rank|dense_rank|row_number)/) { } 0 0 0
elsif (@$args == 0) { } 0 0 0
2654 0 ▶ die "The analytic function $name takes one or two arguments concat(STR, SEPARATOR?) in the output filter expression $opts->{expression}; got @$args!\n" if @$args==0 or @$args>2;
Branch: 1 branch
BranchTrueFalseTotal
if @$args == 0 or @$args > 2 0 0 0
Condition0%0/3
@$args == 0 or @$args > 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args == 0 or @$args > 2
@$args == 0 @$args > 2
Truth table0%0/3
A or B
A= @$args == 0B= @$args > 2
ABresult
1X1
011
000
2655 0 ▶ if (@$args==2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 2) 0 0 0
2656 0 ▶ unless (defined($args->[1]) and !ref($args->[1]) and $args->[1]!~/^\$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->[1] and not ref $args->[1] and not $args->[1] =~ /^\$/) 0 0 0
Condition0%0/6
defined $args->[1] and not ref $args->[1] and not $args->[1] =~ /^\$/
!ll&&!rl&&r
000
defined $args->[1] and not ref $args->[1]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $args->[1] and not ref $args->[1] and not $args->[1] =~ /^\$/
defined $args->[1] not ref $args->[1] not $args->[1] =~ /^\$/
Truth table0%0/4
A and not(B) and not(C)
A= defined $args->[1]B= not ref $args->[1]C= not $args->[1] =~ /^\$/
ABCresult
0XX0
10X0
1100
1111
2657 0 die "The second argument to concat(STR, SEPARATOR?) must be a literal string or number in $opts->{expression}!\n";
2658 }
2659 }
2660 } elsif (@$args>1) {
2661 0 die "The analytic function $name takes at most one argument in the output filter expression $opts->{expression}\n";
2662 } elsif ($name =~ /^(rank|dense_rank|row_number)/) {
2663 0 ▶ if (@$args>0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args > 0) 0 0 0
2664 0 die "The analytic function $name takes no arguments in the output filter expression $opts->{expression}; got @$args!\n";
2665 }
2666 } elsif (@$args==0) {
2667 0 ▶ if ($opts->{column_count} and !$opts->{is_first_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'column_count'} and not $opts->{'is_first_filter'}) { } 0 0 0
Condition0%0/3
$opts->{"column_count"} and not $opts->{"is_first_filter"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"column_count"} and not $opts->{"is_first_filter"}
$opts->{"column_count"} not $opts->{"is_first_filter"}
Truth table0%0/3
A and not(B)
A= $opts->{"column_count"}B= not $opts->{"is_first_filter"}
ABresult
0X0
100
111
2668 0 $args=['$1'];
2669 } else {
2670 0 $args=['0'];
2671 }
2672 }
2673 0 ▶ if ($name eq 'ratio') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "ratio") 0 0 0
2674 0 return $self->serialize_expression_pt([
2675 'EXP', Treex::PML::CloneValue($args->[0]), 'div', [ 'ANALYTIC_FUNC', 'sum', $args, $over ] # ratio($1 over $2) translates to $1/sum($1 over $2)
2676 ] ,$opts);
2677 }
2678 0 ▶ if ($sort and @$sort and $name !~ /^(concat|rank|dense_rank|row_number)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sort and @$sort and not $name =~ /^(concat|rank|dense_rank|row_number)$/) 0 0 0
Condition0%0/6
$sort and @$sort and not $name =~ /^(concat|rank|dense_rank|row_number)$/
!ll&&!rl&&r
000
$sort and @$sort
!ll&&!rl&&r
000
MC/DC0%0/3
$sort and @$sort and not $name =~ /^(concat|rank|dense_rank|row_number)$/
$sort @$sort not $name =~ /^(concat|rank|dense_rank|row_number)$/
Truth table0%0/4
A and B and not(C)
A= $sortB= @$sortC= not $name =~ /^(concat|rank|dense_rank|row_number)$/
ABCresult
0XX0
10X0
1100
1111
2679 0 warn "The 'sort by' clause has no effect in analytic function ${name}() in expression $opts->{expression}!\n";
2680 }
2681 0 ▶ if ($over and @$over) {
Branch: 1 branch
BranchTrueFalseTotal
if ($over and @$over) { } 0 0 0
Condition0%0/3
$over and @$over
!ll&&!rl&&r
000
MC/DC0%0/2
$over and @$over
$over @$over
Truth table0%0/3
A and B
A= $overB= @$over
ABresult
0X0
100
111
2682 0 ▶ if ($opts->{local_aggregations}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'local_aggregations'}) { } 0 0 0
2683 #
2684 # we now compile the columns just to
2685 # determine a key
2686 # so that we can merge two aggregations into one
2687 # and to obtain variables used in individual clauses
2688 #
2689 0 ▶ if (@$args==0 and ($name !~ /^(rank|dense_rank|row_number)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 0 and not $name =~ /^(rank|dense_rank|row_number)/) 0 0 0
Condition0%0/3
@$args == 0 and not $name =~ /^(rank|dense_rank|row_number)/
!ll&&!rl&&r
000
MC/DC0%0/2
@$args == 0 and not $name =~ /^(rank|dense_rank|row_number)/
@$args == 0 not $name =~ /^(rank|dense_rank|row_number)/
Truth table0%0/3
A and not(B)
A= @$args == 0B= not $name =~ /^(rank|dense_rank|row_number)/
ABresult
0X0
100
111
2690 0 ▶ if ($opts->{column_count} and !$opts->{is_first_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'column_count'} and not $opts->{'is_first_filter'}) { } 0 0 0
Condition0%0/3
$opts->{"column_count"} and not $opts->{"is_first_filter"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"column_count"} and not $opts->{"is_first_filter"}
$opts->{"column_count"} not $opts->{"is_first_filter"}
Truth table0%0/3
A and not(B)
A= $opts->{"column_count"}B= not $opts->{"is_first_filter"}
ABresult
0X0
100
111
2691 0 $args=['$1'];
2692 } else {
2693 0 $args=['0'];
2694 }
2695 }
2696 0 my @vars;
2697 0 my $i = -1;
2698  
2699 my @cols = map {
2700 0 $i++;
2701 0 my $j = 0;
2702 [map {
2703 0 my $ppt = Treex::PML::CloneValue($_);
2704 $self->serialize_expression_pt($ppt,{
2705 output_filter => 1,
2706 var_prefix => 'v',
2707 expression => $opts->{expression},
2708 column_count => $opts->{column_count},
2709 columns_used => $opts->{columns_used},
2710 aggregations => $opts->{aggregations},
2711 is_first_filter => $opts->{is_first_filter},
2712 foreach => $opts->{foreach},
2713 input_columns => $opts->{input_columns},
2714 0 vars_used => ($vars[$i][$j++]={}),
2715 local_aggregations => undef,
2716 0 ▶ })} @{$_||[]}
Branch: 2 branches
BranchTrueFalseTotal
$_ or [] 0 0 0
$sort ? : 0 0 0
2717 ],
2718 } ($args,$over,($sort ? [map $_->[0], @$sort] : []));
2719 0 my $key = $name.':'.join(';',map join(',',@$_), @cols);
2720 0 my $num;
2721 0 ▶ if (exists $opts->{local_aggregations}{ $key }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'local_aggregations'}{$key}) { } 0 0 0
2722 0 $num = $opts->{local_aggregations}{ $key }[0];
2723 } else {
2724 0 $num = scalar keys %{$opts->{local_aggregations}};
2725 0 $opts->{local_aggregations}{ $key } = [
2726 $num,
2727 $name,
2728 $args,
2729 $over,
2730 $sort,
2731 $cols[1], # over (local group cols)
2732 $vars[1], # variables used in over
2733 ];
2734 }
2735 0 my $var = '$l'.$num;
2736 0 $opts->{vars_used}{$var}=1;
2737 0 return $var;
2738 } else {
2739 0 die "Cannot use analytic function $name with an 'over' clause in this context in the output filter expression $opts->{expression}!\n";
2740 }
2741 } else {
2742 0 my ($var, $num);
2743 0 ▶ if ($opts->{old_aggregations} and exists $opts->{old_aggregations}{ $key }) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'old_aggregations'} and exists $opts->{'old_aggregations'}{$key}) { } 0 0 0
elsif ($opts->{'aggregations'} and exists $opts->{'aggregations'}{$key}) { } 0 0 0
Condition0%0/3
$opts->{"old_aggregations"} and exists $opts->{"old_aggregations"}{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"old_aggregations"} and exists $opts->{"old_aggregations"}{$key}
$opts->{"old_aggregations"} exists $opts->{"old_aggregations"}{$key}
Truth table0%0/3
A and B
A= $opts->{"old_aggregations"}B= exists $opts->{"old_aggregations"}{$key}
ABresult
0X0
100
111
2744 $num = $opts->{old_aggregations_first_column} +
2745 0 $opts->{old_aggregations}{ $key }[0] + 1;
2746 0 $var = '$v'.$num;
2747 0 $opts->{columns_used}{$num}=1;
2748 0 $opts->{vars_used}{$var}=1;
2749 ▶ } elsif ($opts->{aggregations} and exists $opts->{aggregations}{ $key }) {
Condition0%0/3
$opts->{"aggregations"} and exists $opts->{"aggregations"}{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"aggregations"} and exists $opts->{"aggregations"}{$key}
$opts->{"aggregations"} exists $opts->{"aggregations"}{$key}
Truth table0%0/3
A and B
A= $opts->{"aggregations"}B= exists $opts->{"aggregations"}{$key}
ABresult
0X0
100
111
2750 0 $num = $opts->{aggregations}{ $key }[0];
2751 } else {
2752 0 ▶ if (!defined $opts->{aggregations}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"aggregations"}) 0 0 0
2753 0 die "Cannot use analytic function $name without an 'over' clause in this context in the output filter expression $opts->{expression} (@{[ %$opts ]})!\n";
2754 }
2755 $num =
2756 0 ▶ keys(%{$opts->{old_aggregations} || {}}) +
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"old_aggregations"} or {} 0 0 0
2757 0 keys(%{$opts->{aggregations}});
2758 0 $opts->{aggregations}{ $key } = [ $num, $name, Treex::PML::CloneValue($args), undef, Treex::PML::CloneValue($sort) ];
2759 }
2760 0 ▶ $var ||= '$a'.$num;
Condition0%0/2
$var ||= '$a' . $num
l!l
00
MC/DC0%0/1
$var ||= '$a' . $num
$var
Truth table0%0/2
A
A= $var
Aresult
11
00
2761 0 $opts->{vars_used}{$var}=1;
2762 0 return $var;
2763 }
2764 } elsif ($type eq 'FUNC') {
2765 0 my $name = $pt->[0];
2766 0 my $args = $pt->[1];
2767 0 my $id;
2768 0 ▶ if ($name=~/^(?:descendants|lbrothers|rbrothers|sons|depth|depth_first_order|name|type_of)$/) {
Branch: 14 branches
BranchTrueFalseTotal
if ($name =~ /^(?:descendants|lbrothers|rbrothers|sons|depth|depth_first_order|name|type_of)$/) { } 0 0 0
elsif ($name =~ /^order_span_(?:min|max)$/) { } 0 0 0
elsif ($name =~ /^(file|tree_no|address|id)$/) { } 0 0 0
elsif ($name =~ /^(?:lower|upper|length)$/) { } 0 0 0
elsif ($name =~ /^(?:abs|floor|ceil|exp|sqrt|ln)$/) { } 0 0 0
elsif ($name =~ /^(?:log|power)$/) { } 0 0 0
elsif ($name =~ /^(?:round|trunc)$/) { } 0 0 0
elsif ($name eq 'percnt') { } 0 0 0
elsif ($name eq 'substr') { } 0 0 0
elsif ($name eq 'replace') { } 0 0 0
elsif ($name eq 'tr') { } 0 0 0
elsif ($name eq 'match') { } 0 0 0
elsif ($name eq 'substitute') { } 0 0 0
elsif ($name eq 'first_defined') { } 0 0 0
2769 0 my $node;
2770 0 ▶ if ($args and @$args==1 and !ref($args->[0]) and $args->[0]=~s/^\$//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//) { } 0 0 0
elsif ($args and @$args) { } 0 0 0
Condition0%0/9
$args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//
!ll&&!rl&&r
000
$args and @$args == 1 and not ref $args->[0]
!ll&&!rl&&r
000
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/4
$args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//
$args @$args == 1 not ref $args->[0] $args->[0] =~ s/^\$//
Truth table0%0/5
A and B and not(C) and D
A= $argsB= @$args == 1C= not ref $args->[0]D= $args->[0] =~ s/^\$//
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2771 0 $node=$self->serialize_target($args->[0],$opts);
2772 ▶ } elsif ($args and @$args) {
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2773 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n";
2774 } else {
2775 0 $node=$self->serialize_target($this_node_id,$opts);
2776 }
2777 0 ▶ my $ret = ($name eq 'descendants') ? qq{ scalar(${node}->descendants) }
Branch: 8 branches
BranchTrueFalseTotal
$name eq 'descendants' ? : 0 0 0
$name eq 'lbrothers' ? : 0 0 0
$name eq 'rbrothers' ? : 0 0 0
$name eq 'depth_first_order' ? : 0 0 0
$name eq 'sons' ? : 0 0 0
$name eq 'depth' ? : 0 0 0
$name eq 'name' ? : 0 0 0
$name eq 'type_of' ? : 0 0 0
2778 : ($name eq 'lbrothers') ? q[ do { my $n = ].$node.q[; my $i=0; $i++ while ($n=$n->lbrother); $i } ]
2779 : ($name eq 'rbrothers') ? q[ do { my $n = ].$node.q[; my $i=0; $i++ while ($n=$n->rbrother); $i } ]
2780 : ($name eq 'depth_first_order') ? q[ do { my $n = ].$node.q[; my $r=$n->root; my $i=0; $i++ while ($n!=$r and $r=$r->following); $i } ]
2781 : ($name eq 'sons') ? qq{ scalar(${node}->children) }
2782 : ($name eq 'depth') ? qq{ ${node}->level }
2783 : ($name eq 'name') ? qq{ ${node}->{'#name'} }
2784 : ($name eq 'type_of') ? q[ do { my $t=].$node.q[->type->get_decl_path; $t=~s/^\!|\.type$//g; $t } ]
2785 # FIXME: need to pass fsfile as well
2786 : die "PMLTQ internal error while compiling expression: should never get here!";
2787 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
2788 die "Cannot use function '$name' at this point of an output filter: '$opts->{expression}'\n"
2789 0 ▶ if defined($opts->{column_count});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"column_count"} 0 0 0
2790 0 return $self->serialize_column_node_ref($ret,$opts);
2791 } else {
2792 0 return $ret;
2793 }
2794 } elsif ($name =~ /^order_span_(?:min|max)$/) {
2795 0 my $node;
2796 my $node_type;
2797 0 ▶ if ($args and @$args==1 and !ref($args->[0]) and $args->[0]=~s/^\$//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//) { } 0 0 0
elsif ($args and @$args) { } 0 0 0
Condition0%0/9
$args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//
!ll&&!rl&&r
000
$args and @$args == 1 and not ref $args->[0]
!ll&&!rl&&r
000
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/4
$args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//
$args @$args == 1 not ref $args->[0] $args->[0] =~ s/^\$//
Truth table0%0/5
A and B and not(C) and D
A= $argsB= @$args == 1C= not ref $args->[0]D= $args->[0] =~ s/^\$//
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2798 0 $node_type = $self->{name2type}{$args->[0]};
2799 0 $node=$self->serialize_target($args->[0],$opts);
2800 ▶ } elsif ($args and @$args) {
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2801 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n";
2802 } else {
2803 0 $node_type = $opts->{type};
2804 0 $node=$self->serialize_target($this_node_id,$opts);
2805 }
2806 0 my $attr;
2807 0 ▶ if (defined ($node_type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node_type) 0 0 0
2808 0 my $decl = $self->{type_mapper}->get_decl_for($node_type);
2809 0 ▶ if ($decl->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 13) 0 0 0
2810 0 $decl = $decl->get_content_decl;
2811 }
2812 0 my ($m)=$decl->find_members_by_role('#ORDER');
2813 0 ▶ $attr = defined($m) && $m->get_name
Condition0%0/3
defined $m && $m->get_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $m && $m->get_name
defined $m $m->get_name
Truth table0%0/3
A && B
A= defined $mB= $m->get_name
ABresult
0X0
100
111
2814 }
2815 0 ▶ if ($attr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr) { } 0 0 0
2816 0 $attr=quotemeta($attr);
2817 0 return qq{ ${node}->{qq($attr)} }
2818 } else {
2819 0 return qq{ \$self->get_cached_$name(${node}) };
2820 }
2821 } elsif ($name =~ /^(file|tree_no|address|id)$/) {
2822 0 my $ref;
2823 0 ▶ if ($args and @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args) { } 0 0 0
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2824 0 $ref = $args->[0];
2825 0 ▶ die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$args > 1 or not $ref =~ s/^\$(?![0-9])// 0 0 0
Condition0%0/3
@$args > 1 or not $ref =~ s/^\$(?![0-9])//
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args > 1 or not $ref =~ s/^\$(?![0-9])//
@$args > 1 not $ref =~ s/^\$(?![0-9])//
Truth table0%0/3
A or not(B)
A= @$args > 1B= not $ref =~ s/^\$(?![0-9])//
ABresult
1X1
011
000
2826 if (@$args>1 or not $ref=~s/^\$(?![0-9])//);
2827 } else {
2828 0 $ref = $this_node_id;
2829 }
2830 0 my ($target,$file) = $self->serialize_target2($ref,$opts);
2831 0 my $ret;
2832 0 ▶ if ($name eq 'file') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'file') { } 0 0 0
2833 0 $ret = qq{$file->filename};
2834 } else {
2835 0 ▶ if ($name eq 'id') {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'id') { } 0 0 0
elsif ($name eq 'tree_no') { } 0 0 0
elsif ($name eq 'address') { } 0 0 0
2836 0 my $decl = $self->{type_mapper}->get_decl_for( $self->{name2type}{$ref} );
2837 0 ▶ if ($decl->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 13) 0 0 0
2838 0 $decl = $decl->get_content_decl;
2839 }
2840 0 my ($m)=$decl->find_members_by_role('#ID');
2841 0 ▶ my $id_attr = defined($m) && $m->get_name;
Condition0%0/3
defined $m && $m->get_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $m && $m->get_name
defined $m $m->get_name
Truth table0%0/3
A && B
A= defined $mB= $m->get_name
ABresult
0X0
100
111
2842 0 ▶ $ret= defined $id_attr ? $target.qq{->{q($id_attr)}} : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $id_attr ? : 0 0 0
2843 } elsif ($name eq 'tree_no') {
2844 # FIXME: die if this function is root on a member node
2845 0 $ret= qq{1+Treex::PML::Index($file->treeList,$target->root)};
2846 } elsif ($name eq 'address') {
2847 # FIXME: die if this function is root on a member node
2848 0 $ret= qq{TredMacro::ThisAddress($target,$file)};
2849 } else {
2850 0 die "Function ${name}() not yet implemented!\n";
2851 }
2852 }
2853 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
2854 die "Cannot use function '$name' at this point of an output filter: '$opts->{expression}'\n"
2855 0 ▶ if defined($opts->{column_count});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"column_count"} 0 0 0
2856 0 return $self->serialize_column_node_ref($ret,$opts);
2857 } else {
2858 0 return $ret;
2859 }
2860 } elsif ($name=~/^(?:lower|upper|length)$/) {
2861 0 ▶ if ($args and @$args==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 1) { } 0 0 0
Condition0%0/3
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 1
$args @$args == 1
Truth table0%0/3
A and B
A= $argsB= @$args == 1
ABresult
0X0
100
111
2862 0 ▶ my $func = $name eq 'lower' ? 'lc'
Branch: 2 branches
BranchTrueFalseTotal
$name eq 'lower' ? : 0 0 0
$name eq 'upper' ? : 0 0 0
2863 : $name eq 'upper' ? 'uc'
2864 : $name;
2865 0 return $func.'('
2866 . $self->serialize_expression_pt($args->[0],$opts)
2867 . ')';
2868 } else {
2869 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(string)\n";
2870 }
2871 } elsif ($name=~/^(?:abs|floor|ceil|exp|sqrt|ln)$/) {
2872 0 ▶ if ($args and @$args==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 1) { } 0 0 0
Condition0%0/3
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 1
$args @$args == 1
Truth table0%0/3
A and B
A= $argsB= @$args == 1
ABresult
0X0
100
111
2873 0 ▶ my $func = $name eq 'ln' ? 'log' : $name;
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'ln' ? : 0 0 0
2874 0 return $func.'('
2875 . $self->serialize_expression_pt($args->[0],$opts)
2876 . ')';
2877 } else {
2878 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(number)\n";
2879 }
2880 } elsif ($name =~ /^(?:log|power)$/) {
2881 0 ▶ my $func = $name eq 'log' ? 'log(%2$s)/log(%1$s)' : '(%s ** %s)';
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'log' ? : 0 0 0
2882 0 ▶ if ($args and @$args==1 or @$args==2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 1 or @$args == 2) { } 0 0 0
Condition0%0/6
$args and @$args == 1 or @$args == 2
l!l&&r!l&&!r
000
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args == 1 or @$args == 2
$args @$args == 1 @$args == 2
Truth table0%0/5
A and B or C
A= $argsB= @$args == 1C= @$args == 2
ABCresult
11X1
0X11
1011
0X00
1000
2883 0 my @args = map $self->serialize_expression_pt($_,$opts), @$args;
2884 0 ▶ @args = (10,@args) if @args==1;
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 0 0 0
2885 0 return sprintf($func, @args);
2886 } else {
2887 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(base,number) or ${name}(number)\n";
2888 }
2889 } elsif ($name=~/^(?:round|trunc)$/) {
2890 0 ▶ if ($args and @$args and @$args<3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args and @$args < 3) { } 0 0 0
Condition0%0/6
$args and @$args and @$args < 3
!ll&&!rl&&r
000
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args and @$args < 3
$args @$args @$args < 3
Truth table0%0/4
A and B and C
A= $argsB= @$argsC= @$args < 3
ABCresult
0XX0
10X0
1100
1111
2891 return $name.'('
2892 0 . join(',',map { $self->serialize_expression_pt($_,$opts) } @$args)
2893 . ')';
2894 } else {
2895 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(string)\n";
2896 }
2897 } elsif ($name eq 'percnt') {
2898 0 ▶ if ($args and @$args>0 and @$args<3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args > 0 and @$args < 3) { } 0 0 0
Condition0%0/6
$args and @$args > 0 and @$args < 3
!ll&&!rl&&r
000
$args and @$args > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args > 0 and @$args < 3
$args @$args > 0 @$args < 3
Truth table0%0/4
A and B and C
A= $argsB= @$args > 0C= @$args < 3
ABCresult
0XX0
10X0
1100
1111
2899 0 my @args = map { $self->serialize_expression_pt($_,$opts) } @$args;
2900 0 ▶ return 'round(100*('.$args[0].')'
Branch: 1 branch
BranchTrueFalseTotal
@args > 1 ? : 0 0 0
2901 . (@args>1 ? ','.$args[1] : '').q[)];
2902 } else {
2903 0 die "Wrong arguments for function percnt() in expression $opts->{expression} of node '$this_node_id'!\nUsage: percnt(number,precision?)\n";
2904 }
2905 } elsif ($name eq 'substr') {
2906 0 ▶ if ($args and @$args>1 and @$args<4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args > 1 and @$args < 4) { } 0 0 0
Condition0%0/6
$args and @$args > 1 and @$args < 4
!ll&&!rl&&r
000
$args and @$args > 1
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args > 1 and @$args < 4
$args @$args > 1 @$args < 4
Truth table0%0/4
A and B and C
A= $argsB= @$args > 1C= @$args < 4
ABCresult
0XX0
10X0
1100
1111
2907 return 'substr('
2908 0 . join(',', map { $self->serialize_expression_pt($_,$opts) } @$args)
2909 . ')';
2910 } else {
2911 0 die "Wrong arguments for function substr() in expression $opts->{expression} of node '$this_node_id'!\nUsage: substr(string,from,length?)\n";
2912 }
2913  
2914 } elsif ($name eq 'replace') {
2915 0 ▶ if ($args and @$args==3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 3) { } 0 0 0
Condition0%0/3
$args and @$args == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 3
$args @$args == 3
Truth table0%0/3
A and B
A= $argsB= @$args == 3
ABresult
0X0
100
111
2916 0 my @args = map { $self->serialize_expression_pt($_,$opts) } @$args;
2917 0 return 'do{ my ($str,$from,$to) = (' .join(',', @args).'); $str=~s/\Q$from/$to/g; $str }';
2918 } else {
2919 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,target,replacement)\n"
2920 }
2921 } elsif ($name eq 'tr') {
2922 0 ▶ if ($args and @$args==3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 3) { } 0 0 0
Condition0%0/3
$args and @$args == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 3
$args @$args == 3
Truth table0%0/3
A and B
A= $argsB= @$args == 3
ABresult
0X0
100
111
2923 0 my @args = map { $self->serialize_expression_pt($_,$opts) } @$args;
2924 0 return 'do{ my ($str,$from,$to) = (' .join(',', @args).'); $from=~s{/}{\\/}g; $to=~s{/}{\\/}g; eval qq{$str=~tr/$from/$to/, 1} or die $@; $str; }';
2925 } else {
2926 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,from_chars,to_chars)\n"
2927 }
2928 } elsif ($name eq 'match') {
2929 0 ▶ if ($args and @$args>=2 and @$args<=3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args >= 2 and @$args <= 3) { } 0 0 0
Condition0%0/6
$args and @$args >= 2 and @$args <= 3
!ll&&!rl&&r
000
$args and @$args >= 2
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args >= 2 and @$args <= 3
$args @$args >= 2 @$args <= 3
Truth table0%0/4
A and B and C
A= $argsB= @$args >= 2C= @$args <= 3
ABCresult
0XX0
10X0
1100
1111
2930 0 my @args = map { $self->serialize_expression_pt($_,$opts) } @$args[0,1];
2931 0 my $match_opts = $args->[2];
2932 0 ▶ if (defined($match_opts) and (ref($match_opts) or $match_opts!~/^\s*'[icnm]*'\s*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnm]*'\s*$/)) 0 0 0
Condition0%0/6
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnm]*'\s*$/)
!ll&&!rl&&r
000
ref $match_opts or not $match_opts =~ /^\s*'[icnm]*'\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnm]*'\s*$/)
defined $match_opts ref $match_opts not $match_opts =~ /^\s*'[icnm]*'\s*$/
Truth table0%0/4
A and B or not(C)
A= defined $match_optsB= ref $match_optsC= not $match_opts =~ /^\s*'[icnm]*'\s*$/
ABCresult
0XX0
1000
11X1
1011
2933 0 die "Wrong match options [$match_opts] for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,pattern,options?), where options is a literal string consisting only of characters from the set [icnm]\n";
2934 }
2935 0 $match_opts=~s/^\s*'([icnm]*)'\s*$/$1/;
2936 0 return 'do{ my ($str,$regexp) = (' .join(',', @args).'); $str=~/($regexp)/'.$match_opts.' ? $1 : undef }';
2937 } else {
2938 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,from_chars,to_chars)\n"
2939 }
2940 } elsif ($name eq 'substitute') {
2941 0 ▶ if ($args and @$args>=3 and @$args<=4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args >= 3 and @$args <= 4) { } 0 0 0
Condition0%0/6
$args and @$args >= 3 and @$args <= 4
!ll&&!rl&&r
000
$args and @$args >= 3
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args >= 3 and @$args <= 4
$args @$args >= 3 @$args <= 4
Truth table0%0/4
A and B and C
A= $argsB= @$args >= 3C= @$args <= 4
ABCresult
0XX0
10X0
1100
1111
2942 0 my @args = map { $self->serialize_expression_pt($_,$opts) } @$args[0..2];
2943 0 my $match_opts = $args->[3];
2944 0 ▶ if (defined($match_opts) and (ref($match_opts) or $match_opts!~/^\s*'[icnmg]*'\s*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnmg]*'\s*$/)) 0 0 0
Condition0%0/6
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnmg]*'\s*$/)
!ll&&!rl&&r
000
ref $match_opts or not $match_opts =~ /^\s*'[icnmg]*'\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnmg]*'\s*$/)
defined $match_opts ref $match_opts not $match_opts =~ /^\s*'[icnmg]*'\s*$/
Truth table0%0/4
A and B or not(C)
A= defined $match_optsB= ref $match_optsC= not $match_opts =~ /^\s*'[icnmg]*'\s*$/
ABCresult
0XX0
1000
11X1
1011
2945 0 die "Wrong match options [$match_opts] for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,pattern,options?), where options is a literal string consisting only of characters from the set [icnmg]\n";
2946 }
2947 0 $match_opts=~s/^\s*'([icnmg]*)'\s*$/$1/;
2948 0 return 'do{ my ($str,$regexp,$replacement) = (' .join(',', @args).'); $regexp=~s{/}{\\\\/}g; $replacement=~s{/}{\\\\/}g; $replacement=~s{(\\\\([0-9])|\\\\[^0-9])}{defined $2 ? q($).$2 : $1}ge; eval qq{\$str=~s/$regexp/$replacement/'.$match_opts.'}; $str }';
2949 } else {
2950 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,from_chars,to_chars)\n"
2951 }
2952 } elsif ($name eq 'first_defined') {
2953 0 ▶ if (!$args or @$args<2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args or @$args < 2) 0 0 0
Condition0%0/3
not $args or @$args < 2
l!l&&r!l&&!r
000
MC/DC0%0/2
not $args or @$args < 2
not $args @$args < 2
Truth table0%0/3
not(A) or B
A= not $argsB= @$args < 2
ABresult
1X1
011
000
2954 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(value1,value2,...)\n";
2955 }
2956 0 ▶ my $foreach = $opts->{foreach} ||= [];
Condition0%0/2
$opts->{"foreach"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"foreach"} ||= []
$opts->{"foreach"}
Truth table0%0/2
A
A= $opts->{"foreach"}
Aresult
11
00
2957 0 my @vars;
2958 0 for my $arg (@$args) {
2959 0 my $vars=[];
2960 0 push @$foreach, [0, $self->serialize_expression_pt($arg,{%$opts,no_node_ref=>1,return_vars=>$vars}),$vars];
2961 0 push @vars,'$var'.$#$foreach;
2962 }
2963 0 push @$foreach,
2964 [0,
2965 '('.join(' ',map qq[defined($_) ? $_ :],@vars).' undef)',
2966 [] # no defined() test on variables
2967 ];
2968 0 my $ret = '$var'.$#$foreach;
2969 0 ▶ push @{$opts->{return_vars}||=[]},$ret;
Condition0%0/2
$opts->{"return_vars"} ||= []
l!l
00
MC/DC0%0/1
$opts->{"return_vars"} ||= []
$opts->{"return_vars"}
Truth table0%0/2
A
A= $opts->{"return_vars"}
Aresult
11
00
2970 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"output_filter"}) 0 0 0
2971 0 $ret =$self->serialize_column_node_ref($ret,$opts);
2972 }
2973 0 return $ret;
2974 } else {
2975 0 die "$name() NOT YET IMPLEMENTED!\n";
2976 }
2977 } elsif ($type eq 'EXP') {
2978 0 my $out.='(';
2979 0 ▶ while (@$pt) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pt) 0 0 0
2980 0 $out.=$self->serialize_expression_pt(shift @$pt,$opts);
2981 0 ▶ if (@$pt) { # op
Branch: 1 branch
BranchTrueFalseTotal
if (@$pt) 0 0 0
2982 0 my $op = shift @$pt;
2983 0 ▶ if ($op eq 'div') {
Branch: 4 branches
BranchTrueFalseTotal
if ($op eq 'div') { } 0 0 0
elsif ($op eq 'mod') { } 0 0 0
elsif ($op eq '&') { } 0 0 0
elsif (not $op =~ /[-+*]/) { } 0 0 0
2984 0 $op='/'
2985 } elsif ($op eq 'mod') {
2986 0 $op='%'
2987 } elsif ($op eq '&') {
2988 0 $op=' . '
2989 } elsif ($op !~ /[-+*]/) {
2990 0 die "Urecognized operator '$op' in expression $opts->{expression} of node '$this_node_id'\n";
2991 }
2992 0 $out.=$op;
2993 }
2994 }
2995 0 $out.=')';
2996 0 return $out;
2997 } elsif ($type eq 'SET') {
2998 return '('
2999 0 . join(',', map { $self->serialize_expression_pt($_,$opts) } @$pt)
3000 . ')';
3001 }
3002 } else {
3003 0 ▶ if ($pt=~/^[-0-9']/) { # literal
Branch: 3 branches
BranchTrueFalseTotal
if ($pt =~ /^[-0-9']/) { } 0 0 0
elsif ($pt =~ s/^(['"])(.*)\1$/$2/s) { } 0 0 0
elsif ($pt =~ s/^\$//) { } 0 0 0
3004 0 return qq( $pt );
3005 } elsif ($pt=~s/^(['"])(.*)\1$/$2/s) { # literal string
3006 0 $pt=~s/\\([^\\])/$1/sg;
3007 0 $pt=~s/'/\\'/sg;
3008 0 $pt=q{'}.$pt.q{'};
3009 } elsif ($pt=~s/^\$//) { # a plain variable
3010 0 ▶ if ($pt eq '$') {
Branch: 2 branches
BranchTrueFalseTotal
if ($pt eq '$') { } 0 0 0
elsif ($pt =~ /^[1-9][0-9]*$/) { } 0 0 0
3011 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
3012 0 die "Cannot use node reference '$$' in output filters: '$opts->{expression}'\n";
3013 } else {
3014 0 return '$node';
3015 }
3016 } elsif ($pt =~ /^[1-9][0-9]*$/) { #column reference
3017 die "Column reference \$$pt can only be used in an output filter; error in expression '$opts->{expression}' of node '$this_node_id'\n"
3018 0 ▶ unless $opts->{'output_filter'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"output_filter"} 0 0 0
3019 die "Column reference \$$pt used at position where there is yet no column to refer to\n"
3020 0 ▶ unless defined $opts->{'column_count'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"column_count"} 0 0 0
3021 die "Column reference \$$pt used at position where there are only $opts->{'column_count'} columns\n"
3022 0 ▶ if $pt > $opts->{'column_count'};
Branch: 1 branch
BranchTrueFalseTotal
if $pt > $opts->{"column_count"} 0 0 0
3023 0 ▶ my $var = '$'.$opts->{var_prefix}.$pt.($opts->{var_suffix}||'');
Condition0%0/2
$opts->{'var_suffix'} || ''
l!l
00
MC/DC0%0/1
$opts->{'var_suffix'} || ''
$opts->{'var_suffix'}
Truth table0%0/2
A
A= $opts->{'var_suffix'}
Aresult
11
00
3024 0 $opts->{columns_used}{$pt}=1;
3025 0 $opts->{vars_used}{$var}=1;
3026 0 return $var;
3027 } else {
3028 0 my ($ret_node,$ret_file) = $self->serialize_target2($pt,$opts);
3029 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
3030 die "Cannot use node reference '$pt' at this point of an output filter: '$opts->{expression}'\n"
3031 0 ▶ if defined($opts->{column_count});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"column_count"} 0 0 0
3032 0 my $ret = qq{TredMacro::ThisAddress($ret_node,$ret_file)};
3033 0 return $self->serialize_column_node_ref($ret,$opts);
3034 } else {
3035 0 return $ret_node;
3036 }
3037 }
3038 } else { # unrecognized token
3039 0 die "Token '$pt' not recognized in expression $opts->{expression} of node '$this_node_id'\n";
3040 }
3041 }
3042 }
3043  
3044 sub serialize_column_node_ref {
3045 0 ▶ my ($self, $ret, $opts)=@_;
Subroutine serialize_column_node_ref: not called CC=3 SCAR=24.8
Pod undocumented
3046 0 ▶ return $ret if $opts->{no_node_ref};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_node_ref"} 0 0 0
3047 0 push @{$opts->{input_columns}},$ret;
3048 0 my $i = scalar @{$opts->{input_columns}};
3049 0 ▶ my $var = '$'.$opts->{var_prefix}.$i.($opts->{var_suffix}||'');
Condition0%0/2
$opts->{'var_suffix'} || ''
l!l
00
MC/DC0%0/1
$opts->{'var_suffix'} || ''
$opts->{'var_suffix'}
Truth table0%0/2
A
A= $opts->{'var_suffix'}
Aresult
11
00
3050 0 $opts->{columns_used}{ $i }=1;
3051 0 $opts->{vars_used}{$var}=1;
3052 0 return $var;
3053 }
3054  
3055 sub serialize_expression {
3056 0 ▶ my ($self,$opts)=@_;
Subroutine serialize_expression: not called CC=2 SCAR=17.9
Pod undocumented
3057 0 my $pt = PMLTQ::Common::parse_expression($opts->{expression}); # $pt stands for parse tree
3058 0 ▶ die "Invalid expression '$opts->{expression}' on node '$opts->{id}'" unless defined $pt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pt 0 0 0
3059 0 return $self->serialize_expression_pt($pt,$opts);
3060 }
3061  
3062 sub test_occurrences {
3063 0 ▶ my ($self,$seed,$fsfile,$test_max) = (shift,shift,shift,shift);
Subroutine test_occurrences: not called CC=12 SCAR=50.5
Pod undocumented
3064 0 $self->reset();
3065 0 my $count=0;
3066 0 ▶ print STDERR "<subquery> $seed->{id},$test_max.\n" if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3067 0 ▶ while ($self->find_next_match({boolean => 1, subquery => 1, seed=>$seed, fsfile=>$fsfile})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->find_next_match({"boolean", 1, "subquery", 1, "seed", $seed, "fsfile", $fsfile})) 0 0 0
3068 0 $count++;
3069 0 ▶ last unless $count<=$test_max;
Branch: 1 branch
BranchTrueFalseTotal
unless $count <= $test_max 0 0 0
3070 0 $self->backtrack(0); # this is here to count on DISTINCT
3071 # roots of the subquery (i.e. the node with occurrences specified).
3072 }
3073 0 my ($min,$max_plus1)=@_;
3074 0 my $ret=0;
3075 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
3076 0 ($min,$max_plus1)=(shift,shift);
3077 0 ▶ if ((!defined($min) || $count>=$min) and
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($min) || $count >= $min and !defined($max_plus1) || $count < $max_plus1) 0 0 0
Condition0%0/9
!defined($min) || $count >= $min and !defined($max_plus1) || $count < $max_plus1
!ll&&!rl&&r
000
not defined $min or $count >= $min
l!l&&r!l&&!r
000
not defined $max_plus1 or $count < $max_plus1
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($min) || $count >= $min and !defined($max_plus1) || $count < $max_plus1
not defined $min $count >= $min not defined $max_plus1 $count < $max_plus1
Truth table0%0/7
not(A) or B and not(C) or D
A= not defined $minB= $count >= $minC= not defined $max_plus1D= $count < $max_plus1
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
3078 (!defined($max_plus1) || $count<$max_plus1)) {
3079 0 $ret=1;
3080 0 last;
3081 }
3082 }
3083 0 ▶ print STDERR "occurrences: >=$count ($ret)\n" if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3084 0 ▶ print STDERR "</subquery>\n" if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3085 0 ▶ $self->reset() if $count;
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 0 0
3086 0 return $ret;
3087 }
3088  
3089 sub backtrack {
3090 0 ▶ my ($self,$pos)=@_;
Subroutine backtrack: not called CC=4 SCAR=30.0
Pod undocumented
3091 0 my $query_pos = \$self->{query_pos}; # a scalar reference
3092 0 ▶ return unless $$query_pos >= $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless $$query_pos >= $pos 0 0 0
3093  
3094 0 my $iterators = $self->{iterators};
3095 0 my $matched_nodes = $self->{matched_nodes};
3096 0 my $pos2match_pos = $self->{pos2match_pos};
3097 0 my $have = $self->{have};
3098 0 my $iterator;
3099 my $node;
3100 0 ▶ while ($pos<$$query_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $$query_pos) 0 0 0
3101 0 $node = delete $matched_nodes->[$pos2match_pos->[$$query_pos]];
3102 0 ▶ delete $have->{$node} if $node;
Branch: 1 branch
BranchTrueFalseTotal
if $node 0 0 0
3103 0 $$query_pos--;
3104 }
3105 0 return 1;
3106 }
3107 sub find_next_match {
3108 0 ▶ my ($self,$opts)=@_;
Subroutine find_next_match: not called CC=32 SCAR=69.6
Pod undocumented
3109 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
3110 0 ▶ $STOP = 0 unless $opts->{subquery};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"subquery"} 0 0 0
3111 0 my $iterators = $self->{iterators};
3112 0 my $parent_pos = $self->{parent_pos};
3113 0 my $query_pos = \$self->{query_pos}; # a scalar reference
3114 0 my $matched_nodes = $self->{matched_nodes};
3115 0 my $pos2match_pos = $self->{pos2match_pos};
3116 0 my $is_overlapping = $self->{is_overlapping};
3117 0 my $have = $self->{have};
3118  
3119 0 my $iterator = $iterators->[$$query_pos];
3120 0 my $node = $iterator->node;
3121 0 ▶ if ($node) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node) { } 0 0 0
elsif ($$query_pos == 0) { } 0 0 0
3122 0 delete $have->{$node};
3123 0 ▶ print STDERR ("iterate $$query_pos $iterator: $self->{debug}[$$query_pos]\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG 0 0 0
3124 0 $node
3125 = $matched_nodes->[$pos2match_pos->[$$query_pos]]
3126 = $iterator->next;
3127 0 ▶ $have->{$node}=1 if ($node and !$is_overlapping->[$$query_pos]);
Branch: 1 branch
BranchTrueFalseTotal
if $node and not $$is_overlapping[$$query_pos] 0 0 0
Condition0%0/3
$node and not $$is_overlapping[$$query_pos]
!ll&&!rl&&r
000
MC/DC0%0/2
$node and not $$is_overlapping[$$query_pos]
$node not $$is_overlapping[$$query_pos]
Truth table0%0/3
A and not(B)
A= $nodeB= not $$is_overlapping[$$query_pos]
ABresult
0X0
100
111
3128 } elsif ($$query_pos==0) {
3129 # first
3130 0 ▶ print STDERR "Starting subquery on $opts->{seed}->{id} $opts->{seed}->{t_lemma}.$opts->{seed}->{functor}\n" if $opts->{seed} and $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"seed"} and $PMLTQ::BtredEvaluator::DEBUG 0 0 0
Condition0%0/3
$opts->{"seed"} and $PMLTQ::BtredEvaluator::DEBUG
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"seed"} and $PMLTQ::BtredEvaluator::DEBUG
$opts->{"seed"} $PMLTQ::BtredEvaluator::DEBUG
Truth table0%0/3
A and B
A= $opts->{"seed"}B= $PMLTQ::BtredEvaluator::DEBUG
ABresult
0X0
100
111
3131 $node
3132 = $matched_nodes->[$pos2match_pos->[$$query_pos]]
3133 0 = $iterator->start( $opts->{seed}, $opts->{fsfile} );
3134 0 ▶ $have->{$node}=1 if $node and !$is_overlapping->[$$query_pos];
Branch: 1 branch
BranchTrueFalseTotal
if $node and not $$is_overlapping[$$query_pos] 0 0 0
Condition0%0/3
$node and not $$is_overlapping[$$query_pos]
!ll&&!rl&&r
000
MC/DC0%0/2
$node and not $$is_overlapping[$$query_pos]
$node not $$is_overlapping[$$query_pos]
Truth table0%0/3
A and not(B)
A= $nodeB= not $$is_overlapping[$$query_pos]
ABresult
0X0
100
111
3135 }
3136 0 while (1) {
3137 0 ▶ return if ($STOP);
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::STOP 0 0 0
3138 0 ▶ if (!$node) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $node) { } 0 0 0
3139 0 ▶ if ($$query_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$query_pos) { } 0 0 0
3140 # backtrack
3141 0 $matched_nodes->[$pos2match_pos->[$$query_pos]]=undef;
3142 0 $$query_pos--; # backtrack
3143 0 ▶ print STDERR ("backtrack to $$query_pos\n") if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3144 0 $iterator=$iterators->[$$query_pos];
3145  
3146 0 $node = $iterator->node;
3147 0 ▶ delete $have->{$node} if $node and !$is_overlapping->[$$query_pos];
Branch: 1 branch
BranchTrueFalseTotal
if $node and not $$is_overlapping[$$query_pos] 0 0 0
Condition0%0/3
$node and not $$is_overlapping[$$query_pos]
!ll&&!rl&&r
000
MC/DC0%0/2
$node and not $$is_overlapping[$$query_pos]
$node not $$is_overlapping[$$query_pos]
Truth table0%0/3
A and not(B)
A= $nodeB= not $$is_overlapping[$$query_pos]
ABresult
0X0
100
111
3148  
3149 0 ▶ print STDERR ("iterate $$query_pos $iterator: $self->{debug}[$$query_pos]\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG 0 0 0
3150 0 $node
3151 = $matched_nodes->[$pos2match_pos->[$$query_pos]]
3152 = $iterator->next;
3153 0 ▶ $have->{$node}=1 if $node and !$is_overlapping->[$$query_pos];
Branch: 1 branch
BranchTrueFalseTotal
if $node and not $$is_overlapping[$$query_pos] 0 0 0
Condition0%0/3
$node and not $$is_overlapping[$$query_pos]
!ll&&!rl&&r
000
MC/DC0%0/2
$node and not $$is_overlapping[$$query_pos]
$node not $$is_overlapping[$$query_pos]
Truth table0%0/3
A and not(B)
A= $nodeB= not $$is_overlapping[$$query_pos]
ABresult
0X0
100
111
3154 0 next;
3155 } else {
3156 0 ▶ print STDERR "no match\n" if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3157 0 return; # NO RESULT
3158 }
3159 } else {
3160 0 ▶ print STDERR ("match $node->{id} [$$query_pos,$pos2match_pos->[$$query_pos]]: $node->{mwes}.$node->{t_lemma}.$node->{functor}\n")
Branch: 1 branch
BranchTrueFalseTotal
if ref $node and $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
Condition0%0/3
ref $node and $PMLTQ::BtredEvaluator::DEBUG > 4
!ll&&!rl&&r
000
MC/DC0%0/2
ref $node and $PMLTQ::BtredEvaluator::DEBUG > 4
ref $node $PMLTQ::BtredEvaluator::DEBUG > 4
Truth table0%0/3
A and B
A= ref $nodeB= $PMLTQ::BtredEvaluator::DEBUG > 4
ABresult
0X0
100
111
3161 if ref($node) and $DEBUG > 4;
3162  
3163 0 ▶ if ($$query_pos<$#$iterators) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$query_pos < $iterators->$#*) { } 0 0 0
3164 0 $$query_pos++;
3165 0 $iterator = $iterators->[ $parent_pos->[$$query_pos] ];
3166 0 my ($seed,$fsfile) = ($iterator->node, $iterator->file);
3167 0 ▶ print STDERR 'SEED ',$seed->{id},".\n" if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3168 0 $iterator = $iterators->[$$query_pos];
3169 0 $node
3170 = $matched_nodes->[$pos2match_pos->[$$query_pos]]
3171 = $iterator->start($seed,$fsfile);
3172 0 ▶ print STDERR ("restart $$query_pos $iterator from $seed->{id},$seed->{t_lemma}.$seed->{functor} $self->{debug}[$$query_pos]\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG 0 0 0
3173 0 ▶ print STDERR "res_ref: " .(ref($node)) ."\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG 0 0 0
3174 #print STDERR Dumper($node);
3175 0 ▶ $have->{$node}=1 if $node and !$is_overlapping->[$$query_pos];
Branch: 1 branch
BranchTrueFalseTotal
if $node and not $$is_overlapping[$$query_pos] 0 0 0
Condition0%0/3
$node and not $$is_overlapping[$$query_pos]
!ll&&!rl&&r
000
MC/DC0%0/2
$node and not $$is_overlapping[$$query_pos]
$node not $$is_overlapping[$$query_pos]
Truth table0%0/3
A and not(B)
A= $nodeB= not $$is_overlapping[$$query_pos]
ABresult
0X0
100
111
3176 0 next;
3177  
3178 } else {
3179 0 ▶ print STDERR ("complete match [bool: $opts->{boolean}]\n") if $DEBUG > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::BtredEvaluator::DEBUG > 4 0 0 0
3180 # complete match:
3181 0 ▶ if ($opts->{boolean}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'boolean'}) { } 0 0 0
3182 0 return 1;
3183 } else {
3184 0 $self->{result_files}=[map { $_->file } @$iterators];
3185 0 return $self->{results}=[map { $_->node } @$iterators];
3186 }
3187 }
3188 }
3189 }
3190 0 return;
3191 }
3192  
3193 sub plan_query {
3194 0 ▶ my ($type_mapper,$query_tree)=@_;
Subroutine plan_query: not called CC=2 SCAR=17.9
Pod undocumented
3195 0 require PMLTQ::Planner;
3196 0 ▶ $query_tree||=$TredMacro::root;
Condition0%0/3
$query_tree ||= $TredMacro::root
l!l&&r!l&&!r
000
MC/DC0%0/2
$query_tree ||= $TredMacro::root
$query_tree $TredMacro::root
Truth table0%0/3
A ||= B
A= $query_treeB= $TredMacro::root
ABresult
1X1
011
000
3197 0 PMLTQ::Planner::name_all_query_nodes($query_tree);
3198 0 my @query_nodes=PMLTQ::Common::FilterQueryNodes($query_tree);
3199 0 PMLTQ::Planner::plan($type_mapper,\@query_nodes,$query_tree);
3200 }
3201  
3202 1 1; # End of PMLTQ::BtredEvaluator
3203  
3204 __END__
« blib/lib/PMLTQ/SQLEvaluator.pm ↑ Summary blib/lib/PMLTQ/_Parser.pm »