From 4f71429bec9dffe029b2d1f2ee9272aa97ec78fc Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Fri, 23 Mar 2018 09:58:31 +0000 Subject: [PATCH] Add support for parsing extended type encodings. Extended type encodings add more detailed information to object and block types: * Objects are encoded as @"ClassName". * Blocks are encoded as @? In the new ABI, we use classic type encodings for selectors and extended type encodings everywhere else. --- encoding2.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/encoding2.c b/encoding2.c index 8e68019..e6b5b2b 100644 --- a/encoding2.c +++ b/encoding2.c @@ -149,6 +149,31 @@ inline static size_t max(size_t v, size_t v2) return v>v2 ? v : v2; } +static const char *skip_object_extended_qualifiers(const char *type) +{ + if (*(type+1) == '?') + { + type++; + if (*(type+1) == '<') + { + type += 2; + while (*type != '>') + { + type++; + } + } + } + else if (type[1] == '"') + { + type += 2; + while (*type != '"') + { + type++; + } + } + return type; +} + static const char *sizeof_union_field(const char *type, size_t *size); static const char *sizeof_type(const char *type, size_t *size) @@ -172,11 +197,7 @@ static const char *sizeof_type(const char *type, size_t *size) { round_up(size, (alignof(id) * 8)); *size += (sizeof(id) * 8); - if (*(type+1) == '?') - { - type++; - } - return type + 1; + return skip_object_extended_qualifiers(type) + 1; } case '?': case 'v': return type+1; @@ -272,11 +293,7 @@ static const char *alignof_type(const char *type, size_t *align) case '@': { *align = max((alignof(id) * 8), *align);\ - if (*(type+1) == '?') - { - type++; - } - return type + 1; + return skip_object_extended_qualifiers(type) + 1; } case '?': case 'v': return type+1;