From 57a0d9afaea979af927b060d0334b4c1729fabab Mon Sep 17 00:00:00 2001 From: rfm Date: Mon, 13 Nov 2023 18:57:33 +0000 Subject: [PATCH] Add code to ignore generics markup in declarations. --- Tools/AGSParser.m | 66 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/Tools/AGSParser.m b/Tools/AGSParser.m index 802309fdae..f8ce15c3f7 100644 --- a/Tools/AGSParser.m +++ b/Tools/AGSParser.m @@ -1410,6 +1410,10 @@ - (void) parseDeclaratorInto: (NSMutableDictionary*)d [p appendString: @"("]; pos++; [self parseDeclaratorInto: d]; + if ([self parseSpace] < length && buffer[pos] == '<') + { + [self skipGeneric]; + } if ([self parseSpace] < length && buffer[pos] == '(') { [self parseArgsInto: d]; // parse function args. @@ -1520,7 +1524,7 @@ - (NSMutableDictionary*) parseDeclaration goto fail; } if (([s isEqual: @"__attribute__"]) - || ([s isEqual: @"__asm__"])) + || ([s isEqual: @"__asm__"])) { if ([self skipSpaces] < length && buffer[pos] == '(') { @@ -1843,10 +1847,11 @@ - (NSMutableDictionary*) parseDeclaration /* - * Handle protocol specification if necessary + * Handle protocol or generic specification if necessary */ if ([self parseSpace] < length && buffer[pos] == '<') { + unsigned save = pos; NSString *p; do @@ -1859,13 +1864,21 @@ - (NSMutableDictionary*) parseDeclaration } } while ([self parseSpace] < length && buffer[pos] == ','); - pos++; - [self parseSpace]; - [a sortUsingSelector: @selector(compare:)]; - [t appendString: @"<"]; - [t appendString: [a componentsJoinedByString: @","]]; - [t appendString: @">"]; - [a removeAllObjects]; + if ('>' == buffer[pos]) + { + pos++; + [self parseSpace]; + [a sortUsingSelector: @selector(compare:)]; + [t appendString: @"<"]; + [t appendString: [a componentsJoinedByString: @","]]; + [t appendString: @">"]; + [a removeAllObjects]; + } + else + { + pos = save; + [self skipGeneric]; + } } [d setObject: t forKey: @"BaseType"]; @@ -1932,6 +1945,10 @@ - (NSMutableDictionary*) parseDeclaration if ([self parseSpace] < length) { + if (buffer[pos] == '<') + { + [self skipGeneric]; + } if (buffer[pos] == '[') { NSMutableString *suffix; @@ -4929,6 +4946,37 @@ - (unsigned) skipBlock: (BOOL*)isEmpty return pos; } +- (unsigned) skipGeneric +{ + unsigned depth = 0; + unsigned save = pos; + + NSAssert(buffer[pos] == '<', NSInternalInconsistencyException); + while (pos < length) + { + unichar c = buffer[pos++]; + + if (c == '\\') + { + pos++; + } + else if ('<' == c) + { + depth++; + } + else if ('>' == c && --depth == 0) + { + break; + } + } + if (depth > 0 + || (pos < length && buffer[pos - 1] != '>')) + { + return save; + } + return pos; +} + - (unsigned) skipLiteral { unichar term = buffer[pos++];