]> git.saurik.com Git - cycript.git/blame - sig/types.hpp
Add all supported binding API headers to analysis.
[cycript.git] / sig / types.hpp
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
c1d3e52e 2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
b4aa79af
JF
3*/
4
f95d2598 5/* GNU Affero General Public License, Version 3 {{{ */
b4aa79af 6/*
f95d2598
JF
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c15969fd 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598
JF
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b3378a02 19**/
b4aa79af
JF
20/* }}} */
21
ea2d184c
JF
22#ifndef SIG_TYPES_H
23#define SIG_TYPES_H
24
b799113b
JF
25#include <cstdlib>
26#include <stdint.h>
27
0559abf8
JF
28#include <JavaScriptCore/JSBase.h>
29
30#ifdef HAVE_FFI_FFI_H
31#include <ffi/ffi.h>
32#else
33#include <ffi.h>
34#endif
35
37954781 36#include "Standard.hpp"
ea2d184c 37
0559abf8
JF
38class CYPool;
39struct CYTypedIdentifier;
574d4720 40struct CYTypedParameter;
0559abf8 41
ea2d184c
JF
42namespace sig {
43
0559abf8
JF
44#define JOC_TYPE_INOUT (1 << 0)
45#define JOC_TYPE_IN (1 << 1)
46#define JOC_TYPE_BYCOPY (1 << 2)
47#define JOC_TYPE_OUT (1 << 3)
48#define JOC_TYPE_BYREF (1 << 4)
49#define JOC_TYPE_CONST (1 << 5)
50#define JOC_TYPE_ONEWAY (1 << 6)
51
52struct Type {
53 uint8_t flags;
54
55 Type() :
56 flags(0)
57 {
58 }
59
a109809e 60 virtual Type *Copy(CYPool &pool, const char *rename = NULL) const = 0;
0559abf8
JF
61 virtual const char *GetName() const;
62
63 virtual const char *Encode(CYPool &pool) const = 0;
64 virtual CYTypedIdentifier *Decode(CYPool &pool) const = 0;
65
66 virtual ffi_type *GetFFI(CYPool &pool) const = 0;
67 virtual void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const = 0;
68 virtual JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize = false, JSObjectRef owner = NULL) const = 0;
0559abf8
JF
69};
70
71template <typename Type_>
72struct Primitive :
73 Type
74{
75 Primitive *Copy(CYPool &pool, const char *name) const {
76 return new(pool) Primitive();
77 }
78
79 const char *Encode(CYPool &pool) const override;
80 CYTypedIdentifier *Decode(CYPool &pool) const override;
81
82 ffi_type *GetFFI(CYPool &pool) const override;
83 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
84 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
ea2d184c
JF
85};
86
87struct Element {
b799113b 88 const char *name;
0559abf8 89 Type *type;
ea2d184c
JF
90 size_t offset;
91};
92
93struct Signature {
0559abf8 94 Element *elements;
ea2d184c
JF
95 size_t count;
96};
97
0559abf8
JF
98struct Void :
99 Type
100{
a109809e 101 Void *Copy(CYPool &pool, const char *rename = NULL) const override;
ea2d184c 102
0559abf8
JF
103 const char *Encode(CYPool &pool) const override;
104 CYTypedIdentifier *Decode(CYPool &pool) const override;
105
106 ffi_type *GetFFI(CYPool &pool) const override;
107 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
108 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
109};
110
111struct Unknown :
112 Type
113{
a109809e 114 Unknown *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
115
116 const char *Encode(CYPool &pool) const override;
117 CYTypedIdentifier *Decode(CYPool &pool) const override;
118
119 ffi_type *GetFFI(CYPool &pool) const override;
120 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
121 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
122};
123
124struct String :
125 Type
126{
a109809e 127 String *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
128
129 const char *Encode(CYPool &pool) const override;
130 CYTypedIdentifier *Decode(CYPool &pool) const override;
131
132 ffi_type *GetFFI(CYPool &pool) const override;
133 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
134 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
135};
136
137struct Meta :
138 Type
139{
a109809e 140 Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
141
142 const char *Encode(CYPool &pool) const override;
143 CYTypedIdentifier *Decode(CYPool &pool) const override;
144
145 ffi_type *GetFFI(CYPool &pool) const override;
146 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
147 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
148};
149
150struct Selector :
151 Type
152{
a109809e 153 Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
154
155 const char *Encode(CYPool &pool) const override;
156 CYTypedIdentifier *Decode(CYPool &pool) const override;
157
158 ffi_type *GetFFI(CYPool &pool) const override;
159 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
160 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
161};
162
163struct Bits :
164 Type
165{
166 size_t size;
167
168 Bits(size_t size) :
169 size(size)
170 {
171 }
172
a109809e 173 Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
174
175 const char *Encode(CYPool &pool) const override;
176 CYTypedIdentifier *Decode(CYPool &pool) const override;
177
178 ffi_type *GetFFI(CYPool &pool) const override;
179 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
180 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
181};
182
183struct Pointer :
184 Type
185{
186 Type &type;
187
188 Pointer(Type &type) :
189 type(type)
190 {
191 }
192
a109809e 193 Pointer *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
194
195 const char *Encode(CYPool &pool) const override;
196 CYTypedIdentifier *Decode(CYPool &pool) const override;
197
198 ffi_type *GetFFI(CYPool &pool) const override;
199 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
200 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
201};
202
203struct Array :
204 Type
205{
206 Type &type;
207 size_t size;
208
209 Array(Type &type, size_t size = _not(size_t)) :
210 type(type),
211 size(size)
212 {
213 }
214
a109809e 215 Array *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
216
217 const char *Encode(CYPool &pool) const override;
218 CYTypedIdentifier *Decode(CYPool &pool) const override;
219
220 ffi_type *GetFFI(CYPool &pool) const override;
221 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
222 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
0559abf8
JF
223};
224
225struct Object :
226 Type
227{
21d5f610 228 const char *name;
ea2d184c 229
0559abf8
JF
230 Object(const char *name = NULL) :
231 name(name)
232 {
233 }
ea2d184c 234
a109809e 235 Object *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
236
237 const char *Encode(CYPool &pool) const override;
238 CYTypedIdentifier *Decode(CYPool &pool) const override;
239
240 ffi_type *GetFFI(CYPool &pool) const override;
241 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
242 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
ea2d184c
JF
243};
244
0559abf8
JF
245struct Aggregate :
246 Type
247{
248 bool overlap;
249 const char *name;
250 Signature signature;
ea2d184c 251
0559abf8
JF
252 Aggregate(bool overlap, const char *name = NULL) :
253 overlap(overlap),
254 name(name)
255 {
256 }
3fe16be7 257
a109809e 258 Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
259 const char *GetName() const override;
260
261 const char *Encode(CYPool &pool) const override;
262 CYTypedIdentifier *Decode(CYPool &pool) const override;
263
264 ffi_type *GetFFI(CYPool &pool) const override;
265 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
266 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
267};
268
269struct Callable :
270 Type
271{
272 Signature signature;
574d4720
JF
273
274 CYTypedIdentifier *Decode(CYPool &pool) const override;
275 virtual CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const = 0;
0559abf8
JF
276};
277
278struct Function :
279 Callable
280{
574d4720
JF
281 bool variadic;
282
283 Function(bool variadic) :
284 variadic(variadic)
285 {
286 }
287
a109809e 288 Function *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
289
290 const char *Encode(CYPool &pool) const override;
574d4720 291 CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override;
0559abf8
JF
292
293 ffi_type *GetFFI(CYPool &pool) const override;
294 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
295 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
296};
297
298struct Block :
299 Callable
300{
a109809e 301 Block *Copy(CYPool &pool, const char *rename = NULL) const override;
0559abf8
JF
302
303 const char *Encode(CYPool &pool) const override;
304 CYTypedIdentifier *Decode(CYPool &pool) const override;
574d4720 305 CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override;
0559abf8
JF
306
307 ffi_type *GetFFI(CYPool &pool) const override;
308 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
309 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
310};
311
312Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
313void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
bd17e6f3 314
ea2d184c
JF
315}
316
317#endif/*SIG_TYPES_H*/