forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDFindMethodVisitor.m
166 lines (135 loc) · 3.95 KB
/
CDFindMethodVisitor.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2015 Steve Nygard.
#import "CDFindMethodVisitor.h"
#import "CDClassDump.h"
#import "CDObjectiveC1Processor.h"
#import "CDMachOFile.h"
#import "CDOCProtocol.h"
#import "CDLCDylib.h"
#import "CDOCClass.h"
#import "CDOCCategory.h"
#import "CDOCMethod.h"
//#import "CDTypeController.h"
@interface CDFindMethodVisitor ()
@property (readonly) NSMutableString *resultString;
@property (nonatomic, strong) CDOCProtocol *context;
@property (assign) BOOL hasShownContext;
@end
#pragma mark -
@implementation CDFindMethodVisitor
{
NSString *_searchString;
NSMutableString *_resultString;
CDOCProtocol *_context;
BOOL _hasShownContext;
}
- (id)init;
{
if ((self = [super init])) {
_searchString = nil;
_resultString = [[NSMutableString alloc] init];
_context = nil;
_hasShownContext = NO;
}
return self;
}
#pragma mark -
- (void)willBeginVisiting;
{
[self.classDump appendHeaderToString:self.resultString];
if (self.classDump.hasObjectiveCRuntimeInfo) {
//[[classDump typeController] appendStructuresToString:resultString symbolReferences:nil];
//[resultString appendString:@"// [structures go here]\n"];
}
}
- (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)processor;
{
if (!self.classDump.hasObjectiveCRuntimeInfo) {
[self.resultString appendString:@"//\n"];
[self.resultString appendString:@"// This file does not contain any Objective-C runtime information.\n"];
[self.resultString appendString:@"//\n"];
}
}
- (void)didEndVisiting;
{
[self writeResultToStandardOutput];
}
- (void)writeResultToStandardOutput;
{
NSData *data = [self.resultString dataUsingEncoding:NSUTF8StringEncoding];
[(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:data];
}
- (void)willVisitProtocol:(CDOCProtocol *)protocol;
{
[self setContext:protocol];
}
- (void)didVisitProtocol:(CDOCProtocol *)protocol;
{
if (self.hasShownContext)
[self.resultString appendString:@"\n"];
}
- (void)willVisitClass:(CDOCClass *)aClass;
{
[self setContext:aClass];
}
- (void)didVisitClass:(CDOCClass *)aClass;
{
if (self.hasShownContext)
[self.resultString appendString:@"\n"];
}
- (void)willVisitIvarsOfClass:(CDOCClass *)aClass;
{
}
- (void)didVisitIvarsOfClass:(CDOCClass *)aClass;
{
}
- (void)willVisitCategory:(CDOCCategory *)category;
{
[self setContext:category];
}
- (void)didVisitCategory:(CDOCCategory *)category;
{
if (self.hasShownContext)
[self.resultString appendString:@"\n"];
}
- (void)visitClassMethod:(CDOCMethod *)method;
{
NSRange range = [method.name rangeOfString:self.searchString];
if (range.length > 0) {
[self showContextIfNecessary];
[self.resultString appendString:@"+ "];
[method appendToString:self.resultString typeController:self.classDump.typeController];
[self.resultString appendString:@"\n"];
}
}
- (void)visitInstanceMethod:(CDOCMethod *)method propertyState:(CDVisitorPropertyState *)propertyState;
{
NSRange range = [method.name rangeOfString:self.searchString];
if (range.length > 0) {
[self showContextIfNecessary];
[self.resultString appendString:@"- "];
[method appendToString:self.resultString typeController:self.classDump.typeController];
[self.resultString appendString:@"\n"];
}
}
- (void)visitIvar:(CDOCInstanceVariable *)ivar;
{
}
#pragma mark -
- (void)setContext:(CDOCProtocol *)newContext;
{
if (newContext != _context) {
_context = newContext;
self.hasShownContext = NO;
}
}
- (void)showContextIfNecessary;
{
if (self.hasShownContext == NO) {
[self.resultString appendString:[self.context methodSearchContext]];
[self.resultString appendString:@"\n"];
self.hasShownContext = YES;
}
}
@end