-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathRTIvar.m
145 lines (116 loc) · 2.49 KB
/
RTIvar.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
#import "RTIvar.h"
@interface _RTObjCIvar : RTIvar
{
Ivar _ivar;
}
@end
@implementation _RTObjCIvar
- (id)initWithObjCIvar: (Ivar)ivar
{
if((self = [self init]))
{
_ivar = ivar;
}
return self;
}
- (NSString *)name
{
return [NSString stringWithUTF8String: ivar_getName(_ivar)];
}
- (NSString *)typeEncoding
{
return [NSString stringWithUTF8String: ivar_getTypeEncoding(_ivar)];
}
- (ptrdiff_t)offset
{
return ivar_getOffset(_ivar);
}
@end
@interface _RTComponentsIvar : RTIvar
{
NSString *_name;
NSString *_typeEncoding;
}
@end
@implementation _RTComponentsIvar
- (id)initWithName: (NSString *)name typeEncoding: (NSString *)typeEncoding
{
if((self = [self init]))
{
_name = [name copy];
_typeEncoding = [typeEncoding copy];
}
return self;
}
- (void)dealloc
{
[_name release];
[_typeEncoding release];
[super dealloc];
}
- (NSString *)name
{
return _name;
}
- (NSString *)typeEncoding
{
return _typeEncoding;
}
- (ptrdiff_t)offset
{
return -1;
}
@end
@implementation RTIvar
+ (id)ivarWithObjCIvar: (Ivar)ivar
{
return [[[self alloc] initWithObjCIvar: ivar] autorelease];
}
+ (id)ivarWithName: (NSString *)name typeEncoding: (NSString *)typeEncoding
{
return [[[self alloc] initWithName: name typeEncoding: typeEncoding] autorelease];
}
+ (id)ivarWithName: (NSString *)name encode: (const char *)encodeStr
{
return [self ivarWithName: name typeEncoding: [NSString stringWithUTF8String: encodeStr]];
}
- (id)initWithObjCIvar: (Ivar)ivar
{
[self release];
return [[_RTObjCIvar alloc] initWithObjCIvar: ivar];
}
- (id)initWithName: (NSString *)name typeEncoding: (NSString *)typeEncoding
{
[self release];
return [[_RTComponentsIvar alloc] initWithName: name typeEncoding: typeEncoding];
}
- (NSString *)description
{
return [NSString stringWithFormat: @"<%@ %p: %@ %@ %ld>", [self class], self, [self name], [self typeEncoding], (long)[self offset]];
}
- (BOOL)isEqual: (id)other
{
return [other isKindOfClass: [RTIvar class]] &&
[[self name] isEqual: [other name]] &&
[[self typeEncoding] isEqual: [other typeEncoding]];
}
- (NSUInteger)hash
{
return [[self name] hash] ^ [[self typeEncoding] hash];
}
- (NSString *)name
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (NSString *)typeEncoding
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (ptrdiff_t)offset
{
[self doesNotRecognizeSelector: _cmd];
return 0;
}
@end