forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDOCClass.m
More file actions
159 lines (122 loc) · 4.64 KB
/
CDOCClass.m
File metadata and controls
159 lines (122 loc) · 4.64 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2006 Steve Nygard
#import "CDOCClass.h"
#import <Foundation/Foundation.h>
#import "NSArray-Extensions.h"
#import "CDClassDump.h"
#import "CDOCIvar.h"
#import "CDOCMethod.h"
#import "CDSymbolReferences.h"
#import "CDType.h"
#import "CDTypeParser.h"
@implementation CDOCClass
- (void)dealloc;
{
[superClassName release];
[ivars release];
[super dealloc];
}
- (NSString *)superClassName;
{
return superClassName;
}
- (void)setSuperClassName:(NSString *)newSuperClassName;
{
if (newSuperClassName == superClassName)
return;
[superClassName release];
superClassName = [newSuperClassName retain];
}
- (NSArray *)ivars;
{
return ivars;
}
- (void)setIvars:(NSArray *)newIvars;
{
if (newIvars == ivars)
return;
[ivars release];
ivars = [newIvars retain];
}
- (void)addToXMLElement:(NSXMLElement *)xmlElement classDump:(CDClassDump *)aClassDump symbolReferences:(CDSymbolReferences *)symbolReferences;
{
int count, index;
NSXMLElement *classElement;
if ([aClassDump shouldMatchRegex] == YES && [aClassDump regexMatchesString:[self name]] == NO)
return;
classElement = [NSXMLElement elementWithName:@"class"];
[classElement addChild:[NSXMLElement elementWithName:@"name" stringValue:name]];
if (superClassName != nil)
[classElement addChild:[NSXMLElement elementWithName:@"superclass" stringValue:superClassName]];
if ([protocols count] > 0) {
NSArray *protocolsArray = [protocols arrayByMappingSelector:@selector(name)];
count = [protocolsArray count];
NSMutableArray *adoptedProtocolElements = [NSMutableArray arrayWithCapacity:count];
for (index = 0; index < count; index++) {
[adoptedProtocolElements addObject:[NSXMLElement elementWithName:@"protocol" stringValue:[protocolsArray objectAtIndex:index]]];
}
[classElement addChild:[NSXMLElement elementWithName:@"adopts" children:adoptedProtocolElements attributes:nil]];
[symbolReferences addProtocolNamesFromArray:protocolsArray];
}
count = [ivars count];
if (count > 0) {
for (index = 0; index < count; index++)
[[ivars objectAtIndex:index] addToXMLElement:classElement classDump:aClassDump symbolReferences:symbolReferences];
}
[self addMethodsToXMLElement:classElement classDump:aClassDump symbolReferences:symbolReferences];
[xmlElement addChild:classElement];
}
- (void)appendToString:(NSMutableString *)resultString classDump:(CDClassDump *)aClassDump symbolReferences:(CDSymbolReferences *)symbolReferences;
{
int count, index;
if ([aClassDump shouldMatchRegex] == YES && [aClassDump regexMatchesString:[self name]] == NO)
return;
[resultString appendFormat:@"@interface %@", name];
if (superClassName != nil)
[resultString appendFormat:@" : %@", superClassName];
if ([protocols count] > 0) {
[resultString appendFormat:@" <%@>", [[protocols arrayByMappingSelector:@selector(name)] componentsJoinedByString:@", "]];
[symbolReferences addProtocolNamesFromArray:[protocols arrayByMappingSelector:@selector(name)]];
}
[resultString appendString:@"\n{\n"];
count = [ivars count];
if (count > 0) {
for (index = 0; index < count; index++) {
[[ivars objectAtIndex:index] appendToString:resultString classDump:aClassDump symbolReferences:symbolReferences];
[resultString appendString:@"\n"];
}
}
[resultString appendString:@"}\n\n"];
[self appendMethodsToString:resultString classDump:aClassDump symbolReferences:symbolReferences];
if ([classMethods count] > 0 || [instanceMethods count] > 0)
[resultString appendString:@"\n"];
[resultString appendString:@"@end\n\n"];
}
- (void)registerStructuresWithObject:(id <CDStructureRegistration>)anObject phase:(int)phase;
{
int count, index;
CDTypeParser *parser;
[super registerStructuresWithObject:anObject phase:phase];
count = [ivars count];
for (index = 0; index < count; index++) {
CDType *aType;
parser = [[CDTypeParser alloc] initWithType:[(CDOCIvar *)[ivars objectAtIndex:index] type]];
aType = [parser parseType];
[aType phase:phase registerStructuresWithObject:anObject usedInMethod:NO];
[parser release];
}
}
//
// CDTopologicalSort protocol
//
- (NSString *)identifier;
{
return [self name];
}
- (NSArray *)dependancies;
{
if (superClassName == nil)
return [NSArray array];
return [NSArray arrayWithObject:superClassName];
}
@end