ClassFile/Role/Parser/Actions.pm

filter: Statementstmt 29.4% 33 / 112 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 38.1% 8 / 21 Podpod 0.0% 0 / 12 totaltotal 16.2% 41 / 252 SCAR 66.1
CC
35
Cov
17%
utf8
342.0
float
90.0
double
90.0
CRAP 741.8
« ClassFile/Role/Parser.pm ↑ Summary ClassFile/BNF/AttributesArray.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Java::ClassFile::Role::Parser::Actions;
5  
6 # ABSTRACT: Grammar actions role for .class file parsing
7  
8 3 our $VERSION = '0.008'; # VERSION
9  
10 3 our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY
11  
12 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 #
14 # This package is part of the core of the engine. So it is optimized
15 # using directly the stack (i.e. no $self)
16 #
17 3 ▶use Math::BigFloat qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Bit::Vector qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 use constant {
21 3 FLOAT_POSITIVE_INF => Math::BigFloat->binf(),
22 FLOAT_NEGATIVE_INF => Math::BigFloat->binf('-'),
23 FLOAT_NAN => Math::BigFloat->bnan(),
24 FLOAT_POSITIVE_ONE => Math::BigFloat->new('1'),
25 FLOAT_NEGATIVE_ONE => Math::BigFloat->new('-1'),
26 3 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28  
29 #
30 # Note: we use Bit::Vector for portability, some steps could have been replaced with unpack
31 #
32 sub _bytesToVector {
33 #
34 # Increase bit numbers by 1 ensure to_Dec() returns the unsigned version
35 # Default is to not increase the number of bits, i.e. to_Dec() returns a signed value
36 #
37 0 ▶ my $vector = Bit::Vector->new($_[2] ? (8 * length($_[1]) + 1) : (8 * length($_[1])));
Subroutine _bytesToVector: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
38 0 $vector->Chunk_List_Store(8, reverse unpack('C*', $_[1])), $vector
39 }
40  
41 # sub u1 { $_[0]->_bytesToVector($_[1], 1)->to_Dec } # Ask for an unsigned value explicitely
42 # sub signedU1 { $_[0]->_bytesToVector($_[1] )->to_Dec }
43 # sub u2 { $_[0]->_bytesToVector($_[1], 1)->to_Dec } # Ask for an unsigned value explicitely
44 0 ▶sub u1 { unpack('C', $_[1]) }
Subroutine u1: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub signedU1 { unpack('c', $_[1]) }
Subroutine signedU1: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub u2 { unpack('n', $_[1]) }
Subroutine u2: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub signedU2 { $_[0]->_bytesToVector($_[1] )->to_Dec }
Subroutine signedU2: not called CC=1 SCAR=6.9
Pod undocumented
48 0 ▶sub u4 { $_[0]->_bytesToVector($_[1], 1)->to_Dec } # Ask for an unsigned value explicitely
Subroutine u4: not called CC=1 SCAR=6.9
Pod undocumented
49 0 ▶sub signedU4 { $_[0]->_bytesToVector($_[1], )->to_Dec }
Subroutine signedU4: not called CC=1 SCAR=6.9
Pod undocumented
50  
51 3 my @bitsForFloatCmp =
52 (
53 Bit::Vector->new_Hex( 32, '7f800000' ),
54 Bit::Vector->new_Hex( 32, 'ff800000' ),
55 Bit::Vector->new_Hex( 32, '7f800001' ),
56 Bit::Vector->new_Hex( 32, '7fffffff' ),
57 Bit::Vector->new_Hex( 32, 'ff800001' ),
58 Bit::Vector->new_Hex( 32, 'ffffffff' )
59 );
60 3 my @bitsForFloatMantissa =
61 (
62 Bit::Vector->new_Hex( 32, 'ff' ),
63 Bit::Vector->new_Hex( 32, '7fffff' ),
64 Bit::Vector->new_Hex( 32, '800000' )
65 );
66 3 my @mathForFloat =
67 (
68 Math::BigFloat->new('150'),
69 Math::BigFloat->new('2'),
70 );
71  
72 0 ▶sub floatToString { $_[0]->double($_[1], $_[2])->bstr() }
Subroutine floatToString: not called CC=1 SCAR=6.9
Pod undocumented
73 sub float {
74 0 ▶ my $vector = $_[0]->_bytesToVector($_[1]);
Subroutine float: not called CC=9 SCAR=45.0
Pod undocumented
75  
76 0 my $value;
77 0 ▶ if ($vector->equal($bitsForFloatCmp[0])) {
Branch: 3 branches
BranchTrueFalseTotal
if ($vector->equal($bitsForFloatCmp[0])) { } 0 0 0
elsif ($vector->equal($bitsForFloatCmp[1])) { } 0 0 0
elsif ($vector->Lexicompare($bitsForFloatCmp[2]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[3]) <= 0 or $vector->Lexicompare($bitsForFloatCmp[4]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[5]) <= 0) { } 0 0 0
78 0 $value = FLOAT_POSITIVE_INF->copy
79 }
80 elsif ($vector->equal( $bitsForFloatCmp[1])) {
81 0 $value = FLOAT_NEGATIVE_INF->copy
82 }
83 ▶ elsif (
Condition0%0/9
$vector->Lexicompare($bitsForFloatCmp[2]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[3]) <= 0 or $vector->Lexicompare($bitsForFloatCmp[4]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[5]) <= 0
l!l&&r!l&&!r
000
$vector->Lexicompare($bitsForFloatCmp[2]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[3]) <= 0
!ll&&!rl&&r
000
$vector->Lexicompare($bitsForFloatCmp[4]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[5]) <= 0
!ll&&!rl&&r
000
MC/DC0%0/4
$vector->Lexicompare($bitsForFloatCmp[2]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[3]) <= 0 or $vector->Lexicompare($bitsForFloatCmp[4]) >= 0 and $vector->Lexicompare($bitsForFloatCmp[5]) <= 0
$vector->Lexicompare($bitsForFloatCmp[2]) >= 0 $vector->Lexicompare($bitsForFloatCmp[3]) <= 0 $vector->Lexicompare($bitsForFloatCmp[4]) >= 0 $vector->Lexicompare($bitsForFloatCmp[5]) <= 0
Truth table0%0/7
A and B or C and D
A= $vector->Lexicompare($bitsForFloatCmp[2]) >= 0B= $vector->Lexicompare($bitsForFloatCmp[3]) <= 0C= $vector->Lexicompare($bitsForFloatCmp[4]) >= 0D= $vector->Lexicompare($bitsForFloatCmp[5]) <= 0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
84 (
85 $vector->Lexicompare( $bitsForFloatCmp[2] ) >= 0 &&
86 $vector->Lexicompare( $bitsForFloatCmp[3] ) <= 0
87 )
88 ||
89 (
90 $vector->Lexicompare( $bitsForFloatCmp[4] ) >= 0 &&
91 $vector->Lexicompare( $bitsForFloatCmp[5] ) <= 0
92 )
93 ) {
94 0 $value = FLOAT_NAN->copy
95 }
96 else {
97 #
98 # int s = ((bits >> 31) == 0) ? 1 : -1;
99 #
100 0 my $s = $vector->Clone();
101 0 $s->Move_Right(31);
102 0 ▶ my $sf = ($s->to_Dec() == 0) ? FLOAT_POSITIVE_ONE->copy() : FLOAT_NEGATIVE_ONE->copy();
Branch: 1 branch
BranchTrueFalseTotal
$s->to_Dec == 0 ? : 0 0 0
103 #
104 # int e = ((bits >> 23) & 0xff);
105 #
106 0 my $e = $vector->Clone();
107 0 $e->Move_Right(23);
108 0 $e->And( $e, $bitsForFloatMantissa[0] );
109 #
110 # int m = (e == 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
111 # ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^
112 # \ /
113 # \ /
114 # same things
115 #
116 0 my $m = $vector->Clone();
117 0 $m->And( $m, $bitsForFloatMantissa[1] );
118 0 ▶ if ( $e->to_Dec() == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->to_Dec == 0) { } 0 0 0
119 0 $m->Move_Left(1)
120 } else {
121 0 $m->Or( $m, $bitsForFloatMantissa[2] )
122 }
123 #
124 # $value = $s * $m * (2 ** ($e - 150))
125 # Note: Bit::Vector->to_Dec() returns a string
126 0 my $mf = Math::BigFloat->new($m->to_Dec());
127 0 my $ef = Math::BigFloat->new($e->to_Dec());
128  
129 0 $ef->bsub($mathForFloat[0]); # $e - 150
130 0 my $mantissaf = $mathForFloat[1]->copy(); # 2
131 0 $mantissaf->bpow($ef); # 2 ** ($e - 150)
132 0 $mf->bmul($mantissaf); # $m * (2 ** ($e - 150))
133 0 $mf->bmul($sf); # $s * $m * (2 ** ($e - 150))
134 0 $value = $mf
135 }
136  
137 0 $value
138 }
139  
140 sub long {
141 0 ▶ my $vhigh = $_[0]->_bytesToVector($_[1]);
Subroutine long: not called CC=1 SCAR=6.9
Pod undocumented
142 0 my $vlow = $_[0]->_bytesToVector($_[2]);
143 #
144 # ((long) high_bytes << 32) + low_bytes
145 #
146 0 Bit::Vector->Concat_List($vhigh, $vlow)->to_Dec()
147 }
148  
149 3 my @bitsForDoubleCmp = (
150 Bit::Vector->new_Hex( 64, "7ff0000000000000" ),
151 Bit::Vector->new_Hex( 64, "fff0000000000000" ),
152 Bit::Vector->new_Hex( 64, "7ff0000000000001" ),
153 Bit::Vector->new_Hex( 64, "7fffffffffffffff" ),
154 Bit::Vector->new_Hex( 64, "fff0000000000001" ),
155 Bit::Vector->new_Hex( 64, "ffffffffffffffff" )
156 );
157 3 my @bitsForDoubleMantissa =
158 (
159 Bit::Vector->new_Hex( 64, '7ff' ),
160 Bit::Vector->new_Hex( 64, 'fffffffffffff' ),
161 Bit::Vector->new_Hex( 64, '10000000000000' )
162 );
163 3 my @mathForDouble =
164 (
165 Math::BigFloat->new('1075'),
166 Math::BigFloat->new('2'),
167 );
168  
169 0 ▶sub doubleToString { $_[0]->double($_[1], $_[2])->bstr() }
Subroutine doubleToString: not called CC=1 SCAR=6.9
Pod undocumented
170 sub double {
171 0 ▶ my $vhigh = $_[0]->_bytesToVector($_[1]);
Subroutine double: not called CC=9 SCAR=45.0
Pod undocumented
172 0 my $vlow = $_[0]->_bytesToVector($_[2]);
173 #
174 # ((long) high_bytes << 32) + low_bytes
175 #
176 0 my $vector = Bit::Vector->Concat_List($vhigh, $vlow);
177 #
178 # Same technique as in float
179 #
180 0 my $value;
181 0 ▶ if ($vector->equal($bitsForDoubleCmp[0])) {
Branch: 3 branches
BranchTrueFalseTotal
if ($vector->equal($bitsForDoubleCmp[0])) { } 0 0 0
elsif ($vector->equal($bitsForDoubleCmp[1])) { } 0 0 0
elsif ($vector->Lexicompare($bitsForDoubleCmp[2]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[3]) <= 0 or $vector->Lexicompare($bitsForDoubleCmp[4]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[5]) <= 0) { } 0 0 0
182 0 $value = FLOAT_POSITIVE_INF->copy
183 }
184 elsif ($vector->equal( $bitsForDoubleCmp[1])) {
185 0 $value = FLOAT_NEGATIVE_INF->copy
186 }
187 ▶ elsif (
Condition0%0/9
$vector->Lexicompare($bitsForDoubleCmp[2]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[3]) <= 0 or $vector->Lexicompare($bitsForDoubleCmp[4]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[5]) <= 0
l!l&&r!l&&!r
000
$vector->Lexicompare($bitsForDoubleCmp[2]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[3]) <= 0
!ll&&!rl&&r
000
$vector->Lexicompare($bitsForDoubleCmp[4]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[5]) <= 0
!ll&&!rl&&r
000
MC/DC0%0/4
$vector->Lexicompare($bitsForDoubleCmp[2]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[3]) <= 0 or $vector->Lexicompare($bitsForDoubleCmp[4]) >= 0 and $vector->Lexicompare($bitsForDoubleCmp[5]) <= 0
$vector->Lexicompare($bitsForDoubleCmp[2]) >= 0 $vector->Lexicompare($bitsForDoubleCmp[3]) <= 0 $vector->Lexicompare($bitsForDoubleCmp[4]) >= 0 $vector->Lexicompare($bitsForDoubleCmp[5]) <= 0
Truth table0%0/7
A and B or C and D
A= $vector->Lexicompare($bitsForDoubleCmp[2]) >= 0B= $vector->Lexicompare($bitsForDoubleCmp[3]) <= 0C= $vector->Lexicompare($bitsForDoubleCmp[4]) >= 0D= $vector->Lexicompare($bitsForDoubleCmp[5]) <= 0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
188 (
189 $vector->Lexicompare( $bitsForDoubleCmp[2] ) >= 0 &&
190 $vector->Lexicompare( $bitsForDoubleCmp[3] ) <= 0
191 )
192 ||
193 (
194 $vector->Lexicompare( $bitsForDoubleCmp[4] ) >= 0 &&
195 $vector->Lexicompare( $bitsForDoubleCmp[5] ) <= 0
196 )
197 ) {
198 0 $value = FLOAT_NAN->copy
199 }
200 else {
201 #
202 # int s = ((bits >> 63) == 0) ? 1 : -1;
203 #
204 0 my $s = $vector->Clone();
205 0 $s->Move_Right(63);
206 0 ▶ my $sf = ($s->to_Dec() == 0) ? FLOAT_POSITIVE_ONE->copy() : FLOAT_NEGATIVE_ONE->copy();
Branch: 1 branch
BranchTrueFalseTotal
$s->to_Dec == 0 ? : 0 0 0
207 #
208 # int e = (int)((bits >> 52) & 0x7ffL);
209 #
210 0 my $e = $vector->Clone();
211 0 $e->Move_Right(52);
212 0 $e->And( $e, $bitsForDoubleMantissa[0] );
213 #
214 # long m = (e == 0) ? (bits & 0xfffffffffffffL) << 1 : (bits & 0xfffffffffffffL) | 0x10000000000000L;
215 # ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^
216 # \ /
217 # \ /
218 # same things
219 0 my $m = $vector->Clone();
220 0 $m->And( $m, $bitsForDoubleMantissa[1] );
221 0 ▶ if ( $e->to_Dec() == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->to_Dec == 0) { } 0 0 0
222 0 $m->Move_Left(1)
223 } else {
224 0 $m->Or( $m, $bitsForDoubleMantissa[2] )
225 }
226 #
227 # $value = $s * $m * (2 ** ($e - 1075))
228 #
229 0 my $mf = Math::BigFloat->new($m->to_Dec());
230 0 my $ef = Math::BigFloat->new($e->to_Dec());
231  
232 0 $ef->bsub($mathForDouble[0]); # $e - 1075
233 0 my $mantissaf = $mathForDouble[1]->copy(); # 2
234 0 $mantissaf->bpow($ef); # 2 ** ($e - 150)
235 0 $mf->bmul($mantissaf); # $m * (2 ** ($e - 150))
236 0 $mf->bmul($sf); # $s * $m * (2 ** ($e - 150))
237 0 $value = $mf
238 }
239  
240 0 $value
241 }
242  
243 sub utf8 {
244 #
245 # Disable all conversion warnings:
246 # either we know we succeed, either we abort -;
247 #
248 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
249  
250 0 ▶ my $s = undef;
Subroutine utf8: not called CC=18 SCAR=58.3
Pod undocumented
251 0 ▶ return $s unless (length($_[1]));
Branch: 1 branch
BranchTrueFalseTotal
unless length $_[1] 0 0 0
252  
253 0 my @bytes = unpack('C*', $_[1]);
254 0 my ($val0, $val1, $val2, $val3, $val4, $val5) = '';
255  
256 0 ▶ while (@bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bytes) 0 0 0
257 #
258 # This is to avoid a internal op with ';' : @bytes is guaranteed to be shifted
259 #
260 0 ▶ if ((($val0 = shift(@bytes)) & 0x80) == 0) { # 0x80 == 10000000 => 0xxxxxxx
Branch: 4 branches
BranchTrueFalseTotal
if ((($val0 = shift @bytes) & 128) == 0) { } 0 0 0
elsif (($val0 & 224) == 192 and $#bytes >= 0 and (($val1 = $bytes[0]) & 192) == 128) { } 0 0 0
elsif ($val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160 and (($val2 = $bytes[1]) & 192) == 128 and ($val3 = $bytes[2]) == 237 and (($val4 = $bytes[3]) & 240) == 176 and (($val5 = $bytes[4]) & 192) == 128) { } 0 0 0
elsif (($val0 & 240) == 224 and $#bytes >= 1 and (($val1 = $bytes[0]) & 192) == 128 and (($val2 = $bytes[1]) & 192) == 128) { } 0 0 0
261 #
262 # 1 byte
263 #
264 0 $s .= chr($val0)
265 }
266 ▶ elsif ((($val0 & 0xE0) == 0xC0) && # 0xE0 == 11100000, 0xC0 == 11000000 => 110xxxxx
Condition0%0/6
($val0 & 224) == 192 and $#bytes >= 0 and (($val1 = $bytes[0]) & 192) == 128
!ll&&!rl&&r
000
($val0 & 224) == 192 and $#bytes >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
($val0 & 224) == 192 and $#bytes >= 0 and (($val1 = $bytes[0]) & 192) == 128
($val0 & 224) == 192 $#bytes >= 0 (($val1 = $bytes[0]) & 192) == 128
Truth table0%0/4
A and B and C
A= ($val0 & 224) == 192B= $#bytes >= 0C= (($val1 = $bytes[0]) & 192) == 128
ABCresult
0XX0
10X0
1100
1111
267 ($#bytes >= 0) &&
268 ((($val1 = $bytes[0]) & 0xC0) == 0x80)) { # 0xC0 == 11000000, 0x80 == 10000000 => 10xxxxxx
269 #
270 # 2 bytes
271 #
272 0 shift(@bytes), $s .= chr((($val0 & 0x1F) << 6) + ($val1 & 0x3F))
273 }
274 ▶ elsif (($val0 == 0xED) && # 0xED == 11101101 => 11101101
Condition0%0/18
$val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160 and (($val2 = $bytes[1]) & 192) == 128 and ($val3 = $bytes[2]) == 237 and (($val4 = $bytes[3]) & 240) == 176 and (($val5 = $bytes[4]) & 192) == 128
!ll&&!rl&&r
000
$val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160 and (($val2 = $bytes[1]) & 192) == 128 and ($val3 = $bytes[2]) == 237 and (($val4 = $bytes[3]) & 240) == 176
!ll&&!rl&&r
000
$val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160 and (($val2 = $bytes[1]) & 192) == 128 and ($val3 = $bytes[2]) == 237
!ll&&!rl&&r
000
$val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160 and (($val2 = $bytes[1]) & 192) == 128
!ll&&!rl&&r
000
$val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160
!ll&&!rl&&r
000
$val0 == 237 and $#bytes >= 4
!ll&&!rl&&r
000
MC/DC0%0/7
$val0 == 237 and $#bytes >= 4 and (($val1 = $bytes[0]) & 240) == 160 and (($val2 = $bytes[1]) & 192) == 128 and ($val3 = $bytes[2]) == 237 and (($val4 = $bytes[3]) & 240) == 176 and (($val5 = $bytes[4]) & 192) == 128
$val0 == 237 $#bytes >= 4 (($val1 = $bytes[0]) & 240) == 160 (($val2 = $bytes[1]) & 192) == 128 ($val3 = $bytes[2]) == 237 (($val4 = $bytes[3]) & 240) == 176 (($val5 = $bytes[4]) & 192) == 128
Truth table0%0/8
A and B and C and D and E and F and G
A= $val0 == 237B= $#bytes >= 4C= (($val1 = $bytes[0]) & 240) == 160D= (($val2 = $bytes[1]) & 192) == 128E= ($val3 = $bytes[2]) == 237F= (($val4 = $bytes[3]) & 240) == 176G= (($val5 = $bytes[4]) & 192) == 128
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
275 ($#bytes >= 4) &&
276 ((($val1 = $bytes[0]) & 0xF0) == 0xA0) && # 0xF0 == 11110000, 0xA0 == 10100000 => 1010xxxx
277 ((($val2 = $bytes[1]) & 0xC0) == 0x80) && # 0xC0 == 11000000, 0x80 == 10000000 => 10xxxxxx
278 ( ($val3 = $bytes[2]) == 0xED) && # 0xED == 11101101 => 11101101
279 ((($val4 = $bytes[3]) & 0xF0) == 0xB0) && # 0xF0 == 11110000, 0xB0 == 10110000 => 1011xxxx
280 ((($val5 = $bytes[4]) & 0xC0) == 0x80)) { # 0xC0 == 11000000, 0x80 == 10000000 => 10xxxxxx
281 #
282 # 6 bytes, for supplementary characters are tested BEFORE 3 bytes, because it is a doubled 3-bytes encoding
283 #
284 0 splice(@bytes, 0, 5), $s .= chr(0x10000 + (($val1 & 0x0F) << 16) + (($val2 & 0x3F) << 10) + (($val4 & 0x0F) << 6) + ($val5 & 0x3F))
285 }
286 ▶ elsif ((($val0 & 0xF0) == 0xE0) && # 0xF0 == 11110000, 0xE0 == 11100000 => 1110xxxx
Condition0%0/9
($val0 & 240) == 224 and $#bytes >= 1 and (($val1 = $bytes[0]) & 192) == 128 and (($val2 = $bytes[1]) & 192) == 128
!ll&&!rl&&r
000
($val0 & 240) == 224 and $#bytes >= 1 and (($val1 = $bytes[0]) & 192) == 128
!ll&&!rl&&r
000
($val0 & 240) == 224 and $#bytes >= 1
!ll&&!rl&&r
000
MC/DC0%0/4
($val0 & 240) == 224 and $#bytes >= 1 and (($val1 = $bytes[0]) & 192) == 128 and (($val2 = $bytes[1]) & 192) == 128
($val0 & 240) == 224 $#bytes >= 1 (($val1 = $bytes[0]) & 192) == 128 (($val2 = $bytes[1]) & 192) == 128
Truth table0%0/5
A and B and C and D
A= ($val0 & 240) == 224B= $#bytes >= 1C= (($val1 = $bytes[0]) & 192) == 128D= (($val2 = $bytes[1]) & 192) == 128
ABCDresult
0XXX0
10XX0
110X0
11100
11111
287 ($#bytes >= 1) &&
288 ((($val1 = $bytes[0]) & 0xC0) == 0x80) && # 0xC0 == 11000000, 0x80 == 10000000 => 10xxxxxx
289 ((($val2 = $bytes[1]) & 0xC0) == 0x80)) { # 0xC0 == 11000000, 0x80 == 10000000 => 10xxxxxx
290 #
291 # 3 bytes
292 #
293 0 splice(@bytes, 0, 2), $s .= chr((($val0 & 0xF ) << 12) + (($val1 & 0x3F) << 6) + ($val2 & 0x3F))
294 }
295 else {
296 0 $_[0]->fatalf('Unable to map byte with value 0x%x', $val0)
297 }
298 }
299  
300 $s
301 0 }
302  
303 3 1;
304  
305 __END__
306  
307 =pod
308  
309 =encoding UTF-8
310  
311 =head1 NAME
312  
313 MarpaX::Java::ClassFile::Role::Parser::Actions - Grammar actions role for .class file parsing
314  
315 =head1 VERSION
316  
317 version 0.008
318  
319 =head1 DESCRIPTION
320  
321 MarpaX::Java::ClassFile::ClassFile::Common::Actions is an internal class used by L<MarpaX::Java::ClassFile::ClassFile>, please refer to the later.
322  
323 =head1 AUTHOR
324  
325 Jean-Damien Durand <jeandamiendurand@free.fr>
326  
327 =head1 COPYRIGHT AND LICENSE
328  
329 This software is copyright (c) 2016 by Jean-Damien Durand.
330  
331 This is free software; you can redistribute it and/or modify it under
332 the same terms as the Perl 5 programming language system itself.
333  
334 =cut
« ClassFile/Role/Parser.pm ↑ Summary ClassFile/BNF/AttributesArray.pm »