ClassFile/BNF/ClassFile.pm

filter: Statementstmt 63.8% 30 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 10 / 18 Podpod n/a totaltotal 55.5% 40 / 72 SCAR 16.5
CC
4
Cov
58%
__ANON__
20.0
grammar
2.0
__ANON__
2.0
CRAP 5.2
« ClassFile.pm ↑ Summary ClassFile/BNF/OpCodeArray.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Java::ClassFile::BNF::ClassFile;
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: Parsing of a ClassFile
8  
9 our $VERSION = '0.008'; # VERSION
10  
11 our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY
12  
13 2 ▶use Data::Section -setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use MarpaX::Java::ClassFile::Util::BNF qw/bnf/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Types::Standard qw/ArrayRef Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Types::Common::Numeric qw/PositiveOrZeroInt/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use MarpaX::Java::ClassFile::Util::ArrayRefWeakenisation qw/arrayRefWeakenisator/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use MarpaX::Java::ClassFile::Util::ProductionMode qw/prod_isa/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 #
21 # require because we do not import ANYTHING from these module, just require they are loaded
22 #
23 require Marpa::R2;
24 require MarpaX::Java::ClassFile::Struct::ClassFile;
25 require MarpaX::Java::ClassFile::BNF::ConstantPoolArray;
26 require MarpaX::Java::ClassFile::BNF::InterfacesArray;
27 require MarpaX::Java::ClassFile::BNF::FieldsArray;
28 require MarpaX::Java::ClassFile::BNF::MethodsArray;
29 require MarpaX::Java::ClassFile::BNF::AttributesArray;
30  
31 has _nonweak_constant_pool => ( is => 'rwp', prod_isa(ArrayRef), default => sub { [] } );
32  
33 my $_data = ${ __PACKAGE__->section_data('bnf') };
34 my $_grammar = Marpa::R2::Scanless::G->new( { source => \__PACKAGE__->bnf($_data) } );
35  
36 # --------------------------------------------------------
37 # What role MarpaX::Java::ClassFile::Role::Parser requires
38 # --------------------------------------------------------
39 0 ▶sub grammar { $_grammar }
Subroutine grammar: not called CC=1 SCAR=6.9
40 sub callbacks {
41 return {
42 #
43 # Size of constant pool array is constant_pool_count - 1 as per the spec.
44 # Implicitely from the spec, indices in constant pool start at 1:
45 # - The final action on Constant pool will insert a fake undef entry at position 0
46 #
47 'constant_pool_count$' => sub {
48 0 ▶ $_[0]->constant_pool_count($_[0]->literalU2('constant_pool_count'));
Subroutine __ANON__: not called CC=4 SCAR=30.0
49 0 my $constant_pool = $_[0]->inner('ConstantPoolArray', size => $_[0]->constant_pool_count - 1);
50 #
51 # Keep the version with references. This will go in the structure.
52 # C.f. call to MarpaX::Java::ClassFile::Struct::ClassFile->new().
53 #
54 0 $_[0]->_set__nonweak_constant_pool([ @{$constant_pool} ]);
55 #
56 # The default constant_pool attribute is weakened.
57 # Thus this can be propagated to any other subgrammar, thus any other
58 # sub structure -;
59 #
60 0 $_[0]->arrayRefWeakenisator($constant_pool);
61 0 $_[0]->constant_pool($constant_pool);
62 #
63 # Pass this information to any child, weakened, so that they can pass it
64 # to their child as well, and so on.
65 #
66 0 foreach (@{$constant_pool}) {
67 0 ▶ $_->_constant_pool($constant_pool) if (blessed($_) && ($_->can('_constant_pool')))
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_) and $_->can("_constant_pool") 0 0 0
Condition0%0/3
builtin::blessed($_) and $_->can("_constant_pool")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_) and $_->can("_constant_pool")
builtin::blessed($_) $_->can("_constant_pool")
Truth table0%0/3
A and B
A= builtin::blessed($_)B= $_->can("_constant_pool")
ABresult
0X0
100
111
68 }
69 },
70 0 ▶ 'interfaces_count$' => sub { $_[0]->inner('InterfacesArray', size => $_[0]->literalU2('interfaces_count')) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 ▶ 'fields_count$' => sub { $_[0]->inner('FieldsArray', size => $_[0]->literalU2('fields_count')) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 ▶ 'methods_count$' => sub { $_[0]->inner('MethodsArray', size => $_[0]->literalU2('methods_count')) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 ▶ 'attributes_count$' => sub { $_[0]->inner('AttributesArray', size => $_[0]->literalU2('attributes_count')) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 }
75 0 ▶}
Subroutine callbacks: not called CC=1 SCAR=6.9
76  
77 # ---------------
78 # Grammar actions
79 # ---------------
80 sub _ClassFile {
81 0 ▶ my ($self,
Subroutine _ClassFile: not called CC=1 SCAR=6.9
82 $magic,
83 $minor_version,
84 $major_version,
85 $constant_pool_count,
86 # $constant_pool,
87 $access_flags,
88 $this_class,
89 $super_class,
90 $interfaces_count,
91 $interfaces,
92 $fields_count,
93 $fields,
94 $methods_count,
95 $methods,
96 $attributes_count,
97 $attributes) = @_;
98  
99 0 MarpaX::Java::ClassFile::Struct::ClassFile->new(
100 magic => $magic,
101 minor_version => $minor_version,
102 major_version => $major_version,
103 constant_pool_count => $constant_pool_count,
104 constant_pool => $_[0]->_nonweak_constant_pool,
105 access_flags => $access_flags,
106 this_class => $this_class,
107 super_class => $super_class,
108 interfaces_count => $interfaces_count,
109 interfaces => $interfaces,
110 fields_count => $fields_count,
111 fields => $fields,
112 methods_count => $methods_count,
113 methods => $methods,
114 attributes_count => $attributes_count,
115 attributes => $attributes
116 )
117 }
118  
119 with 'MarpaX::Java::ClassFile::Role::Parser';
120  
121 #
122 # We want to say that exhaustion is definitely fatal
123 #
124 has '+exhaustion' => (default => sub { 'fatal' });
125 #
126 # We want to take control over constant_pool count and content in this class (and only here btw)
127 #
128 has '+constant_pool_count' => ( is => 'rw' );
129 has '+constant_pool' => ( is => 'rw' );
130  
131 1;
132  
133 =pod
134  
135 =encoding UTF-8
136  
137 =head1 NAME
138  
139 MarpaX::Java::ClassFile::BNF::ClassFile - Parsing of a ClassFile
140  
141 =head1 VERSION
142  
143 version 0.008
144  
145 =head1 AUTHOR
146  
147 Jean-Damien Durand <jeandamiendurand@free.fr>
148  
149 =head1 COPYRIGHT AND LICENSE
150  
151 This software is copyright (c) 2016 by Jean-Damien Durand.
152  
153 This is free software; you can redistribute it and/or modify it under
154 the same terms as the Perl 5 programming language system itself.
155  
156 =cut
157  
158 __DATA__
159 __[ bnf ]__
160 :default ::= action => ::first
161 event 'constant_pool_count$' = completed constant_pool_count
162 event 'interfaces_count$' = completed interfaces_count
163 event 'fields_count$' = completed fields_count
164 event 'methods_count$' = completed methods_count
165 event 'attributes_count$' = completed attributes_count
166 ClassFile ::=
167 magic
168 minor_version
169 major_version
170 constant_pool_count
171 (constant_pool) # C.f. in the constant_pool_count$ event
172 access_flags
173 this_class
174 super_class
175 interfaces_count
176 interfaces
177 fields_count
178 fields
179 methods_count
180 methods
181 attributes_count
182 attributes
183 action => _ClassFile
184  
185 magic ::= U4 action => u4
186 minor_version ::= U2 action => u2
187 major_version ::= U2 action => u2
188 constant_pool_count ::= U2 action => u2
189 constant_pool ::= MANAGED action => ::first
190 access_flags ::= U2 action => u2
191 this_class ::= U2 action => u2
192 super_class ::= U2 action => u2
193 interfaces_count ::= U2 action => u2
194 interfaces ::= MANAGED action => ::first
195 fields_count ::= U2 action => u2
196 fields ::= MANAGED action => ::first
197 methods_count ::= U2 action => u2
198 methods ::= MANAGED action => ::first
199 attributes_count ::= U2 action => u2
200 attributes ::= MANAGED action => ::first
« ClassFile.pm ↑ Summary ClassFile/BNF/OpCodeArray.pm »