Mildew/AST/If.pm

filter: Statementstmt 36.3% 32 / 88 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 12 / 15 Podpod n/a totaltotal 36.3% 44 / 121 CC 13 SCAR 27.4
CC
13
Cov
30%
__ANON__
27.5
__ANON__
27.5
__ANON__
26.3
CRAP 15.5
« VAST/statement.pm ↑ Summary Mildew/AST/Call.pm »
1 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use MooseX::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶class Mildew::AST::If extends Mildew::AST::Base {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=3.6
4 4 ▶ use Mildew::AST::Helpers;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 has 'cond' => (is => 'ro');
6 4 has 'then' => (is => 'ro');
7 4 has 'else' => (is => 'ro');
8 4 has 'elsif' => (is => 'ro');
9 0 ▶ method m0ld($ret) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=5 SCAR=33.1
10 0 my $id_cond = Mildew::AST::unique_id;
11 0 my $label_then = Mildew::AST::unique_label;
12 0 my $label_else = Mildew::AST::unique_label;
13 0 my $label_endif = Mildew::AST::unique_label;
14 0 my $cond = $self->cond->m0ld($id_cond);
15 0 my $then = 'noop;';
16 0 ▶ $then = $self->then->m0ld($ret) if $self->then;
Branch: 1 branch
BranchTrueFalseTotal
if $self->then 0 0 0
17 0 my $else = 'noop;';
18 0 ▶ if ($self->else) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->else) 0 0 0
19 0 $else = $self->else->m0ld($ret);
20 }
21 0 my $elsifs = '';
22 0 ▶ if ($self->elsif) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->elsif) 0 0 0
23 0 foreach my $part (@{$self->elsif}) {
24 0 my $id_elsif_cond = Mildew::AST::unique_id;
25 0 my $label_elsif_then = Mildew::AST::unique_label;
26 0 my $label_elsif_else = Mildew::AST::unique_label;
27 0 my $elsif_cond = $part->cond->m0ld($id_elsif_cond);
28 0 my $elsif_then = $part->then->m0ld($ret);
29 0 $elsifs .= $elsif_cond."\n".
30 'my '.$id_elsif_cond.'_val = '.$id_elsif_cond.'."FETCH"();'."\n".
31 'my '.$id_elsif_cond.'_bool = '.$id_elsif_cond.'_val."true"();'."\n".
32 'if '.$id_elsif_cond.'_bool { goto '.$label_elsif_then.' } else { goto '.$label_elsif_else.' };'."\n".
33 $label_elsif_then.':'."\n".
34 $elsif_then."\n".
35 'goto '.$label_endif.';'."\n".
36 $label_elsif_else.': noop;'."\n"
37 }
38 }
39
40 0 $cond."\n".
41 'my '.$id_cond.'_val = '.$id_cond.'."FETCH"();'."\n".
42 'my '.$id_cond.'_bool = '.$id_cond.'_val."true"();'."\n".
43 'if '.$id_cond.'_bool { goto '.$label_then.' } else { goto '.$label_else.' };'."\n".
44 $label_then.':'."\n".
45 $then."\n".
46 'goto '.$label_endif.';'."\n".
47 $label_else.':'."\n".
48 $elsifs.
49 $else."\n".
50 $label_endif.': noop;'."\n"
51 4 }
52 0 ▶ method simplified {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=5 SCAR=33.1
53  
54  
55 0 my $endif = Mildew::AST::Seq->new(stmts=>[],id=>Mildew::AST::unique_label);
56 0 my $result = Mildew::AST::unique_reg;
57  
58 0 ▶ my @parts = ($self,$self->elsif ? @{$self->elsif}: ());
Branch: 1 branch
BranchTrueFalseTotal
$self->elsif ? : 0 0 0
59 0 my $branch;
60 my @setup;
61 0 for my $part (@parts) {
62 0 my $old_branch = $branch;
63 0 my ($cond,@cond_setup) = call(true=>FETCH($part->cond))->simplified;
64 0 my ($then_val,@then_setup) = $part->then->simplified;
65 0 my $then = Mildew::AST::Seq->new(id=>Mildew::AST::unique_label,stmts=>[@then_setup,Mildew::AST::Assign->new(lvalue=>$result,rvalue=>$then_val),Mildew::AST::Goto->new(block=>$endif)]);
66 0 $branch = Mildew::AST::Branch->new(cond=>$cond,then=>$then);
67 0 my $block = Mildew::AST::Seq->new(id=>Mildew::AST::unique_label,stmts=>[@cond_setup,$branch,$then]);
68 0 push(@setup,$block);
69 0 ▶ $old_branch->else($block) if $old_branch;
Branch: 1 branch
BranchTrueFalseTotal
if $old_branch 0 0 0
70 }
71  
72 0 ▶ if ($self->else) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->else) { } 0 0 0
73 0 my ($else_val,@else_setup) = $self->else->simplified;
74 0 my $else = Mildew::AST::Seq->new(id=>Mildew::AST::unique_label,stmts=>[@else_setup,Mildew::AST::Assign->new(lvalue=>$result,rvalue=>$else_val),Mildew::AST::Goto->new(block=>$endif)]);
75 0 $branch->else($else);
76 0 push(@setup,$else);
77 } else {
78 0 $branch->else($endif);
79 }
80  
81 0 ($result,@setup,$endif);
82 4 }
83 0 ▶ method pretty {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=5 SCAR=32.7
84 0 my $code;
85 0 ▶ if ($self->then) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->then) { } 0 0 0
86 0 $code =
87 'if ' . $self->cond->pretty . " {\n"
88 . Mildew::AST::indent($self->then->pretty) . "\n"
89 . "}\n";
90 } else {
91 0 $code =
92 'unless ' . $self->cond->pretty . " {\n"
93 . Mildew::AST::indent($self->else->pretty) . "\n"
94 . "}\n";
95 }
96 0 ▶ if ($self->elsif) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->elsif) 0 0 0
97 0 foreach my $part (@{$self->elsif}) {
98 0 $code .=
99 'elsif '.$part->cond->pretty . " {\n"
100 . Mildew::AST::indent($self->then->pretty). "\n"
101 . "}\n";
102 }
103 }
104 0 ▶ if ($self->else) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->else) 0 0 0
105 0 $code .=
106 "else {\n"
107 . Mildew::AST::indent($self->else->pretty). "\n"
108 . "}\n";
109 }
110 0 $code;
111 4 }
112 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
« VAST/statement.pm ↑ Summary Mildew/AST/Call.pm »