]> git.saurik.com Git - cycript.git/blobdiff - sig/types.hpp
With -p on all platforms, we can't use asprintf().
[cycript.git] / sig / types.hpp
index ea0a307ade3d2b32b6dc63d624b86e6e50118be3..78729c474efbdae513a32bc979f2789082ff1463 100644 (file)
@@ -36,7 +36,7 @@
 #include "Standard.hpp"
 
 class CYPool;
-struct CYTypedIdentifier;
+struct CYType;
 struct CYTypedParameter;
 
 namespace sig {
@@ -57,11 +57,17 @@ struct Type {
     {
     }
 
+    template <typename Type_>
+    _finline Type_ *Flag(Type_ *type) const {
+        type->flags = flags;
+        return type;
+    }
+
     virtual Type *Copy(CYPool &pool, const char *rename = NULL) const = 0;
     virtual const char *GetName() const;
 
     virtual const char *Encode(CYPool &pool) const = 0;
-    virtual CYTypedIdentifier *Decode(CYPool &pool) const = 0;
+    virtual CYType *Decode(CYPool &pool) const = 0;
 
     virtual ffi_type *GetFFI(CYPool &pool) const = 0;
     virtual void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const = 0;
@@ -73,11 +79,11 @@ struct Primitive :
     Type
 {
     Primitive *Copy(CYPool &pool, const char *name) const {
-        return new(pool) Primitive();
+        return Flag(new(pool) Primitive());
     }
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -98,10 +104,18 @@ struct Signature {
 struct Void :
     Type
 {
+    Void() {
+    }
+
+    Void(bool constant) {
+        if (constant)
+            flags |= JOC_TYPE_CONST;
+    }
+
     Void *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -114,7 +128,7 @@ struct Unknown :
     Unknown *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -124,10 +138,18 @@ struct Unknown :
 struct String :
     Type
 {
+    String() {
+    }
+
+    String(bool constant) {
+        if (constant)
+            flags |= JOC_TYPE_CONST;
+    }
+
     String *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -141,7 +163,7 @@ struct Meta :
     Meta *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -154,7 +176,7 @@ struct Selector :
     Selector *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -175,7 +197,7 @@ struct Bits :
     Bits *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -195,7 +217,7 @@ struct Pointer :
     Pointer *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -217,7 +239,7 @@ struct Array :
     Array *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -238,7 +260,7 @@ struct Object :
     Object *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -246,6 +268,39 @@ struct Object :
 };
 #endif
 
+struct Constant {
+    const char *name;
+    double value;
+};
+
+struct Enum :
+    Type
+{
+    Type &type;
+    unsigned count;
+    const char *name;
+
+    Constant *constants;
+
+    Enum(Type &type, unsigned count, const char *name = NULL) :
+        type(type),
+        count(count),
+        name(name),
+        constants(NULL)
+    {
+    }
+
+    Enum *Copy(CYPool &pool, const char *rename = NULL) const override;
+    const char *GetName() const override;
+
+    const char *Encode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
+
+    ffi_type *GetFFI(CYPool &pool) const override;
+    void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
+    JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
+};
+
 struct Aggregate :
     Type
 {
@@ -263,7 +318,7 @@ struct Aggregate :
     const char *GetName() const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
+    CYType *Decode(CYPool &pool) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -275,8 +330,8 @@ struct Callable :
 {
     Signature signature;
 
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
-    virtual CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const = 0;
+    CYType *Decode(CYPool &pool) const override;
+    virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0;
 };
 
 struct Function :
@@ -292,7 +347,7 @@ struct Function :
     Function *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override;
+    CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;
@@ -306,8 +361,8 @@ struct Block :
     Block *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *Decode(CYPool &pool) const override;
-    CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override;
+    CYType *Decode(CYPool &pool) const override;
+    CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override;
 
     ffi_type *GetFFI(CYPool &pool) const override;
     void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override;