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;
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 CYTypedIdentifier *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 CYTypedIdentifier *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 CYTypedIdentifier *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 CYTypedIdentifier *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 CYTypedIdentifier *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;
140 Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
142 const char *Encode(CYPool &pool) const override;
143 CYTypedIdentifier *Decode(CYPool &pool) const override;
145 ffi_type *GetFFI(CYPool &pool) const override;
146 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
147 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
153 Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
155 const char *Encode(CYPool &pool) const override;
156 CYTypedIdentifier *Decode(CYPool &pool) const override;
158 ffi_type *GetFFI(CYPool &pool) const override;
159 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
160 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
173 Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
175 const char *Encode(CYPool &pool) const override;
176 CYTypedIdentifier *Decode(CYPool &pool) const override;
178 ffi_type *GetFFI(CYPool &pool) const override;
179 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
180 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
188 Pointer(Type &type) :
193 Pointer *Copy(CYPool &pool, const char *rename = NULL) const override;
195 const char *Encode(CYPool &pool) const override;
196 CYTypedIdentifier *Decode(CYPool &pool) const override;
198 ffi_type *GetFFI(CYPool &pool) const override;
199 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
200 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
209 Array(Type &type, size_t size = _not(size_t)) :
215 Array *Copy(CYPool &pool, const char *rename = NULL) const override;
217 const char *Encode(CYPool &pool) const override;
218 CYTypedIdentifier *Decode(CYPool &pool) const override;
220 ffi_type *GetFFI(CYPool &pool) const override;
221 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
222 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
230 Object(const char *name = NULL) :
235 Object *Copy(CYPool &pool, const char *rename = NULL) const override;
237 const char *Encode(CYPool &pool) const override;
238 CYTypedIdentifier *Decode(CYPool &pool) const override;
240 ffi_type *GetFFI(CYPool &pool) const override;
241 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
242 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
252 Aggregate(bool overlap, const char *name = NULL) :
258 Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
259 const char *GetName() const override;
261 const char *Encode(CYPool &pool) const override;
262 CYTypedIdentifier *Decode(CYPool &pool) const override;
264 ffi_type *GetFFI(CYPool &pool) const override;
265 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
266 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
274 CYTypedIdentifier *Decode(CYPool &pool) const override;
275 virtual CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const = 0;
283 Function(bool variadic) :
288 Function *Copy(CYPool &pool, const char *rename = NULL) const override;
290 const char *Encode(CYPool &pool) const override;
291 CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override;
293 ffi_type *GetFFI(CYPool &pool) const override;
294 void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
295 JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
301 Block *Copy(CYPool &pool, const char *rename = NULL) const override;
303 const char *Encode(CYPool &pool) const override;
304 CYTypedIdentifier *Decode(CYPool &pool) const override;
305 CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) 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;
312 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
313 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);
317 #endif/*SIG_TYPES_H*/