forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDClassDump.m
More file actions
790 lines (626 loc) · 22.7 KB
/
CDClassDump.m
File metadata and controls
790 lines (626 loc) · 22.7 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
// 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 "CDClassDump.h"
#import <Foundation/Foundation.h>
#import "NSArray-Extensions.h"
#import "CDDylibCommand.h"
#import "CDFatArch.h"
#import "CDFatFile.h"
#import "CDMachOFile.h"
#import "CDObjCSegmentProcessor.h"
#import "CDStructureTable.h"
#import "CDSymbolReferences.h"
#import "CDType.h"
#import "CDTypeFormatter.h"
#import "CDTypeParser.h"
@implementation CDClassDump
static NSMutableSet *wrapperExtensions = nil;
+ (void)initialize;
{
// TODO (old): Try grabbing these from an environment variable.
wrapperExtensions = [[NSMutableSet alloc] init];
[wrapperExtensions addObject:@"app"];
[wrapperExtensions addObject:@"framework"];
[wrapperExtensions addObject:@"bundle"];
[wrapperExtensions addObject:@"palette"];
[wrapperExtensions addObject:@"plugin"];
}
// How does this handle something ending in "/"?
+ (BOOL)isWrapperAtPath:(NSString *)path;
{
return [wrapperExtensions containsObject:[path pathExtension]];
}
+ (NSString *)pathToMainFileOfWrapper:(NSString *)wrapperPath;
{
NSString *base, *extension, *mainFile;
base = [wrapperPath lastPathComponent];
extension = [base pathExtension];
base = [base stringByDeletingPathExtension];
if ([@"framework" isEqual:extension] == YES) {
mainFile = [NSString stringWithFormat:@"%@/%@", wrapperPath, base];
} else {
// app, bundle, palette, plugin
mainFile = [NSString stringWithFormat:@"%@/Contents/MacOS/%@", wrapperPath, base];
}
return mainFile;
}
// Allow user to specify wrapper instead of the actual Mach-O file.
+ (NSString *)adjustUserSuppliedPath:(NSString *)path;
{
NSString *fullyResolvedPath, *basePath, *resolvedBasePath;
if ([self isWrapperAtPath:path] == YES) {
path = [self pathToMainFileOfWrapper:path];
}
fullyResolvedPath = [path stringByResolvingSymlinksInPath];
basePath = [path stringByDeletingLastPathComponent];
resolvedBasePath = [basePath stringByResolvingSymlinksInPath];
//NSLog(@"fullyResolvedPath: %@", fullyResolvedPath);
//NSLog(@"basePath: %@", basePath);
//NSLog(@"resolvedBasePath: %@", resolvedBasePath);
// I don't want to resolve all of the symlinks, just the ones starting from the wrapper.
// If I have a symlink from my home directory to /System/Library/Frameworks/AppKit.framework, I want to see the
// path to my home directory.
// This is an easy way to cheat so that we don't have to deal with NSFileManager ourselves.
// This is clever, but it fails when the symlink goes outside of the wrapper. For example, currently
// /System/Library/PrivateFrameworks/ICACameraPriv.framework/ICACameraPriv is a symbolic link to
// ../../Frameworks/ICADevices.framework/Versions/A/ICADevices and so now we check to make sure the
// first parts of the paths are the same.
if ([fullyResolvedPath hasPrefix:resolvedBasePath] == NO)
return fullyResolvedPath;
return [basePath stringByAppendingString:[fullyResolvedPath substringFromIndex:[resolvedBasePath length]]];
}
- (id)init;
{
if ([super init] == nil)
return nil;
executablePath = nil;
machOFilesByID = [[NSMutableDictionary alloc] init];
objCSegmentProcessors = [[NSMutableArray alloc] init];
structureTable = [[CDStructureTable alloc] init];
[structureTable setAnonymousBaseName:@"CDAnonymousStruct"];
[structureTable setName:@"Structs"];
unionTable = [[CDStructureTable alloc] init];
[unionTable setAnonymousBaseName:@"CDAnonymousUnion"];
[unionTable setName:@"Unions"];
ivarTypeFormatter = [[CDTypeFormatter alloc] init];
[ivarTypeFormatter setShouldExpand:NO];
[ivarTypeFormatter setShouldAutoExpand:YES];
[ivarTypeFormatter setBaseLevel:1];
[ivarTypeFormatter setDelegate:self];
methodTypeFormatter = [[CDTypeFormatter alloc] init];
[methodTypeFormatter setShouldExpand:NO];
[methodTypeFormatter setShouldAutoExpand:NO];
[methodTypeFormatter setBaseLevel:0];
[methodTypeFormatter setDelegate:self];
structDeclarationTypeFormatter = [[CDTypeFormatter alloc] init];
[structDeclarationTypeFormatter setShouldExpand:YES]; // But don't expand named struct members...
[structDeclarationTypeFormatter setShouldAutoExpand:YES];
[structDeclarationTypeFormatter setBaseLevel:0];
[structDeclarationTypeFormatter setDelegate:self]; // But need to ignore some things?
frameworkNamesByClassName = [[NSMutableDictionary alloc] init];
preferredCPUType = CPU_TYPE_ANY;
//preferredCPUType = CPU_TYPE_POWERPC;
//preferredCPUType = CPU_TYPE_I386;
flags.shouldShowHeader = YES;
return self;
}
- (void)dealloc;
{
[executablePath release];
[outputPath release];
[machOFilesByID release];
[objCSegmentProcessors release];
[structureTable release];
[unionTable release];
[ivarTypeFormatter release];
[methodTypeFormatter release];
[structDeclarationTypeFormatter release];
[frameworkNamesByClassName release];
if (flags.shouldMatchRegex == YES)
regfree(&compiledRegex);
[super dealloc];
}
- (NSString *)executablePath;
{
return executablePath;
}
- (void)setExecutablePath:(NSString *)newPath;
{
if (newPath == executablePath)
return;
[executablePath release];
executablePath = [newPath retain];
}
- (BOOL)shouldProcessRecursively;
{
return flags.shouldProcessRecursively;
}
- (void)setShouldProcessRecursively:(BOOL)newFlag;
{
flags.shouldProcessRecursively = newFlag;
}
- (BOOL)shouldGenerateSeparateHeaders;
{
return flags.shouldGenerateSeparateHeaders;
}
- (void)setShouldGenerateSeparateHeaders:(BOOL)newFlag;
{
flags.shouldGenerateSeparateHeaders = newFlag;
}
- (BOOL)shouldSortClasses;
{
return flags.shouldSortClasses;
}
- (void)setShouldSortClasses:(BOOL)newFlag;
{
flags.shouldSortClasses = newFlag;
}
- (BOOL)shouldSortClassesByInheritance;
{
return flags.shouldSortClassesByInheritance;
}
- (void)setShouldSortClassesByInheritance:(BOOL)newFlag;
{
flags.shouldSortClassesByInheritance = newFlag;
}
- (BOOL)shouldSortMethods;
{
return flags.shouldSortMethods;
}
- (void)setShouldSortMethods:(BOOL)newFlag;
{
flags.shouldSortMethods = newFlag;
}
- (BOOL)shouldShowIvarOffsets;
{
return flags.shouldShowIvarOffsets;
}
- (void)setShouldShowIvarOffsets:(BOOL)newFlag;
{
flags.shouldShowIvarOffsets = newFlag;
}
- (BOOL)shouldShowMethodAddresses;
{
return flags.shouldShowMethodAddresses;
}
- (void)setShouldShowMethodAddresses:(BOOL)newFlag;
{
flags.shouldShowMethodAddresses = newFlag;
}
- (BOOL)shouldGenerateXML;
{
return flags.shouldGenerateXML;
}
- (void)setShouldGenerateXML:(BOOL)newFlag;
{
flags.shouldGenerateXML = newFlag;
}
- (BOOL)shouldMatchRegex;
{
return flags.shouldMatchRegex;
}
- (void)setShouldMatchRegex:(BOOL)newFlag;
{
if (flags.shouldMatchRegex == YES && newFlag == NO)
regfree(&compiledRegex);
flags.shouldMatchRegex = newFlag;
}
- (BOOL)shouldShowHeader;
{
return flags.shouldShowHeader;
}
- (void)setShouldShowHeader:(BOOL)newFlag;
{
flags.shouldShowHeader = newFlag;
}
- (BOOL)setRegex:(char *)regexCString errorMessage:(NSString **)errorMessagePointer;
{
int result;
if (flags.shouldMatchRegex == YES)
regfree(&compiledRegex);
result = regcomp(&compiledRegex, regexCString, REG_EXTENDED);
if (result != 0) {
char regex_error_buffer[256];
if (regerror(result, &compiledRegex, regex_error_buffer, 256) > 0) {
if (errorMessagePointer != NULL) {
*errorMessagePointer = [NSString stringWithCString:regex_error_buffer];
}
} else {
if (errorMessagePointer != NULL)
*errorMessagePointer = nil;
}
return NO;
}
[self setShouldMatchRegex:YES];
return YES;
}
- (BOOL)regexMatchesString:(NSString *)aString;
{
int result;
result = regexec(&compiledRegex, [aString UTF8String], 0, NULL, 0);
if (result != 0) {
if (result != REG_NOMATCH) {
char regex_error_buffer[256];
if (regerror(result, &compiledRegex, regex_error_buffer, 256) > 0)
NSLog(@"Error with regex matching string, %@", [NSString stringWithCString:regex_error_buffer]);
}
return NO;
}
return YES;
}
- (NSString *)outputPath;
{
return outputPath;
}
- (void)setOutputPath:(NSString *)aPath;
{
if (aPath == outputPath)
return;
[outputPath release];
outputPath = [aPath retain];
}
- (cpu_type_t)preferredCPUType;
{
return preferredCPUType;
}
- (void)setPreferredCPUType:(cpu_type_t)aPreferredCPUType;
{
preferredCPUType = aPreferredCPUType;
}
- (BOOL)containsObjectiveCSegments;
{
unsigned int count, index;
count = [objCSegmentProcessors count];
for (index = 0; index < count; index++) {
if ([[objCSegmentProcessors objectAtIndex:index] hasModules])
return YES;
}
return NO;
}
- (CDStructureTable *)structureTable;
{
return structureTable;
}
- (CDStructureTable *)unionTable;
{
return unionTable;
}
- (CDTypeFormatter *)ivarTypeFormatter;
{
return ivarTypeFormatter;
}
- (CDTypeFormatter *)methodTypeFormatter;
{
return methodTypeFormatter;
}
- (CDTypeFormatter *)structDeclarationTypeFormatter;
{
return structDeclarationTypeFormatter;
}
// Return YES if successful, NO if there was an error.
- (BOOL)processFilename:(NSString *)aFilename;
{
NSString *adjustedPath;
adjustedPath = [[self class] adjustUserSuppliedPath:aFilename];
[self setExecutablePath:[adjustedPath stringByDeletingLastPathComponent]];
return [self _processFilename:adjustedPath];
}
// Return YES if successful, NO if there was an error.
- (BOOL)_processFilename:(NSString *)aFilename;
{
CDFatFile *aFatFile;
CDMachOFile *aMachOFile;
CDObjCSegmentProcessor *aProcessor;
// TODO (2005-07-08): This isn't good enough. You only have your
// choice on the main file. Link frameworks MUST be the same
// architecture, either as a stand-alone Mach-O file or within a fat file.
// Initial combinations:
// 1. macho file, no cpu preference
// 2. macho file, cpu preference same as macho file
// 3. macho file, cpu preference different from macho file
// 4. fat file, no cpu preference
// 5. fat file, cpu preference contained in fat file
// 6. fat file, cpu preference not contained in fat file
//
// Actions:
// 1, 2, 4, 5: All subsequent files must be same cpu
// 3. Print message saying that arch isn't available in this macho file
// 6. Print message saying that arch isn't available in this fat file
//
// For linked frameworks/libraries, if the arch isn't available silently skip?
aFatFile = [[CDFatFile alloc] initWithFilename:aFilename];
if (aFatFile == nil) {
aMachOFile = [[CDMachOFile alloc] initWithFilename:aFilename];
if (aMachOFile == nil) {
fprintf(stderr, "class-dump: Input file (%s) is neither a Mach-O file nor a fat archive.\n", [aFilename fileSystemRepresentation]);
return NO;
}
if (preferredCPUType == CPU_TYPE_ANY) {
preferredCPUType = [aMachOFile cpuType];
} else if ([aMachOFile cpuType] != preferredCPUType) {
fprintf(stderr, "class-dump: Mach-O file (%s) does not contain required cpu type: %s.\n",
[aFilename fileSystemRepresentation], [CDNameForCPUType(preferredCPUType) UTF8String]);
[aMachOFile release];
return NO;
}
} else {
CDFatArch *fatArch;
fatArch = [aFatFile fatArchWithCPUType:preferredCPUType];
if (fatArch == nil) {
if (preferredCPUType == CPU_TYPE_ANY)
fprintf(stderr, "class-dump: Fat archive (%s) did not contain any cpu types!\n", [aFilename fileSystemRepresentation]);
else
fprintf(stderr, "class-dump: Fat archive (%s) does not contain required cpu type: %s.\n",
[aFilename fileSystemRepresentation], [CDNameForCPUType(preferredCPUType) UTF8String]);
[aFatFile release];
return NO;
}
if (preferredCPUType == CPU_TYPE_ANY) {
preferredCPUType = [fatArch cpuType];
}
aMachOFile = [[CDMachOFile alloc] initWithFilename:aFilename archiveOffset:[fatArch offset]];
[aFatFile release];
if (aMachOFile == nil)
return NO;
}
[aMachOFile setDelegate:self];
// TODO (2005-07-03): Look for the newer exception handling stuff.
NS_DURING {
[aMachOFile process];
} NS_HANDLER {
[aMachOFile release];
return NO;
} NS_ENDHANDLER;
aProcessor = [[CDObjCSegmentProcessor alloc] initWithMachOFile:aMachOFile];
[aProcessor process];
[objCSegmentProcessors addObject:aProcessor];
[aProcessor release];
assert([aMachOFile filename] != nil);
[machOFilesByID setObject:aMachOFile forKey:[aMachOFile filename]];
[aMachOFile release];
return YES;
}
- (void)generateOutput;
{
[self registerPhase:1];
[self registerPhase:2];
[self generateMemberNames];
if ([self shouldGenerateXML] == YES)
[self generateXMLToStandardOut];
else if ([self shouldGenerateSeparateHeaders] == YES)
[self generateSeparateHeaders];
else
[self generateToStandardOut];
}
- (void)generateXMLToStandardOut;
{
NSXMLDocument *xmlDoc;
int count, index;
NSData *data;
xmlDoc = [[NSXMLDocument alloc] initWithRootElement:[NSXMLElement elementWithName:@"classdump"]];
if ([self containsObjectiveCSegments]) {
#warning TODO structures
//[self appendStructuresToString:resultString symbolReferences:nil];
count = [objCSegmentProcessors count];
for (index = 0; index < count; index++) {
[[objCSegmentProcessors objectAtIndex:index] addToXMLElement:[xmlDoc rootElement] classDump:self];
}
} else {
[[xmlDoc rootElement] addChild:[NSXMLNode commentWithStringValue:@"This file does not contain any Objective-C runtime information."]];
}
data = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
[(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:data];
[xmlDoc release];
}
- (void)generateToStandardOut;
{
NSMutableString *resultString;
int count, index;
NSData *data;
resultString = [[NSMutableString alloc] init];
[self appendHeaderToString:resultString];
if ([self containsObjectiveCSegments]) {
[self appendStructuresToString:resultString symbolReferences:nil];
count = [objCSegmentProcessors count];
for (index = 0; index < count; index++) {
[[objCSegmentProcessors objectAtIndex:index] appendFormattedString:resultString classDump:self];
}
} else {
[resultString appendString:@"This file does not contain any Objective-C runtime information.\n"];
}
data = [resultString dataUsingEncoding:NSUTF8StringEncoding];
[(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:data];
[resultString release];
}
- (void)generateSeparateHeaders;
{
int count, index;
if ([self containsObjectiveCSegments] == NO) {
NSLog(@"Warning: This file does not contain any Objective-C runtime information.");
return;
}
[self buildClassFrameworks];
if (outputPath != nil) {
NSFileManager *fileManager;
BOOL isDirectory;
fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:outputPath isDirectory:&isDirectory] == NO) {
BOOL result;
result = [fileManager createDirectoryAtPath:outputPath attributes:nil];
if (result == NO) {
NSLog(@"Error: Couldn't create output directory: %@", outputPath);
return;
}
} else if (isDirectory == NO) {
NSLog(@"Error: File exists at output path: %@", outputPath);
return;
}
}
[self generateStructureHeader];
count = [objCSegmentProcessors count];
for (index = 0; index < count; index++) {
[[objCSegmentProcessors objectAtIndex:index] generateSeparateHeadersClassDump:self];
}
}
- (void)generateStructureHeader;
{
NSMutableString *resultString;
NSString *filename;
CDSymbolReferences *symbolReferences;
NSString *referenceString;
unsigned int referenceIndex;
resultString = [[NSMutableString alloc] init];
[self appendHeaderToString:resultString];
symbolReferences = [[CDSymbolReferences alloc] init];
referenceIndex = [resultString length];
[self appendStructuresToString:resultString symbolReferences:symbolReferences];
referenceString = [symbolReferences referenceString];
if (referenceString != nil)
[resultString insertString:referenceString atIndex:referenceIndex];
filename = @"CDStructures.h";
if (outputPath != nil)
filename = [outputPath stringByAppendingPathComponent:filename];
[[resultString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filename atomically:YES];
[symbolReferences release];
[resultString release];
}
- (void)logInfo;
{
[structureTable logInfo];
[unionTable logInfo];
}
- (void)appendStructuresToString:(NSMutableString *)resultString symbolReferences:(CDSymbolReferences *)symbolReferences;
{
[structureTable appendNamedStructuresToString:resultString classDump:self formatter:structDeclarationTypeFormatter symbolReferences:symbolReferences];
[structureTable appendTypedefsToString:resultString classDump:self formatter:structDeclarationTypeFormatter symbolReferences:symbolReferences];
[unionTable appendNamedStructuresToString:resultString classDump:self formatter:structDeclarationTypeFormatter symbolReferences:symbolReferences];
[unionTable appendTypedefsToString:resultString classDump:self formatter:structDeclarationTypeFormatter symbolReferences:symbolReferences];
}
- (CDMachOFile *)machOFileWithID:(NSString *)anID;
{
NSString *adjustedID;
CDMachOFile *aMachOFile;
NSString *replacementString = @"@executable_path";
if ([anID hasPrefix:replacementString] == YES) {
adjustedID = [executablePath stringByAppendingString:[anID substringFromIndex:[replacementString length]]];
} else {
adjustedID = anID;
}
aMachOFile = [machOFilesByID objectForKey:adjustedID];
if (aMachOFile == nil) {
[self _processFilename:adjustedID];
aMachOFile = [machOFilesByID objectForKey:adjustedID];
}
return aMachOFile;
}
- (void)machOFile:(CDMachOFile *)aMachOFile loadDylib:(CDDylibCommand *)aDylibCommand;
{
if ([aDylibCommand cmd] == LC_LOAD_DYLIB && [self shouldProcessRecursively] == YES)
[self machOFileWithID:[aDylibCommand name]];
}
- (void)appendHeaderToString:(NSMutableString *)resultString;
{
// Since this changes each version, for regression testing it'll be better to be able to not show it.
if (flags.shouldShowHeader == NO)
return;
[resultString appendString:@"/*\n"];
[resultString appendFormat:@" * Generated by class-dump %@.\n", CLASS_DUMP_VERSION];
[resultString appendString:@" *\n"];
[resultString appendString:@" * class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2006 by Steve Nygard.\n"];
[resultString appendString:@" */\n\n"];
}
- (CDType *)typeFormatter:(CDTypeFormatter *)aFormatter replacementForType:(CDType *)aType;
{
if ([aType type] == '{')
return [structureTable replacementForType:aType];
if ([aType type] == '(')
return [unionTable replacementForType:aType];
return nil;
}
- (NSString *)typeFormatter:(CDTypeFormatter *)aFormatter typedefNameForStruct:(CDType *)structType level:(int)level;
{
CDType *replacementType, *searchType;
CDStructureTable *targetTable;
if (level == 0 && aFormatter == structDeclarationTypeFormatter)
return nil;
if ([structType type] == '{') {
targetTable = structureTable;
} else {
targetTable = unionTable;
}
// We need to catch top level replacements, not just replacements for struct members.
replacementType = [targetTable replacementForType:structType];
if (replacementType != nil)
searchType = replacementType;
else
searchType = structType;
return [targetTable typedefNameForStructureType:searchType];
}
- (void)registerPhase:(int)phase;
{
NSAutoreleasePool *pool;
int count, index;
pool = [[NSAutoreleasePool alloc] init];
count = [objCSegmentProcessors count];
for (index = 0; index < count; index++) {
[[objCSegmentProcessors objectAtIndex:index] registerStructuresWithObject:self phase:phase];
}
[self endPhase:phase];
[pool release];
}
- (void)endPhase:(int)phase;
{
if (phase == 1) {
[structureTable finishPhase1];
[unionTable finishPhase1];
} else if (phase == 2) {
[structureTable generateNamesForAnonymousStructures];
[unionTable generateNamesForAnonymousStructures];
}
}
- (void)phase1RegisterStructure:(CDType *)aStructure;
{
if ([aStructure type] == '{') {
[structureTable phase1RegisterStructure:aStructure];
} else if ([aStructure type] == '(') {
[unionTable phase1RegisterStructure:aStructure];
} else {
NSLog(@"%s, unknown structure type: %d", _cmd, [aStructure type]);
}
}
- (BOOL)phase2RegisterStructure:(CDType *)aStructure usedInMethod:(BOOL)isUsedInMethod countReferences:(BOOL)shouldCountReferences;
{
if ([aStructure type] == '{') {
return [structureTable phase2RegisterStructure:aStructure withObject:self usedInMethod:isUsedInMethod countReferences:shouldCountReferences];
} else if ([aStructure type] == '(') {
return [unionTable phase2RegisterStructure:aStructure withObject:self usedInMethod:isUsedInMethod countReferences:shouldCountReferences];
} else {
NSLog(@"%s, unknown structure type: %d", _cmd, [aStructure type]);
}
return NO;
}
- (void)generateMemberNames;
{
[structureTable generateMemberNames];
[unionTable generateMemberNames];
}
- (void)buildClassFrameworks;
{
[objCSegmentProcessors makeObjectsPerformSelector:@selector(registerClassesWithObject:) withObject:frameworkNamesByClassName];
}
- (NSString *)frameworkForClassName:(NSString *)aClassName;
{
return [frameworkNamesByClassName objectForKey:aClassName];
}
- (void)appendImportForClassName:(NSString *)aClassName toString:(NSMutableString *)resultString;
{
if (aClassName != nil) {
NSString *classFramework;
classFramework = [self frameworkForClassName:aClassName];
if (classFramework == nil)
[resultString appendFormat:@"#import \"%@.h\"\n\n", aClassName];
else
[resultString appendFormat:@"#import <%@/%@.h>\n\n", classFramework, aClassName];
}
}
@end