Add code to ignore generics markup in declarations.

This commit is contained in:
rfm 2023-11-13 18:57:33 +00:00
parent a5cb4d8647
commit 57a0d9afae

View file

@ -1410,6 +1410,10 @@ recheck:
[p appendString: @"("]; [p appendString: @"("];
pos++; pos++;
[self parseDeclaratorInto: d]; [self parseDeclaratorInto: d];
if ([self parseSpace] < length && buffer[pos] == '<')
{
[self skipGeneric];
}
if ([self parseSpace] < length && buffer[pos] == '(') if ([self parseSpace] < length && buffer[pos] == '(')
{ {
[self parseArgsInto: d]; // parse function args. [self parseArgsInto: d]; // parse function args.
@ -1520,7 +1524,7 @@ recheck:
goto fail; goto fail;
} }
if (([s isEqual: @"__attribute__"]) if (([s isEqual: @"__attribute__"])
|| ([s isEqual: @"__asm__"])) || ([s isEqual: @"__asm__"]))
{ {
if ([self skipSpaces] < length && buffer[pos] == '(') if ([self skipSpaces] < length && buffer[pos] == '(')
{ {
@ -1843,10 +1847,11 @@ recheck:
/* /*
* Handle protocol specification if necessary * Handle protocol or generic specification if necessary
*/ */
if ([self parseSpace] < length && buffer[pos] == '<') if ([self parseSpace] < length && buffer[pos] == '<')
{ {
unsigned save = pos;
NSString *p; NSString *p;
do do
@ -1859,13 +1864,21 @@ recheck:
} }
} }
while ([self parseSpace] < length && buffer[pos] == ','); while ([self parseSpace] < length && buffer[pos] == ',');
pos++; if ('>' == buffer[pos])
[self parseSpace]; {
[a sortUsingSelector: @selector(compare:)]; pos++;
[t appendString: @"<"]; [self parseSpace];
[t appendString: [a componentsJoinedByString: @","]]; [a sortUsingSelector: @selector(compare:)];
[t appendString: @">"]; [t appendString: @"<"];
[a removeAllObjects]; [t appendString: [a componentsJoinedByString: @","]];
[t appendString: @">"];
[a removeAllObjects];
}
else
{
pos = save;
[self skipGeneric];
}
} }
[d setObject: t forKey: @"BaseType"]; [d setObject: t forKey: @"BaseType"];
@ -1932,6 +1945,10 @@ recheck:
if ([self parseSpace] < length) if ([self parseSpace] < length)
{ {
if (buffer[pos] == '<')
{
[self skipGeneric];
}
if (buffer[pos] == '[') if (buffer[pos] == '[')
{ {
NSMutableString *suffix; NSMutableString *suffix;
@ -4929,6 +4946,37 @@ fail:
return pos; 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 - (unsigned) skipLiteral
{ {
unichar term = buffer[pos++]; unichar term = buffer[pos++];