blib/lib/PMLTQ/BtredEvaluator.pm

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