| 1 | package FFI::Platypus::TypeParser::Version0; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 47 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 47 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 47 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 47 | ▶ | use parent qw( FFI::Platypus::TypeParser ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: FFI Type Parser Version Zero | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 47 | our $VERSION = '2.12'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 47 | our @CARP_NOT = qw( FFI::Platypus FFI::Platypus::TypeParser ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # The type parser is responsible for deciding if something is a legal | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # alias name. Since this needs to be checked before the type is parsed | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # it is separate from set_alias below. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | sub check_alias | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 194 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_alias: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 194 | my($self, $alias) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 194 | ▶ | croak "spaces not allowed in alias" if $alias =~ /\s/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 194 | ▶ | croak "allowed characters for alias: [A-Za-z0-9_]" if $alias !~ /^[A-Za-z0-9_]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | croak "alias \"$alias\" conflicts with existing type" | ||||||||||||||||||||||||||||||||||||||||||
| 24 | if defined $self->type_map->{$alias} | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 194 | ▶ | || $self->types->{$alias}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->type_map->{$alias} or $self->types->{$alias}
MC/DC0%0/2
defined $self->type_map->{$alias} or $self->types->{$alias}
defined $self->type_map->{$alias}
$self->types->{$alias}
Truth table33%1/3
A or B
A= defined $self->type_map->{$alias}B= $self->types->{$alias}
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 194 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | sub set_alias | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 194 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_alias: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 194 | my($self, $alias, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 194 | $self->types->{$alias} = $type; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # This method takes a string representation of the a type and | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # returns the internal platypus type representation. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | sub parse | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 2006 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=28 SCAR=33.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2006 | my($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2006 | ▶ | return $self->types->{$name} if defined $self->types->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # Darmock and Legacy Code at Tanagra | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1365 | ▶ | unless($name =~ /-\>/ || $name =~ /^record\s*\([0-9A-Z:a-z_]+\)$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$name =~ /-\>/ or $name =~ /^record\s*\([0-9A-Z:a-z_]+\)$/ or $name =~ /^string(_rw|_ro|\s+rw|\s+ro|\s*\([0-9]+\))$/
$name =~ /-\>/ or $name =~ /^record\s*\([0-9A-Z:a-z_]+\)$/
MC/DC100%3/3
$name =~ /-\>/ or $name =~ /^record\s*\([0-9A-Z:a-z_]+\)$/ or $name =~ /^string(_rw|_ro|\s+rw|\s+ro|\s*\([0-9]+\))$/
$name =~ /-\>/
$name =~ /^record\s*\([0-9A-Z:a-z_]+\)$/
$name =~ /^string(_rw|_ro|\s+rw|\s+ro|\s*\([0-9]+\))$/
Truth table100%4/4
A or B or C
A= $name =~ /-\>/B= $name =~ /^record\s*\([0-9A-Z:a-z_]+\)$/C= $name =~ /^string(_rw|_ro|\s+rw|\s+ro|\s*\([0-9]+\))$/
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | || $name =~ /^string(_rw|_ro|\s+rw|\s+ro|\s*\([0-9]+\))$/) | ||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 1263 | my $basic = $name; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1263 | my $extra = ''; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1263 | ▶ | if($basic =~ s/\s*((\*|\[|\<).*)$//) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 351 | $extra = " $1"; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 1263 | ▶ | if(defined $self->type_map->{$basic}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1228 | my $new_name = $self->type_map->{$basic} . $extra; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1228 | ▶ | if($new_name ne $name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # hopefully no recursion here. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 145 | return $self->types->{$name} = $self->parse($new_name); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1220 | ▶ | if($name =~ m/^ \( (.*) \) \s* -\> \s* (.*) \s* $/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 41 | my @argument_types = map { $self->parse($_) } map { my $t = $_; $t =~ s/^\s+//; $t =~ s/\s+$//; $t } split /,/, $1; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 41 | my $return_type = $self->parse($2); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | return $self->types->{$name} = $self->create_type_closure($self->abi, $return_type, @argument_types); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1179 | ▶ | if($name =~ /^ string \s* \( ([0-9]+) \) $/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | return $self->types->{$name} = $self->create_type_record( | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | $1, # size | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1168 | ▶ | if($name =~ /^ string ( _rw | _ro | \s+ro | \s+rw | ) $/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 67 | ▶ | return $self->types->{$name} = $self->create_type_string( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $1 and $1 =~ /rw/
MC/DC50%1/2
defined $1 and $1 =~ /rw/
defined $1
$1 =~ /rw/
Truth table66%2/3
A and B
A= defined $1B= $1 =~ /rw/
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | defined $1 && $1 =~ /rw/ ? 1 : 0, # rw | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1101 | ▶ | if($name =~ /^ record \s* \( ([0-9]+) \) $/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | return $self->types->{$name} = $self->create_type_record( | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | $1, # size | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1095 | ▶ | if($name =~ /^ record \s* \( ([0-9:A-Za-z_]+) \) $/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 33 | my $size; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 33 | my $classname = $1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 33 | ▶ | unless($classname->can('ffi_record_size') || $classname->can('_ffi_record_size')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$classname->can("ffi_record_size") or $classname->can("_ffi_record_size")
MC/DC0%0/2
$classname->can("ffi_record_size") or $classname->can("_ffi_record_size")
$classname->can("ffi_record_size")
$classname->can("_ffi_record_size")
Truth table66%2/3
A or B
A= $classname->can("ffi_record_size")B= $classname->can("_ffi_record_size")
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $pm = "$classname.pm"; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $pm =~ s/\//::/g; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | require $pm; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 33 | ▶ | if($classname->can('ffi_record_size')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | $size = $classname->ffi_record_size; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | elsif($classname->can('_ffi_record_size')) | ||||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 31 | $size = $classname->_ffi_record_size; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | else | ||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | croak "$classname has not ffi_record_size or _ffi_record_size method"; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 33 | ▶ | return $self->global_types->{record}->{$classname} ||= $self->create_type_record( | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->global_types->{"record"}{$classname} ||= $self->create_type_record(0, $size, $classname)
MC/DC0%0/2
$self->global_types->{"record"}{$classname} ||= $self->create_type_record(0, $size, $classname)
$self->global_types->{"record"}{$classname}
$self->create_type_record(0, $size, $classname)
Truth table66%2/3
A ||= B
A= $self->global_types->{"record"}{$classname}B= $self->create_type_record(0, $size, $classname)
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | $size, # size | ||||||||||||||||||||||||||||||||||||||||||
| 119 | $classname, # record_class | ||||||||||||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | # array types | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 1062 | ▶ | if($name =~ /^([\S]+)\s+ \[ ([0-9]*) \] $/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 205 | ▶ | my $size = $2 || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 || ''
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 205 | ▶ | my $basic = $self->global_types->{basic}->{$1} || croak("unknown ffi/platypus type $name [$size]"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->global_types->{'basic'}{$1} || croak("unknown ffi/platypus type $name [$size]")
MC/DC0%0/1
$self->global_types->{'basic'}{$1} || croak("unknown ffi/platypus type $name [$size]")
$self->global_types->{'basic'}{$1}
Truth table50%1/2
A
A= $self->global_types->{'basic'}{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 205 | ▶ | if($size) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 182 | return $self->types->{$name} = $self->create_type_array( | |||||||||||||||||||||||||||||||||||||||||
| 131 | $basic->type_code, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | $size, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | else | ||||||||||||||||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 23 | ▶ | return $self->global_types->{array}->{$name} ||= $self->create_type_array( | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->global_types->{"array"}{$name} ||= $self->create_type_array($basic->type_code, 0)
MC/DC0%0/2
$self->global_types->{"array"}{$name} ||= $self->create_type_array($basic->type_code, 0)
$self->global_types->{"array"}{$name}
$self->create_type_array($basic->type_code, 0)
Truth table66%2/3
A ||= B
A= $self->global_types->{"array"}{$name}B= $self->create_type_array($basic->type_code, 0)
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | $basic->type_code, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | # pointer types | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 857 | ▶ | if($name =~ s/\s+\*$//) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 80 | ▶ | return $self->global_types->{ptr}->{$name} || croak("unknown ffi/platypus type $name *"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->global_types->{'ptr'}{$name} || croak("unknown ffi/platypus type $name *")
MC/DC0%0/1
$self->global_types->{'ptr'}{$name} || croak("unknown ffi/platypus type $name *")
$self->global_types->{'ptr'}{$name}
Truth table50%1/2
A
A= $self->global_types->{'ptr'}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # basic types | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 777 | ▶ | return $self->global_types->{basic}->{$name} || croak("unknown ffi/platypus type $name"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->global_types->{'basic'}{$name} || croak("unknown ffi/platypus type $name")
MC/DC100%1/1
$self->global_types->{'basic'}{$name} || croak("unknown ffi/platypus type $name")
$self->global_types->{'basic'}{$name}
Truth table100%2/2
A
A= $self->global_types->{'basic'}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 47 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | __END__ | ||||||||||||||||||||||||||||||||||||||||||