Debian Codegraph @

lib/FFI/Platypus/TypeParser.pm

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