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.
|
2012-02-23 10:33:58 +00:00
|
|
|
// Copyright (C) 1997-1998, 2000-2001, 2004-2012 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"
|
2009-08-09 17:45:25 +00:00
|
|
|
#import "CDTypeController.h"
|
2003-12-09 01:50:32 +00:00
|
|
|
|
|
|
|
@implementation CDOCMethod
|
2012-02-23 10:28:37 +00:00
|
|
|
{
|
2012-07-16 04:10:34 +00:00
|
|
|
NSString *_name;
|
|
|
|
NSString *_type;
|
|
|
|
NSUInteger _imp;
|
2012-02-23 10:28:37 +00:00
|
|
|
|
2012-07-16 04:10:34 +00:00
|
|
|
BOOL _hasParsedType;
|
|
|
|
NSArray *_parsedMethodTypes;
|
2012-02-23 10:28:37 +00:00
|
|
|
}
|
2003-12-09 01:50:32 +00:00
|
|
|
|
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
|
|
|
|
2012-07-16 10:20:50 +00:00
|
|
|
- (id)initWithName:(NSString *)name type:(NSString *)type imp:(NSUInteger)imp;
|
2009-06-22 20:41:18 +00:00
|
|
|
{
|
2012-07-16 10:20:50 +00:00
|
|
|
if ((self = [self initWithName:name type:type])) {
|
|
|
|
[self setImp:imp];
|
2011-05-13 08:56:08 +00:00
|
|
|
}
|
2009-06-22 20:41:18 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-07-16 10:20:50 +00:00
|
|
|
- (id)initWithName:(NSString *)name type:(NSString *)type;
|
2003-12-09 01:50:32 +00:00
|
|
|
{
|
2011-05-13 08:56:08 +00:00
|
|
|
if ((self = [super init])) {
|
2012-07-16 10:20:50 +00:00
|
|
|
_name = name;
|
|
|
|
_type = type;
|
2012-07-16 04:10:34 +00:00
|
|
|
_imp = 0;
|
2011-05-13 08:56:08 +00:00
|
|
|
|
2012-07-16 04:10:34 +00:00
|
|
|
_hasParsedType = NO;
|
|
|
|
_parsedMethodTypes = nil;
|
2011-05-13 08:56:08 +00:00
|
|
|
}
|
2009-07-30 06:42:26 +00:00
|
|
|
|
2003-12-09 01:50:32 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-07-16 04:10:34 +00:00
|
|
|
return [[CDOCMethod alloc] initWithName:self.name type:self.type imp:self.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",
|
2012-07-16 04:10:34 +00:00
|
|
|
NSStringFromClass([self class]), self.name, self.type, self.imp];
|
2009-06-22 20:41:18 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2009-07-30 06:42:26 +00:00
|
|
|
- (NSArray *)parsedMethodTypes;
|
|
|
|
{
|
2012-07-16 04:10:34 +00:00
|
|
|
if (_hasParsedType == NO) {
|
2011-06-18 23:19:31 +00:00
|
|
|
NSError *error = nil;
|
2009-07-30 06:42:26 +00:00
|
|
|
|
2012-12-10 05:10:54 +00:00
|
|
|
CDTypeParser *parser = [[CDTypeParser alloc] initWithString:self.type];
|
2012-07-16 04:10:34 +00:00
|
|
|
_parsedMethodTypes = [parser parseMethodType:&error];
|
|
|
|
if (_parsedMethodTypes == nil)
|
|
|
|
NSLog(@"Warning: Parsing method types failed, %@", self.name);
|
|
|
|
_hasParsedType = YES;
|
2009-07-30 06:42:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 04:10:34 +00:00
|
|
|
return _parsedMethodTypes;
|
2009-07-30 06:42:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-26 14:25:37 +00:00
|
|
|
- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController;
|
2003-12-10 06:21:50 +00:00
|
|
|
{
|
2012-07-16 04:10:34 +00:00
|
|
|
NSString *formattedString = [typeController.methodTypeFormatter formatMethodName:self.name type:self.type];
|
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:@";"];
|
2012-07-16 04:10:34 +00:00
|
|
|
if (typeController.shouldShowMethodAddresses && self.imp != 0) {
|
2012-02-25 12:03:48 +00:00
|
|
|
if (typeController.targetArchUses64BitABI)
|
2012-07-16 04:10:34 +00:00
|
|
|
[resultString appendFormat:@"\t// IMP=0x%016lx", self.imp];
|
2010-06-03 07:52:51 +00:00
|
|
|
else
|
2012-07-16 04:10:34 +00:00
|
|
|
[resultString appendFormat:@"\t// IMP=0x%08lx", self.imp];
|
2010-06-03 07:52:51 +00:00
|
|
|
}
|
2003-12-19 06:22:28 +00:00
|
|
|
} else
|
2012-07-16 04:10:34 +00:00
|
|
|
[resultString appendFormat:@" // Error parsing type: %@, name: %@", self.type, self.name];
|
2003-12-10 06:21:50 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 00:50:16 +00:00
|
|
|
#pragma mark - Sorting
|
|
|
|
|
2012-12-10 04:48:39 +00:00
|
|
|
- (NSComparisonResult)ascendingCompareByName:(CDOCMethod *)other;
|
2003-12-10 06:21:50 +00:00
|
|
|
{
|
2012-12-10 04:48:39 +00:00
|
|
|
return [self.name compare:other.name];
|
2003-12-10 06:21:50 +00:00
|
|
|
}
|
|
|
|
|
2003-12-09 01:50:32 +00:00
|
|
|
@end
|