]> git.saurik.com Git - cycript.git/blobdiff - sig/types.hpp
Maintain a logical setup for const on sig::String.
[cycript.git] / sig / types.hpp
index 3bed8fd0ca5b8447adbe0c0143b106182388f050..30d8dbdd6106bfa1cfc3b6055124741830687417 100644 (file)
@@ -1,5 +1,5 @@
-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015  Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016  Jay Freeman (saurik)
 */
 
 /* GNU Affero General Public License, Version 3 {{{ */
@@ -36,7 +36,8 @@
 #include "Standard.hpp"
 
 class CYPool;
-struct CYTypedIdentifier;
+struct CYType;
+struct CYTypedParameter;
 
 namespace sig {
 
@@ -56,11 +57,17 @@ struct Type {
     {
     }
 
-    virtual Type *Copy(CYPool &pool, const char *name = NULL) const = 0;
+    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;
@@ -72,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;
@@ -97,10 +104,10 @@ struct Signature {
 struct Void :
     Type
 {
-    Void *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
@@ -110,10 +117,10 @@ struct Void :
 struct Unknown :
     Type
 {
-    Unknown *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
@@ -123,23 +130,32 @@ struct Unknown :
 struct String :
     Type
 {
-    String *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
     JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
 };
 
+#ifdef CY_OBJECTIVEC
 struct Meta :
     Type
 {
-    Meta *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
@@ -149,15 +165,16 @@ struct Meta :
 struct Selector :
     Type
 {
-    Selector *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
     JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
 };
+#endif
 
 struct Bits :
     Type
@@ -169,10 +186,10 @@ struct Bits :
     {
     }
 
-    Bits *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
@@ -189,10 +206,10 @@ struct Pointer :
     {
     }
 
-    Pointer *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
@@ -211,16 +228,17 @@ struct Array :
     {
     }
 
-    Array *Copy(CYPool &pool, const char *name = NULL) const override;
+    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;
     JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
 };
 
+#ifdef CY_OBJECTIVEC
 struct Object :
     Type
 {
@@ -231,11 +249,44 @@ struct Object :
     {
     }
 
-    Object *Copy(CYPool &pool, const char *name = NULL) const override;
+    Object *Copy(CYPool &pool, const char *rename = NULL) 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;
+};
+#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;
-    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;
@@ -255,11 +306,11 @@ struct Aggregate :
     {
     }
 
-    Aggregate *Copy(CYPool &pool, const char *name = NULL) const override;
+    Aggregate *Copy(CYPool &pool, const char *rename = NULL) const override;
     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;
@@ -270,33 +321,46 @@ struct Callable :
     Type
 {
     Signature signature;
+
+    CYType *Decode(CYPool &pool) const override;
+    virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0;
 };
 
 struct Function :
     Callable
 {
-    Function *Copy(CYPool &pool, const char *name = NULL) const override;
+    bool variadic;
+
+    Function(bool variadic) :
+        variadic(variadic)
+    {
+    }
+
+    Function *Copy(CYPool &pool, const char *rename = NULL) const override;
 
     const char *Encode(CYPool &pool) const override;
-    CYTypedIdentifier *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;
     JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
 };
 
+#ifdef CY_OBJECTIVEC
 struct Block :
     Callable
 {
-    Block *Copy(CYPool &pool, const char *name = NULL) const override;
+    Block *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;
+    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;
     JSValueRef FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const override;
 };
+#endif
 
 Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
 void joc_parse_signature(Signature *signature, char **name, char eos, bool variable);