X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/e2ce853b4a48f8278dc46e4143aa845b18948651..96d36aaa89e579a53bd5848c22a462ca8eb13f80:/sig/parse.cpp diff --git a/sig/parse.cpp b/sig/parse.cpp index b78015d..7e025f8 100644 --- a/sig/parse.cpp +++ b/sig/parse.cpp @@ -118,10 +118,9 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback name = NULL; else { const char *quote = strchr(*encoding + 1, '"'); - if (quote == NULL) { - printf("unterminated specific id type {%s}\n", *encoding - 10); - _assert(false); - } else if (!named || quote[1] == eos || quote[1] == '"') { + if (quote == NULL) + CYThrow("unterminated specific id type {%s}", *encoding - 10); + else if (!named || quote[1] == eos || quote[1] == '"') { name = pool.strmemdup(*encoding + 1, quote - *encoding - 1); *encoding = quote + 1; } else { @@ -145,10 +144,8 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback case '[': { size_t size(strtoul(*encoding, (char **) encoding, 10)); type = new(pool) Array(*Parse_(pool, encoding, eos, false, callback), size); - if (**encoding != ']') { - printf("']' != \"%s\"\n", *encoding); - _assert(false); - } + if (**encoding != ']') + CYThrow("']' != \"%s\"", *encoding); ++*encoding; } break; @@ -172,6 +169,7 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback break; case 'c': type = new(pool) Primitive(); break; + case 'D': type = new(pool) Primitive(); break; case 'd': type = new(pool) Primitive(); break; case 'f': type = new(pool) Primitive(); break; case 'i': type = new(pool) Primitive(); break; @@ -180,6 +178,11 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback case 's': type = new(pool) Primitive(); break; case 'v': type = new(pool) Void(); break; +#ifdef __SIZEOF_INT128__ + case 't': type = new(pool) Primitive(); break; + case 'T': type = new(pool) Primitive(); break; +#endif + case '{': type = new(pool) Aggregate(false); next = '}'; @@ -190,16 +193,22 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback char end = next; const char *begin = *encoding; - do next = *(*encoding)++; - while ( - next != '=' && - next != '}' - ); + do switch (next = *(*encoding)++) { + case '\0': + _assert(false); + case '}': + // XXX: this is actually a type reference + aggregate->signature.count = _not(size_t); + next = '='; // this is a "break". I'm sorry + } while (next != '='); + size_t length = *encoding - begin - 1; if (strncmp(begin, "?", length) != 0) aggregate->name = (char *) pool.strmemdup(begin, length); - if (next == '=') + if (aggregate->signature.count == _not(size_t)) + aggregate->signature.elements = NULL; + else Parse_(pool, &aggregate->signature, encoding, end, callback); // XXX: this is a hack to support trivial unions @@ -225,8 +234,7 @@ Type *Parse_(CYPool &pool, const char **encoding, char eos, bool named, Callback break; default: - printf("invalid type character: '%c' {%s}\n", next, *encoding - 10); - _assert(false); + CYThrow("invalid type character: '%c' {%s}", next, *encoding - 10); } type->flags = flags; @@ -272,6 +280,11 @@ const char *Primitive::Encode(CYPool &pool) const { return "f"; } +template <> +const char *Primitive::Encode(CYPool &pool) const { + return "D"; +} + template <> const char *Primitive::Encode(CYPool &pool) const { return "c"; @@ -282,6 +295,13 @@ const char *Primitive::Encode(CYPool &pool) const { return "i"; } +#ifdef __SIZEOF_INT128__ +template <> +const char *Primitive::Encode(CYPool &pool) const { + return "t"; +} +#endif + template <> const char *Primitive::Encode(CYPool &pool) const { return "l"; @@ -307,6 +327,13 @@ const char *Primitive::Encode(CYPool &pool) const { return "I"; } +#ifdef __SIZEOF_INT128__ +template <> +const char *Primitive::Encode(CYPool &pool) const { + return "T"; +} +#endif + template <> const char *Primitive::Encode(CYPool &pool) const { return "L"; @@ -362,8 +389,17 @@ const char *Object::Encode(CYPool &pool) const { } #endif +const char *Enum::Encode(CYPool &pool) const { + return type.Encode(pool); +} + const char *Aggregate::Encode(CYPool &pool) const { - return pool.strcat(overlap ? "(" : "{", name == NULL ? "?" : name, "=", Unparse(pool, &signature), overlap ? ")" : "}", NULL); + bool reference(signature.count == _not(size_t)); + return pool.strcat(overlap ? "(" : "{", + name == NULL ? "?" : name, + reference ? "" : "=", + reference ? "" : Unparse(pool, &signature), + overlap ? ")" : "}", NULL); } const char *Function::Encode(CYPool &pool) const {