From bd6c52e8d470f990ed0f1396765860aa3458827d Mon Sep 17 00:00:00 2001 From: rfm Date: Mon, 21 Oct 2024 19:25:51 +0100 Subject: [PATCH] Add skipping of generics in a few more places. --- Tools/AGSParser.m | 74 ++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/Tools/AGSParser.m b/Tools/AGSParser.m index 8a051f796..bce7821aa 100644 --- a/Tools/AGSParser.m +++ b/Tools/AGSParser.m @@ -1855,34 +1855,21 @@ - (NSMutableArray*) parseDeclarations */ if ([self parseSpace] < length && buffer[pos] == '<') { - unsigned save = pos; - NSString *p; + NSArray *protocols = [self parseProtocolList]; - do - { - pos++; - p = [self parseIdentifier]; - if (p != nil) - { - [a addObject: p]; - } - } - while ([self parseSpace] < length && buffer[pos] == ','); - if ('>' == buffer[pos]) - { - pos++; - [self parseSpace]; + if (protocols) + { + [a addObjectsFromArray: protocols]; [a sortUsingSelector: @selector(compare:)]; [t appendString: @"<"]; [t appendString: [a componentsJoinedByString: @","]]; [t appendString: @">"]; [a removeAllObjects]; - } - else - { - pos = save; - [self skipGeneric]; - } + } + else + { + [self skipGeneric]; + } } baseType = t; } @@ -2464,7 +2451,7 @@ - (NSMutableDictionary*) parseImplementation { pos++; if ((base = [self parseIdentifier]) == nil - || [self parseSpace] >= length) + || [self parseSpaceOrGeneric] >= length) { [self log: @"@interface with bad base class"]; goto fail; @@ -2561,7 +2548,7 @@ - (NSMutableDictionary*) parseInterface } if ((name = [self parseIdentifier]) == nil - || [self parseSpace] >= length) + || [self parseSpaceOrGeneric] >= length) { [self log: @"interface with bad name"]; goto fail; @@ -2626,7 +2613,17 @@ - (NSMutableDictionary*) parseInterface if (protocols == nil) { - goto fail; + unsigned saved = pos; + + if ([self skipGeneric] > saved) + { + [self parseSpace]; + } + else + { + [self log: @"bad protocol list"]; + goto fail; + } } else if ([protocols count] > 0) { @@ -4329,6 +4326,7 @@ - (NSMutableDictionary*) parseProtocol if (protocols == nil) { + [self log: @"bad protocol list"]; goto fail; } else if ([protocols count] > 0) @@ -4389,6 +4387,7 @@ - (NSMutableArray*) parseProtocolList { NSMutableArray *protocols; NSString *p; + unsigned start = pos; protocols = [NSMutableArray arrayWithCapacity: 2]; pos++; @@ -4411,7 +4410,7 @@ - (NSMutableArray*) parseProtocolList if (pos >= length || buffer[pos] != '>' || ++pos >= length || [self parseSpace] >= length || [protocols count] == 0) { - [self log: @"bad protocol list"]; + pos = start; return nil; } return protocols; @@ -4523,7 +4522,28 @@ - (unsigned) parseSpace: (NSCharacterSet*)spaceSet - (unsigned) parseSpace { - return [self parseSpace: spacenl]; + [self parseSpace: spacenl]; + return pos; +} + +- (unsigned) parseSpaceOrGeneric +{ + [self parseSpace: spacenl]; + + if (pos < length && '<' == buffer[pos]) + { + unsigned saved = pos; + + if ([self skipGeneric] > saved) + { + [self parseSpace]; + } + else + { + [self log: @"bad generic"]; + } + } + return pos; } - (NSString*) parseVersion