ClassFile/Role/Parser.pm

filter: Statementstmt 23.8% 65 / 273 Branchbran 2.5% 2 / 80 Conditioncond 0.0% 0 / 43 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 22.3% 15 / 67 Podpod 0.0% 0 / 29 totaltotal 15.8% 82 / 519 SCAR 75.6
CC
57
Cov
17%
_value
132.0
_build_ast
72.0
lexeme_read
56.0
CRAP 1920.2
↑ Summary ClassFile/Role/Parser/Actions.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::Role::Parser;
5  
6 # ABSTRACT: Parsing engine role for .class file parsing
7  
8 2 our $VERSION = '0.008'; # VERSION
9  
10 2 our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY
11  
12 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 #
14 # Note: This package is part of the core of the engine. Therefore it
15 # optimized except the logging (when you trace this package, I assume
16 # you are not interested in micro-optimizations)
17 #
18 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use MarpaX::Java::ClassFile::Util::MarpaTrace qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use MarpaX::Java::ClassFile::Util::ProductionMode qw/prod_isa/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Data::Section -setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use Types::Common::Numeric qw/PositiveOrZeroInt/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Types::Standard qw/Any ScalarRef Bool ArrayRef Str Undef ConsumerOf InstanceOf/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Types::Encodings qw/Bytes/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 #
29 # Required parameters
30 #
31 2 has inputRef => ( is => 'ro', prod_isa(ScalarRef[Bytes]), required => 1);
32 #
33 # Parameters with a default
34 #
35 0 ▶has marpaRecceHook => ( is => 'ro', prod_isa(Bool), default => sub { 1 });
Subroutine __ANON__: not called CC=1 SCAR=1.2
36 0 ▶has constant_pool_count => ( is => 'ro', prod_isa(PositiveOrZeroInt), default => sub { 0 } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
37 0 ▶has constant_pool => ( is => 'ro', prod_isa(ArrayRef), default => sub { [] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
38 0 ▶has pos => ( is => 'rwp', prod_isa(PositiveOrZeroInt), default => sub { 0 });
Subroutine __ANON__: not called CC=1 SCAR=1.2
39 0 ▶has exhaustion => ( is => 'ro', prod_isa(Str), default => sub { 'event' });
Subroutine __ANON__: not called CC=1 SCAR=1.2
40 0 ▶has parent => ( is => 'ro', prod_isa(Undef|ConsumerOf['MarpaX::Java::ClassFile::Role::Parser']), default => sub { return });
Subroutine __ANON__: not called CC=1 SCAR=1.2
41 #
42 # Lazy parameters
43 #
44 2 has max => ( is => 'rwp', prod_isa(PositiveOrZeroInt), lazy => 1, builder => 1);
45 2 has whoami => ( is => 'ro', prod_isa(Str), lazy => 1, builder => 1);
46 2 has ast => ( is => 'ro', prod_isa(Any), lazy => 1, builder => 1);
47  
48 2 my $MARPA_TRACE_FILE_HANDLE;
49 my $MARPA_TRACE_BUFFER;
50 2 my %_registrations = ();
51 2 my %_DOES_INNERGRAMMAR = ();
52  
53 sub BEGIN {
54 #
55 ## We do not want Marpa to pollute STDERR
56 #
57 ## Autovivify a new file handle
58 #
59 2 ▶ open($MARPA_TRACE_FILE_HANDLE, '>', \$MARPA_TRACE_BUFFER);
Subroutine BEGIN: called CC=4 SCAR=20.1
60 2 ▶ if (! defined($MARPA_TRACE_FILE_HANDLE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $MARPA_TRACE_FILE_HANDLE) { } 0 2 2
61 0 croak "Cannot create temporary file handle to tie Marpa logging, $!\n";
62 } else {
63 2 ▶ if (! tie ${$MARPA_TRACE_FILE_HANDLE}, 'MarpaX::Java::ClassFile::Util::MarpaTrace') {
Branch: 1 branch
BranchTrueFalseTotal
if (not tie(${$MARPA_TRACE_FILE_HANDLE;}, "MarpaX::Java::ClassFile::Util::MarpaTrace")) 0 2 2
64 0 croak "Cannot tie $MARPA_TRACE_FILE_HANDLE, $!\n";
65 0 ▶ if (! close($MARPA_TRACE_FILE_HANDLE)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (close $MARPA_TRACE_FILE_HANDLE) 0 0 0
66 0 croak "Cannot close temporary file handle, $!\n";
67 }
68 0 $MARPA_TRACE_FILE_HANDLE = undef;
69 }
70 }
71 }
72  
73 sub _build_max {
74 # my ($self) = @_;
75 0 ▶ length(${$_[0]->inputRef})
Subroutine _build_max: not called CC=1 SCAR=6.9
76 }
77  
78 sub _build_whoami {
79 # my ($self, $class) = @_;
80 0 ▶ my $whoami = (split(/::/, $_[1] // blessed($_[0])))[-1];
Subroutine _build_whoami: not called CC=3 SCAR=24.8
Condition0%0/3
$_[1] // builtin::blessed($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] // builtin::blessed($_[0])
$_[1] builtin::blessed($_[0])
Truth table0%0/3
A // B
A= $_[1]B= builtin::blessed($_[0])
ABresult
1X1
011
000
81  
82 0 ▶ return join('->', $_[0]->parent->whoami, $whoami) if (defined($_[0]->parent));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]->parent 0 0 0
83 0 $whoami
84 }
85  
86 # -----------------------
87 # General events dispatch
88 # -----------------------
89 sub manageEvents {
90 # my ($self) = @_;
91  
92 0 ▶ my @eventNames = map { $_->[0] } (@{$_[0]->_events});
Subroutine manageEvents: not called CC=3 SCAR=24.8
Pod undocumented
93 # $_[0]->tracef('Events: %s', \@eventNames);
94 0 foreach (@eventNames) {
95 0 $_[0]->tracef('--------- %s', $_);
96 0 my $callback = $_[0]->callbacks->{$_};
97 0 ▶ $_[0]->_croak("Unmanaged event $_") unless defined($callback);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $callback 0 0 0
98 0 $_[0]->$callback
99 }
100 }
101  
102 ▶sub _build__r {
Subroutine _build__r: not called CC=1 SCAR=0.0
103 # my ($self) = @_;
104 }
105  
106 sub _build_ast {
107 # my ($self) = @_;
108 #
109 # For our marpa tied logger
110 #
111 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
112 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::SELF = $_[0];
Subroutine _build_ast: not called CC=8 SCAR=42.8
113 0 local $MarpaX::Java::ClassFile::Role::Parser::G = $_[0]->grammar;
114 #
115 # It is far quicker to maintain ourself booleans for trace and debug mode
116 # rather than letting logger's tracef() and debugf() handle the request.
117 # Further more we do //= because these really should be constant once
118 # parse is starting.
119 # The following can look strange but is my way to makes sure that $[0]->log is called once per parse -;
120 # even when setting localized variables.
121 #
122 0 my $IS_TRACE = $MarpaX::Java::ClassFile::Role::Parser::IS_TRACE;
123 0 my $IS_DEBUG = $MarpaX::Java::ClassFile::Role::Parser::IS_DEBUG;
124 0 my $IS_INFO = $MarpaX::Java::ClassFile::Role::Parser::IS_INFO;
125 0 my $IS_WARN = $MarpaX::Java::ClassFile::Role::Parser::IS_WARN;
126 0 my $IS_ERROR = $MarpaX::Java::ClassFile::Role::Parser::IS_ERROR;
127 0 my $IS_FATAL = $MarpaX::Java::ClassFile::Role::Parser::IS_FATAL;
128  
129 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::IS_TRACE = $IS_TRACE // $_[0]->log->is_trace;
Condition0%0/3
$IS_TRACE // $_[0]->log->is_trace
l!l&&r!l&&!r
000
MC/DC0%0/2
$IS_TRACE // $_[0]->log->is_trace
$IS_TRACE $_[0]->log->is_trace
Truth table0%0/3
A // B
A= $IS_TRACEB= $_[0]->log->is_trace
ABresult
1X1
011
000
130 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::IS_DEBUG = $IS_DEBUG // $_[0]->log->is_debug;
Condition0%0/3
$IS_DEBUG // $_[0]->log->is_debug
l!l&&r!l&&!r
000
MC/DC0%0/2
$IS_DEBUG // $_[0]->log->is_debug
$IS_DEBUG $_[0]->log->is_debug
Truth table0%0/3
A // B
A= $IS_DEBUGB= $_[0]->log->is_debug
ABresult
1X1
011
000
131 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::IS_INFO = $IS_INFO // $_[0]->log->is_info;
Condition0%0/3
$IS_INFO // $_[0]->log->is_info
l!l&&r!l&&!r
000
MC/DC0%0/2
$IS_INFO // $_[0]->log->is_info
$IS_INFO $_[0]->log->is_info
Truth table0%0/3
A // B
A= $IS_INFOB= $_[0]->log->is_info
ABresult
1X1
011
000
132 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::IS_WARN = $IS_WARN // $_[0]->log->is_warn;
Condition0%0/3
$IS_WARN // $_[0]->log->is_warn
l!l&&r!l&&!r
000
MC/DC0%0/2
$IS_WARN // $_[0]->log->is_warn
$IS_WARN $_[0]->log->is_warn
Truth table0%0/3
A // B
A= $IS_WARNB= $_[0]->log->is_warn
ABresult
1X1
011
000
133 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::IS_ERROR = $IS_ERROR // $_[0]->log->is_error;
Condition0%0/3
$IS_ERROR // $_[0]->log->is_error
l!l&&r!l&&!r
000
MC/DC0%0/2
$IS_ERROR // $_[0]->log->is_error
$IS_ERROR $_[0]->log->is_error
Truth table0%0/3
A // B
A= $IS_ERRORB= $_[0]->log->is_error
ABresult
1X1
011
000
134 0 ▶ local $MarpaX::Java::ClassFile::Role::Parser::IS_FATAL = $IS_FATAL // $_[0]->log->is_fatal;
Condition0%0/3
$IS_FATAL // $_[0]->log->is_fatal
l!l&&r!l&&!r
000
MC/DC0%0/2
$IS_FATAL // $_[0]->log->is_fatal
$IS_FATAL $_[0]->log->is_fatal
Truth table0%0/3
A // B
A= $IS_FATALB= $_[0]->log->is_fatal
ABresult
1X1
011
000
135 #
136 # Localize recognizer
137 #
138 0 local $MarpaX::Java::ClassFile::Role::Parser::R = Marpa::R2::Scanless::R->new({
139 trace_file_handle => $MARPA_TRACE_FILE_HANDLE,
140 grammar => $_[0]->grammar,
141 exhaustion => $_[0]->exhaustion,
142 trace_terminals => $MarpaX::Java::ClassFile::Role::Parser::IS_TRACE
143 });
144  
145 0 local $MarpaX::Java::ClassFile::Role::Parser::LEX_CONTEXT = 1;
146 0 $_[0]->_read;
147 0 ▶ while ($_[0]->pos < $_[0]->max) { $_[0]->_resume }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->pos < $_[0]->max) 0 0 0
148 0 undef $MarpaX::Java::ClassFile::Role::Parser::LEX_CONTEXT;
149  
150 0 $_[0]->_value
151 }
152  
153 sub exhausted {
154 0 ▶ $_[0]->_set_max($_[0]->pos)
Subroutine exhausted: not called CC=1 SCAR=6.9
Pod undocumented
155 }
156  
157 sub _read {
158 # my ($self) = @_;
159  
160 0 ▶ $_[0]->tracef('read($inputRef, %s)', $_[0]->pos);
Subroutine _read: not called CC=3 SCAR=24.8
161 0 eval {
162 0 my $pos = $MarpaX::Java::ClassFile::Role::Parser::R->read($_[0]->inputRef, $_[0]->pos);
163 #
164 # read() MAY return zero. This happen if there is an event at
165 # the very beginning of the grammar
166 #
167 0 ▶ $_[0]->_set_pos($pos) if ($pos)
Branch: 1 branch
BranchTrueFalseTotal
if $pos 0 0 0
168 };
169 0 ▶ $_[0]->_croak($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
170 0 $_[0]->manageEvents
171 }
172  
173 sub _events {
174 # my ($self) = @_;
175  
176 0 ▶ $_[0]->tracef('events()');
Subroutine _events: not called CC=2 SCAR=17.9
177 0 my $eventsRef = eval { $MarpaX::Java::ClassFile::Role::Parser::R->events };
178 0 ▶ $_[0]->_croak($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
179 0 $eventsRef
180 }
181  
182 sub _value {
183 # my ($self) = @_;
184  
185 0 ▶ $_[0]->tracef('ambiguity_metric()');
Subroutine _value: not called CC=11 SCAR=48.8
186 0 my $ambiguity_metric = eval { $MarpaX::Java::ClassFile::Role::Parser::R->ambiguity_metric() };
187 0 ▶ $_[0]->_croak($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
188 0 ▶ $_[0]->_croak('Ambiguity metric is undefined') if (! defined($ambiguity_metric));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ambiguity_metric 0 0 0
189 0 ▶ $_[0]->_croak('Parse is ambiguous') if ($ambiguity_metric != 1);
Branch: 1 branch
BranchTrueFalseTotal
if $ambiguity_metric != 1 0 0 0
190  
191 0 $_[0]->tracef('value($_[0])');
192 #
193 # Registration hook ?
194 #
195 0 my $marpaRecceHook = $_[0]->marpaRecceHook;
196 0 ▶ $MarpaX::Java::ClassFile::Role::Parser::R->registrations($_registrations{ref($_[0])}) if ($marpaRecceHook && defined($_registrations{ref($_[0])}));
Branch: 1 branch
BranchTrueFalseTotal
if $marpaRecceHook and defined $_registrations{ref $_[0]} 0 0 0
Condition0%0/3
$marpaRecceHook and defined $_registrations{ref $_[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
$marpaRecceHook and defined $_registrations{ref $_[0]}
$marpaRecceHook defined $_registrations{ref $_[0]}
Truth table0%0/3
A and B
A= $marpaRecceHookB= defined $_registrations{ref $_[0]}
ABresult
0X0
100
111
197 0 my $valueRef = eval { $MarpaX::Java::ClassFile::Role::Parser::R->value($_[0]) };
198 #
199 # Register hooks if not already the case
200 #
201 0 ▶ $_registrations{ref($_[0])} = $MarpaX::Java::ClassFile::Role::Parser::R->registrations if ($marpaRecceHook && ! defined($_registrations{ref($_[0])}));
Branch: 1 branch
BranchTrueFalseTotal
if $marpaRecceHook and not defined $_registrations{ref $_[0]} 0 0 0
Condition0%0/3
$marpaRecceHook and not defined $_registrations{ref $_[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
$marpaRecceHook and not defined $_registrations{ref $_[0]}
$marpaRecceHook not defined $_registrations{ref $_[0]}
Truth table0%0/3
A and not(B)
A= $marpaRecceHookB= not defined $_registrations{ref $_[0]}
ABresult
0X0
100
111
202 0 ▶ $_[0]->_croak($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
203 0 ▶ $_[0]->_croak('Value reference is undefined') if (! defined($valueRef));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $valueRef 0 0 0
204  
205 0 my $value = ${$valueRef};
206 0 ▶ $_[0]->_croak('Value is undefined') if (! defined($value));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
207  
208 0 $value
209 }
210  
211 sub _resume {
212 # my ($self) = @_;
213  
214 0 ▶ $_[0]->tracef('resume(%s)', $_[0]->pos);
Subroutine _resume: not called CC=2 SCAR=17.9
215 0 eval { $_[0]->_set_pos($MarpaX::Java::ClassFile::Role::Parser::R->resume($_[0]->pos)) };
216 0 ▶ $_[0]->_croak($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
217 0 $_[0]->manageEvents
218 }
219  
220 sub _literal {
221 # my ($self, $symbol) = @_;
222  
223 0 ▶ $_[0]->tracef('last_completed_span(\'%s\')', $_[1]);
Subroutine _literal: not called CC=2 SCAR=17.9
224 0 my @span = $MarpaX::Java::ClassFile::Role::Parser::R->last_completed_span($_[1]);
225 0 ▶ $_[0]->_croak("No symbol instance for the symbol $_[1]") if (! @span);
Branch: 1 branch
BranchTrueFalseTotal
unless @span 0 0 0
226 0 $_[0]->tracef('literal(%s, %s)', $span[0], $span[1]);
227 0 $MarpaX::Java::ClassFile::Role::Parser::R->literal(@span)
228 }
229  
230 sub _pause {
231 # my ($self, $symbol) = @_;
232  
233 0 ▶ $_[0]->tracef('pause_span()');
Subroutine _pause: not called CC=2 SCAR=17.9
234 0 my @span = $MarpaX::Java::ClassFile::Role::Parser::R->pause_span();
235 0 ▶ $_[0]->_croak('No pause span') if (! @span);
Branch: 1 branch
BranchTrueFalseTotal
unless @span 0 0 0
236 0 $_[0]->tracef('literal(%s, %s)', $span[0], $span[1]);
237 0 $MarpaX::Java::ClassFile::Role::Parser::R->literal(@span)
238 }
239  
240 #
241 # Helpers to read a U1/U2/U4/MANAGED lexemes
242 #
243 sub _lexeme_read_helper {
244 # my ($self, $lexeme_name, $lexeme_length, $ignoreEvents) = @_;
245  
246 0 ▶ if ($_[2]) {
Subroutine _lexeme_read_helper: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 0 0 0
247 0 ▶ $_[0]->fatalf('Not enough bytes, pos=%d, max=%d, asking for %d', $_[0]->pos, $_[0]->max, $_[2]) if ($_[2] + $_[0]->pos > $_[0]->max);
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] + $_[0]->pos > $_[0]->max 0 0 0
248 0 my $bytes = substr(${$_[0]->inputRef}, $_[0]->pos, $_[2]);
249 0 $_[0]->lexeme_read($_[1], $_[2], $bytes, $_[3])
250 } else {
251 0 $_[0]->lexeme_read($_[1], 0, undef, $_[3])
252 }
253 }
254  
255 sub lexeme_read_u1 {
256 # my ($self, $ignoreEvents) = @_;
257 0 ▶ $_[0]->_lexeme_read_helper('U1', 1, $_[1])
Subroutine lexeme_read_u1: not called CC=1 SCAR=6.9
Pod undocumented
258 }
259  
260 sub lexeme_read_u2 {
261 # my ($self, $ignoreEvents) = @_;
262 0 ▶ $_[0]->_lexeme_read_helper('U2', 2, $_[1])
Subroutine lexeme_read_u2: not called CC=1 SCAR=6.9
Pod undocumented
263 }
264  
265 sub lexeme_read_u4 {
266 # my ($self, $ignoreEvents) = @_;
267 0 ▶ $_[0]->_lexeme_read_helper('U4', 4, $_[1])
Subroutine lexeme_read_u4: not called CC=1 SCAR=6.9
Pod undocumented
268 }
269  
270 sub lexeme_read_managed {
271 # my ($self, $lexeme_length, $ignoreEvents) = @_;
272 0 ▶ $_[0]->_lexeme_read_helper('MANAGED', $_[1], $_[2])
Subroutine lexeme_read_managed: not called CC=1 SCAR=6.9
Pod undocumented
273 }
274  
275 sub lexeme_read {
276 # my ($self, $lexeme_name, $lexeme_length, $lexeme_value, $ignoreEvents) = @_;
277  
278 #
279 # If the length is zero, force the read to be at position 0.
280 # We will anyway explicitely re-set position and it works
281 # because we always do $MarpaX::Java::ClassFile::Role::Parser::R->resume($self->pos) -;
282 #
283 0 ▶ my $_lexeme_length = $_[2] || 1;
Subroutine lexeme_read: not called CC=7 SCAR=40.3
Pod undocumented
Condition0%0/2
$_[2] || 1
l!l
00
MC/DC0%0/1
$_[2] || 1
$_[2]
Truth table0%0/2
A
A= $_[2]
Aresult
11
00
284 0 ▶ my $_lexeme_pos = $_[2] ? $_[0]->pos : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
285 0 $_[0]->tracef('lexeme_read(\'%s\', %s, %s, $value)', $_[1], $_lexeme_pos, $_lexeme_length);
286 0 my $pos;
287 0 eval {
288 #
289 # Do the lexeme_read in any case
290 #
291 0 ▶ $pos = $MarpaX::Java::ClassFile::Role::Parser::R->lexeme_read($_[1], $_lexeme_pos, $_lexeme_length, $_[3]) || croak sprintf('lexeme_read failure for symbol %s at position %s, length %s', $_[1], $_lexeme_pos, $_lexeme_length);
Condition0%0/3
$MarpaX::Java::ClassFile::Role::Parser::R->lexeme_read($_[1], $_lexeme_pos, $_lexeme_length, $_[3]) || croak(sprintf('lexeme_read failure for symbol %s at position %s, length %s', $_[1], $_lexeme_pos, $_lexeme_length))
l!l&&r!l&&!r
000
MC/DC0%0/2
$MarpaX::Java::ClassFile::Role::Parser::R->lexeme_read($_[1], $_lexeme_pos, $_lexeme_length, $_[3]) || croak(sprintf('lexeme_read failure for symbol %s at position %s, length %s', $_[1], $_lexeme_pos, $_lexeme_length))
$MarpaX::Java::ClassFile::Role::Parser::R->lexeme_read($_[1], $_lexeme_pos, $_lexeme_length, $_[3]) croak(sprintf('lexeme_read failure for symbol %s at position %s, length %s', $_[1], $_lexeme_pos, $_lexeme_length))
Truth table0%0/3
A || B
A= $MarpaX::Java::ClassFile::Role::Parser::R->lexeme_read($_[1], $_lexeme_pos, $_lexeme_length, $_[3])B= croak(sprintf('lexeme_read failure for symbol %s at position %s, length %s', $_[1], $_lexeme_pos, $_lexeme_length))
ABresult
1X1
011
000
292 #
293 # And commit its return position unless length is 0
294 # It is illegal to do a lexeme_read with a length <= 0, so it is guaranteed here
295 # that position has moved
296 #
297 0 ▶ $_[0]->_set_pos($pos) if ($_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 0 0 0
298 };
299 0 ▶ $_[0]->_croak($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
300 0 ▶ $_[0]->manageEvents unless ($_[4])
Branch: 1 branch
BranchTrueFalseTotal
unless $_[4] 0 0 0
301 }
302  
303 sub pauseU1 {
304 # my ($self, $symbol) = @_;
305  
306 0 ▶ my $u1 = $_[0]->u1($_[0]->_pause);
Subroutine pauseU1: not called CC=1 SCAR=6.9
Pod undocumented
307 0 $_[0]->tracef('Got u1=%s', $u1);
308 0 $u1
309 }
310  
311 sub pauseSignedU1 {
312 # my ($self, $symbol) = @_;
313  
314 0 ▶ my $signedU1 = $_[0]->signedU1($_[0]->_pause);
Subroutine pauseSignedU1: not called CC=1 SCAR=6.9
Pod undocumented
315 0 $_[0]->tracef('Got signedU1=%s', $signedU1);
316 0 $signedU1
317 }
318  
319 sub pauseU2 {
320 # my ($self, $symbol) = @_;
321  
322 0 ▶ my $u2 = $_[0]->u2($_[0]->_pause);
Subroutine pauseU2: not called CC=1 SCAR=6.9
Pod undocumented
323 0 $_[0]->tracef('Got u2=%s', $u2);
324 0 $u2
325 }
326  
327 sub pauseSignedU2 {
328 # my ($self, $symbol) = @_;
329  
330 0 ▶ my $signedU2 = $_[0]->signedU2($_[0]->_pause);
Subroutine pauseSignedU2: not called CC=1 SCAR=6.9
Pod undocumented
331 0 $_[0]->tracef('Got signedU2=%s', $signedU2);
332 0 $signedU2
333 }
334  
335 sub pauseU4 {
336 # my ($self, $symbol) = @_;
337  
338 0 ▶ my $u4 = $_[0]->u4($_[0]->_pause);
Subroutine pauseU4: not called CC=1 SCAR=6.9
Pod undocumented
339 0 $_[0]->tracef('Got u4=%s', $u4);
340 0 $u4
341 }
342  
343 sub pauseSignedU4 {
344 # my ($self, $symbol) = @_;
345  
346 0 ▶ my $signedU4 = $_[0]->signedU4($_[0]->_pause);
Subroutine pauseSignedU4: not called CC=1 SCAR=6.9
Pod undocumented
347 0 $_[0]->tracef('Got signedU4=%s', $signedU4);
348 0 $signedU4
349 }
350  
351 sub literalU1 {
352 # my ($self, $symbol) = @_;
353  
354 0 ▶ my $u1 = $_[0]->u1($_[0]->_literal($_[1]));
Subroutine literalU1: not called CC=1 SCAR=6.9
Pod undocumented
355 0 $_[0]->tracef('Got u1=%s', $u1);
356 0 $u1
357 }
358  
359 sub literalSignedU1 {
360 # my ($self, $symbol) = @_;
361  
362 0 ▶ my $signedU1 = $_[0]->signedU1($_[0]->_literal($_[1]));
Subroutine literalSignedU1: not called CC=1 SCAR=6.9
Pod undocumented
363 0 $_[0]->tracef('Got signedU1=%s', $signedU1);
364 0 $signedU1
365 }
366  
367 sub literalU2 {
368 # my ($self, $_[1]) = @_;
369  
370 0 ▶ my $u2 = $_[0]->u2($_[0]->_literal($_[1]));
Subroutine literalU2: not called CC=1 SCAR=6.9
Pod undocumented
371 0 $_[0]->tracef('Got u2=%s', $u2);
372 0 $u2
373 }
374  
375 sub literalSignedU2 {
376 # my ($self, $symbol) = @_;
377  
378 0 ▶ my $signedU2 = $_[0]->signedU2($_[0]->_literal($_[1]));
Subroutine literalSignedU2: not called CC=1 SCAR=6.9
Pod undocumented
379 0 $_[0]->tracef('Got signedU2=%s', $signedU2);
380 0 $signedU2
381 }
382  
383 sub literalU4 {
384 # my ($self, $symbol) = @_;
385  
386 0 ▶ my $u4 = $_[0]->u4($_[0]->_literal($_[1]));
Subroutine literalU4: not called CC=1 SCAR=6.9
Pod undocumented
387 0 $_[0]->tracef('Got u4=%s', $u4);
388 0 $u4
389 }
390  
391 sub literalSignedU4 {
392 # my ($self, $symbol) = @_;
393  
394 0 ▶ my $signedU4 = $_[0]->signedU4($_[0]->_literal($_[1]));
Subroutine literalSignedU4: not called CC=1 SCAR=6.9
Pod undocumented
395 0 $_[0]->tracef('Got signedU4=%s', $signedU4);
396 0 $signedU4
397 }
398  
399 sub literal {
400 # my ($self, $symbol) = @_;
401  
402 0 ▶ $_[0]->_literal($_[1])
Subroutine literal: not called CC=1 SCAR=6.9
Pod undocumented
403 }
404  
405 sub activate {
406 # my ($self, $eventName, $status) = @_;
407  
408 0 ▶ $_[0]->tracef('activate(\'%s\', %s)', $_[1], $_[2]);
Subroutine activate: not called CC=1 SCAR=6.9
Pod undocumented
409 0 $MarpaX::Java::ClassFile::Role::Parser::R->activate($_[1], $_[2])
410 }
411  
412 #
413 # An inner grammar is an opaque thing, so associated
414 # lexeme must be MANAGED.
415 #
416 sub _inner {
417 # my ($self, $innerGrammarClass, $ignoreEvent, %args) = @_;
418  
419 0 ▶ my $innerClass = "MarpaX::Java::ClassFile::BNF::$_[1]";
Subroutine _inner: not called CC=5 SCAR=34.0
420 #
421 # Even if MarpaX::Java::ClassFile::Role::Parser::InnerGrammar is able to hangle size == 0
422 # stand-alone, there is really no need to go throw an object creation
423 # when we know that the result /will be/ []
424 #
425 0 my %args = @_[3..$#_];
426 0 ▶ if ($_DOES_INNERGRAMMAR{$innerClass} //= $innerClass->DOES('MarpaX::Java::ClassFile::Role::Parser::InnerGrammar') ? 1 : 0) { # To make sure this is defined
Branch: 2 branches
BranchTrueFalseTotal
if ($_DOES_INNERGRAMMAR{$innerClass} //= $innerClass->DOES("MarpaX::Java::ClassFile::Role::Parser::InnerGrammar") ? 1 : 0) 0 0 0
$innerClass->DOES('MarpaX::Java::ClassFile::Role::Parser::InnerGrammar') ? : 0 0 0
Condition0%0/3
$_DOES_INNERGRAMMAR{$innerClass} //= $innerClass->DOES("MarpaX::Java::ClassFile::Role::Parser::InnerGrammar") ? 1 : 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$_DOES_INNERGRAMMAR{$innerClass} //= $innerClass->DOES("MarpaX::Java::ClassFile::Role::Parser::InnerGrammar") ? 1 : 0
$_DOES_INNERGRAMMAR{$innerClass} $innerClass->DOES("MarpaX::Java::ClassFile::Role::Parser::InnerGrammar") ? 1 : 0
Truth table0%0/3
A //= B
A= $_DOES_INNERGRAMMAR{$innerClass}B= $innerClass->DOES("MarpaX::Java::ClassFile::Role::Parser::InnerGrammar") ? 1 : 0
ABresult
1X1
011
000
427 0 ▶ if (! $args{size}) { # ok if undef
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"size"}) 0 0 0
428 # $_[0]->tracef('Bypassing inner grammar %s at position %s, with%s outside event, extra arguments: %s', $innerClass, $_[0]->pos, $_[2] ? 'out' : '', { @_[3..$#_] });
429 0 $_[0]->lexeme_read('MANAGED', 0, [], $_[2]);
430 0 return []
431 }
432 }
433 # $_[0]->tracef('Starting inner grammar %s at position %s, with%s outside event, extra arguments: %s', $innerClass, $_[0]->pos, $_[2] ? 'out' : '', { @_[3..$#_] });
434 0 my $inner = $innerClass->new(parent => $_[0],
435 constant_pool_count => $_[0]->constant_pool_count,
436 constant_pool => $_[0]->constant_pool,
437 inputRef => $_[0]->inputRef,
438 pos => $_[0]->pos,
439 log => $_[0]->log,
440 %args);
441 0 my $innerGrammarValue = $inner->ast;
442 0 $_[0]->lexeme_read('MANAGED', $inner->pos - $_[0]->pos, $innerGrammarValue, $_[2]);
443 0 $innerGrammarValue
444 }
445 0 ▶sub inner { $_[0]->_inner($_[1], 0, @_[2..$#_]) }
Subroutine inner: not called CC=1 SCAR=6.9
Pod undocumented
446 0 ▶sub inner_silent { $_[0]->_inner($_[1], 1, @_[2..$#_]) }
Subroutine inner_silent: not called CC=1 SCAR=6.9
Pod undocumented
447  
448 #
449 # Logging/croak stuff : voluntarily not optimized
450 #
451 sub _dolog {
452 0 ▶ my ($self, $method, $format, @arguments) = @_;
Subroutine _dolog: not called CC=2 SCAR=17.9
453 #
454 # If we are in an action, we do nothing else
455 # but propage the message to the log handler
456 # as-is. Current and max positions are meaningul
457 # only in the lexing phase, that may not use
458 # another level but TRACE btw -;
459 #
460 0 ▶ if ($MarpaX::Java::ClassFile::Role::Parser::LEX_CONTEXT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MarpaX::Java::ClassFile::Role::Parser::LEX_CONTEXT) { } 0 0 0
461 0 my $inputLength = length(${$self->inputRef});
462 0 my $nbcharacters = length("$inputLength");
463 0 my ($offset, $max) = ($self->pos, $self->max);
464  
465 0 $self->log->$method("[pos %*s->%*s] %s: $format", $nbcharacters, $offset, $nbcharacters, $self->max, $self->whoami, @arguments)
466 } else {
467 0 $self->log->$method("%s: $format", $self->whoami, @arguments)
468 }
469 }
470  
471 sub debugf {
472 0 ▶ my ($self, $format, @arguments) = @_;
Subroutine debugf: not called CC=2 SCAR=17.9
Pod undocumented
473  
474 0 ▶ return unless $MarpaX::Java::ClassFile::Role::Parser::IS_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $MarpaX::Java::ClassFile::Role::Parser::IS_DEBUG 0 0 0
475 0 $self->_dolog('debugf', $format, @arguments)
476 }
477  
478 sub infof {
479 0 ▶ my ($self, $format, @arguments) = @_;
Subroutine infof: not called CC=2 SCAR=17.9
Pod undocumented
480  
481 0 ▶ return unless $MarpaX::Java::ClassFile::Role::Parser::IS_INFO;
Branch: 1 branch
BranchTrueFalseTotal
unless $MarpaX::Java::ClassFile::Role::Parser::IS_INFO 0 0 0
482 0 $self->_dolog('infof', $format, @arguments);
483 }
484  
485 sub errorf {
486 0 ▶ my ($self, $format, @arguments) = @_;
Subroutine errorf: not called CC=2 SCAR=17.9
Pod undocumented
487  
488 0 ▶ return unless $MarpaX::Java::ClassFile::Role::Parser::IS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
unless $MarpaX::Java::ClassFile::Role::Parser::IS_ERROR 0 0 0
489 0 $self->_dolog('errorf', $format, @arguments)
490 }
491  
492 sub warnf {
493 0 ▶ my ($self, $format, @arguments) = @_;
Subroutine warnf: not called CC=2 SCAR=17.9
Pod undocumented
494  
495 0 ▶ return unless $MarpaX::Java::ClassFile::Role::Parser::IS_WARN;
Branch: 1 branch
BranchTrueFalseTotal
unless $MarpaX::Java::ClassFile::Role::Parser::IS_WARN 0 0 0
496 0 $self->_dolog('warnf', $format, @arguments)
497 }
498  
499 sub tracef {
500 0 ▶ my ($self, $format, @arguments) = @_;
Subroutine tracef: not called CC=2 SCAR=17.9
Pod undocumented
501  
502 0 ▶ return unless $MarpaX::Java::ClassFile::Role::Parser::IS_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
unless $MarpaX::Java::ClassFile::Role::Parser::IS_TRACE 0 0 0
503 0 $self->_dolog('tracef', $format, @arguments)
504 }
505  
506 sub fatalf {
507 0 ▶ my ($self, $format, @arguments) = @_;
Subroutine fatalf: not called CC=2 SCAR=17.9
Pod undocumented
508  
509 0 ▶ $self->_dolog('fatalf', $format, @arguments) if ($MarpaX::Java::ClassFile::Role::Parser::IS_FATAL);
Branch: 1 branch
BranchTrueFalseTotal
if $MarpaX::Java::ClassFile::Role::Parser::IS_FATAL 0 0 0
510 0 croak sprintf($format, @arguments)
511 }
512  
513 sub _croak {
514 0 ▶ my ($self, $msg) = @_;
Subroutine _croak: not called CC=3 SCAR=24.8
515  
516 0 ▶ $msg //= '';
Condition0%0/2
$msg //= ""
l!l
00
MC/DC0%0/1
$msg //= ""
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
517 #
518 # Should never happen that $self->_r is not set at this stage but who knows
519 #
520 0 ▶ $msg .= "\nContext:\n" . $MarpaX::Java::ClassFile::Role::Parser::R->show_progress if $MarpaX::Java::ClassFile::Role::Parser::LEX_CONTEXT;
Branch: 1 branch
BranchTrueFalseTotal
if $MarpaX::Java::ClassFile::Role::Parser::LEX_CONTEXT 0 0 0
521 0 croak($msg)
522 }
523  
524 2 with qw/MooX::Log::Any MarpaX::Java::ClassFile::Role::Parser::Actions/;
525  
526 2 requires 'callbacks';
527 2 requires 'grammar';
528  
529 #
530 # Marpa Hooks
531 #
532 sub BEGIN {
533 #
534 # Marpa internal optimisation: we do not want the closures to be rechecked every time
535 # we call $r->value(). This is a static information, although determined at run-time
536 # the first time $r->value() is called on a recognizer.
537 #
538 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
539 2 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
540  
541 sub Marpa::R2::Recognizer::registrations {
542 0 ▶ my $recce = shift;
Subroutine registrations: not called CC=6 SCAR=37.4
543 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
544 0 my $hash = shift;
545 0 ▶ if (! defined($hash) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $hash or ref $hash ne "HASH" or grep {not exists $hash->{$_};} "NULL_VALUES", "REGISTRATIONS", "CLOSURE_BY_SYMBOL_ID", "CLOSURE_BY_RULE_ID", "RESOLVE_PACKAGE", "RESOLVE_PACKAGE_SOURCE", "PER_PARSE_CONSTRUCTOR") 0 0 0
Condition0%0/6
not defined $hash or ref $hash ne "HASH" or grep {not exists $hash->{$_};} "NULL_VALUES", "REGISTRATIONS", "CLOSURE_BY_SYMBOL_ID", "CLOSURE_BY_RULE_ID", "RESOLVE_PACKAGE", "RESOLVE_PACKAGE_SOURCE", "PER_PARSE_CONSTRUCTOR"
l!l&&r!l&&!r
000
not defined $hash or ref $hash ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $hash or ref $hash ne "HASH" or grep {not exists $hash->{$_};} "NULL_VALUES", "REGISTRATIONS", "CLOSURE_BY_SYMBOL_ID", "CLOSURE_BY_RULE_ID", "RESOLVE_PACKAGE", "RESOLVE_PACKAGE_SOURCE", "PER_PARSE_CONSTRUCTOR"
not defined $hash ref $hash ne "HASH" grep {not exists $hash->{$_};} "NULL_VALUES", "REGISTRATIONS", "CLOSURE_BY_SYMBOL_ID", "CLOSURE_BY_RULE_ID", "RESOLVE_PACKAGE", "RESOLVE_PACKAGE_SOURCE", "PER_PARSE_CONSTRUCTOR"
Truth table0%0/4
not(A) or B or C
A= not defined $hashB= ref $hash ne "HASH"C= grep {not exists $hash->{$_};} "NULL_VALUES", "REGISTRATIONS", "CLOSURE_BY_SYMBOL_ID", "CLOSURE_BY_RULE_ID", "RESOLVE_PACKAGE", "RESOLVE_PACKAGE_SOURCE", "PER_PARSE_CONSTRUCTOR"
ABCresult
1XX1
01X1
0011
0000
546 ref($hash) ne 'HASH' ||
547 0 grep {! exists($hash->{$_})} qw/
548 NULL_VALUES
549 REGISTRATIONS
550 CLOSURE_BY_SYMBOL_ID
551 CLOSURE_BY_RULE_ID
552 RESOLVE_PACKAGE
553 RESOLVE_PACKAGE_SOURCE
554 PER_PARSE_CONSTRUCTOR
555 /) {
556 Marpa::R2::exception(
557 "Attempt to reuse registrations failed:\n",
558 " Registration data is not a hash containing all necessary keys:\n",
559 0 ▶ " Got : " . ((ref($hash) eq 'HASH') ? join(', ', sort keys %{$hash}) : '') . "\n",
Branch: 1 branch
BranchTrueFalseTotal
ref $hash eq 'HASH' ? : 0 0 0
560 " Want: CLOSURE_BY_RULE_ID, CLOSURE_BY_SYMBOL_ID, NULL_VALUES, PER_PARSE_CONSTRUCTOR, REGISTRATIONS, RESOLVE_PACKAGE, RESOLVE_PACKAGE_SOURCE\n"
561 );
562 }
563 0 $recce->[Marpa::R2::Internal::Recognizer::NULL_VALUES] = $hash->{NULL_VALUES};
564 0 $recce->[Marpa::R2::Internal::Recognizer::REGISTRATIONS] = $hash->{REGISTRATIONS};
565 0 $recce->[Marpa::R2::Internal::Recognizer::CLOSURE_BY_SYMBOL_ID] = $hash->{CLOSURE_BY_SYMBOL_ID};
566 0 $recce->[Marpa::R2::Internal::Recognizer::CLOSURE_BY_RULE_ID] = $hash->{CLOSURE_BY_RULE_ID};
567 0 $recce->[Marpa::R2::Internal::Recognizer::RESOLVE_PACKAGE] = $hash->{RESOLVE_PACKAGE};
568 0 $recce->[Marpa::R2::Internal::Recognizer::RESOLVE_PACKAGE_SOURCE] = $hash->{RESOLVE_PACKAGE_SOURCE};
569 $recce->[Marpa::R2::Internal::Recognizer::PER_PARSE_CONSTRUCTOR] = $hash->{PER_PARSE_CONSTRUCTOR}
570 0 }
571 return {
572 0 NULL_VALUES => $recce->[Marpa::R2::Internal::Recognizer::NULL_VALUES],
573 REGISTRATIONS => $recce->[Marpa::R2::Internal::Recognizer::REGISTRATIONS],
574 CLOSURE_BY_SYMBOL_ID => $recce->[Marpa::R2::Internal::Recognizer::CLOSURE_BY_SYMBOL_ID],
575 CLOSURE_BY_RULE_ID => $recce->[Marpa::R2::Internal::Recognizer::CLOSURE_BY_RULE_ID],
576 RESOLVE_PACKAGE => $recce->[Marpa::R2::Internal::Recognizer::RESOLVE_PACKAGE],
577 RESOLVE_PACKAGE_SOURCE => $recce->[Marpa::R2::Internal::Recognizer::RESOLVE_PACKAGE_SOURCE],
578 PER_PARSE_CONSTRUCTOR => $recce->[Marpa::R2::Internal::Recognizer::PER_PARSE_CONSTRUCTOR]
579 }
580 }
581  
582 sub Marpa::R2::Scanless::R::registrations {
583 0 ▶ my $slr = shift;
Subroutine registrations: not called CC=1 SCAR=6.9
584 0 my $thick_g1_recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE];
585 0 $thick_g1_recce->registrations(@_)
586 }
587 }
588  
589  
590 2 1;
591  
592 __END__
593  
594 =pod
595  
596 =encoding UTF-8
597  
598 =head1 NAME
599  
600 MarpaX::Java::ClassFile::Role::Parser - Parsing engine role for .class file parsing
601  
602 =head1 VERSION
603  
604 version 0.008
605  
606 =head1 DESCRIPTION
607  
608 MarpaX::Java::ClassFile::Role::Parser is the parse engine role used by L<MarpaX::Java::ClassFile::ClassFile>, please refer to the later.
609  
610 =head1 AUTHOR
611  
612 Jean-Damien Durand <jeandamiendurand@free.fr>
613  
614 =head1 COPYRIGHT AND LICENSE
615  
616 This software is copyright (c) 2016 by Jean-Damien Durand.
617  
618 This is free software; you can redistribute it and/or modify it under
619 the same terms as the Perl 5 programming language system itself.
620  
621 =cut
↑ Summary ClassFile/Role/Parser/Actions.pm »