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.007001';
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 17281 ▶sub _current_scope { $_[0]->_scope_stack->[-1] }
Subroutine _current_scope: called CC=1 SCAR=0.0
22  
23 sub _push_scope {
24 11215 ▶ my ( $self, $initial ) = @_;
Subroutine _push_scope: called CC=2 SCAR=6.9
25  
26 11215 ▶ push @{ $self->_scope_stack }, { %{ $initial // {} } };
Condition100%2/2
$initial // {}
l!l
47036512
MC/DC100%1/1
$initial // {}
$initial
Truth table100%2/2
A
A= $initial
Aresult
11
00
27  
28 11215 return;
29 }
30  
31 sub _pop_scope {
32 11215 ▶ my ( $self ) = @_;
Subroutine _pop_scope: called CC=1 SCAR=0.0
33  
34 11215 pop @{ $self->_scope_stack };
35  
36 11215 return;
37 }
38  
39 sub _declare_name {
40 17281 ▶ my ( $self, $name ) = @_;
Subroutine _declare_name: called CC=3 SCAR=12.0
41  
42 17281 ▶ return if !defined $name or $name eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or $name eq "" 0 17281 17281
Condition33%1/3
not defined $name or $name eq ""
l!l&&r!l&&!r
0017281
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 17281 $self->_current_scope->{$name} = 1;
44  
45 17281 return;
46 }
47  
48 sub _lookup_depth {
49 44167 ▶ my ( $self, $name ) = @_;
Subroutine _lookup_depth: called CC=4 SCAR=13.9
50  
51 44167 ▶ return undef if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 44167 44167
52 44167 my $scopes = $self->_scope_stack;
53 44167 ▶ for ( my $i = $#$scopes; $i >= 0; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 113631 3269 116900
54 113631 ▶ return $#$scopes - $i if exists $scopes->[$i]{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $scopes->[$i]{$name} 40898 72733 113631
55 }
56  
57 3269 return undef;
58 }
59  
60 sub _annotate_var {
61 44167 ▶ my ( $self, $node ) = @_;
Subroutine _annotate_var: called CC=2 SCAR=6.9
62  
63 44167 delete $node->{_env_depth};
64 44167 delete $node->{_binding_name};
65 44167 my $depth = $self->_lookup_depth( $node->name );
66 44167 ▶ return if !defined $depth;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $depth 3269 40898 44167
67  
68 40898 $node->{_env_depth} = $depth;
69 40898 $node->{_binding_name} = $node->name;
70  
71 40898 return;
72 }
73  
74 sub _block_can_reuse_current_env {
75 133280 ▶ my ( $self, $node, $seen ) = @_;
Subroutine _block_can_reuse_current_env: called CC=34 SCAR=35.8
76  
77 133280 ▶ return 1 if !defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 1182 132098 133280
78 132098 ▶ $seen //= {};
Condition100%2/2
$seen //= {}
l!l
1227739325
MC/DC100%1/1
$seen //= {}
$seen
Truth table100%2/2
A
A= $seen
Aresult
11
00
79  
80 132098 ▶ if ( blessed($node) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node)) 41546 90552 132098
81 41546 my $addr = refaddr($node);
82 41546 ▶ return 1 if defined $addr and $seen->{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and $seen->{$addr}++ 0 41546 41546
Condition33%1/3
defined $addr and $seen->{$addr}++
!ll&&!rl&&r
0415460
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 41546 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Let');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Let") 2258 39288 41546
85 39288 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::LetUnpack');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::LetUnpack") 1 39287 39288
86 39287 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Function');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Function") 3 39284 39287
87 39284 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Class');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Class") 0 39284 39284
88 39284 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Trait');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Trait") 0 39284 39284
89 39284 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Import');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Import") 117 39167 39284
90 39167 ▶ return 0 if $node->isa('Zuzu::AST::Stmt::Catch');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::Catch") 24 39143 39167
91 39143 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Stmt::For") and $node->declare_loop_var 211 38932 39143
Condition66%2/3
$node->isa("Zuzu::AST::Stmt::For") and $node->declare_loop_var
!ll&&!rl&&r
389320211
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 38932 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Call');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Call") 1442 37490 38932
96 37490 ▶ return 0 if $node->isa('Zuzu::AST::Expr::MemberCall');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::MemberCall") 2246 35244 37490
97 35244 ▶ return 0 if $node->isa('Zuzu::AST::Expr::DynamicMemberCall');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::DynamicMemberCall") 4 35240 35244
98 35240 ▶ return 0 if $node->isa('Zuzu::AST::Expr::New');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::New") 152 35088 35240
99 35088 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Function');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Function") 7 35081 35088
100 35081 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Spawn');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Spawn") 1 35080 35081
101 35080 ▶ return 0 if $node->isa('Zuzu::AST::Expr::Await');
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("Zuzu::AST::Expr::Await") 46 35034 35080
102  
103 35034 for my $value ( values %{ $node } ) {
104 110017 ▶ return 0 if !$self->_block_can_reuse_current_env( $value, $seen );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_block_can_reuse_current_env($value, $seen) 12298 97719 110017
105 }
106  
107 22736 return 1;
108 }
109  
110 90552 ▶ if ( ref($node) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "ARRAY") 11238 79314 90552
111 11238 my $addr = refaddr($node);
112 11238 ▶ return 1 if defined $addr and $seen->{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and $seen->{$addr}++ 0 11238 11238
Condition33%1/3
defined $addr and $seen->{$addr}++
!ll&&!rl&&r
0112380
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 11238 for my $value ( @{ $node } ) {
114 13085 ▶ return 0 if !$self->_block_can_reuse_current_env( $value, $seen );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_block_can_reuse_current_env($value, $seen) 7059 6026 13085
115 }
116 4179 return 1;
117 }
118  
119 79314 ▶ if ( ref($node) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "HASH") 288 79026 79314
120 288 my $addr = refaddr($node);
121 288 ▶ return 1 if defined $addr and $seen->{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and $seen->{$addr}++ 0 288 288
Condition33%1/3
defined $addr and $seen->{$addr}++
!ll&&!rl&&r
02880
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 288 for my $value ( values %{ $node } ) {
123 853 ▶ return 0 if !$self->_block_can_reuse_current_env( $value, $seen );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_block_can_reuse_current_env($value, $seen) 6 847 853
124 }
125 282 return 1;
126 }
127  
128 79026 return 1;
129 }
130  
131 sub _visit_block {
132 9325 ▶ my ( $self, $node ) = @_;
Subroutine _visit_block: called CC=8 SCAR=20.9
133  
134 9325 ▶ return if !defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 9325 9325
135 9325 ▶ $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 6512 9325
136 9325 ▶ if ( $node->reuse_current_env ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->reuse_current_env) 2813 6512 9325
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 6512 $self->_push_scope;
144 6512 ▶ for my $stmt ( @{ $node->statements // [] } ) {
Condition50%1/2
$node->statements // []
l!l
65120
MC/DC0%0/1
$node->statements // []
$node->statements
Truth table50%1/2
A
A= $node->statements
Aresult
11
00
145 18698 $self->_visit_node($stmt);
146 }
147 6512 $self->_pop_scope;
148  
149 6512 return;
150 }
151  
152 sub _declare_function_params {
153 3512 ▶ my ( $self, $node ) = @_;
Subroutine _declare_function_params: called CC=5 SCAR=16.1
154  
155 3512 $self->_declare_name('__argc__');
156 3512 ▶ for my $name ( @{ $node->params // [] } ) {
Condition50%1/2
$node->params // []
l!l
35120
MC/DC0%0/1
$node->params // []
$node->params
Truth table50%1/2
A
A= $node->params
Aresult
11
00
157 4997 $self->_declare_name($name);
158 }
159 3512 ▶ $self->_declare_name( $node->vararg )
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->vararg 62 3450 3512
160 if defined $node->vararg;
161 3512 ▶ $self->_declare_name( $node->named_vararg )
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->named_vararg 115 3397 3512
162 if defined $node->named_vararg;
163  
164 3512 return;
165 }
166  
167 sub _visit_function_like {
168 3553 ▶ my ( $self, $node ) = @_;
Subroutine _visit_function_like: called CC=6 SCAR=17.9
169  
170 3553 ▶ return if $node->can('is_predeclared') and $node->is_predeclared;
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("is_predeclared") and $node->is_predeclared 41 3512 3553
Condition100%3/3
$node->can("is_predeclared") and $node->is_predeclared
!ll&&!rl&&r
458305441
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 3512 my %initial;
173 3512 ▶ if ( $node->isa('Zuzu::AST::Stmt::Method') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Method")) 1584 1928 3512
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 3512 $self->_push_scope( \%initial );
180 3512 $self->_declare_function_params($node);
181 3512 $self->_visit_block( $node->body );
182 3512 $self->_pop_scope;
183  
184 3512 return;
185 }
186  
187 sub _visit_node {
188 134920 ▶ my ( $self, $node ) = @_;
Subroutine _visit_node: called CC=102 SCAR=46.6
189  
190 134920 ▶ return if !defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 112 134808 134920
191 134808 ▶ return if !blessed($node);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) 0 134808 134808
192  
193 134808 ▶ if ( $node->isa('Zuzu::AST::Program') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Program")) 751 134057 134808
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 3905 $self->_visit_node($stmt);
196 }
197 751 return;
198 }
199  
200 134057 ▶ if ( $node->isa('Zuzu::AST::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Block")) 274 133783 134057
201 274 $self->_visit_block($node);
202 274 return;
203 }
204  
205 133783 ▶ if ( $node->isa('Zuzu::AST::Expr::Var') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Var")) 44167 89616 133783
206 44167 $self->_annotate_var($node);
207 44167 return;
208 }
209  
210 89616 ▶ if ( $node->isa('Zuzu::AST::Stmt::Let') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Let")) 5727 83889 89616
211 5727 ▶ $self->_visit_node( $node->init ) if defined $node->init;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->init 5676 51 5727
212 5727 $self->_declare_name( $node->name );
213 5727 return;
214 }
215  
216 83889 ▶ if ( $node->isa('Zuzu::AST::Stmt::LetUnpack') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::LetUnpack")) 18 83871 83889
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 83871 ▶ if ( $node->isa('Zuzu::AST::Stmt::Assign') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Assign")) 2195 81676 83871
230 2195 $self->_visit_node( $node->target );
231 2195 ▶ $self->_visit_node( $node->expr ) if defined $node->expr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->expr 2187 8 2195
232 2195 ▶ $self->_visit_node( $node->match_expr ) if defined $node->match_expr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->match_expr 8 2187 2195
233 2195 ▶ $self->_visit_node( $node->replace_expr ) if defined $node->replace_expr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->replace_expr 8 2187 2195
234 2195 return;
235 }
236  
237 81676 ▶ if ( $node->isa('Zuzu::AST::Stmt::Expr') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Expr")) 4070 77606 81676
238 4070 $self->_visit_node( $node->expr );
239 4070 return;
240 }
241  
242 77606 ▶ if ( $node->isa('Zuzu::AST::Stmt::Return') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Return")) 5317 72289 77606
243 5317 ▶ $self->_visit_node( $node->expr ) if $node->can('expr');
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("expr") 5317 0 5317
244 5317 return;
245 }
246  
247 72289 ▶ if ( $node->isa('Zuzu::AST::Stmt::If') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::If")) 3860 68429 72289
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 68429 ▶ if ( $node->isa('Zuzu::AST::Stmt::PostfixIf') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::PostfixIf")) 1205 67224 68429
255 1205 $self->_visit_node( $node->cond );
256 1205 $self->_visit_node( $node->statement );
257 1205 return;
258 }
259  
260 67224 ▶ if ( $node->isa('Zuzu::AST::Stmt::While') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::While")) 496 66728 67224
261 496 $self->_visit_node( $node->cond );
262 496 $self->_visit_block( $node->body );
263 496 return;
264 }
265  
266 66728 ▶ if ( $node->isa('Zuzu::AST::Stmt::For') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::For")) 740 65988 66728
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 65988 ▶ if ( $node->isa('Zuzu::AST::Stmt::Function') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Function")) 1502 64486 65988
281 1502 $self->_declare_name( $node->name );
282 1502 $self->_visit_function_like($node);
283 1502 return;
284 }
285  
286 64486 ▶ if ( $node->isa('Zuzu::AST::Expr::Function') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Function")) 458 64028 64486
287 458 $self->_visit_function_like($node);
288 458 return;
289 }
290  
291 64028 ▶ if ( $node->isa('Zuzu::AST::Stmt::Method') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Method")) 1593 62435 64028
292 1593 $self->_visit_function_like($node);
293 1593 return;
294 }
295  
296 62435 ▶ if ( $node->isa('Zuzu::AST::Stmt::Class') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Class")) 300 62135 62435
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 62135 ▶ if ( $node->isa('Zuzu::AST::Stmt::Trait') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Trait")) 14 62121 62135
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 62121 ▶ if ( $node->isa('Zuzu::AST::Stmt::Try') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Try")) 151 61970 62121
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 61970 ▶ if ( $node->isa('Zuzu::AST::Stmt::Catch') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Catch")) 153 61817 61970
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 61817 ▶ if ( $node->isa('Zuzu::AST::Stmt::Import') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Stmt::Import")) 693 61124 61817
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 61124 ▶ 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")) 14759 46365 61124
Condition100%3/3
$node->isa("Zuzu::AST::Expr::Call") or $node->isa("Zuzu::AST::Expr::MemberCall")
l!l&&r!l&&!r
6686807346365
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 14759 ▶ $self->_visit_node( $node->callee ) if $node->can('callee');
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("callee") 6686 8073 14759
355 14759 ▶ $self->_visit_node( $node->object ) if $node->can('object');
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("object") 8073 6686 14759
356 14759 ▶ for my $arg ( @{ $node->args // [] } ) {
Condition50%1/2
$node->args // []
l!l
147590
MC/DC0%0/1
$node->args // []
$node->args
Truth table50%1/2
A
A= $node->args
Aresult
11
00
357 21113 ▶ $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 21108 21113
Condition100%3/3
ref $arg eq "ARRAY" and $arg->[2]
!ll&&!rl&&r
161209475
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 21113 ▶ $self->_visit_node( ref($arg) eq 'ARRAY' ? $arg->[1] : $arg );
Branch: 1 branch
BranchTrueFalseTotal
ref $arg eq 'ARRAY' ? : 20952 161 21113
359 }
360 14759 return;
361 }
362  
363 46365 ▶ if ( $node->isa('Zuzu::AST::Expr::DynamicMemberCall') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::DynamicMemberCall")) 11 46354 46365
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 46354 ▶ if ( $node->isa('Zuzu::AST::Expr::Spread') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Spread")) 19 46335 46354
374 19 $self->_visit_node( $node->expr );
375 19 return;
376 }
377  
378 46335 ▶ if ( $node->isa('Zuzu::AST::Expr::Binary') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Binary")) 11103 35232 46335
379 11103 $self->_visit_node( $node->left );
380 11103 $self->_visit_node( $node->right );
381 11103 return;
382 }
383  
384 35232 ▶ if ( $node->isa('Zuzu::AST::Expr::Unary') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Unary")) 1798 33434 35232
385 1798 $self->_visit_node( $node->expr );
386 1798 return;
387 }
388  
389 33434 ▶ 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 33310 33434
Condition100%3/3
$node->isa("Zuzu::AST::Expr::Await") or $node->isa("Zuzu::AST::Expr::Spawn")
l!l&&r!l&&!r
1071733310
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 33310 ▶ if ( $node->isa('Zuzu::AST::Expr::Ternary') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Ternary")) 596 32714 33310
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 32714 ▶ if ( $node->isa('Zuzu::AST::Expr::Index') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Index")) 1105 31609 32714
402 1105 $self->_visit_node( $node->array );
403 1105 $self->_visit_node( $node->index );
404 1105 return;
405 }
406  
407 31609 ▶ if ( $node->isa('Zuzu::AST::Expr::DictGet') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::DictGet")) 2430 29179 31609
408 2430 $self->_visit_node( $node->dict );
409 2430 $self->_visit_node( $node->key );
410 2430 return;
411 }
412  
413 29179 ▶ if ( $node->isa('Zuzu::AST::Expr::Slice') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Slice")) 23 29156 29179
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 29156 ▶ if ( $node->isa('Zuzu::AST::Expr::IncDec') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::IncDec")) 690 28466 29156
421 690 $self->_visit_node( $node->target );
422 690 return;
423 }
424  
425 28466 ▶ 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 27238 27333
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
11903827238
$node->isa("Zuzu::AST::Expr::Array") or $node->isa("Zuzu::AST::Expr::Set")
l!l&&r!l&&!r
11335727276
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 27238 ▶ if ( $node->isa('Zuzu::AST::Expr::Range') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Range")) 10 27228 27238
433 10 $self->_visit_node( $node->start );
434 10 $self->_visit_node( $node->end );
435 10 return;
436 }
437  
438 27228 ▶ if ( $node->isa('Zuzu::AST::Expr::Dict') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::Dict")) 801 26427 27228
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 2231 ▶ next if ref($pair) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pair ne "ARRAY" 0 2231 2231
441 2231 $self->_visit_node( $pair->[0] );
442 2231 $self->_visit_node( $pair->[1] );
443 }
444 801 return;
445 }
446  
447 26427 ▶ if ( $node->isa('Zuzu::AST::Expr::New') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Zuzu::AST::Expr::New")) 754 25673 26427
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 25673 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 »