]> git.saurik.com Git - cycript.git/blobdiff - sig/parse.cpp
Redid the trampoline generator in what will hopefully be a more portable fashion.
[cycript.git] / sig / parse.cpp
index 1c0ec2339494bcfeb2f9be18b1ca476c976e8439..05b321373a762960cc500abb8592fac9e18dacb5 100644 (file)
 */
 /* }}} */
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include "minimal/stdlib.h"
-
-#include <apr-1/apr_strings.h>
-
-#include <string.h>
-
+#include <apr_strings.h>
 #include "sig/parse.hpp"
+#include "Error.hpp"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
 namespace sig {
 
@@ -118,7 +114,10 @@ struct Type *Parse_(apr_pool_t *pool, const char **name, char eos, bool named, C
         case '#': type->primitive = typename_P; break;
 
         case '(':
-            type->primitive = union_P;
+            if (type->data.signature.count < 2)
+                type->primitive = struct_P;
+            else
+                type->primitive = union_P;
             next = ')';
         goto aggregate;
 
@@ -157,13 +156,13 @@ struct Type *Parse_(apr_pool_t *pool, const char **name, char eos, bool named, C
 
         case '^':
             type->primitive = pointer_P;
-            if (**name == 'v') {
-                type->data.data.type = NULL;
-                ++*name;
-            } else if (**name == '"') {
+            if (**name == '"') {
                 type->data.data.type = NULL;
             } else {
                 type->data.data.type = Parse_(pool, name, eos, named, callback);
+                sig::Type *&target(type->data.data.type);
+                if (target != NULL && target->primitive == void_P)
+                    target = NULL;
             }
         break;
 
@@ -275,7 +274,7 @@ const char *Unparse(apr_pool_t *pool, struct Type *type) {
             return apr_psprintf(pool, "[%lu%s]", type->data.data.size, value);
         } break;
 
-        case pointer_P: return apr_psprintf(pool, "^%s", type->data.data.type == NULL ? "" : Unparse(pool, type->data.data.type));
+        case pointer_P: return apr_psprintf(pool, "^%s", type->data.data.type == NULL ? "v" : Unparse(pool, type->data.data.type));
         case bit_P: return apr_psprintf(pool, "b%zu", type->data.data.size);
         case char_P: return "c";
         case double_P: return "d";