class-dump/Source/CDOCMethod.m

108 lines
2.7 KiB
Mathematica
Raw Normal View History

2009-06-23 22:31:13 +00:00
// -*- mode: ObjC -*-
// 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
#import "CDOCMethod.h"
#import "CDClassDump.h"
#import "CDTypeFormatter.h"
2009-07-30 06:42:26 +00:00
#import "CDTypeParser.h"
#import "CDTypeController.h"
@implementation CDOCMethod
{
NSString *_name;
NSString *_type;
NSUInteger _imp;
BOOL _hasParsedType;
NSArray *_parsedMethodTypes;
}
2004-01-20 05:00:23 +00:00
- (id)init;
{
[NSException raise:@"RejectUnusedImplementation" format:@"-initWithName:type:imp: is the designated initializer"];
return nil;
}
- (id)initWithName:(NSString *)name type:(NSString *)type imp:(NSUInteger)imp;
{
if ((self = [self initWithName:name type:type])) {
[self setImp:imp];
}
return self;
}
- (id)initWithName:(NSString *)name type:(NSString *)type;
{
if ((self = [super init])) {
_name = name;
_type = type;
_imp = 0;
_hasParsedType = NO;
_parsedMethodTypes = nil;
}
2009-07-30 06:42:26 +00:00
return self;
}
2011-06-19 00:50:16 +00:00
#pragma mark - NSCopying
2011-06-19 00:50:16 +00:00
- (id)copyWithZone:(NSZone *)zone;
{
return [[CDOCMethod alloc] initWithName:self.name type:self.type imp:self.imp];
}
2011-06-19 00:50:16 +00:00
#pragma mark - Debugging
2011-06-19 00:50:16 +00:00
- (NSString *)description;
{
2011-06-19 00:50:16 +00:00
return [NSString stringWithFormat:@"[%@] name: %@, type: %@, imp: 0x%016lx",
NSStringFromClass([self class]), self.name, self.type, self.imp];
}
2011-06-19 00:50:16 +00:00
#pragma mark -
2009-07-30 06:42:26 +00:00
- (NSArray *)parsedMethodTypes;
{
if (_hasParsedType == NO) {
NSError *error = nil;
2009-07-30 06:42:26 +00:00
CDTypeParser *parser = [[CDTypeParser alloc] initWithString:self.type];
_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
}
return _parsedMethodTypes;
2009-07-30 06:42:26 +00:00
}
- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController;
{
2012-12-11 02:06:50 +00:00
NSString *formattedString = [typeController.methodTypeFormatter formatMethodName:self.name typeString:self.type];
if (formattedString != nil) {
[resultString appendString:formattedString];
[resultString appendString:@";"];
if (typeController.shouldShowMethodAddresses && self.imp != 0) {
if (typeController.targetArchUses64BitABI)
[resultString appendFormat:@"\t// IMP=0x%016lx", self.imp];
else
[resultString appendFormat:@"\t// IMP=0x%08lx", self.imp];
}
} else
[resultString appendFormat:@" // Error parsing type: %@, name: %@", self.type, self.name];
}
2011-06-19 00:50:16 +00:00
#pragma mark - Sorting
2012-12-10 04:48:39 +00:00
- (NSComparisonResult)ascendingCompareByName:(CDOCMethod *)other;
{
2012-12-10 04:48:39 +00:00
return [self.name compare:other.name];
}
@end