1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 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"
39 struct CYTypedIdentifier;
43 #define JOC_TYPE_INOUT (1 << 0)
44 #define JOC_TYPE_IN (1 << 1)
45 #define JOC_TYPE_BYCOPY (1 << 2)
46 #define JOC_TYPE_OUT (1 << 3)
47 #define JOC_TYPE_BYREF (1 << 4)
48 #define JOC_TYPE_CONST (1 << 5)
49 #define JOC_TYPE_ONEWAY (1 << 6)
59 virtual Type *Copy(CYPool &pool, const char *name = NULL) const = 0;
60 virtual const char *GetName() const;
62 virtual const char *Encode(CYPool &pool) const = 0;
63 virtual CYTypedIdentifier *Decode(CYPool &pool) const = 0;
65 virtual ffi_type *GetFFI(CYPool &pool) const = 0;
66 virtual void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const = 0;
67 virtual JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize = false, JSObjectRef owner = NULL) const = 0;
69 virtual size_t Translate(Type *&type) const {
74 template <typename Type_>
78 Primitive *Copy(CYPool &pool, const char *name) const {
79 return new(pool) Primitive();
82 const char *Encode(CYPool &pool) const override;
83 CYTypedIdentifier *Decode(CYPool &pool) const override;
85 ffi_type *GetFFI(CYPool &pool) const override;
86 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
87 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
104 Void *Copy(CYPool &pool, const char *name = NULL) const override;
106 const char *Encode(CYPool &pool) const override;
107 CYTypedIdentifier *Decode(CYPool &pool) const override;
109 ffi_type *GetFFI(CYPool &pool) const override;
110 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
111 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
117 Unknown *Copy(CYPool &pool, const char *name = NULL) const override;
119 const char *Encode(CYPool &pool) const override;
120 CYTypedIdentifier *Decode(CYPool &pool) const override;
122 ffi_type *GetFFI(CYPool &pool) const override;
123 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
124 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
130 String *Copy(CYPool &pool, const char *name = NULL) const override;
132 const char *Encode(CYPool &pool) const override;
133 CYTypedIdentifier *Decode(CYPool &pool) const override;
135 ffi_type *GetFFI(CYPool &pool) const override;
136 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
137 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
143 Meta *Copy(CYPool &pool, const char *name = NULL) const override;
145 const char *Encode(CYPool &pool) const override;
146 CYTypedIdentifier *Decode(CYPool &pool) const override;
148 ffi_type *GetFFI(CYPool &pool) const override;
149 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
150 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
156 Selector *Copy(CYPool &pool, const char *name = NULL) const override;
158 const char *Encode(CYPool &pool) const override;
159 CYTypedIdentifier *Decode(CYPool &pool) const override;
161 ffi_type *GetFFI(CYPool &pool) const override;
162 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
163 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
176 Bits *Copy(CYPool &pool, const char *name = NULL) const override;
178 const char *Encode(CYPool &pool) const override;
179 CYTypedIdentifier *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;
191 Pointer(Type &type) :
196 Pointer *Copy(CYPool &pool, const char *name = NULL) const override;
198 const char *Encode(CYPool &pool) const override;
199 CYTypedIdentifier *Decode(CYPool &pool) const override;
201 ffi_type *GetFFI(CYPool &pool) const override;
202 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
203 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
212 Array(Type &type, size_t size = _not(size_t)) :
218 Array *Copy(CYPool &pool, const char *name = NULL) const override;
220 const char *Encode(CYPool &pool) const override;
221 CYTypedIdentifier *Decode(CYPool &pool) const override;
223 ffi_type *GetFFI(CYPool &pool) const override;
224 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
225 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
227 size_t Translate(Type *&type) const override {
238 Object(const char *name = NULL) :
243 Object *Copy(CYPool &pool, const char *name = NULL) const override;
244 const char *GetName() const override;
246 const char *Encode(CYPool &pool) const override;
247 CYTypedIdentifier *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;
261 Aggregate(bool overlap, const char *name = NULL) :
267 Aggregate *Copy(CYPool &pool, const char *name = NULL) const override;
268 const char *GetName() const override;
270 const char *Encode(CYPool &pool) const override;
271 CYTypedIdentifier *Decode(CYPool &pool) const override;
273 ffi_type *GetFFI(CYPool &pool) const override;
274 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
275 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
287 Function *Copy(CYPool &pool, const char *name = NULL) const override;
289 const char *Encode(CYPool &pool) const override;
290 CYTypedIdentifier *Decode(CYPool &pool) const override;
292 ffi_type *GetFFI(CYPool &pool) const override;
293 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
294 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
300 Block *Copy(CYPool &pool, const char *name = NULL) const override;
302 const char *Encode(CYPool &pool) const override;
303 CYTypedIdentifier *Decode(CYPool &pool) const override;
305 ffi_type *GetFFI(CYPool &pool) const override;
306 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
307 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
310 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
311 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
315 #endif/*SIG_TYPES_H*/