Skip to content

Commit

Permalink
Add code to ignore generics markup in declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Nov 13, 2023
1 parent a5cb4d8 commit 57a0d9a
Showing 1 changed file with 57 additions and 9 deletions.
66 changes: 57 additions & 9 deletions Tools/AGSParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1520,7 +1524,7 @@ - (NSMutableDictionary*) parseDeclaration
goto fail;
}
if (([s isEqual: @"__attribute__"])
|| ([s isEqual: @"__asm__"]))
|| ([s isEqual: @"__asm__"]))
{
if ([self skipSpaces] < length && buffer[pos] == '(')
{
Expand Down Expand Up @@ -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
Expand All @@ -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"];
Expand Down Expand Up @@ -1932,6 +1945,10 @@ - (NSMutableDictionary*) parseDeclaration

if ([self parseSpace] < length)
{
if (buffer[pos] == '<')
{
[self skipGeneric];
}
if (buffer[pos] == '[')
{
NSMutableString *suffix;
Expand Down Expand Up @@ -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++];
Expand Down

0 comments on commit 57a0d9a

Please sign in to comment.