| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package MarpaX::Languages::IDL::AST::Data::Scan::Impl::Perl5; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Perl5 default implementation for transpiling IDL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.007'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # AUTHORITY | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use MarpaX::Languages::IDL::AST::Data::Scan::Impl::Perl5::_BaseTypes -all; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Scalar::Util qw/blessed reftype/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Types::Standard -all; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Types::Common::Numeric -all; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | LEXEME_START => $[, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | LEXEME_LENGTH => $[ + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | LEXEME_VALUE => $[ + 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | SEMICOLON => ';' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | extends 'MarpaX::Languages::IDL::AST::Data::Scan::Impl::_Default'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | has output => (is => 'rwp', isa => Str); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | has main => (is => 'rwp', isa => Str, default => sub { 'IDL' }, trigger => 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | has indent => (is => 'ro', isa => Str, default => sub { ' ' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | has separator => (is => 'ro', isa => Str, default => sub { ' ' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | has newline => (is => 'ro', isa => Str, default => sub { "\n" } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | has _lines => (is => 'rw', isa => ArrayRef[ArrayRef[Str]]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub _trigger_main { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trigger_main: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my ($self, $main) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->_logger->debugf('main namespace is now %s', $main); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _pushLine { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pushLine: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | push(@{$self->_lines}, $self->level ? [ $self->indent x $self->level ] : [ ]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | after trigger_level => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->_pushLine; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # We do not want to pollute perl5's main namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | around globalScope => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $globalScope = $self->$orig; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($globalScope =~ /^::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $globalScope = join('', $self->main, $globalScope) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $globalScope = $globalScope ? join('::', $self->main, $globalScope) : $self->main | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $globalScope | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # At startup initialize work area and result | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | around dsstart => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($orig, $self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->_lines([]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->_set_output(''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return $self->$orig($item) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # At end set result an reset work area | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | around dsend => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $separator = $self->separator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->_set_output(join($self->newline, map { join($separator, @{$_}) } @{$self->_lines})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->_lines([]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return $self->$orig | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # At dsopen, catch the need to push a new line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | around dsread => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my ($orig, $self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # We identify a token like this: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # this is a blessed array containing only scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # [ start, length, value ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $blessed = blessed($item) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
builtin::blessed($item) // ""
MC/DC0%0/1
builtin::blessed($item) // ""
builtin::blessed($item)
Truth table0%0/2
A
A= builtin::blessed($item)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $blessed =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $reftype = reftype($item) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
builtin::reftype($item) // ""
MC/DC0%0/1
builtin::reftype($item) // ""
builtin::reftype($item)
Truth table0%0/2
A
A= builtin::reftype($item)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $isLexeme = $blessed && $reftype eq 'ARRAY' && scalar(@{$item}) == 3 && ! grep { ref } @{$item}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$blessed && $reftype eq 'ARRAY' && scalar @{$item;} == 3 && !grep({ref $_;} @{$item;})
$blessed and $reftype eq "ARRAY" and scalar @{$item;} == 3
$blessed and $reftype eq "ARRAY"
MC/DC0%0/4
$blessed && $reftype eq 'ARRAY' && scalar @{$item;} == 3 && !grep({ref $_;} @{$item;})
$blessed
$reftype eq "ARRAY"
scalar @{$item;} == 3
!grep({ref $_;} @{$item;})
Truth table0%0/5
A and B and C && not(D)
A= $blessedB= $reftype eq "ARRAY"C= scalar @{$item;} == 3D= !grep({ref $_;} @{$item;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Derive using blessed information | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # ------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($blessed eq 'CPPSTYLEDIRECTIVE') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # ---------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $token = $item->[LEXEME_VALUE]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # We support only the #pragma prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($token =~ /#pragma\s+prefix\s"([^"]+)\"/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $pragma = substr($token, $-[1], $+[1] - $-[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $newPragma = $pragma; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $newPragma =~ s/\./::/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->_set_main($self->main . '::' . $newPragma); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->_logger->infof('Ignored: %s', $token) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # -------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($blessed eq 'TYPEDEF') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # ------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($isLexeme) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $token = $item->[LEXEME_VALUE]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | push(@{$self->_lines->[-1]}, $token); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # We want to force a newline if semicolon or CPP directive | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($token eq SEMICOLON || $blessed eq 'CPPSTYLEDIRECTIVE') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$token eq ";" or $blessed eq "CPPSTYLEDIRECTIVE"
MC/DC0%0/2
$token eq ";" or $blessed eq "CPPSTYLEDIRECTIVE"
$token eq ";"
$blessed eq "CPPSTYLEDIRECTIVE"
Truth table0%0/3
A or B
A= $token eq ";"B= $blessed eq "CPPSTYLEDIRECTIVE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->_pushLine | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return $self->$orig($item) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||