-
Notifications
You must be signed in to change notification settings - Fork 28
/
CDOCMethod.m
103 lines (81 loc) · 2.82 KB
/
CDOCMethod.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-2019 Steve Nygard.
#import "CDOCMethod.h"
#import "CDClassDump.h"
#import "CDTypeFormatter.h"
#import "CDTypeParser.h"
#import "CDTypeController.h"
@implementation CDOCMethod
{
NSString *_name;
NSString *_typeString;
NSUInteger _address;
BOOL _hasParsedType;
NSArray *_parsedMethodTypes;
}
- (id)init;
{
[NSException raise:@"RejectUnusedImplementation" format:@"-initWithName:typeString:imp: is the designated initializer"];
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;
}
return self;
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone;
{
return [[CDOCMethod alloc] initWithName:self.name typeString:self.typeString address:self.address];
}
#pragma mark - Debugging
- (NSString *)description;
{
return [NSString stringWithFormat:@"[%@] name: %@, typeString: %@, address: 0x%016lx",
NSStringFromClass([self class]), self.name, self.typeString, self.address];
}
#pragma mark -
- (NSArray *)parsedMethodTypes;
{
if (_hasParsedType == NO) {
NSError *error = nil;
CDTypeParser *parser = [[CDTypeParser alloc] initWithString:self.typeString];
_parsedMethodTypes = [parser parseMethodType:&error];
if (_parsedMethodTypes == nil)
NSLog(@"Warning: Parsing method types failed, %@", self.name);
_hasParsedType = YES;
}
return _parsedMethodTypes;
}
- (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];
}
#pragma mark - Sorting
- (NSComparisonResult)ascendingCompareByName:(CDOCMethod *)other;
{
return [self.name compare:other.name];
}
@end