Files
swift-mirror/test/Interpreter/Inputs/ObjCClasses/ObjCClasses.m
Slava Pestov 0004bc480a IRGen: Differentiate between Swift.Bool and ObjCBool
SIL already does this where necessary, except with foreign throwing
functions; this patch changes Sema and the ClangImporter to give
them an ObjCBool foreign error result type explicitly.

This fixes a problem where calls to functions taking and returning
the C99 _Bool type were miscompiled on Mac OS X x86-64, because
IRGen was conflating the Objective-C BOOL type (which is a signed
char on some platforms) and C99 _Bool (which lowers as the LLVM
i1 type).

Fixes <rdar://problem/26506458> and <rdar://problem/27365520>.
2016-08-10 10:34:24 -07:00

167 lines
2.5 KiB
Objective-C

#import "ObjCClasses.h"
#import <Foundation/NSError.h>
#include <stdio.h>
#include <assert.h>
@implementation HasHiddenIvars
@synthesize x;
@synthesize y;
@synthesize z;
@synthesize t;
@end
@implementation TestingNSError
+ (BOOL)throwNilError:(NSError **)error {
return 0;
}
+ (nullable void *)maybeThrow:(BOOL)shouldThrow error:(NSError **)error {
if (shouldThrow) {
*error = [NSError errorWithDomain:@"pointer error" code:0 userInfo:nil];
return 0;
}
return (void *)42;
}
+ (nullable void (^)(void))blockThrowError:(NSError **)error {
*error = [NSError errorWithDomain:@"block error" code:0 userInfo:nil];
return 0;
}
@end
@implementation Container
- (id)initWithObject:(id)anObject {
if ((self = [super init]) != nil) {
self.object = anObject;
}
return self;
}
- (void)processObjectWithBlock:(void (^)(id))block {
block(self.object);
}
- (void)updateObjectWithBlock:(id (^)())block {
self.object = block();
}
@synthesize object;
- (id)initWithCat1:(id)anObject {
return [self initWithObject:anObject];
}
- (id)getCat1 {
return self.object;
}
- (void)setCat1:(id)obj {
self.object = obj;
}
- (id)cat1Property {
return self.object;
}
- (void)setCat1Property:(id)prop {
self.object = prop;
}
@end
@implementation SubContainer
@end
@implementation NestedContainer
@end
@implementation StringContainer
@end
@implementation CopyingContainer
@end
@implementation Animal
- (NSString *)noise {
return @"eep";
}
@end
@implementation Dog
- (NSString *)noise {
return @"woof";
}
@end
@implementation AnimalContainer
@end
#if __has_feature(objc_class_property)
static int _value = 0;
@implementation ClassWithClassProperty
+ (int)value {
return _value;
}
+ (void)setValue:(int)newValue {
_value = newValue;
}
+ (void)reset {
_value = 0;
}
@end
@implementation ObjCSubclassWithClassProperty
+ (BOOL)optionalClassProp {
return YES;
}
@end
@implementation PropertyNamingConflict
- (id)prop { return self; }
+ (id)prop { return nil; }
@end
#endif
@implementation BridgedInitializer
- (id) initWithArray: (NSArray*) array {
_objects = array;
return self;
}
- (NSInteger) count {
return _objects.count;
}
@end
static unsigned counter = 0;
@implementation NSLifetimeTracked
+ (id) allocWithZone:(NSZone *)zone {
counter++;
return [super allocWithZone:zone];
}
- (void) dealloc {
counter--;
}
+ (unsigned) count {
return counter;
}
@end
@implementation TestingBool
- (void) shouldBeTrueObjCBool: (BOOL)value {
assert(value);
}
- (void) shouldBeTrueCBool: (_Bool)value {
assert(value);
}
@end