Skip to content

Commit

Permalink
Prefix instance variables with _, and synthesize by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
nygard committed Jul 16, 2012
1 parent 40c7ee8 commit 33c1478
Show file tree
Hide file tree
Showing 77 changed files with 1,387 additions and 1,628 deletions.
44 changes: 22 additions & 22 deletions Source/CDBalanceFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

@implementation CDBalanceFormatter
{
NSScanner *scanner;
NSCharacterSet *openCloseSet;
NSScanner *_scanner;
NSCharacterSet *_openCloseSet;

NSMutableString *result;
NSMutableString *_result;
}

- (id)initWithString:(NSString *)str;
{
if ((self = [super init])) {
scanner = [[NSScanner alloc] initWithString:str];
openCloseSet = [NSCharacterSet characterSetWithCharactersInString:@"{}<>()"];
_scanner = [[NSScanner alloc] initWithString:str];
_openCloseSet = [NSCharacterSet characterSetWithCharactersInString:@"{}<>()"];

result = [[NSMutableString alloc] init];
_result = [[NSMutableString alloc] init];
}

return self;
Expand All @@ -36,35 +36,35 @@ - (void)parse:(NSString *)open index:(NSUInteger)openIndex level:(NSUInteger)lev
BOOL foundOpen = NO;
BOOL foundClose = NO;

while ([scanner isAtEnd] == NO) {
while ([_scanner isAtEnd] == NO) {
NSString *pre;

if ([scanner scanUpToCharactersFromSet:openCloseSet intoString:&pre]) {
if ([_scanner scanUpToCharactersFromSet:_openCloseSet intoString:&pre]) {
if (debug) NSLog(@"pre = '%@'", pre);
[result appendFormat:@"%@%@\n", [NSString spacesIndentedToLevel:level], pre];
[_result appendFormat:@"%@%@\n", [NSString spacesIndentedToLevel:level], pre];
}
if (debug) NSLog(@"remaining: '%@'", [[scanner string] substringFromIndex:[scanner scanLocation]]);
if (debug) NSLog(@"remaining: '%@'", [[_scanner string] substringFromIndex:[_scanner scanLocation]]);

foundOpen = foundClose = NO;
for (NSUInteger index = 0; index < 3; index++) {
if (debug) NSLog(@"Checking open %lu: '%@'", index, opens[index]);
if ([scanner scanString:opens[index] intoString:NULL]) {
if ([_scanner scanString:opens[index] intoString:NULL]) {
if (debug) NSLog(@"Start %@", opens[index]);
[result appendSpacesIndentedToLevel:level];
[result appendString:opens[index]];
[result appendString:@"\n"];
[_result appendSpacesIndentedToLevel:level];
[_result appendString:opens[index]];
[_result appendString:@"\n"];

[self parse:opens[index] index:[scanner scanLocation] - 1 level:level + 1];
[self parse:opens[index] index:[_scanner scanLocation] - 1 level:level + 1];

[result appendSpacesIndentedToLevel:level];
[result appendString:closes[index]];
[result appendString:@"\n"];
[_result appendSpacesIndentedToLevel:level];
[_result appendString:closes[index]];
[_result appendString:@"\n"];
foundOpen = YES;
break;
}

if (debug) NSLog(@"Checking close %lu: '%@'", index, closes[index]);
if ([scanner scanString:closes[index] intoString:NULL]) {
if ([_scanner scanString:closes[index] intoString:NULL]) {
if ([open isEqualToString:opens[index]]) {
if (debug) NSLog(@"End %@", closes[index]);
} else {
Expand All @@ -76,7 +76,7 @@ - (void)parse:(NSString *)open index:(NSUInteger)openIndex level:(NSUInteger)lev
}

if (foundOpen == NO && foundClose == NO) {
if (debug) NSLog(@"Unknown @ %lu: %@", [scanner scanLocation], [[scanner string] substringFromIndex:[scanner scanLocation]]);
if (debug) NSLog(@"Unknown @ %lu: %@", [_scanner scanLocation], [[_scanner string] substringFromIndex:[_scanner scanLocation]]);
break;
}

Expand All @@ -89,9 +89,9 @@ - (NSString *)format;
{
[self parse:nil index:0 level:0];

if (debug) NSLog(@"result:\n%@", result);
if (debug) NSLog(@"result:\n%@", _result);

return [NSString stringWithString:result];
return [NSString stringWithString:_result];
}

@end
118 changes: 49 additions & 69 deletions Source/CDClassDump.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,51 @@ - (CDMachOFile *)machOFileWithID:(NSString *)anID;

@implementation CDClassDump
{
CDSearchPathState *searchPathState;
CDSearchPathState *_searchPathState;

BOOL shouldProcessRecursively;
BOOL shouldSortClasses; // And categories, protocols
BOOL shouldSortClassesByInheritance; // And categories, protocols
BOOL shouldSortMethods;
BOOL _shouldProcessRecursively;
BOOL _shouldSortClasses; // And categories, protocols
BOOL _shouldSortClassesByInheritance; // And categories, protocols
BOOL _shouldSortMethods;

BOOL shouldShowIvarOffsets;
BOOL shouldShowMethodAddresses;
BOOL shouldShowHeader;
BOOL _shouldShowIvarOffsets;
BOOL _shouldShowMethodAddresses;
BOOL _shouldShowHeader;

NSRegularExpression *regularExpression;
NSRegularExpression *_regularExpression;

NSString *sdkRoot;
NSMutableArray *machOFiles;
NSMutableDictionary *machOFilesByID;
NSMutableArray *objcProcessors;
NSString *_sdkRoot;
NSMutableArray *_machOFiles;
NSMutableDictionary *_machOFilesByID;
NSMutableArray *_objcProcessors;

CDTypeController *typeController;
CDTypeController *_typeController;

CDArch targetArch;
CDArch _targetArch;
}

- (id)init;
{
if ((self = [super init])) {
searchPathState = [[CDSearchPathState alloc] init];
sdkRoot = nil;
_searchPathState = [[CDSearchPathState alloc] init];
_sdkRoot = nil;

machOFiles = [[NSMutableArray alloc] init];
machOFilesByID = [[NSMutableDictionary alloc] init];
objcProcessors = [[NSMutableArray alloc] init];
_machOFiles = [[NSMutableArray alloc] init];
_machOFilesByID = [[NSMutableDictionary alloc] init];
_objcProcessors = [[NSMutableArray alloc] init];

typeController = [[CDTypeController alloc] initWithClassDump:self];
_typeController = [[CDTypeController alloc] initWithClassDump:self];

// These can be ppc, ppc7400, ppc64, i386, x86_64
targetArch.cputype = CPU_TYPE_ANY;
targetArch.cpusubtype = 0;
_targetArch.cputype = CPU_TYPE_ANY;
_targetArch.cpusubtype = 0;

shouldShowHeader = YES;
_shouldShowHeader = YES;
}

return self;
}

#pragma mark -

@synthesize searchPathState;
@synthesize shouldProcessRecursively;
@synthesize shouldSortClasses;
@synthesize shouldSortClassesByInheritance;
@synthesize shouldSortMethods;
@synthesize shouldShowIvarOffsets;
@synthesize shouldShowMethodAddresses;
@synthesize shouldShowHeader;

@synthesize regularExpression;

#pragma mark - Regular expression handling

- (BOOL)shouldShowName:(NSString *)name;
Expand All @@ -98,14 +85,9 @@ - (BOOL)shouldShowName:(NSString *)name;

#pragma mark -

@synthesize sdkRoot;
@synthesize machOFiles;
@synthesize objcProcessors;
@synthesize targetArch;

- (BOOL)containsObjectiveCData;
{
for (CDObjectiveCProcessor *processor in objcProcessors) {
for (CDObjectiveCProcessor *processor in self.objcProcessors) {
if ([processor hasObjectiveCData])
return YES;
}
Expand All @@ -115,7 +97,7 @@ - (BOOL)containsObjectiveCData;

- (BOOL)hasEncryptedFiles;
{
for (CDMachOFile *machOFile in machOFiles) {
for (CDMachOFile *machOFile in self.machOFiles) {
if ([machOFile isEncrypted]) {
return YES;
}
Expand All @@ -129,12 +111,10 @@ - (BOOL)hasObjectiveCRuntimeInfo;
return self.containsObjectiveCData || self.hasEncryptedFiles;
}

@synthesize typeController;

- (BOOL)loadFile:(CDFile *)file;
{
//NSLog(@"targetArch: (%08x, %08x)", targetArch.cputype, targetArch.cpusubtype);
CDMachOFile *aMachOFile = [file machOFileWithArch:targetArch];
CDMachOFile *aMachOFile = [file machOFileWithArch:_targetArch];
//NSLog(@"aMachOFile: %@", aMachOFile);
if (aMachOFile == nil) {
fprintf(stderr, "Error: file doesn't contain the specified arch.\n\n");
Expand All @@ -143,18 +123,18 @@ - (BOOL)loadFile:(CDFile *)file;

// Set before processing recursively. This was getting caught on CoreUI on 10.6
assert([aMachOFile filename] != nil);
[machOFiles addObject:aMachOFile];
[machOFilesByID setObject:aMachOFile forKey:[aMachOFile filename]];
[_machOFiles addObject:aMachOFile];
[_machOFilesByID setObject:aMachOFile forKey:[aMachOFile filename]];

if ([self shouldProcessRecursively]) {
@try {
for (CDLoadCommand *loadCommand in [aMachOFile loadCommands]) {
if ([loadCommand isKindOfClass:[CDLCDylib class]]) {
CDLCDylib *aDylibCommand = (CDLCDylib *)loadCommand;
if ([aDylibCommand cmd] == LC_LOAD_DYLIB) {
[searchPathState pushSearchPaths:[aMachOFile runPaths]];
[self.searchPathState pushSearchPaths:[aMachOFile runPaths]];
[self machOFileWithID:[aDylibCommand path]]; // Loads as a side effect
[searchPathState popSearchPaths];
[self.searchPathState popSearchPaths];
}
}
}
Expand All @@ -172,10 +152,10 @@ - (BOOL)loadFile:(CDFile *)file;

- (void)processObjectiveCData;
{
for (CDMachOFile *machOFile in machOFiles) {
for (CDMachOFile *machOFile in self.machOFiles) {
CDObjectiveCProcessor *aProcessor = [[[machOFile processorClass] alloc] initWithMachOFile:machOFile];
[aProcessor process];
[objcProcessors addObject:aProcessor];
[_objcProcessors addObject:aProcessor];
}
}

Expand All @@ -184,7 +164,7 @@ - (void)recursivelyVisit:(CDVisitor *)visitor;
{
[visitor willBeginVisiting];

for (CDObjectiveCProcessor *processor in objcProcessors) {
for (CDObjectiveCProcessor *processor in self.objcProcessors) {
[processor recursivelyVisit:visitor];
}

Expand All @@ -198,10 +178,10 @@ - (CDMachOFile *)machOFileWithID:(NSString *)anID;
NSString *rpathPrefix = @"@rpath";

if ([anID hasPrefix:executablePathPrefix]) {
adjustedID = [anID stringByReplacingOccurrencesOfString:executablePathPrefix withString:searchPathState.executablePath];
adjustedID = [anID stringByReplacingOccurrencesOfString:executablePathPrefix withString:self.searchPathState.executablePath];
} else if ([anID hasPrefix:rpathPrefix]) {
//NSLog(@"Searching for %@ through run paths: %@", anID, [searchPathState searchPaths]);
for (NSString *searchPath in [searchPathState searchPaths]) {
for (NSString *searchPath in [self.searchPathState searchPaths]) {
NSString *str = [anID stringByReplacingOccurrencesOfString:rpathPrefix withString:searchPath];
//NSLog(@"trying %@", str);
if ([[NSFileManager defaultManager] fileExistsAtPath:str]) {
Expand All @@ -214,21 +194,21 @@ - (CDMachOFile *)machOFileWithID:(NSString *)anID;
adjustedID = anID;
//NSLog(@"Did not find it.");
}
} else if (sdkRoot != nil) {
adjustedID = [sdkRoot stringByAppendingPathComponent:anID];
} else if (self.sdkRoot != nil) {
adjustedID = [self.sdkRoot stringByAppendingPathComponent:anID];
} else {
adjustedID = anID;
}

CDMachOFile *aMachOFile = [machOFilesByID objectForKey:adjustedID];
CDMachOFile *aMachOFile = [_machOFilesByID objectForKey:adjustedID];
if (aMachOFile == nil) {
NSData *data = [[NSData alloc] initWithContentsOfMappedFile:adjustedID];
CDFile *aFile = [CDFile fileWithData:data filename:adjustedID searchPathState:searchPathState];
CDFile *aFile = [CDFile fileWithData:data filename:adjustedID searchPathState:self.searchPathState];

if (aFile == nil || [self loadFile:aFile] == NO)
NSLog(@"Warning: Failed to load: %@", adjustedID);

aMachOFile = [machOFilesByID objectForKey:adjustedID];
aMachOFile = [_machOFilesByID objectForKey:adjustedID];
if (aMachOFile == nil) {
NSLog(@"Warning: Couldn't load MachOFile with ID: %@, adjustedID: %@", anID, adjustedID);
}
Expand Down Expand Up @@ -258,25 +238,25 @@ - (void)appendHeaderToString:(NSMutableString *)resultString;

- (void)registerTypes;
{
for (CDObjectiveCProcessor *processor in objcProcessors) {
[processor registerTypesWithObject:typeController phase:0];
for (CDObjectiveCProcessor *processor in self.objcProcessors) {
[processor registerTypesWithObject:self.typeController phase:0];
}
[typeController endPhase:0];
[self.typeController endPhase:0];

[typeController workSomeMagic];
[self.typeController workSomeMagic];
}

- (void)showHeader;
{
if ([machOFiles count] > 0) {
[[[machOFiles lastObject] headerString:YES] print];
if ([self.machOFiles count] > 0) {
[[[self.machOFiles lastObject] headerString:YES] print];
}
}

- (void)showLoadCommands;
{
if ([machOFiles count] > 0) {
[[[machOFiles lastObject] loadCommandString:YES] print];
if ([self.machOFiles count] > 0) {
[[[self.machOFiles lastObject] loadCommandString:YES] print];
}
}

Expand Down
2 changes: 0 additions & 2 deletions Source/CDClassFrameworkVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ - (void)willVisitClass:(CDOCClass *)aClass;

#pragma mark -

@synthesize frameworkName = _frameworkName;

- (void)addClassName:(NSString *)name referencedInFramework:(NSString *)frameworkName;
{
if (name != nil && frameworkName != nil)
Expand Down
2 changes: 1 addition & 1 deletion Source/CDDataCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- (id)initWithData:(NSData *)someData;
- (id)initWithData:(NSData *)someData offset:(NSUInteger)anOffset;

- (NSData *)data;
@property (readonly) NSData *data;
- (const void *)bytes;

@property (nonatomic, assign) NSUInteger offset;
Expand Down
Loading

0 comments on commit 33c1478

Please sign in to comment.