-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOCVContext.m
84 lines (71 loc) · 1.84 KB
/
OCVContext.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// OCVContext.m
// ObjCViz
//
// Created by Olivier Gutknecht on 12/17/06.
// Copyright 2006 No Distance. See LICENSE.txt file.
//
#import "OCVContext.h"
#import "OCVField.h"
#import "OCVDotRepresentations.h"
@implementation NSObject (OCVContext)
-(NSString*)graphvizRepresentation
{
OCVContext* c = [[OCVContext alloc] init];
NSMutableString* m = [[NSMutableString alloc] init];
[m appendString:@"digraph ObjC {\n"];
[c appendGraphvizRepresentationFor:self toString:m];
[m appendString:@"}\n"];
[c release];
return [m autorelease];
}
@end
@implementation OCVContext
-(id)init
{
self = [super init];
if (self)
{
visited = [[NSMutableSet alloc] init];
}
return self;
}
-(void)dealloc
{
[visited release];
[super dealloc];
}
-(void)processFieldsForObject:(id)obj fields:(NSArray*)f toString:(NSMutableString*)s
{
OCVField* field;
NSEnumerator* e = [f objectEnumerator];
while (field = [e nextObject])
{
if (![field isPrimitive]) {
NSString* name = [field name];
id ref = [field valueForObject:obj];
if (ref==nil) {
NSString* refName = [NSString stringWithFormat:@"%@%@",[obj dotName],name];
[s appendFormat:@"%@ -> %@ [label=\"%@\",fontsize=12];\n",[obj dotName],refName, name];
[s appendFormat:@"%@ [label=\"nil\"];\n",refName];
}
else
{
[s appendFormat:@"%@ -> %@ [label=\"%@\",fontsize=12];\n",[obj dotName],[ref dotName], name];
[self appendGraphvizRepresentationFor:ref toString:s];
}
}
}
}
-(void)appendGraphvizRepresentationFor:(id)obj toString:(NSMutableString*)s
{
if (obj==nil)
obj = [NSNull null];
if ([visited containsObject:obj])
return;
[visited addObject:obj];
[obj appendDotRepresentationToString:s withContext:self];
if ([obj processFields])
[self processFieldsForObject:obj fields:[obj OCV_fields] toString:s];
}
@end