mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-10 08:10:49 +00:00
Add -where to report the current parser line and position within it
This commit is contained in:
parent
57f066442e
commit
1f5af5388b
2 changed files with 248 additions and 175 deletions
|
@ -124,6 +124,7 @@
|
|||
- (unsigned) skipToEndOfLine;
|
||||
- (unsigned) skipUnit;
|
||||
- (NSMutableArray*) sources;
|
||||
- (NSString*) where;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3859,7 +3859,9 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
{
|
||||
NSString *directive = [self parseIdentifier];
|
||||
|
||||
if ([directive isEqual: @"define"] && inHeader)
|
||||
if ([directive isEqual: @"define"])
|
||||
{
|
||||
if (inHeader)
|
||||
{
|
||||
NSMutableDictionary *defn;
|
||||
|
||||
|
@ -3875,7 +3877,8 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
{
|
||||
if (dict == nil)
|
||||
{
|
||||
dict = [[NSMutableDictionary alloc] initWithCapacity: 8];
|
||||
dict = [[NSMutableDictionary alloc]
|
||||
initWithCapacity: 8];
|
||||
[info setObject: dict forKey: @"Macros"];
|
||||
RELEASE(dict);
|
||||
}
|
||||
|
@ -3899,6 +3902,15 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
}
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Macro definition inside source is ignored since it is not
|
||||
* visible to the outside world.
|
||||
*/
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
}
|
||||
else if ([directive isEqual: @"endif"])
|
||||
{
|
||||
|
@ -3910,6 +3922,7 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
{
|
||||
[ifStack removeLastObject];
|
||||
}
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else if ([directive isEqual: @"elif"])
|
||||
{
|
||||
|
@ -3922,6 +3935,7 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
[ifStack removeLastObject];
|
||||
[ifStack addObject: [ifStack lastObject]];
|
||||
}
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else if ([directive isEqual: @"else"])
|
||||
{
|
||||
|
@ -3934,6 +3948,7 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
[ifStack removeLastObject];
|
||||
[ifStack addObject: [ifStack lastObject]];
|
||||
}
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else if ([directive isEqual: @"if"])
|
||||
{
|
||||
|
@ -4061,11 +4076,10 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
}
|
||||
[ifStack addObject: top];
|
||||
RELEASE(top);
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else if ([directive hasPrefix: @"if"])
|
||||
else if ([directive isEqual: @"ifdef"])
|
||||
{
|
||||
BOOL isIfDef = [directive isEqual: @"ifdef"];
|
||||
|
||||
[self parseSpace: spaces];
|
||||
if (pos < length && buffer[pos] != '\n')
|
||||
{
|
||||
|
@ -4075,48 +4089,65 @@ countAttributes(NSSet *keys, NSDictionary *a)
|
|||
top = [[ifStack lastObject] mutableCopy];
|
||||
arg = [self parseIdentifier];
|
||||
if ([arg isEqual: @"NO_GNUSTEP"])
|
||||
{
|
||||
if (isIfDef)
|
||||
{
|
||||
[self log: @"Unexpected #ifdef NO_GNUSTEP (nonsense)"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[top removeObjectForKey: @"MacOS-X"];
|
||||
[top setObject: @"NotMacOS-X" forKey: @"NotMacOS-X"];
|
||||
[top removeObjectForKey: @"OpenStep"];
|
||||
[top setObject: @"NotOpenStep" forKey: @"NotOpenStep"];
|
||||
}
|
||||
}
|
||||
else if ([arg isEqual: @"STRICT_MACOS_X"])
|
||||
{
|
||||
if (isIfDef)
|
||||
{
|
||||
[top removeObjectForKey: @"NotMacOS-X"];
|
||||
[top setObject: @"MacOS-X" forKey: @"MacOS-X"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[top removeObjectForKey: @"MacOS-X"];
|
||||
[top setObject: @"NotMacOS-X" forKey: @"NotMacOS-X"];
|
||||
}
|
||||
}
|
||||
else if ([arg isEqual: @"STRICT_OPENSTEP"])
|
||||
{
|
||||
if (isIfDef)
|
||||
{
|
||||
[top removeObjectForKey: @"NotOpenStep"];
|
||||
[top setObject: @"OpenStep" forKey: @"OpenStep"];
|
||||
}
|
||||
else
|
||||
[ifStack addObject: top];
|
||||
RELEASE(top);
|
||||
}
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else if ([directive isEqual: @"ifndef"])
|
||||
{
|
||||
[self parseSpace: spaces];
|
||||
if (pos < length && buffer[pos] != '\n')
|
||||
{
|
||||
NSMutableDictionary *top;
|
||||
NSString *arg;
|
||||
|
||||
top = [[ifStack lastObject] mutableCopy];
|
||||
arg = [self parseIdentifier];
|
||||
if ([arg isEqual: @"NO_GNUSTEP"])
|
||||
{
|
||||
[top removeObjectForKey: @"MacOS-X"];
|
||||
[top setObject: @"NotMacOS-X" forKey: @"NotMacOS-X"];
|
||||
[top removeObjectForKey: @"OpenStep"];
|
||||
[top setObject: @"NotOpenStep" forKey: @"NotOpenStep"];
|
||||
}
|
||||
else if ([arg isEqual: @"STRICT_MACOS_X"])
|
||||
{
|
||||
[top removeObjectForKey: @"MacOS-X"];
|
||||
[top setObject: @"NotMacOS-X" forKey: @"NotMacOS-X"];
|
||||
}
|
||||
else if ([arg isEqual: @"STRICT_OPENSTEP"])
|
||||
{
|
||||
[top removeObjectForKey: @"OpenStep"];
|
||||
[top setObject: @"NotOpenStep" forKey: @"NotOpenStep"];
|
||||
}
|
||||
}
|
||||
[ifStack addObject: top];
|
||||
RELEASE(top);
|
||||
}
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else if ([directive isEqual: @"import"]
|
||||
|| [directive isEqual: @"include"])
|
||||
{
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self log: @"Warning - unknown preprocessor directive %@", directive];
|
||||
return [self skipRemainderOfLine];
|
||||
}
|
||||
}
|
||||
return [self skipRemainderOfLine];
|
||||
|
@ -4840,7 +4871,7 @@ fail:
|
|||
{
|
||||
while (pos < length)
|
||||
{
|
||||
if (buffer[pos++] == '\n')
|
||||
if ('\n' == buffer[pos++])
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -4975,5 +5006,46 @@ fail:
|
|||
{
|
||||
return AUTORELEASE([source mutableCopy]);
|
||||
}
|
||||
|
||||
- (NSString*) where
|
||||
{
|
||||
int index;
|
||||
int start = 0;
|
||||
int end;
|
||||
NSString *l;
|
||||
NSString *s;
|
||||
|
||||
for (index = [lines count] - 1; index >= 0; index--)
|
||||
{
|
||||
NSNumber *num = [lines objectAtIndex: index];
|
||||
|
||||
if ((start = [num intValue]) <= (int)pos)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index >= [lines count] || index < 0)
|
||||
{
|
||||
start = 0;
|
||||
index = -1;
|
||||
}
|
||||
|
||||
if (index + 1 < [lines count])
|
||||
{
|
||||
end = [[lines objectAtIndex: index + 1] intValue];
|
||||
}
|
||||
else
|
||||
{
|
||||
end = length;
|
||||
}
|
||||
l = [[NSString alloc] initWithCharactersNoCopy: buffer + start
|
||||
length: end - start
|
||||
freeWhenDone: NO];
|
||||
s = [NSString stringWithFormat: @"Character %d in line %d:%@",
|
||||
pos - start, index + 2, l];
|
||||
RELEASE(l);
|
||||
return s;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue