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 template <typename Type_>
61 _finline Type_ *Flag(Type_ *type) const {
66 virtual Type *Copy(CYPool &pool, const char *rename = NULL) const = 0;
67 virtual const char *GetName() const;
69 virtual const char *Encode(CYPool &pool) const = 0;
70 virtual CYType *Decode(CYPool &pool) const = 0;
72 virtual ffi_type *GetFFI(CYPool &pool) const = 0;
73 virtual void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const = 0;
74 virtual JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize = false, JSObjectRef owner = NULL) const = 0;
77 template <typename Type_>
81 Primitive *Copy(CYPool &pool, const char *name) const {
82 return Flag(new(pool) Primitive());
85 const char *Encode(CYPool &pool) const override;
86 CYType *Decode(CYPool &pool) const override;
88 ffi_type *GetFFI(CYPool &pool) const override;
89 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
90 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
110 Void(bool constant) {
112 flags |= JOC_TYPE_CONST;
115 Void *Copy(CYPool &pool, const char *rename = NULL) const override;
117 const char *Encode(CYPool &pool) const override;
118 CYType *Decode(CYPool &pool) const override;
120 ffi_type *GetFFI(CYPool &pool) const override;
121 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
122 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
128 Unknown *Copy(CYPool &pool, const char *rename = NULL) const override;
130 const char *Encode(CYPool &pool) const override;
131 CYType *Decode(CYPool &pool) const override;
133 ffi_type *GetFFI(CYPool &pool) const override;
134 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
135 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
144 String(bool constant) {
146 flags |= JOC_TYPE_CONST;
149 String *Copy(CYPool &pool, const char *rename = NULL) const override;
151 const char *Encode(CYPool &pool) const override;
152 CYType *Decode(CYPool &pool) const override;
154 ffi_type *GetFFI(CYPool &pool) const override;
155 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
156 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
163 Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
165 const char *Encode(CYPool &pool) const override;
166 CYType *Decode(CYPool &pool) const override;
168 ffi_type *GetFFI(CYPool &pool) const override;
169 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
170 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
176 Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
178 const char *Encode(CYPool &pool) const override;
179 CYType *Decode(CYPool &pool) const override;
181 ffi_type *GetFFI(CYPool &pool) const override;
182 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
183 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
197 Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
199 const char *Encode(CYPool &pool) const override;
200 CYType *Decode(CYPool &pool) const override;
202 ffi_type *GetFFI(CYPool &pool) const override;
203 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
204 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
212 Pointer(Type &type) :
217 Pointer *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 Array(Type &type, size_t size = _not(size_t)) :
239 Array *Copy(CYPool &pool, const char *rename = NULL) const override;
241 const char *Encode(CYPool &pool) const override;
242 CYType *Decode(CYPool &pool) const override;
244 ffi_type *GetFFI(CYPool &pool) const override;
245 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
246 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
255 Object(const char *name = NULL) :
260 Object *Copy(CYPool &pool, const char *rename = NULL) const override;
262 const char *Encode(CYPool &pool) const override;
263 CYType *Decode(CYPool &pool) const override;
265 ffi_type *GetFFI(CYPool &pool) const override;
266 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
267 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
285 Enum(Type &type, unsigned count, const char *name = NULL) :
293 Enum *Copy(CYPool &pool, const char *rename = NULL) const override;
294 const char *GetName() const override;
296 const char *Encode(CYPool &pool) const override;
297 CYType *Decode(CYPool &pool) const override;
299 ffi_type *GetFFI(CYPool &pool) const override;
300 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
301 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
311 Aggregate(bool overlap, const char *name = NULL) :
317 Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
318 const char *GetName() const override;
320 const char *Encode(CYPool &pool) const override;
321 CYType *Decode(CYPool &pool) const override;
323 ffi_type *GetFFI(CYPool &pool) const override;
324 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
325 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
333 CYType *Decode(CYPool &pool) const override;
334 virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0;
342 Function(bool variadic) :
347 Function *Copy(CYPool &pool, const char *rename = NULL) const override;
349 const char *Encode(CYPool &pool) const override;
350 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
352 ffi_type *GetFFI(CYPool &pool) const override;
353 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
354 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
361 Block *Copy(CYPool &pool, const char *rename = NULL) const override;
363 const char *Encode(CYPool &pool) const override;
364 CYType *Decode(CYPool &pool) const override;
365 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
367 ffi_type *GetFFI(CYPool &pool) const override;
368 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
369 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
373 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
374 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
378 #endif/*SIG_TYPES_H*/