1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
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.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
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/>.
28 #include <JavaScriptCore/JSBase.h>
36 #include "Standard.hpp"
40 struct CYTypedParameter;
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)
60 virtual Type *Copy(CYPool &pool, const char *rename = NULL) const = 0;
61 virtual const char *GetName() const;
63 virtual const char *Encode(CYPool &pool) const = 0;
64 virtual CYType *Decode(CYPool &pool) const = 0;
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;
71 template <typename Type_>
75 Primitive *Copy(CYPool &pool, const char *name) const {
76 return new(pool) Primitive();
79 const char *Encode(CYPool &pool) const override;
80 CYType *Decode(CYPool &pool) const override;
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;
101 Void *Copy(CYPool &pool, const char *rename = NULL) const override;
103 const char *Encode(CYPool &pool) const override;
104 CYType *Decode(CYPool &pool) const override;
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;
114 Unknown *Copy(CYPool &pool, const char *rename = NULL) const override;
116 const char *Encode(CYPool &pool) const override;
117 CYType *Decode(CYPool &pool) const override;
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;
127 String *Copy(CYPool &pool, const char *rename = NULL) const override;
129 const char *Encode(CYPool &pool) const override;
130 CYType *Decode(CYPool &pool) const override;
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;
141 Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
143 const char *Encode(CYPool &pool) const override;
144 CYType *Decode(CYPool &pool) const override;
146 ffi_type *GetFFI(CYPool &pool) const override;
147 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
148 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
154 Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
156 const char *Encode(CYPool &pool) const override;
157 CYType *Decode(CYPool &pool) const override;
159 ffi_type *GetFFI(CYPool &pool) const override;
160 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
161 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
175 Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
177 const char *Encode(CYPool &pool) const override;
178 CYType *Decode(CYPool &pool) const override;
180 ffi_type *GetFFI(CYPool &pool) const override;
181 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
182 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
190 Pointer(Type &type) :
195 Pointer *Copy(CYPool &pool, const char *rename = NULL) const override;
197 const char *Encode(CYPool &pool) const override;
198 CYType *Decode(CYPool &pool) const override;
200 ffi_type *GetFFI(CYPool &pool) const override;
201 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
202 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
211 Array(Type &type, size_t size = _not(size_t)) :
217 Array *Copy(CYPool &pool, const char *rename = NULL) const override;
219 const char *Encode(CYPool &pool) const override;
220 CYType *Decode(CYPool &pool) const override;
222 ffi_type *GetFFI(CYPool &pool) const override;
223 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
224 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
233 Object(const char *name = NULL) :
238 Object *Copy(CYPool &pool, const char *rename = NULL) const override;
240 const char *Encode(CYPool &pool) const override;
241 CYType *Decode(CYPool &pool) const override;
243 ffi_type *GetFFI(CYPool &pool) const override;
244 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
245 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
263 Enum(Type &type, unsigned count, const char *name = NULL) :
271 Enum *Copy(CYPool &pool, const char *rename = NULL) const override;
272 const char *GetName() const override;
274 const char *Encode(CYPool &pool) const override;
275 CYType *Decode(CYPool &pool) const override;
277 ffi_type *GetFFI(CYPool &pool) const override;
278 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
279 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
289 Aggregate(bool overlap, const char *name = NULL) :
295 Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
296 const char *GetName() const override;
298 const char *Encode(CYPool &pool) const override;
299 CYType *Decode(CYPool &pool) const override;
301 ffi_type *GetFFI(CYPool &pool) const override;
302 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
303 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
311 CYType *Decode(CYPool &pool) const override;
312 virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0;
320 Function(bool variadic) :
325 Function *Copy(CYPool &pool, const char *rename = NULL) const override;
327 const char *Encode(CYPool &pool) const override;
328 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
330 ffi_type *GetFFI(CYPool &pool) const override;
331 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
332 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
339 Block *Copy(CYPool &pool, const char *rename = NULL) const override;
341 const char *Encode(CYPool &pool) const override;
342 CYType *Decode(CYPool &pool) const override;
343 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
345 ffi_type *GetFFI(CYPool &pool) const override;
346 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
347 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
351 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
352 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
356 #endif/*SIG_TYPES_H*/