class-dump/Source/CDOCMethod.m

104 lines
2.8 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.
2019-03-02 06:56:10 +00:00
// Copyright (C) 1997-2019 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 *_typeString;
NSUInteger _address;
BOOL _hasParsedType;
NSArray *_parsedMethodTypes;
}
2004-01-20 05:00:23 +00:00
- (id)init;
{
[NSException raise:@"RejectUnusedImplementation" format:@"-initWithName:typeString:imp: is the designated initializer"];
2004-01-20 05:00:23 +00:00
return nil;
}
- (id)initWithName:(NSString *)name typeString:(NSString *)typeString;
{
return [self initWithName:name typeString:typeString address:0];
}
- (id)initWithName:(NSString *)name typeString:(NSString *)typeString address:(NSUInteger)address;
{
if ((self = [super init])) {
_name = name;
_typeString = typeString;
_address = address;
_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 typeString:self.typeString address:self.address];
}
2011-06-19 00:50:16 +00:00
#pragma mark - Debugging
2011-06-19 00:50:16 +00:00
- (NSString *)description;
{
return [NSString stringWithFormat:@"[%@] name: %@, typeString: %@, address: 0x%016lx",
NSStringFromClass([self class]), self.name, self.typeString, self.address];
}
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.typeString];
_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;
{
NSString *formattedString = [typeController.methodTypeFormatter formatMethodName:self.name typeString:self.typeString];
if (formattedString != nil) {
[resultString appendString:formattedString];
[resultString appendString:@";"];
if (typeController.shouldShowMethodAddresses && self.address != 0) {
if (typeController.targetArchUses64BitABI)
[resultString appendFormat:@"\t// IMP=0x%016lx", self.address];
else
[resultString appendFormat:@"\t// IMP=0x%08lx", self.address];
}
} else
[resultString appendFormat:@" // Error parsing type: %@, name: %@", self.typeString, 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