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;
136 String(bool constant) {
138 flags |= JOC_TYPE_CONST;
141 String *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;
155 Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
157 const char *Encode(CYPool &pool) const override;
158 CYType *Decode(CYPool &pool) const override;
160 ffi_type *GetFFI(CYPool &pool) const override;
161 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
162 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
168 Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
170 const char *Encode(CYPool &pool) const override;
171 CYType *Decode(CYPool &pool) const override;
173 ffi_type *GetFFI(CYPool &pool) const override;
174 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
175 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
189 Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
191 const char *Encode(CYPool &pool) const override;
192 CYType *Decode(CYPool &pool) const override;
194 ffi_type *GetFFI(CYPool &pool) const override;
195 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
196 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
204 Pointer(Type &type) :
209 Pointer *Copy(CYPool &pool, const char *rename = NULL) const override;
211 const char *Encode(CYPool &pool) const override;
212 CYType *Decode(CYPool &pool) const override;
214 ffi_type *GetFFI(CYPool &pool) const override;
215 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
216 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
225 Array(Type &type, size_t size = _not(size_t)) :
231 Array *Copy(CYPool &pool, const char *rename = NULL) const override;
233 const char *Encode(CYPool &pool) const override;
234 CYType *Decode(CYPool &pool) const override;
236 ffi_type *GetFFI(CYPool &pool) const override;
237 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
238 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
247 Object(const char *name = NULL) :
252 Object *Copy(CYPool &pool, const char *rename = NULL) const override;
254 const char *Encode(CYPool &pool) const override;
255 CYType *Decode(CYPool &pool) const override;
257 ffi_type *GetFFI(CYPool &pool) const override;
258 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
259 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
277 Enum(Type &type, unsigned count, const char *name = NULL) :
285 Enum *Copy(CYPool &pool, const char *rename = NULL) const override;
286 const char *GetName() const override;
288 const char *Encode(CYPool &pool) const override;
289 CYType *Decode(CYPool &pool) const override;
291 ffi_type *GetFFI(CYPool &pool) const override;
292 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
293 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
303 Aggregate(bool overlap, const char *name = NULL) :
309 Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
310 const char *GetName() const override;
312 const char *Encode(CYPool &pool) const override;
313 CYType *Decode(CYPool &pool) const override;
315 ffi_type *GetFFI(CYPool &pool) const override;
316 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
317 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
325 CYType *Decode(CYPool &pool) const override;
326 virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0;
334 Function(bool variadic) :
339 Function *Copy(CYPool &pool, const char *rename = NULL) const override;
341 const char *Encode(CYPool &pool) const override;
342 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
344 ffi_type *GetFFI(CYPool &pool) const override;
345 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
346 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
353 Block *Copy(CYPool &pool, const char *rename = NULL) const override;
355 const char *Encode(CYPool &pool) const override;
356 CYType *Decode(CYPool &pool) const override;
357 CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
359 ffi_type *GetFFI(CYPool &pool) const override;
360 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
361 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
365 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
366 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
370 #endif/*SIG_TYPES_H*/