| 1 | 6 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | package assign::Array; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use assign::Struct; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use base 'assign::Struct'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use assign::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use XXX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 71 | ▶ | sub parse_elem { | ||||||||||||||||||||||||||
|
Subroutine
parse_elem: called CC=14 SCAR=26.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 71 | my ($self) = @_; | |||||||||||||||||||||||||||
| 13 | 71 | my $in = $self->{in}; | |||||||||||||||||||||||||||
| 14 | 71 | my $elems = $self->{elems}; | |||||||||||||||||||||||||||
| 15 | 71 | ▶ | while (@$in) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 117 | my $tok = shift(@$in); | |||||||||||||||||||||||||||
| 17 | 117 | my $type = ref($tok); | |||||||||||||||||||||||||||
| 18 | 117 | ▶ | next if $type eq 'PPI::Token::Whitespace'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 68 | ▶ | if ($type eq 'PPI::Token::Symbol') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 62 | my $str = $tok->content; | |||||||||||||||||||||||||||
| 22 | 62 | ▶ | if ($str =~ /^[\$\@]\w+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 62 | my $elem = $self->get_var($str); | |||||||||||||||||||||||||||
| 24 | 62 | push @$elems, $elem; | |||||||||||||||||||||||||||
| 25 | 62 | return 1; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # Parse @$a in the following if-statement. | ||||||||||||||||||||||||||||
| 30 | 6 | ▶ | if ($type eq 'PPI::Token::Cast') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $tok->content eq '@' or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | XXX $tok, "unexpected token"; | ||||||||||||||||||||||||||||
| 33 | 1 | $tok = shift(@$in); | |||||||||||||||||||||||||||
| 34 | 1 | $type = ref($tok); | |||||||||||||||||||||||||||
| 35 | 1 | my $str = $tok->content; | |||||||||||||||||||||||||||
| 36 | 1 | ▶ | $type eq 'PPI::Token::Symbol' and $str =~ /^\$\w+$/ or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "PPI::Token::Symbol" and $str =~ /^\$\w+$/
MC/DC0%0/2
$type eq "PPI::Token::Symbol" and $str =~ /^\$\w+$/
$type eq "PPI::Token::Symbol"
$str =~ /^\$\w+$/
Truth table33%1/3
A and B
A= $type eq "PPI::Token::Symbol"B= $str =~ /^\$\w+$/
| |||||||||||||||||||||||||||||
| 37 | XXX $tok, "unexpected token"; | ||||||||||||||||||||||||||||
| 38 | 1 | my $elem = $self->get_var($str); | |||||||||||||||||||||||||||
| 39 | 1 | $elem->{cast} = 1; | |||||||||||||||||||||||||||
| 40 | 1 | push @$elems, $elem; | |||||||||||||||||||||||||||
| 41 | 1 | return 1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | if ($type eq 'PPI::Token::Number') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | my $str = $tok->content; | |||||||||||||||||||||||||||
| 46 | 2 | ▶ | if ($str =~ /^[1-9][0-9]*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 2 | push @$elems, assign::skip_num->new($str); | |||||||||||||||||||||||||||
| 48 | 2 | return 1; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | if ($type eq 'PPI::Token::Magic') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 3 | my $str = $tok->content; | |||||||||||||||||||||||||||
| 53 | 3 | ▶ | if ($str eq '_') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 2 | push @$elems, assign::skip->new; | |||||||||||||||||||||||||||
| 55 | 2 | return 1; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if ($str eq '$_') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | push @$elems, assign::var->new($str); | |||||||||||||||||||||||||||
| 59 | 1 | return 1; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | XXX $tok, "unexpected token"; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 3 | return 0; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 23 | ▶ | sub gen_code { | ||||||||||||||||||||||||||
|
Subroutine
gen_code: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 23 | my ($self, $decl, $oper, $from, $init) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 23 | my $code = [ @$init ]; | |||||||||||||||||||||||||||
| 71 | 23 | my $elems = $self->{elems}; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 23 | ▶ | if ($decl) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | push @$code, | ||||||||||||||||||||||||||||
| 75 | "$decl(" . | ||||||||||||||||||||||||||||
| 76 | join(', ', | ||||||||||||||||||||||||||||
| 77 | map $_->val, | ||||||||||||||||||||||||||||
| 78 | 57 | grep {$_->val ne '$_'} | |||||||||||||||||||||||||||
| 79 | 21 | grep {$_->val =~ /^[\$\@]/} | |||||||||||||||||||||||||||
| 80 | @$elems | ||||||||||||||||||||||||||||
| 81 | ) . | ||||||||||||||||||||||||||||
| 82 | ');'; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 23 | my $i = 0; | |||||||||||||||||||||||||||
| 86 | 23 | for my $elem (@$elems) { | |||||||||||||||||||||||||||
| 87 | 68 | my $type = ref $elem; | |||||||||||||||||||||||||||
| 88 | 68 | ▶ | if ($type eq 'assign::skip') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 2 | $i++; | |||||||||||||||||||||||||||
| 90 | 2 | next; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 66 | ▶ | if ($type eq 'assign::skip_num') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 2 | $i += $elem->val; | |||||||||||||||||||||||||||
| 94 | 2 | next; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 64 | my $var = $elem->val; | |||||||||||||||||||||||||||
| 98 | 64 | ▶ | my $def = $elem->{def} // ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$elem->{"def"} // ""
MC/DC100%1/1
$elem->{"def"} // ""
$elem->{"def"}
Truth table100%2/2
A
A= $elem->{"def"}
| |||||||||||||||||||||||||||||
| 99 | 64 | ▶ | $def &&= " // $def"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$def &&= " // $def"
MC/DC100%1/1
$def &&= " // $def"
$def
Truth table100%2/2
A
A= $def
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | push @$code, | ||||||||||||||||||||||||||||
| 102 | ($elem->sigil eq '@') | ||||||||||||||||||||||||||||
| 103 | ? "$var $oper \@$from\[$i..\@$from-1\]$def;" : | ||||||||||||||||||||||||||||
| 104 | ($elem->{cast}) | ||||||||||||||||||||||||||||
| 105 | 64 | ▶ | ? "$var $oper \[\@$from\[$i..\@$from-1\]\]$def;" : | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 106 | "$var $oper $from\->[$i]$def;"; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 64 | $i++; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 23 | return join "\n", @$code; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 6 | 1; | |||||||||||||||||||||||||||