2009-06-23 22:31:13 +00:00
|
|
|
// -*- mode: ObjC -*-
|
|
|
|
|
2005-08-13 20:32:02 +00:00
|
|
|
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
|
2011-05-13 07:25:11 +00:00
|
|
|
// Copyright (C) 1997-1998, 2000-2001, 2004-2011 Steve Nygard.
|
2004-01-06 01:52:00 +00:00
|
|
|
|
2003-12-09 01:50:32 +00:00
|
|
|
#import "CDOCMethod.h"
|
|
|
|
|
2004-01-05 21:01:25 +00:00
|
|
|
#import "CDClassDump.h"
|
2003-12-19 05:53:43 +00:00
|
|
|
#import "CDTypeFormatter.h"
|
2009-07-30 06:42:26 +00:00
|
|
|
#import "CDTypeParser.h"
|
|
|
|
#import "NSError-CDExtensions.h"
|
2009-08-09 17:45:25 +00:00
|
|
|
#import "CDTypeController.h"
|
2003-12-09 01:50:32 +00:00
|
|
|
|
|
|
|
@implementation CDOCMethod
|
|
|
|
|
2004-01-20 05:00:23 +00:00
|
|
|
- (id)init;
|
|
|
|
{
|
|
|
|
[NSException raise:@"RejectUnusedImplementation" format:@"-initWithName:type:imp: is the designated initializer"];
|
|
|
|
return nil;
|
|
|
|
}
|
2003-12-09 01:50:32 +00:00
|
|
|
|
2009-06-24 16:18:22 +00:00
|
|
|
- (id)initWithName:(NSString *)aName type:(NSString *)aType imp:(NSUInteger)anImp;
|
2009-06-22 20:41:18 +00:00
|
|
|
{
|
2011-05-13 08:56:08 +00:00
|
|
|
if ((self = [self initWithName:aName type:aType])) {
|
|
|
|
[self setImp:anImp];
|
|
|
|
}
|
2009-06-22 20:41:18 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithName:(NSString *)aName type:(NSString *)aType;
|
2003-12-09 01:50:32 +00:00
|
|
|
{
|
2011-05-13 08:56:08 +00:00
|
|
|
if ((self = [super init])) {
|
|
|
|
name = [aName retain];
|
|
|
|
type = [aType retain];
|
|
|
|
imp = 0;
|
|
|
|
|
|
|
|
hasParsedType = NO;
|
|
|
|
parsedMethodTypes = nil;
|
|
|
|
}
|
2009-07-30 06:42:26 +00:00
|
|
|
|
2003-12-09 01:50:32 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc;
|
|
|
|
{
|
|
|
|
[name release];
|
|
|
|
[type release];
|
|
|
|
|
2009-07-30 06:42:26 +00:00
|
|
|
[parsedMethodTypes release];
|
|
|
|
|
2003-12-09 01:50:32 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
#pragma mark - NSCopying
|
2003-12-09 01:50:32 +00:00
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
- (id)copyWithZone:(NSZone *)zone;
|
2003-12-09 01:50:32 +00:00
|
|
|
{
|
2011-06-19 00:50:16 +00:00
|
|
|
return [[CDOCMethod alloc] initWithName:name type:type imp:imp];
|
2003-12-09 01:50:32 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
#pragma mark - Debugging
|
2003-12-09 01:50:32 +00:00
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
- (NSString *)description;
|
2009-06-22 20:41:18 +00:00
|
|
|
{
|
2011-06-19 00:50:16 +00:00
|
|
|
return [NSString stringWithFormat:@"[%@] name: %@, type: %@, imp: 0x%016lx",
|
|
|
|
NSStringFromClass([self class]), name, type, imp];
|
2009-06-22 20:41:18 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
@synthesize name;
|
|
|
|
@synthesize type;
|
|
|
|
@synthesize imp;
|
|
|
|
|
2009-07-30 06:42:26 +00:00
|
|
|
- (NSArray *)parsedMethodTypes;
|
|
|
|
{
|
|
|
|
if (hasParsedType == NO) {
|
|
|
|
CDTypeParser *parser;
|
2011-06-18 23:19:31 +00:00
|
|
|
NSError *error = nil;
|
2009-07-30 06:42:26 +00:00
|
|
|
|
|
|
|
parser = [[CDTypeParser alloc] initWithType:type];
|
|
|
|
parsedMethodTypes = [[parser parseMethodType:&error] retain];
|
|
|
|
if (parsedMethodTypes == nil)
|
2009-09-01 00:04:20 +00:00
|
|
|
NSLog(@"Warning: Parsing method types failed, %@", name);
|
2009-07-30 06:42:26 +00:00
|
|
|
[parser release];
|
|
|
|
hasParsedType = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedMethodTypes;
|
|
|
|
}
|
|
|
|
|
2009-08-09 17:45:25 +00:00
|
|
|
- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController symbolReferences:(CDSymbolReferences *)symbolReferences;
|
2003-12-10 06:21:50 +00:00
|
|
|
{
|
2003-12-12 04:01:38 +00:00
|
|
|
NSString *formattedString;
|
|
|
|
|
2009-08-09 17:45:25 +00:00
|
|
|
formattedString = [[typeController methodTypeFormatter] formatMethodName:name type:type symbolReferences:symbolReferences];
|
2003-12-19 06:22:28 +00:00
|
|
|
if (formattedString != nil) {
|
2003-12-12 04:01:38 +00:00
|
|
|
[resultString appendString:formattedString];
|
2003-12-19 06:22:28 +00:00
|
|
|
[resultString appendString:@";"];
|
2010-06-03 07:52:51 +00:00
|
|
|
if ([typeController shouldShowMethodAddresses] && imp != 0) {
|
|
|
|
if ([typeController targetArchUses64BitABI])
|
|
|
|
[resultString appendFormat:@"\t// IMP=0x%016lx", imp];
|
|
|
|
else
|
|
|
|
[resultString appendFormat:@"\t// IMP=0x%08lx", imp];
|
|
|
|
}
|
2003-12-19 06:22:28 +00:00
|
|
|
} else
|
2003-12-12 04:01:38 +00:00
|
|
|
[resultString appendFormat:@" // Error parsing type: %@, name: %@", type, name];
|
2003-12-10 06:21:50 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
#pragma mark - Sorting
|
|
|
|
|
2003-12-10 06:21:50 +00:00
|
|
|
- (NSComparisonResult)ascendingCompareByName:(CDOCMethod *)otherMethod;
|
|
|
|
{
|
|
|
|
return [name compare:[otherMethod name]];
|
|
|
|
}
|
|
|
|
|
2003-12-09 01:50:32 +00:00
|
|
|
@end
|