forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDOCIvar.m
85 lines (65 loc) · 2.15 KB
/
CDOCIvar.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
// -*- 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-2011 Steve Nygard.
#import "CDOCIvar.h"
#import "NSError-CDExtensions.h"
#import "CDClassDump.h"
#import "CDTypeFormatter.h"
#import "CDTypeParser.h"
#import "CDTypeController.h"
@implementation CDOCIvar
- (id)initWithName:(NSString *)aName type:(NSString *)aType offset:(NSUInteger)anOffset;
{
if ((self = [super init])) {
name = [aName retain];
type = [aType retain];
offset = anOffset;
hasParsedType = NO;
parsedType = nil;
}
return self;
}
- (void)dealloc;
{
[name release];
[type release];
[parsedType release];
[super dealloc];
}
#pragma mark - Debugging
- (NSString *)description;
{
return [NSString stringWithFormat:@"[%@] name: %@, type: '%@', offset: %lu",
NSStringFromClass([self class]), self.name, self.type, self.offset];
}
#pragma mark -
@synthesize name;
@synthesize type;
@synthesize offset;
@synthesize hasParsedType;
- (CDType *)parsedType;
{
if (self.hasParsedType == NO) {
NSError *error = nil;
CDTypeParser *parser = [[CDTypeParser alloc] initWithType:type];
parsedType = [[parser parseType:&error] retain];
if (parsedType == nil)
NSLog(@"Warning: Parsing ivar type failed, %@", name);
[parser release];
self.hasParsedType = YES;
}
return parsedType;
}
- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController symbolReferences:(CDSymbolReferences *)symbolReferences;
{
NSString *formattedString = [[typeController ivarTypeFormatter] formatVariable:name type:type symbolReferences:symbolReferences];
if (formattedString != nil) {
[resultString appendString:formattedString];
[resultString appendString:@";"];
if ([typeController shouldShowIvarOffsets]) {
[resultString appendFormat:@"\t// %1$d = 0x%1$x", offset];
}
} else
[resultString appendFormat:@" // Error parsing type: %@, name: %@", type, name];
}
@end