-
Notifications
You must be signed in to change notification settings - Fork 28
/
CDOCInstanceVariable.m
93 lines (76 loc) · 2.53 KB
/
CDOCInstanceVariable.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
// -*- 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 "CDOCInstanceVariable.h"
#import "CDClassDump.h"
#import "CDTypeFormatter.h"
#import "CDTypeParser.h"
#import "CDTypeController.h"
#import "CDType.h"
@interface CDOCInstanceVariable ()
@property (assign) BOOL hasParsedType;
@end
#pragma mark -
@implementation CDOCInstanceVariable
{
NSString *_name;
NSString *_typeString;
NSUInteger _offset;
BOOL _hasParsedType;
CDType *_type;
NSError *_parseError;
}
- (id)initWithName:(NSString *)name typeString:(NSString *)typeString offset:(NSUInteger)offset;
{
if ((self = [super init])) {
_name = name;
_typeString = typeString;
_offset = offset;
_hasParsedType = NO;
_type = nil;
_parseError = nil;
}
return self;
}
#pragma mark - Debugging
- (NSString *)description;
{
return [NSString stringWithFormat:@"[%@] name: %@, typeString: '%@', offset: %lu",
NSStringFromClass([self class]), self.name, self.typeString, self.offset];
}
#pragma mark -
- (CDType *)type;
{
if (self.hasParsedType == NO && self.parseError == nil) {
CDTypeParser *parser = [[CDTypeParser alloc] initWithString:self.typeString];
NSError *error;
_type = [parser parseType:&error];
if (_type == nil) {
NSLog(@"Warning: Parsing instance variable type failed, %@", self.name);
_parseError = error;
} else {
self.hasParsedType = YES;
}
}
return _type;
}
- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController;
{
CDType *type = [self type]; // Parses it, if necessary;
if (self.parseError != nil) {
if ([self.typeString length] > 0) {
[resultString appendFormat:@" // Error: parsing type: '%@', name: %@", self.typeString, self.name];
} else {
[resultString appendFormat:@" // Error: Empty type, name: %@", self.name];
}
} else {
NSString *formattedString = [[typeController ivarTypeFormatter] formatVariable:self.name type:type];
NSParameterAssert(formattedString != nil);
[resultString appendString:formattedString];
[resultString appendString:@";"];
if ([typeController shouldShowIvarOffsets]) {
[resultString appendFormat:@"\t// %ld = 0x%lx", self.offset, self.offset];
}
}
}
@end