class-dump/Source/CDOCMethod.m

126 lines
3.0 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 *)aName type:(NSString *)aType imp:(NSUInteger)anImp;
{
if ((self = [self initWithName:aName type:aType])) {
[self setImp:anImp];
}
return self;
}
- (id)initWithName:(NSString *)aName type:(NSString *)aType;
{
if ((self = [super init])) {
name = [aName retain];
type = [aType retain];
imp = 0;
hasParsedType = NO;
parsedMethodTypes = nil;
}
2009-07-30 06:42:26 +00:00
return self;
}
- (void)dealloc;
{
[name release];
[type release];
2009-07-30 06:42:26 +00:00
[parsedMethodTypes release];
[super dealloc];
}
2011-06-19 00:50:16 +00:00
#pragma mark - NSCopying
2011-06-19 00:50:16 +00:00
- (id)copyWithZone:(NSZone *)zone;
{
2011-06-19 00:50:16 +00:00
return [[CDOCMethod alloc] initWithName:name type:type imp: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]), name, type, imp];
}
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;
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;
}
- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController symbolReferences:(CDSymbolReferences *)symbolReferences;
{
NSString *formattedString;
formattedString = [[typeController methodTypeFormatter] formatMethodName:name type:type symbolReferences:symbolReferences];
if (formattedString != nil) {
[resultString appendString:formattedString];
[resultString appendString:@";"];
if ([typeController shouldShowMethodAddresses] && imp != 0) {
if ([typeController targetArchUses64BitABI])
[resultString appendFormat:@"\t// IMP=0x%016lx", imp];
else
[resultString appendFormat:@"\t// IMP=0x%08lx", imp];
}
} else
[resultString appendFormat:@" // Error parsing type: %@, name: %@", type, name];
}
2011-06-19 00:50:16 +00:00
#pragma mark - Sorting
- (NSComparisonResult)ascendingCompareByName:(CDOCMethod *)otherMethod;
{
return [name compare:[otherMethod name]];
}
@end