Skip to content

Commit

Permalink
Add diagnostic code and implement lookup for metods in informal proto…
Browse files Browse the repository at this point in the history
…cols
  • Loading branch information
rfm committed Oct 27, 2023
1 parent fa30cfa commit 57f0664
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Source/DocMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ Base_AGSDOC_FLAGS = \
-MacrosTemplate Functions \
-TypedefsTemplate TypesAndConstants \
-VariablesTemplate TypesAndConstants \
-Verbose YES \
-WordMap '{\
}' -Up Base

Expand All @@ -272,7 +271,6 @@ BaseAdditions_AGSDOC_FLAGS = \
-MacrosTemplate Functions \
-TypedefsTemplate TypesAndConstants \
-VariablesTemplate TypesAndConstants \
-Verbose YES \
-WordMap '{\
}' -Up BaseAdditions

Expand Down
1 change: 1 addition & 0 deletions Tools/AGSIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
unsigned ssect;
unsigned sssect;
}
- (NSArray*) find: (NSString*)key;
- (NSString*) globalRef: (NSString*)ref type: (NSString*)type;
- (void) makeRefs: (GSXMLNode*)node;
- (void) mergeRefs: (NSDictionary*)more override: (BOOL)flag;
Expand Down
85 changes: 76 additions & 9 deletions Tools/AGSIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "Foundation/NSArray.h"
#import "Foundation/NSAutoreleasePool.h"
#import "Foundation/NSDictionary.h"
#import "Foundation/NSUserDefaults.h"
#import "AGSIndex.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
#import "GNUstepBase/NSMutableString+GNUstepBase.h"
Expand Down Expand Up @@ -57,29 +58,31 @@
[stack addObject: k];
if (d == nil)
{
if ([s isKindOfClass: [NSString class]] == YES)
if ([s isKindOfClass: [NSString class]])
{
[dst setObject: s forKey: k];
}
else if ([s isKindOfClass: [NSArray class]] == YES)
else if ([s isKindOfClass: [NSArray class]])
{
[dst setObject: s forKey: k];
}
else if ([s isKindOfClass: [NSDictionary class]] == YES)
else if ([s isKindOfClass: [NSDictionary class]])
{
d = [[NSMutableDictionary alloc] initWithCapacity: [s count]];
[dst setObject: d forKey: k];
RELEASE(d);
/* Fall through to populate the new dictionary.
*/
}
else
{
NSLog(@"Unexpected class in merge %@ ignored", stack);
d = nil;
}
}

if (d != nil)
{
if ([d isKindOfClass: [NSString class]] == YES)
if ([d isKindOfClass: [NSString class]])
{
if ([s isKindOfClass: [NSString class]] == NO)
{
Expand All @@ -99,7 +102,7 @@
}
}
}
else if ([d isKindOfClass: [NSArray class]] == YES)
else if ([d isKindOfClass: [NSArray class]])
{
if ([s isKindOfClass: [NSArray class]] == NO)
{
Expand All @@ -118,7 +121,7 @@
}
}
}
else if ([d isKindOfClass: [NSDictionary class]] == YES)
else if ([d isKindOfClass: [NSDictionary class]])
{
if ([s isKindOfClass: [NSDictionary class]] == NO)
{
Expand Down Expand Up @@ -202,6 +205,54 @@ - (void) dealloc
[super dealloc];
}

static void
findKey(id refs, NSString *key, NSMutableArray *path, NSMutableArray *found)
{
if ([refs isKindOfClass: [NSDictionary class]])
{
if ([refs objectForKey: key])
{
[found addObject: AUTORELEASE([path copy])];
}
else
{
NSEnumerator *e = [refs keyEnumerator];
NSString *k;

while ((k = [e nextObject]) != nil)
{
[path addObject: k];
findKey([refs objectForKey: k], key, path, found);
[path removeLastObject];
}
}
}
else if ([refs isKindOfClass: [NSArray class]])
{
if ([refs containsObject: key])
{
[found addObject: AUTORELEASE([path copy])];
}
}
else if ([refs isEqual: key])
{
[found addObject: AUTORELEASE([path copy])];
}
}

/** Looks for a string as a key or value in the index,
* and returns the paths to any occurrences found.
* Returns nil if the string is not found.
*/
- (NSArray*) find: (NSString*)key
{
NSMutableArray *path = [NSMutableArray arrayWithCapacity: 10];
NSMutableArray *found = [NSMutableArray arrayWithCapacity: 10];

findKey(refs, key, path, found);
return ([found count] ? found : nil);
}

- (NSString*) globalRef: (NSString*)ref type: (NSString*)type
{
NSDictionary *t;
Expand Down Expand Up @@ -767,13 +818,29 @@ - (NSString*) unitRef: (NSString*)ref type: (NSString*)type unit: (NSString**)u
if ([*u length] > 0 && [*u characterAtIndex: [*u length] - 1] == ')')
{
*u = [*u substringToIndex: [*u rangeOfString: @"("].location];
s = [t objectForKey: *u];
if (s != nil)
if ((s = [t objectForKey: *u]) != nil)
{
return s;
}
}

/* For a method lookup, try an informal protocol of the class
*/
if ([*u length] > 0 && [type isEqual: @"method"])
{
NSString *p = [NSString stringWithFormat: @"(%@)", *u];

if ((s = [t objectForKey: p]) != nil)
{
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"Warn"])
{
NSLog(@"Warning - found %@ only in informal protocol of %@",
ref, *u);
}
return s;
}
}

/**
* Try all superclasses in turn.
*/
Expand Down
4 changes: 2 additions & 2 deletions Tools/AGSOutput.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static BOOL snuggleStart(NSString *t)
* And finally, here is the actual class description ... outside the chapter.
* This is the class description for <code>AGSOutput</code>, including some
* sample uses of GSDoc, such as cross-references (see [NSString]).
* Functions, like escapeType(), are automatically referenced (if they are
* found).
* Functions, (recognised as an identifier immediately followed by open and
* closing brackets), are automatically referenced (if they are found).
*/
@implementation AGSOutput

Expand Down
1 change: 0 additions & 1 deletion Tools/DocMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ BaseTools_AGSDOC_FLAGS = \
-HeaderDirectory ../Tools \
-Standards YES \
-DTDs ../Tools \
-Verbose YES \
-WordMap '{\
}' -Up BaseTools

Expand Down
42 changes: 36 additions & 6 deletions Tools/autogsdoc.m
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,10 @@ standard PropertyList format (not the XML format of OS X), using
NSDictionary *dict;

[projectRefs mergeRefs: originalIndex override: NO];
if (verbose)
{
NSLog(@"Initialised projectRefs from %@", refsFile);
}
dict = [mgr fileAttributesAtPath: refsFile traverseLink: YES];
rDate = [dict fileModificationDate];
}
Expand Down Expand Up @@ -1596,8 +1600,10 @@ standard PropertyList format (not the XML format of OS X), using
count = [gFiles count];
if (count > 0)
{
NSDictionary *projectIndex;
NSMutableArray *merged
= [[NSMutableArray alloc] initWithCapacity: count];
CREATE_AUTORELEASE_POOL(arp);
NSDictionary *projectIndex;

for (i = 0; i < count; i++)
{
Expand Down Expand Up @@ -1685,6 +1691,7 @@ standard PropertyList format (not the XML format of OS X), using
* accumulate index info in project references
*/
[projectRefs mergeRefs: [localRefs refs] override: NO];
[merged addObject: gsdocfile];
}
else
{
Expand All @@ -1693,10 +1700,20 @@ standard PropertyList format (not the XML format of OS X), using
}
}
}
if (informalProtocols != nil) {
if (verbose)
{
NSLog(@"Merged indexes into projectRefs from %@", merged);
}

if (informalProtocols != nil)
{
[projectRefs addInformalProtocols: informalProtocols];
DESTROY(informalProtocols);
}
if (verbose)
{
NSLog(@"Added informal protocols into projectRefs");
}
}
DESTROY(arp);

/*
Expand All @@ -1712,6 +1729,7 @@ standard PropertyList format (not the XML format of OS X), using
}
}
DESTROY(originalIndex);
DESTROY(merged);
}

globalRefs = [AGSIndex new];
Expand Down Expand Up @@ -1833,11 +1851,13 @@ standard PropertyList format (not the XML format of OS X), using
/*
* Merge any "plain project" references.
*/
if (projects != nil)
if ([projects count] > 0)
{
NSEnumerator *e = [projects keyEnumerator];
NSString *k;
NSEnumerator *e = [projects keyEnumerator];
NSMutableArray *merged;
NSString *k;

merged = [NSMutableArray arrayWithCapacity: [projects count]];
while ((k = [e nextObject]) != nil)
{
if ([mgr isReadableFileAtPath: k] == NO)
Expand Down Expand Up @@ -1873,15 +1893,25 @@ standard PropertyList format (not the XML format of OS X), using
[tmp setDirectory: p];
[globalRefs mergeRefs: [tmp refs] override: YES];
RELEASE(tmp);
[merged addObject: k];
}
}
}
if (verbose)
{
NSLog(@"Merged indexes into globalRefs from %@", merged);

}
}

/*
* Accumulate project index info into global index
*/
[globalRefs mergeRefs: [projectRefs refs] override: YES];
if (verbose)
{
NSLog(@"Merged indexes from projectRefs into globalRefs");
}

RELEASE(pool);
}
Expand Down

0 comments on commit 57f0664

Please sign in to comment.