blib/lib/Zuzu/AST/Visitor/LexicalEnvHints.pm

filter: Statementstmt 99.6% 310 / 311 Branchbran 92.4% 183 / 198 Conditioncond 62.6% 52 / 83 MC/DCmcdc 34.0% 16 / 47 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 1 totaltotal 87.9% 577 / 656 CC 158 SCAR 42.6
CC
158
Cov
92%
_visit_node
106.1
_block_can_reuse_current_env
35.8
_visit_block
8.1
CRAP 70.6
« blib/lib/Zuzu/Module/DB.pm ↑ Summary blib/lib/Zuzu/CLI.pm »
1 package Zuzu::AST::Visitor::LexicalEnvHints;
2  
3 78 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 78 our $VERSION = '0.007000';
6  
7 78 ▶use Scalar::Util qw( blessed refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 78 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 751 ▶has '_scope_stack' => ( is => 'rw', default => sub { [ {} ] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
12  
13 sub apply {
14 751 ▶ my ( $self, $ast ) = @_;
Subroutine apply: called CC=1 SCAR=0.0
Pod undocumented
15  
16 751 $self->_visit_node($ast);
17  
18 751 return $ast;
19 }
20  
21 17267 ▶sub _current_scope { $_[0]->_scope_stack->[-1] }
Subroutine _current_scope: called CC=1 SCAR=0.0
22  
23 sub _push_scope {
24 11209 ▶ my ( $self, $initial ) = @_;
Subroutine _push_scope: called CC=2 SCAR=6.9
25  
26 11209 ▶ push @{ $self->_scope_stack }, { %{ $initial // {} } };
Condition100%2/2
$initial // {}
l!l
47016508
MC/DC100%1/1
$initial // {}
$initial
Truth table100%2/2
A
A= $initial
Aresult
11
00
27  
28 11209 return;
29 }
30  
31 sub _pop_scope {
32 11209 ▶ my ( $self ) = @_;
Subroutine _pop_scope: called CC=1 SCAR=0.0
33  
34 11209 pop @{ $self->_scope_stack };
35  
36 11209 return;
37 }
38  
39 sub _declare_name {
40 17267 ▶ my ( $self, $name ) = @_;
Subroutine _declare_name: called CC=3 SCAR=12.0
41  
42 17267 ▶ return if !defined $name or $name eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or $name eq "" 0 17267 17267
Condition33%1/3
not defined $name or $name eq ""
l!l&&r!l&&!r
0017267
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name $name eq ""
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name eq ""
ABresult
1X1
011
000
43 17267 $self->_current_scope->{$name} = 1;
44  
45 17267 return;
46 }
47  
48 sub _lookup_depth {
49 44145 ▶ my ( $self, $name ) = @_;
Subroutine _lookup_depth: called CC=4 SCAR=13.9
50  
51 44145 ▶ return undef if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 44145 44145
52 44145 my $scopes = $self->_scope_stack;
53 44145 ▶ for ( my $i = $#$scopes; $i >= 0; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 113583 3269 116852
54 113583 ▶ return $#$scopes - $i if exists $scopes->[$i]{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $scopes->[$i]{$name} 40876 72707 113583
55 }
56  
57 3269 return undef;
58 }
59  
60 sub _annotate_var {
61 44145 ▶ my ( $self, $node ) = @_;
Subroutine _annotate_var: called CC=2 SCAR=6.9
62  
63 44145 delete $node->{_env_depth};
64 44145 delete $node->{_binding_name};
65 44145 my $depth = $self->_lookup_depth( $node->name );
66 44145 ▶ return if !defined $depth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $depth 3269 40876 44145
67  
68 40876 $node->{_env_depth} = $depth;
69 40876 $node->{_binding_name} = $node->name;
70  
71 40876 return;
72 }
73  
74 sub _block_can_reuse_current_env {
75 133359 ▶ my ( $self, $node, $seen ) = @_;
Subroutine _block_can_reuse_current_env: called CC=34 SCAR=35.8
76  
77 133359 ▶ return 1 if !defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 1222 132137 133359
78 132137 ▶ $seen //= {};
Condition100%2/2
$seen //= {}
l!l
1228169321
MC/DC100%1/1
$seen //= {}
$seen
Truth table100%2/2
A
A= $seen
Aresult
11
00
79  
80 132137 ▶ if ( blessed($node) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node)) 41506 90631 132137
81 41506 my $addr = refaddr($node);
82 41506 ▶ return 1 if defined $addr and $seen->{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and $seen->{$addr}++ 0 41506 41506
Condition33%1/3
defined $addr and $seen->{$addr}++
!ll&&!rl&&r
0415060
MC/DC0%0/2
defined $addr and $seen->{$addr}++
defined $addr $seen->{$addr}++
Truth table33%1/3
A and B
A= defined $addrB= $seen->{$addr}++
ABresult
0X0
100
111
83  
84 41506 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Let');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Let") 2259 39247 41506
85 39247 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::LetUnpack');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::LetUnpack") 1 39246 39247
86 39246 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Function');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Function") 3 39243 39246
87 39243 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Class');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Class") 0 39243 39243
88 39243 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Trait');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Trait") 0 39243 39243
89 39243 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Import');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Import") 119 39124 39243
90 39124 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Catch');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Catch") 23 39101 39124
91 39101 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::For") and $node->declare_loop_var 216 38885 39101
Condition66%2/3
$node->isa("Zuzu::AST::Stmt::For") and $node->declare_loop_var
!ll&&!rl&&r
388850216
MC/DC50%1/2
$node->isa("Zuzu::AST::Stmt::For") and $node->declare_loop_var
$node->isa("Zuzu::AST::Stmt::For") $node->declare_loop_var
Truth table66%2/3
A and B
A= $node->isa("Zuzu::AST::Stmt::For")B= $node->declare_loop_var
ABresult
0X0
100
111
92 if $node->isa('Zuzu::AST::Stmt::For')
93 and $node->declare_loop_var;
94  
95 38885 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Call');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Call") 1421 37464 38885
96 37464 ▶ return 0 if $node->isa('Zuzu::AST::Expr::MemberCall');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::MemberCall") 2257 35207 37464
97 35207 ▶ return 0 if $node->isa('Zuzu::AST::Expr::DynamicMemberCall');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::DynamicMemberCall") 6 35201 35207
98 35201 ▶ return 0 if $node->isa('Zuzu::AST::Expr::New');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::New") 150 35051 35201
99 35051 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Function');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Function") 7 35044 35051
100 35044 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Spawn');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Spawn") 1 35043 35044
101 35043 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Await');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Await") 45 34998 35043
102  
103 34998 for my $value ( values %{ $node } ) {
104 110189 ▶ return 0 if !$self->_block_can_reuse_current_env( $value, $seen );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_block_can_reuse_current_env($value, $seen) 12312 97877 110189
105 }
106  
107 22686 return 1;
108 }
109  
110 90631 ▶ if ( ref($node) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "ARRAY") 11200 79431 90631
111 11200 my $addr = refaddr($node);
112 11200 ▶ return 1 if defined $addr and $seen->{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and $seen->{$addr}++ 0 11200 11200
Condition33%1/3
defined $addr and $seen->{$addr}++
!ll&&!rl&&r
0112000
MC/DC0%0/2
defined $addr and $seen->{$addr}++
defined $addr $seen->{$addr}++
Truth table33%1/3
A and B
A= defined $addrB= $seen->{$addr}++
ABresult
0X0
100
111
113 11200 for my $value ( @{ $node } ) {
114 13012 ▶ return 0 if !$self->_block_can_reuse_current_env( $value, $seen );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_block_can_reuse_current_env($value, $seen) 7062 5950 13012
115 }
116 4138 return 1;
117 }
118  
119 79431 ▶ if ( ref($node) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "HASH") 283 79148 79431
120 283 my $addr = refaddr($node);
121 283 ▶ return 1 if defined $addr and $seen->{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and $seen->{$addr}++ 0 283 283
Condition33%1/3
defined $addr and $seen->{$addr}++
!ll&&!rl&&r
02830
MC/DC0%0/2
defined $addr and $seen->{$addr}++
defined $addr $seen->{$addr}++
Truth table33%1/3
A and B
A= defined $addrB= $seen->{$addr}++
ABresult
0X0
100
111
122 283 for my $value ( values %{ $node } ) {
123 837 ▶ return 0 if !$self->_block_can_reuse_current_env( $value, $seen );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_block_can_reuse_current_env($value, $seen) 4 833 837
124 }
125 279 return 1;
126 }
127  
128 79148 return 1;
129 }
130  
131 sub _visit_block {
132 9321 ▶ my ( $self, $node ) = @_;
Subroutine _visit_block: called CC=8 SCAR=20.9
133  
134 9321 ▶ return if !defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 9321 9321
135 9321 ▶ $node->reuse_current_env( $self->_block_can_reuse_current_env($node) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->_block_can_reuse_current_env($node) ? : 2813 6508 9321
136 9321 ▶ if ( $node->reuse_current_env ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->reuse_current_env) 2813 6508 9321
137 2813 ▶ for my $stmt ( @{ $node->statements // [] } ) {
Condition50%1/2
$node->statements // []
l!l
28130
MC/DC0%0/1
$node->statements // []
$node->statements
Truth table50%1/2
A
A= $node->statements
Aresult
11
00
138 3375 $self->_visit_node($stmt);
139 }
140 2813 return;
141 }
142  
143 6508 $self->_push_scope;
144 6508 ▶ for my $stmt ( @{ $node->statements // [] } ) {
Condition50%1/2
$node->statements // []
l!l
65080
MC/DC0%0/1
$node->statements // []
$node->statements
Truth table50%1/2
A
A= $node->statements
Aresult
11
00
145 18684 $self->_visit_node($stmt);
146 }
147 6508 $self->_pop_scope;
148  
149 6508 return;
150 }
151  
152 sub _declare_function_params {
153 3510 ▶ my ( $self, $node ) = @_;
Subroutine _declare_function_params: called CC=5 SCAR=16.1
154  
155 3510 $self->_declare_name('__argc__');
156 3510 ▶ for my $name ( @{ $node->params // [] } ) {
Condition50%1/2
$node->params // []
l!l
35100
MC/DC0%0/1
$node->params // []
$node->params
Truth table50%1/2
A
A= $node->params
Aresult
11
00
157 4993 $self->_declare_name($name);
158 }
159 3510 ▶ $self->_declare_name( $node->vararg )
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->vararg 62 3448 3510
160 if defined $node->vararg;
161 3510 ▶ $self->_declare_name( $node->named_vararg )
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->named_vararg 115 3395 3510
162 if defined $node->named_vararg;
163  
164 3510 return;
165 }
166  
167 sub _visit_function_like {
168 3551 ▶ my ( $self, $node ) = @_;
Subroutine _visit_function_like: called CC=6 SCAR=17.9
169  
170 3551 ▶ return if $node->can('is_predeclared') and $node->is_predeclared;
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("is_predeclared") and $node->is_predeclared 41 3510 3551
Condition100%3/3
$node->can("is_predeclared") and $node->is_predeclared
!ll&&!rl&&r
458305241
MC/DC100%2/2
$node->can("is_predeclared") and $node->is_predeclared
$node->can("is_predeclared") $node->is_predeclared
Truth table100%3/3
A and B
A= $node->can("is_predeclared")B= $node->is_predeclared
ABresult
0X0
100
111
171  
172 3510 my %initial;
173 3510 ▶ if ( $node->isa('Zuzu::AST::Stmt::Method') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Method")) 1584 1926 3510
174 1584 $initial{self} = 1;
175 1584 ▶ $initial{super} = 1
Branch: 1 branch
BranchTrueFalseTotal
if not defined $node->uses_super or $node->uses_super 33 1551 1584
Condition100%3/3
not defined $node->uses_super or $node->uses_super
l!l&&r!l&&!r
5281551
MC/DC100%2/2
not defined $node->uses_super or $node->uses_super
not defined $node->uses_super $node->uses_super
Truth table100%3/3
not(A) or B
A= not defined $node->uses_superB= $node->uses_super
ABresult
1X1
011
000
176 if !defined $node->uses_super or $node->uses_super;
177 }
178  
179 3510 $self->_push_scope( \%initial );
180 3510 $self->_declare_function_params($node);
181 3510 $self->_visit_block( $node->body );
182 3510 $self->_pop_scope;
183  
184 3510 return;
185 }
186  
187 sub _visit_node {
188 134868 ▶ my ( $self, $node ) = @_;
Subroutine _visit_node: called CC=102 SCAR=46.6
189  
190 134868 ▶ return if !defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 112 134756 134868
191 134756 ▶ return if !blessed($node);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) 0 134756 134756
192  
193 134756 ▶ if ( $node->isa('Zuzu::AST::Program') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Program")) 751 134005 134756
194 751 ▶ for my $stmt ( @{ $node->statements // [] } ) {
Condition50%1/2
$node->statements // []
l!l
7510
MC/DC0%0/1
$node->statements // []
$node->statements
Truth table50%1/2
A
A= $node->statements
Aresult
11
00
195 3903 $self->_visit_node($stmt);
196 }
197 751 return;
198 }
199  
200 134005 ▶ if ( $node->isa('Zuzu::AST::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Block")) 274 133731 134005
201 274 $self->_visit_block($node);
202 274 return;
203 }
204  
205 133731 ▶ if ( $node->isa('Zuzu::AST::Expr::Var') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Var")) 44145 89586 133731
206 44145 $self->_annotate_var($node);
207 44145 return;
208 }
209  
210 89586 ▶ if ( $node->isa('Zuzu::AST::Stmt::Let') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Let")) 5721 83865 89586
211 5721 ▶ $self->_visit_node( $node->init ) if defined $node->init;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->init 5670 51 5721
212 5721 $self->_declare_name( $node->name );
213 5721 return;
214 }
215  
216 83865 ▶ if ( $node->isa('Zuzu::AST::Stmt::LetUnpack') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::LetUnpack")) 18 83847 83865
217 18 ▶ for my $binding ( @{ $node->bindings // [] } ) {
Condition50%1/2
$node->bindings // []
l!l
180
MC/DC0%0/1
$node->bindings // []
$node->bindings
Truth table50%1/2
A
A= $node->bindings
Aresult
11
00
218 27 $self->_visit_node( $binding->{key_expr} );
219 $self->_visit_node( $binding->{default_expr} )
220 27 ▶ if $binding->{has_default};
Branch: 1 branch
BranchTrueFalseTotal
if $binding->{"has_default"} 4 23 27
221 }
222 18 ▶ $self->_visit_node( $node->init ) if defined $node->init;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->init 18 0 18
223 18 ▶ for my $binding ( @{ $node->bindings // [] } ) {
Condition50%1/2
$node->bindings // []
l!l
180
MC/DC0%0/1
$node->bindings // []
$node->bindings
Truth table50%1/2
A
A= $node->bindings
Aresult
11
00
224 27 $self->_declare_name( $binding->{name} );
225 }
226 18 return;
227 }
228  
229 83847 ▶ if ( $node->isa('Zuzu::AST::Stmt::Assign') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Assign")) 2193 81654 83847
230 2193 $self->_visit_node( $node->target );
231 2193 ▶ $self->_visit_node( $node->expr ) if defined $node->expr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->expr 2185 8 2193
232 2193 ▶ $self->_visit_node( $node->match_expr ) if defined $node->match_expr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->match_expr 8 2185 2193
233 2193 ▶ $self->_visit_node( $node->replace_expr ) if defined $node->replace_expr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->replace_expr 8 2185 2193
234 2193 return;
235 }
236  
237 81654 ▶ if ( $node->isa('Zuzu::AST::Stmt::Expr') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Expr")) 4068 77586 81654
238 4068 $self->_visit_node( $node->expr );
239 4068 return;
240 }
241  
242 77586 ▶ if ( $node->isa('Zuzu::AST::Stmt::Return') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Return")) 5315 72271 77586
243 5315 ▶ $self->_visit_node( $node->expr ) if $node->can('expr');
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("expr") 5315 0 5315
244 5315 return;
245 }
246  
247 72271 ▶ if ( $node->isa('Zuzu::AST::Stmt::If') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::If")) 3860 68411 72271
248 3860 $self->_visit_node( $node->cond );
249 3860 $self->_visit_block( $node->then_block );
250 3860 ▶ $self->_visit_node( $node->else_branch ) if defined $node->else_branch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->else_branch 597 3263 3860
251 3860 return;
252 }
253  
254 68411 ▶ if ( $node->isa('Zuzu::AST::Stmt::PostfixIf') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::PostfixIf")) 1205 67206 68411
255 1205 $self->_visit_node( $node->cond );
256 1205 $self->_visit_node( $node->statement );
257 1205 return;
258 }
259  
260 67206 ▶ if ( $node->isa('Zuzu::AST::Stmt::While') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::While")) 494 66712 67206
261 494 $self->_visit_node( $node->cond );
262 494 $self->_visit_block( $node->body );
263 494 return;
264 }
265  
266 66712 ▶ if ( $node->isa('Zuzu::AST::Stmt::For') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::For")) 740 65972 66712
267 740 $self->_visit_node( $node->collection );
268 740 ▶ if ( $node->declare_loop_var ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->declare_loop_var) { } 738 2 740
269 738 $self->_push_scope( { $node->var => 1 } );
270 738 $self->_visit_block( $node->body );
271 738 $self->_pop_scope;
272 }
273 else {
274 2 $self->_visit_block( $node->body );
275 }
276 740 ▶ $self->_visit_block( $node->else_block ) if defined $node->else_block;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->else_block 15 725 740
277 740 return;
278 }
279  
280 65972 ▶ if ( $node->isa('Zuzu::AST::Stmt::Function') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Function")) 1500 64472 65972
281 1500 $self->_declare_name( $node->name );
282 1500 $self->_visit_function_like($node);
283 1500 return;
284 }
285  
286 64472 ▶ if ( $node->isa('Zuzu::AST::Expr::Function') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Function")) 458 64014 64472
287 458 $self->_visit_function_like($node);
288 458 return;
289 }
290  
291 64014 ▶ if ( $node->isa('Zuzu::AST::Stmt::Method') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Method")) 1593 62421 64014
292 1593 $self->_visit_function_like($node);
293 1593 return;
294 }
295  
296 62421 ▶ if ( $node->isa('Zuzu::AST::Stmt::Class') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Class")) 300 62121 62421
297 300 ▶ $self->_visit_node( $node->parent ) if defined $node->parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->parent 131 169 300
298 300 ▶ for my $trait_ref ( @{ $node->traits // [] } ) {
Condition50%1/2
$node->traits // []
l!l
3000
MC/DC0%0/1
$node->traits // []
$node->traits
Truth table50%1/2
A
A= $node->traits
Aresult
11
00
299 20 $self->_visit_node($trait_ref);
300 }
301 300 ▶ for my $field ( @{ $node->fields // [] } ) {
Condition50%1/2
$node->fields // []
l!l
3000
MC/DC0%0/1
$node->fields // []
$node->fields
Truth table50%1/2
A
A= $node->fields
Aresult
11
00
302 466 ▶ $self->_visit_node( $field->{init} ) if defined $field->{init};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"init"} 374 92 466
303 }
304 300 $self->_declare_name( $node->name );
305 300 $self->_push_scope( { self => 1 } );
306 300 ▶ for my $klass ( @{ $node->classes // [] } ) {
Condition50%1/2
$node->classes // []
l!l
3000
MC/DC0%0/1
$node->classes // []
$node->classes
Truth table50%1/2
A
A= $node->classes
Aresult
11
00
307 0 $self->_visit_node($klass);
308 }
309 300 ▶ for my $method ( @{ $node->methods // [] } ) {
Condition50%1/2
$node->methods // []
l!l
3000
MC/DC0%0/1
$node->methods // []
$node->methods
Truth table50%1/2
A
A= $node->methods
Aresult
11
00
310 1488 $self->_visit_node($method);
311 }
312 300 ▶ for my $method ( @{ $node->static_methods // [] } ) {
Condition50%1/2
$node->static_methods // []
l!l
3000
MC/DC0%0/1
$node->static_methods // []
$node->static_methods
Truth table50%1/2
A
A= $node->static_methods
Aresult
11
00
313 73 $self->_visit_node($method);
314 }
315 300 $self->_pop_scope;
316 300 return;
317 }
318  
319 62121 ▶ if ( $node->isa('Zuzu::AST::Stmt::Trait') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Trait")) 14 62107 62121
320 14 $self->_declare_name( $node->name );
321 14 ▶ for my $method ( @{ $node->methods // [] } ) {
Condition50%1/2
$node->methods // []
l!l
140
MC/DC0%0/1
$node->methods // []
$node->methods
Truth table50%1/2
A
A= $node->methods
Aresult
11
00
322 32 $self->_visit_node($method);
323 }
324 14 return;
325 }
326  
327 62107 ▶ if ( $node->isa('Zuzu::AST::Stmt::Try') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Try")) 151 61956 62107
328 151 $self->_visit_block( $node->block );
329 151 ▶ for my $catch ( @{ $node->catches // [] } ) {
Condition50%1/2
$node->catches // []
l!l
1510
MC/DC0%0/1
$node->catches // []
$node->catches
Truth table50%1/2
A
A= $node->catches
Aresult
11
00
330 153 $self->_visit_node($catch);
331 }
332 151 return;
333 }
334  
335 61956 ▶ if ( $node->isa('Zuzu::AST::Stmt::Catch') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Catch")) 153 61803 61956
336 153 $self->_visit_node( $node->type_expr );
337 153 $self->_push_scope( { $node->name => 1 } );
338 153 $self->_visit_block( $node->block );
339 153 $self->_pop_scope;
340 153 return;
341 }
342  
343 61803 ▶ if ( $node->isa('Zuzu::AST::Stmt::Import') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Import")) 693 61110 61803
344 693 ▶ $self->_visit_node( $node->condition_expr )
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->condition_expr 3 690 693
345 if defined $node->condition_expr;
346 693 ▶ for my $item ( @{ $node->items // [] } ) {
Condition50%1/2
$node->items // []
l!l
6930
MC/DC0%0/1
$node->items // []
$node->items
Truth table50%1/2
A
A= $node->items
Aresult
11
00
347 1217 ▶ next if $item->{star};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"star"} 192 1025 1217
348 1025 $self->_declare_name( $item->{alias} );
349 }
350 693 return;
351 }
352  
353 61110 ▶ if ( $node->isa('Zuzu::AST::Expr::Call') or $node->isa('Zuzu::AST::Expr::MemberCall') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Call") or $node->isa("Zuzu::AST::Expr::MemberCall")) 14755 46355 61110
Condition100%3/3
$node->isa("Zuzu::AST::Expr::Call") or $node->isa("Zuzu::AST::Expr::MemberCall")
l!l&&r!l&&!r
6682807346355
MC/DC100%2/2
$node->isa("Zuzu::AST::Expr::Call") or $node->isa("Zuzu::AST::Expr::MemberCall")
$node->isa("Zuzu::AST::Expr::Call") $node->isa("Zuzu::AST::Expr::MemberCall")
Truth table100%3/3
A or B
A= $node->isa("Zuzu::AST::Expr::Call")B= $node->isa("Zuzu::AST::Expr::MemberCall")
ABresult
1X1
011
000
354 14755 ▶ $self->_visit_node( $node->callee ) if $node->can('callee');
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("callee") 6682 8073 14755
355 14755 ▶ $self->_visit_node( $node->object ) if $node->can('object');
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("object") 8073 6682 14755
356 14755 ▶ for my $arg ( @{ $node->args // [] } ) {
Condition50%1/2
$node->args // []
l!l
147550
MC/DC0%0/1
$node->args // []
$node->args
Truth table50%1/2
A
A= $node->args
Aresult
11
00
357 21105 ▶ $self->_visit_node( $arg->[0] ) if ref($arg) eq 'ARRAY' and $arg->[2];
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "ARRAY" and $arg->[2] 5 21100 21105
Condition100%3/3
ref $arg eq "ARRAY" and $arg->[2]
!ll&&!rl&&r
161209395
MC/DC100%2/2
ref $arg eq "ARRAY" and $arg->[2]
ref $arg eq "ARRAY" $arg->[2]
Truth table100%3/3
A and B
A= ref $arg eq "ARRAY"B= $arg->[2]
ABresult
0X0
100
111
358 21105 ▶ $self->_visit_node( ref($arg) eq 'ARRAY' ? $arg->[1] : $arg );
Branch: 1 branch
BranchTrueFalseTotal
ref $arg eq 'ARRAY' ? : 20944 161 21105
359 }
360 14755 return;
361 }
362  
363 46355 ▶ if ( $node->isa('Zuzu::AST::Expr::DynamicMemberCall') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::DynamicMemberCall")) 11 46344 46355
364 11 $self->_visit_node( $node->object );
365 11 $self->_visit_node( $node->method_expr );
366 11 ▶ for my $arg ( @{ $node->args // [] } ) {
Condition50%1/2
$node->args // []
l!l
110
MC/DC0%0/1
$node->args // []
$node->args
Truth table50%1/2
A
A= $node->args
Aresult
11
00
367 7 ▶ $self->_visit_node( $arg->[0] ) if ref($arg) eq 'ARRAY' and $arg->[2];
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "ARRAY" and $arg->[2] 0 7 7
Condition33%1/3
ref $arg eq "ARRAY" and $arg->[2]
!ll&&!rl&&r
070
MC/DC0%0/2
ref $arg eq "ARRAY" and $arg->[2]
ref $arg eq "ARRAY" $arg->[2]
Truth table33%1/3
A and B
A= ref $arg eq "ARRAY"B= $arg->[2]
ABresult
0X0
100
111
368 7 ▶ $self->_visit_node( ref($arg) eq 'ARRAY' ? $arg->[1] : $arg );
Branch: 1 branch
BranchTrueFalseTotal
ref $arg eq 'ARRAY' ? : 7 0 7
369 }
370 11 return;
371 }
372  
373 46344 ▶ if ( $node->isa('Zuzu::AST::Expr::Spread') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Spread")) 19 46325 46344
374 19 $self->_visit_node( $node->expr );
375 19 return;
376 }
377  
378 46325 ▶ if ( $node->isa('Zuzu::AST::Expr::Binary') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Binary")) 11101 35224 46325
379 11101 $self->_visit_node( $node->left );
380 11101 $self->_visit_node( $node->right );
381 11101 return;
382 }
383  
384 35224 ▶ if ( $node->isa('Zuzu::AST::Expr::Unary') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Unary")) 1800 33424 35224
385 1800 $self->_visit_node( $node->expr );
386 1800 return;
387 }
388  
389 33424 ▶ if ( $node->isa('Zuzu::AST::Expr::Await') or $node->isa('Zuzu::AST::Expr::Spawn') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Await") or $node->isa("Zuzu::AST::Expr::Spawn")) 124 33300 33424
Condition100%3/3
$node->isa("Zuzu::AST::Expr::Await") or $node->isa("Zuzu::AST::Expr::Spawn")
l!l&&r!l&&!r
1071733300
MC/DC100%2/2
$node->isa("Zuzu::AST::Expr::Await") or $node->isa("Zuzu::AST::Expr::Spawn")
$node->isa("Zuzu::AST::Expr::Await") $node->isa("Zuzu::AST::Expr::Spawn")
Truth table100%3/3
A or B
A= $node->isa("Zuzu::AST::Expr::Await")B= $node->isa("Zuzu::AST::Expr::Spawn")
ABresult
1X1
011
000
390 124 $self->_visit_block( $node->block );
391 124 return;
392 }
393  
394 33300 ▶ if ( $node->isa('Zuzu::AST::Expr::Ternary') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Ternary")) 596 32704 33300
395 596 $self->_visit_node( $node->cond );
396 596 ▶ $self->_visit_node( $node->if_true ) if defined $node->if_true;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->if_true 573 23 596
397 596 $self->_visit_node( $node->if_false );
398 596 return;
399 }
400  
401 32704 ▶ if ( $node->isa('Zuzu::AST::Expr::Index') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Index")) 1105 31599 32704
402 1105 $self->_visit_node( $node->array );
403 1105 $self->_visit_node( $node->index );
404 1105 return;
405 }
406  
407 31599 ▶ if ( $node->isa('Zuzu::AST::Expr::DictGet') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::DictGet")) 2430 29169 31599
408 2430 $self->_visit_node( $node->dict );
409 2430 $self->_visit_node( $node->key );
410 2430 return;
411 }
412  
413 29169 ▶ if ( $node->isa('Zuzu::AST::Expr::Slice') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Slice")) 23 29146 29169
414 23 $self->_visit_node( $node->collection );
415 23 ▶ $self->_visit_node( $node->start ) if defined $node->start;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->start 23 0 23
416 23 ▶ $self->_visit_node( $node->length ) if defined $node->length;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->length 15 8 23
417 23 return;
418 }
419  
420 29146 ▶ if ( $node->isa('Zuzu::AST::Expr::IncDec') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::IncDec")) 688 28458 29146
421 688 $self->_visit_node( $node->target );
422 688 return;
423 }
424  
425 28458 ▶ if ( $node->isa('Zuzu::AST::Expr::Array') or $node->isa('Zuzu::AST::Expr::Set') or $node->isa('Zuzu::AST::Expr::Bag') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Array") or $node->isa("Zuzu::AST::Expr::Set") or $node->isa("Zuzu::AST::Expr::Bag")) 95 27230 27325
Condition100%6/6
$node->isa("Zuzu::AST::Expr::Array") or $node->isa("Zuzu::AST::Expr::Set") or $node->isa("Zuzu::AST::Expr::Bag")
l!l&&r!l&&!r
11903827230
$node->isa("Zuzu::AST::Expr::Array") or $node->isa("Zuzu::AST::Expr::Set")
l!l&&r!l&&!r
11335727268
MC/DC100%3/3
$node->isa("Zuzu::AST::Expr::Array") or $node->isa("Zuzu::AST::Expr::Set") or $node->isa("Zuzu::AST::Expr::Bag")
$node->isa("Zuzu::AST::Expr::Array") $node->isa("Zuzu::AST::Expr::Set") $node->isa("Zuzu::AST::Expr::Bag")
Truth table100%4/4
A or B or C
A= $node->isa("Zuzu::AST::Expr::Array")B= $node->isa("Zuzu::AST::Expr::Set")C= $node->isa("Zuzu::AST::Expr::Bag")
ABCresult
1XX1
01X1
0011
0000
426 1228 ▶ for my $item ( @{ $node->items // [] } ) {
Condition50%1/2
$node->items // []
l!l
12280
MC/DC0%0/1
$node->items // []
$node->items
Truth table50%1/2
A
A= $node->items
Aresult
11
00
427 1723 $self->_visit_node($item);
428 }
429 1228 return;
430 }
431  
432 27230 ▶ if ( $node->isa('Zuzu::AST::Expr::Range') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Range")) 10 27220 27230
433 10 $self->_visit_node( $node->start );
434 10 $self->_visit_node( $node->end );
435 10 return;
436 }
437  
438 27220 ▶ if ( $node->isa('Zuzu::AST::Expr::Dict') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Dict")) 801 26419 27220
439 801 ▶ for my $pair ( @{ $node->pairs // [] } ) {
Condition50%1/2
$node->pairs // []
l!l
8010
MC/DC0%0/1
$node->pairs // []
$node->pairs
Truth table50%1/2
A
A= $node->pairs
Aresult
11
00
440 2229 ▶ next if ref($pair) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pair ne "ARRAY" 0 2229 2229
441 2229 $self->_visit_node( $pair->[0] );
442 2229 $self->_visit_node( $pair->[1] );
443 }
444 801 return;
445 }
446  
447 26419 ▶ if ( $node->isa('Zuzu::AST::Expr::New') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::New")) 754 25665 26419
448 754 $self->_visit_node( $node->class_expr );
449 754 ▶ for my $trait_ref ( @{ $node->traits // [] } ) {
Condition50%1/2
$node->traits // []
l!l
7540
MC/DC0%0/1
$node->traits // []
$node->traits
Truth table50%1/2
A
A= $node->traits
Aresult
11
00
450 3 $self->_visit_node( $trait_ref );
451 }
452 754 ▶ for my $pair ( @{ $node->args // [] } ) {
Condition50%1/2
$node->args // []
l!l
7540
MC/DC0%0/1
$node->args // []
$node->args
Truth table50%1/2
A
A= $node->args
Aresult
11
00
453 1674 $self->_visit_node( $pair->[1] );
454 }
455 754 return;
456 }
457  
458 25665 return;
459 }
460  
461 78 1;
462  
463 =pod
464  
465 =head1 COPYRIGHT AND LICENCE
466  
467 B<< Zuzu::AST::Visitor::LexicalEnvHints >> is copyright Toby Inkster.
468  
469 It is free software; you may redistribute it and/or modify it under
470 the terms of either the Artistic License 1.0 or the GNU General Public
471 License version 2.
472  
473 =cut
« blib/lib/Zuzu/Module/DB.pm ↑ Summary blib/lib/Zuzu/CLI.pm »