OLD | NEW |
(Empty) | |
| 1 // -*- mode: ObjC -*- |
| 2 |
| 3 // This file is part of class-dump, a utility for examining the Objective-C seg
ment of Mach-O files. |
| 4 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard. |
| 5 |
| 6 #import "CDOCIvar.h" |
| 7 |
| 8 #import "NSError-CDExtensions.h" |
| 9 #import "CDClassDump.h" |
| 10 #import "CDTypeFormatter.h" |
| 11 #import "CDTypeParser.h" |
| 12 #import "CDTypeController.h" |
| 13 |
| 14 @implementation CDOCIvar |
| 15 |
| 16 - (id)initWithName:(NSString *)aName type:(NSString *)aType offset:(NSUInteger)a
nOffset; |
| 17 { |
| 18 if ([super init] == nil) |
| 19 return nil; |
| 20 |
| 21 name = [aName retain]; |
| 22 type = [aType retain]; |
| 23 offset = anOffset; |
| 24 |
| 25 hasParsedType = NO; |
| 26 parsedType = nil; |
| 27 |
| 28 return self; |
| 29 } |
| 30 |
| 31 - (void)dealloc; |
| 32 { |
| 33 [name release]; |
| 34 [type release]; |
| 35 |
| 36 [parsedType release]; |
| 37 |
| 38 [super dealloc]; |
| 39 } |
| 40 |
| 41 - (NSString *)name; |
| 42 { |
| 43 return name; |
| 44 } |
| 45 |
| 46 - (NSString *)type; |
| 47 { |
| 48 return type; |
| 49 } |
| 50 |
| 51 - (NSUInteger)offset; |
| 52 { |
| 53 return offset; |
| 54 } |
| 55 |
| 56 - (CDType *)parsedType; |
| 57 { |
| 58 if (hasParsedType == NO) { |
| 59 CDTypeParser *parser; |
| 60 NSError *error; |
| 61 |
| 62 parser = [[CDTypeParser alloc] initWithType:type]; |
| 63 parsedType = [[parser parseType:&error] retain]; |
| 64 if (parsedType == nil) |
| 65 NSLog(@"Warning: Parsing ivar type failed, %@", name); |
| 66 [parser release]; |
| 67 |
| 68 hasParsedType = YES; |
| 69 } |
| 70 |
| 71 return parsedType; |
| 72 } |
| 73 |
| 74 - (NSString *)description; |
| 75 { |
| 76 return [NSString stringWithFormat:@"[%@] name: %@, type: '%@', offset: %lu", |
| 77 NSStringFromClass([self class]), name, type, offset]; |
| 78 } |
| 79 |
| 80 - (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeCon
troller *)typeController symbolReferences:(CDSymbolReferences *)symbolReferences
; |
| 81 { |
| 82 NSString *formattedString; |
| 83 |
| 84 formattedString = [[typeController ivarTypeFormatter] formatVariable:name ty
pe:type symbolReferences:symbolReferences]; |
| 85 if (formattedString != nil) { |
| 86 [resultString appendString:formattedString]; |
| 87 [resultString appendString:@";"]; |
| 88 if ([typeController shouldShowIvarOffsets]) { |
| 89 [resultString appendFormat:@"\t// %1$d = 0x%1$x", offset]; |
| 90 } |
| 91 } else |
| 92 [resultString appendFormat:@" // Error parsing type: %@, name: %@", t
ype, name]; |
| 93 } |
| 94 |
| 95 @end |
OLD | NEW |