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;
107 Void *Copy(CYPool &pool, const char *rename = NULL) const override;
109 const char *Encode(CYPool &pool) const override;
110 CYType *Decode(CYPool &pool) const override;
112 ffi_type *GetFFI(CYPool &pool) const override;
113 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
114 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
120 Unknown *Copy(CYPool &pool, const char *rename = NULL) const override;
122 const char *Encode(CYPool &pool) const override;
123 CYType *Decode(CYPool &pool) const override;
125 ffi_type *GetFFI(CYPool &pool) const override;
126 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
127 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
133 String *Copy(CYPool &pool, const char *rename = NULL) const override;
135 const char *Encode(CYPool &pool) const override;
136 CYType *Decode(CYPool &pool) const override;
138 ffi_type *GetFFI(CYPool &pool) const override;
139 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
140 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
147 Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
149 const char *Encode(CYPool &pool) const override;
150 CYType *Decode(CYPool &pool) const override;
152 ffi_type *GetFFI(CYPool &pool) const override;
153 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
154 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
160 Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
162 const char *Encode(CYPool &pool) const override;
163 CYType *Decode(CYPool &pool) const override;
165 ffi_type *GetFFI(CYPool &pool) const override;
166 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
167 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
181 Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
183 const char *Encode(CYPool &pool) const override;
184 CYType *Decode(CYPool &pool) const override;
186 ffi_type *GetFFI(CYPool &pool) const override;
187 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
188 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
196 Pointer(Type &type) :
201 Pointer *Copy(CYPool &pool, const char *rename = NULL) const override;
203 const char *Encode(CYPool &pool) const override;
204 CYType *Decode(CYPool &pool) const override;
206 ffi_type *GetFFI(CYPool &pool) const override;
207 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
208 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
217 Array(Type &type, size_t size = _not(size_t)) :
223 Array *Copy(CYPool &pool, const char *rename = NULL) const override;
225 const char *Encode(CYPool &pool) const override;
226 CYType *Decode(CYPool &pool) const override;
228 ffi_type *GetFFI(CYPool &pool) const override;
229 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
230 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
239 Object(const char *name = NULL) :
244 Object *Copy(CYPool &pool, const char *rename = NULL) const override;
246 const char *Encode(CYPool &pool) const override;
247 CYType *Decode(CYPool &pool) const override;
249 ffi_type *GetFFI(CYPool &pool) const override;
250 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
251 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
269 Enum(Type &type, unsigned count, const char *name = NULL) :
277 Enum *Copy(CYPool &pool, const char *rename = NULL) const override;
278 const char *GetName() const override;
280 const char *Encode(CYPool &pool) const override;
281 CYType *Decode(CYPool &pool) const override;
283 ffi_type *GetFFI(CYPool &pool) const override;
284 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
285 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
295 Aggregate(bool overlap, const char *name = NULL) :
301 Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
302 const char *GetName() const override;
304 const char *Encode(CYPool &pool) const override;
305 CYType *Decode(CYPool &pool) const override;
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;
317 CYType *Decode(CYPool &pool) const override;
318 virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0;
326 Function(bool variadic) :
331 Function *Copy(CYPool &pool, const char *rename = NULL) const override;
333 const char *Encode(CYPool &pool) const override;
334 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
336 ffi_type *GetFFI(CYPool &pool) const override;
337 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
338 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
345 Block *Copy(CYPool &pool, const char *rename = NULL) const override;
347 const char *Encode(CYPool &pool) const override;
348 CYType *Decode(CYPool &pool) const override;
349 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
351 ffi_type *GetFFI(CYPool &pool) const override;
352 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
353 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
357 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
358 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
362 #endif/*SIG_TYPES_H*/