Skip to content

Repair breakage to #import lines in -H mode #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: f73f4f9d
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1814af2
Fix the #import names of protocols in -H mode.
May 24, 2012
6266995
Use __attribute__((visibility("hidden"))) instead of // Not exported
0xced May 29, 2012
dd854e9
Don't assume modern runtime == 64 bits
0xced May 29, 2012
e2a2169
Merge pull request #14 from 0xced/visibility-hidden
nygard May 29, 2012
a9aa2d1
Fix parsing of the type-encodings for blocks and function pointers.
May 25, 2012
7056ff2
Fix an assert-fail if a block or function pointer appears inside a st…
Jun 1, 2012
0a2b5dc
Fix https://github.com/nygard/class-dump/issues/13.
May 31, 2012
0ba19f5
Merge branch 'master' of git://github.com/nygard/class-dump
Jun 5, 2012
d61fe79
Merge branch 'function-pointers'
Jun 5, 2012
10f34d8
Merge branch 'attribute-NSObject'
Jun 5, 2012
2f0d5ad
Correctly pass through the argument to -[NSCopying copyWithZone:].
Jun 29, 2012
3a9be21
Don't duplicate struct definitions for Objective-C++ templated types.
Jun 7, 2012
d7ade3e
Add a poorly tested --mangle-template-types option.
Jul 6, 2012
5adbfb6
Fix https://github.com/nygard/class-dump/issues/16.
Jun 28, 2012
4b09fe0
Use formatVariable:parsedType: to avoid making a copy of the CDType.
Jun 29, 2012
2c518c3
Track alignment and size of CDOCIvars; output sane bitfield types.
Jun 29, 2012
f7144a7
Replace "NSString" with "int" for arraySize and bitfieldSize.
Jun 29, 2012
7fe1666
Merge branch 'template-types'
Jul 6, 2012
7016efc
Merge branch 'empty-structs'
Jul 6, 2012
5dcf158
Merge branch 'better-bitfields'
Jul 6, 2012
d937756
Fix https://github.com/nygard/class-dump/issues/16.
Jun 28, 2012
9963278
Add a poorly tested --mangle-template-types option.
Jul 6, 2012
24f79e7
Merge branch 'template-types'
Jul 6, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Source/CDLCSymbolTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ - (void)loadSymbols;

CDSymbol *symbol = [[CDSymbol alloc] initWithName:str machOFile:self.machOFile nlist32:nlist];
[_symbols addObject:symbol];

if ([str hasPrefix:ObjCClassSymbolPrefix] && symbol.value != 0) {
NSString *className = [str substringFromIndex:[ObjCClassSymbolPrefix length]];
[_classSymbols setObject:symbol forKey:className];
}
}

//NSLog(@"Loaded %lu 32-bit symbols", [symbols count]);
Expand All @@ -151,7 +156,7 @@ - (void)loadSymbols;
CDSymbol *symbol = [[CDSymbol alloc] initWithName:str machOFile:self.machOFile nlist64:nlist];
[_symbols addObject:symbol];

if ([str hasPrefix:ObjCClassSymbolPrefix] && [symbol value] != 0) {
if ([str hasPrefix:ObjCClassSymbolPrefix] && symbol.value != 0) {
NSString *className = [str substringFromIndex:[ObjCClassSymbolPrefix length]];
[_classSymbols setObject:symbol forKey:className];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/CDMultiFileVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ - (NSString *)importStringForProtocolName:(NSString *)name;
if (name != nil) {
NSString *framework = [self frameworkForProtocolName:name];
if (framework == nil)
return [NSString stringWithFormat:@"#import \"%@.h\"\n", name];
return [NSString stringWithFormat:@"#import \"%@-Protocol.h\"\n", name];
else
return [NSString stringWithFormat:@"#import <%@/%@.h>\n", framework, name];
return [NSString stringWithFormat:@"#import <%@/%@-Protocol.h>\n", framework, name];
}

return nil;
Expand Down
4 changes: 3 additions & 1 deletion Source/CDOCIvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

@interface CDOCIvar : NSObject

- (id)initWithName:(NSString *)name type:(NSString *)aType offset:(NSUInteger)offset;
- (id)initWithName:(NSString *)name type:(NSString *)aType offset:(NSUInteger)offset alignment:(NSUInteger)alignment size:(NSUInteger)size;

@property (readonly) NSString *name;
@property (readonly) NSString *type;
@property (readonly) NSUInteger offset;
@property (readonly) NSUInteger alignment;
@property (readonly) NSUInteger size;

@property (nonatomic, readonly) CDType *parsedType;

Expand Down
14 changes: 12 additions & 2 deletions Source/CDOCIvar.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ @implementation CDOCIvar
NSString *name;
NSString *type;
NSUInteger offset;
NSUInteger alignment;
NSUInteger size;

BOOL hasParsedType;
CDType *parsedType;
}

- (id)initWithName:(NSString *)aName type:(NSString *)aType offset:(NSUInteger)anOffset;
- (id)initWithName:(NSString *)aName type:(NSString *)aType offset:(NSUInteger)anOffset alignment:(NSUInteger)anAlignment size:(NSUInteger)aSize;
{
if ((self = [super init])) {
name = aName;
type = aType;
offset = anOffset;
alignment = anAlignment;
size = aSize;

hasParsedType = NO;
parsedType = nil;
Expand All @@ -54,6 +58,8 @@ - (NSString *)description;
@synthesize name;
@synthesize type;
@synthesize offset;
@synthesize alignment;
@synthesize size;
@synthesize hasParsedType;

- (CDType *)parsedType;
Expand All @@ -66,6 +72,10 @@ - (CDType *)parsedType;
if (parsedType == nil)
NSLog(@"Warning: Parsing ivar type failed, %@", name);

if (parsedType.isBitfieldType) {
[parsedType setUnderlyingType:size];
}

self.hasParsedType = YES;
}

Expand All @@ -74,7 +84,7 @@ - (CDType *)parsedType;

- (void)appendToString:(NSMutableString *)resultString typeController:(CDTypeController *)typeController;
{
NSString *formattedString = [[typeController ivarTypeFormatter] formatVariable:name type:type];
NSString *formattedString = [[typeController ivarTypeFormatter] formatVariable:name parsedType:[self parsedType]];
if (formattedString != nil) {
[resultString appendString:formattedString];
[resultString appendString:@";"];
Expand Down
2 changes: 1 addition & 1 deletion Source/CDOCMethod.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (id)initWithName:(NSString *)aName type:(NSString *)aType;

- (id)copyWithZone:(NSZone *)zone;
{
return [[CDOCMethod alloc] initWithName:name type:type imp:imp];
return [[CDOCMethod allocWithZone:zone] initWithName:name type:type imp:imp];
}

#pragma mark - Debugging
Expand Down
2 changes: 1 addition & 1 deletion Source/CDObjectiveC1Processor.m
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ - (CDOCClass *)processClassDefinitionAtAddress:(uint32_t)address;
// bitfields don't need names.
// NSIconRefBitmapImageRep in AppKit on 10.5 has a single-bit bitfield, plus an unnamed 31-bit field.
if (type != nil) {
CDOCIvar *anIvar = [[CDOCIvar alloc] initWithName:name type:type offset:objcIvar.offset];
CDOCIvar *anIvar = [[CDOCIvar alloc] initWithName:name type:type offset:objcIvar.offset alignment:0 size:0];
[ivars addObject:anIvar];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/CDObjectiveC2Processor.m
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ - (NSArray *)loadIvarsAtAddress:(uint64_t)address;
NSString *name = [self.machOFile stringAtAddress:objc2Ivar.name];
NSString *type = [self.machOFile stringAtAddress:objc2Ivar.type];

CDOCIvar *ivar = [[CDOCIvar alloc] initWithName:name type:type offset:objc2Ivar.offset];
CDOCIvar *ivar = [[CDOCIvar alloc] initWithName:name type:type offset:objc2Ivar.offset alignment:objc2Ivar.alignment size:objc2Ivar.size];
[ivars addObject:ivar];
} else {
//NSLog(@"%016lx %016lx %016lx %08x %08x", objc2Ivar.offset, objc2Ivar.name, objc2Ivar.type, objc2Ivar.alignment, objc2Ivar.size);
Expand Down
2 changes: 1 addition & 1 deletion Source/CDStructureInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (id)initWithType:(CDType *)type;

- (id)copyWithZone:(NSZone *)zone;
{
CDStructureInfo *copy = [[CDStructureInfo alloc] initWithType:self.type]; // type gets copied
CDStructureInfo *copy = [[CDStructureInfo allocWithZone:zone] initWithType:self.type]; // type gets copied
copy.referenceCount = self.referenceCount;
copy.isUsedInMethod = self.isUsedInMethod;
copy.typedefName = self.typedefName;
Expand Down
1 change: 1 addition & 0 deletions Source/CDStructureTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ - (void)appendTypedefsToString:(NSMutableString *)resultString
[resultString appendFormat:@"// depth: %u, ref: %u, used in method? %u\n", info.type.structureDepth, info.referenceCount, info.isUsedInMethod];
}

typeFormatter.shouldExpand = NO;
NSString *formattedString = [typeFormatter formatVariable:nil parsedType:info.type];
if (formattedString != nil) {
//[resultString appendFormat:@"%@;\n\n", formattedString];
Expand Down
7 changes: 6 additions & 1 deletion Source/CDTextClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "CDOCCategory.h"
#import "CDOCMethod.h"
#import "CDOCProperty.h"
#import "CDType.h"
#import "CDTypeController.h"
#import "CDTypeFormatter.h"
#import "CDVisitorPropertyState.h"
Expand Down Expand Up @@ -45,7 +46,7 @@ - (id)init;
- (void)willVisitClass:(CDOCClass *)aClass;
{
if (aClass.isExported == NO)
[self.resultString appendString:@"// Not exported\n"];
[self.resultString appendString:@"__attribute__((visibility(\"hidden\")))\n"];

[self.resultString appendFormat:@"@interface %@", aClass.name];
if (aClass.superClassName != nil)
Expand Down Expand Up @@ -284,6 +285,10 @@ - (void)_visitProperty:(CDOCProperty *)property parsedType:(CDType *)parsedType
if (isWeak)
[self.resultString appendString:@"__weak "];

if ([alist containsObject:@"retain"] || [alist containsObject:@"copy"])
if (!parsedType.isGarbageCollectedType)
[self.resultString appendString:@"__attribute__((NSObject)) "];

NSString *formattedString = [self.classDump.typeController.propertyTypeFormatter formatVariable:property.name parsedType:parsedType];
[self.resultString appendFormat:@"%@;", formattedString];

Expand Down
12 changes: 10 additions & 2 deletions Source/CDType.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@
- (id)initIDTypeWithProtocols:(NSArray *)protocols;
- (id)initStructType:(CDTypeName *)name members:(NSArray *)members;
- (id)initUnionType:(CDTypeName *)name members:(NSArray *)members;
- (id)initBitfieldType:(NSString *)bitfieldSize;
- (id)initArrayType:(CDType *)type count:(NSString *)count;
- (id)initBitfieldType:(int)bitfieldSize;
- (id)initArrayType:(CDType *)type count:(int)count;
- (id)initPointerType:(CDType *)type;
- (id)initFunctionPointerType;
- (id)initBlockType;
- (id)initModifier:(int)modifier type:(CDType *)type;

- (void)setUnderlyingType:(NSUInteger)underlyingWidth;

@property (strong) NSString *variableName;

@property (nonatomic, readonly) int type;
@property (readonly) BOOL isIDType;
@property (readonly) BOOL isNamedObject;
@property (readonly) BOOL isTemplateType;
@property (readonly) BOOL isGarbageCollectedType;
@property (readonly) BOOL isBitfieldType;

@property (nonatomic, readonly) CDType *subtype;
@property (nonatomic, readonly) CDTypeName *typeName;
Expand Down Expand Up @@ -64,3 +70,5 @@
- (void)phase3MergeWithTypeController:(CDTypeController *)typeController;

@end

extern BOOL global_shouldMangleTemplateTypes;
Loading