1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
package FFI::Platypus::TypeParser;
use strict;
use warnings;
use 5.008004;
use List::Util 1.45 qw( uniqstr );
use Carp qw( croak );
# ABSTRACT: FFI Type Parser
our $VERSION = '2.10'; # VERSION
# The TypeParser and Type classes are used internally ONLY and
# are not to be exposed to the user. External users should
# not under any circumstances rely on the implementation of
# these classes.
sub new
{
my($class) = @_;
my $self = bless { types => {}, type_map => {}, abi => -1 }, $class;
$self->build;
$self;
}
sub build {}
our %basic_type;
# this just checks if the underlying libffi/platypus implementation
# has the basic type. It is used mainly to verify that exotic types
# like longdouble and complex_float are available before the test
# suite tries to use them.
sub have_type
{
my(undef, $name) = @_;
!!$basic_type{$name};
}
sub create_type_custom
{
my($self, $name, @rest) = @_;
$name = 'opaque' unless defined $name;
my $type = $self->parse($name);
unless($type->is_customizable)
{
croak "$name is not a legal basis for a custom type"
}
$self->_create_type_custom($type, @rest);
}
# this is the type map provided by the language plugin, if any
# in addition to the basic types (which map to themselves).
sub type_map
{
my($self, $new) = @_;
if(defined $new)
{
$self->{type_map} = $new;
}
$self->{type_map};
}
# this stores the types that have been mentioned so far. It also
# usually includes aliases.
sub types
{
shift->{types};
}
# The type parser needs to know the ABI when creating closures
sub abi
{
my($self, $new) = @_;
$self->{abi} = $new if defined $new;
$self->{abi};
}
{
my %store;
foreach my $name (keys %basic_type)
{
my $type_code = $basic_type{$name};
$store{basic}->{$name} = __PACKAGE__->create_type_basic($type_code);
$store{ptr}->{$name} = __PACKAGE__->create_type_pointer($type_code);
$store{rev}->{$type_code} = $name;
}
sub global_types
{
\%store;
}
}
# list all the types that this type parser knows about, including
# those provided by the language plugin (if any), those defined
# by the user, and the basic types that everyone gets.
sub list_types
{
my($self) = @_;
uniqstr( ( keys %{ $self->type_map } ), ( keys %{ $self->types } ) );
}
our @CARP_NOT = qw( FFI::Platypus );
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
FFI::Platypus::TypeParser - FFI Type Parser
=head1 VERSION
version 2.10
=head1 DESCRIPTION
This class is private to FFI::Platypus. See L<FFI::Platypus> for
the public interface to Platypus types.
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Bakkiaraj Murugesan (bakkiaraj)
Dylan Cali (calid)
pipcet
Zaki Mughal (zmughal)
Fitz Elliott (felliott)
Vickenty Fesunov (vyf)
Gregor Herrmann (gregoa)
Shlomi Fish (shlomif)
Damyan Ivanov
Ilya Pavlov (Ilya33)
Petr Písař (ppisar)
Mohammad S Anwar (MANWAR)
Håkon Hægland (hakonhagland, HAKONH)
Meredith (merrilymeredith, MHOWARD)
Diab Jerius (DJERIUS)
Eric Brine (IKEGAMI)
szTheory
José Joaquín Atria (JJATRIA)
Pete Houston (openstrike, HOUSTON)
Lukas Mai (MAUKE)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2015-2022 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|