brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · b919a7b Raw
118 lines · plain
1#import <Foundation/Foundation.h>2 3@interface OverridesALot: NSObject4 5- (void)boring;6 7@end8 9@implementation OverridesALot10 11+ (id)alloc {12  NSLog(@"alloc");13  return [super alloc];14}15 16+ (id)allocWithZone: (NSZone *)z {17  NSLog(@"allocWithZone:");18  return [super allocWithZone: z];19}20 21+ (id)new {22  NSLog(@"new");23  return [super new];24}25 26- (id)init {27  NSLog(@"init");28  return [super init];29}30 31- (id)self {32  NSLog(@"self");33  return [super self];34}35 36+ (id)class {37  NSLog(@"class");38  return [super class];39}40 41- (BOOL)isKindOfClass: (Class)c {42  NSLog(@"isKindOfClass:");43  return [super isKindOfClass: c];44}45 46- (BOOL)respondsToSelector: (SEL)s {47  NSLog(@"respondsToSelector:");48  return [super respondsToSelector: s];49}50 51- (id)retain {52  NSLog(@"retain");53  return [super retain];54}55 56- (oneway void)release {57  NSLog(@"release");58  [super release];59}60 61- (id)autorelease { 62  NSLog(@"autorelease");63  return [super autorelease];64}65 66- (void)boring {67  NSLog(@"boring");68}69 70@end71 72@interface OverridesInit: NSObject73 74- (void)boring;75 76@end77 78@implementation OverridesInit79 80- (id)init {81  NSLog(@"init");82  return [super init];83}84 85@end86 87int main() {88  id obj;89 90  // First make an object of the class that overrides everything,91  // and make sure we step into all the methods:92  93  obj = [OverridesALot alloc]; // Stop here to start stepping94  [obj release]; // Stop Location 295  96  obj = [OverridesALot allocWithZone: NULL]; // Stop Location 397  [obj release]; // Stop Location 498  99  obj = [OverridesALot new]; // Stop Location 5100  [obj release]; // Stop Location 6101  102  obj = [[OverridesALot alloc] init]; // Stop Location 7103  [obj self]; // Stop Location 8104  [obj isKindOfClass: [OverridesALot class]]; // Stop Location 9105  [obj respondsToSelector: @selector(hello)]; // Stop Location 10106  [obj retain];  // Stop Location 11107  [obj autorelease]; // Stop Location 12108  [obj boring]; // Stop Location 13109  [obj release]; // Stop Location 14110 111  // Now try a class that only overrides init but not alloc, to make112  // sure we get into the second method in a combined call:113  114  obj = [[OverridesInit alloc] init]; // Stop Location 15115 116  return 0; // Stop Location 15117}118