]> git.saurik.com Git - cycript.git/blobdiff - Decode.cpp
Find code library, even when relative in debugger.
[cycript.git] / Decode.cpp
index 2187f268c32dc230f01e2bbb9eea0296f1157036..819c675b29d07c4febf0fb5cc04d147da7aac4c0 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 {{{ */
@@ -56,6 +56,13 @@ CYTypedIdentifier *Primitive<signed int>::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 1));
 }
 
+#ifdef __SIZEOF_INT128__
+template <>
+CYTypedIdentifier *Primitive<signed __int128>::Decode(CYPool &pool) const {
+    return $ CYTypedIdentifier($ CYTypeInt128(CYTypeSigned));
+}
+#endif
+
 template <>
 CYTypedIdentifier *Primitive<signed long int>::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 2));
@@ -81,6 +88,13 @@ CYTypedIdentifier *Primitive<unsigned int>::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 1));
 }
 
+#ifdef __SIZEOF_INT128__
+template <>
+CYTypedIdentifier *Primitive<unsigned __int128>::Decode(CYPool &pool) const {
+    return $ CYTypedIdentifier($ CYTypeInt128(CYTypeUnsigned));
+}
+#endif
+
 template <>
 CYTypedIdentifier *Primitive<unsigned long int>::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 2));
@@ -108,6 +122,7 @@ CYTypedIdentifier *String::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeNeutral), $ CYTypePointerTo());
 }
 
+#ifdef CY_OBJECTIVEC
 CYTypedIdentifier *Meta::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeVariable("Class"));
 }
@@ -115,6 +130,7 @@ CYTypedIdentifier *Meta::Decode(CYPool &pool) const {
 CYTypedIdentifier *Selector::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeVariable("SEL"));
 }
+#endif
 
 CYTypedIdentifier *Bits::Decode(CYPool &pool) const {
     _assert(false);
@@ -128,12 +144,14 @@ CYTypedIdentifier *Array::Decode(CYPool &pool) const {
     return CYDecodeType(pool, &type)->Modify($ CYTypeArrayOf($D(size)));
 }
 
+#ifdef CY_OBJECTIVEC
 CYTypedIdentifier *Object::Decode(CYPool &pool) const {
     if (name == NULL)
         return $ CYTypedIdentifier($ CYTypeVariable("id"));
     else
         return $ CYTypedIdentifier($ CYTypeVariable(name), $ CYTypePointerTo());
 }
+#endif
 
 CYTypedIdentifier *Aggregate::Decode(CYPool &pool) const {
     _assert(!overlap);
@@ -150,27 +168,29 @@ CYTypedIdentifier *Aggregate::Decode(CYPool &pool) const {
     return $ CYTypedIdentifier($ CYTypeStruct(identifier, $ CYStructTail(fields)));
 }
 
-CYTypedIdentifier *Function::Decode(CYPool &pool) const {
+CYTypedIdentifier *Callable::Decode(CYPool &pool) const {
     _assert(signature.count != 0);
-    CYTypedParameter *parameter(NULL);
+    CYTypedParameter *parameters(NULL);
     for (size_t i(signature.count - 1); i != 0; --i)
-        parameter = $ CYTypedParameter(CYDecodeType(pool, signature.elements[i].type), parameter);
-    return CYDecodeType(pool, signature.elements[0].type)->Modify($ CYTypeFunctionWith(parameter));
+        parameters = $ CYTypedParameter(CYDecodeType(pool, signature.elements[i].type), parameters);
+    return Modify(pool, CYDecodeType(pool, signature.elements[0].type), parameters);
+}
+
+CYTypedIdentifier *Function::Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const {
+    return result->Modify($ CYTypeFunctionWith(variadic, parameters));
+}
+
+#ifdef CY_OBJECTIVEC
+CYTypedIdentifier *Block::Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const {
+    return result->Modify($ CYTypeBlockWith(parameters));
 }
 
 CYTypedIdentifier *Block::Decode(CYPool &pool) const {
     if (signature.count == 0)
         return $ CYTypedIdentifier($ CYTypeVariable("NSBlock"), $ CYTypePointerTo());
-    else {
-        _assert(signature.count != 1);
-        _assert(dynamic_cast<Object *>(signature.elements[1].type) != NULL);
-
-        CYTypedParameter *parameter(NULL);
-        for (size_t i(signature.count - 1); i != 0; --i)
-            parameter = $ CYTypedParameter(CYDecodeType(pool, signature.elements[i].type), parameter);
-        return CYDecodeType(pool, signature.elements[0].type)->Modify($ CYTypeBlockWith(parameter));
-    }
+    return Callable::Decode(pool);
 }
+#endif
 
 }