1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -E %s -o %t.mm 2*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s 3*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o %t-rw.cpp 4*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -Werror -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp -Wno-attributes 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambucextern char *strdup(const char *str); 7*f4a2713aSLionel Sambucextern "C" void *sel_registerName(const char *); 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuctypedef signed char BOOL; 10*f4a2713aSLionel Sambuctypedef long NSInteger; 11*f4a2713aSLionel Sambuctypedef unsigned long NSUInteger; 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc#if __has_feature(objc_bool) 14*f4a2713aSLionel Sambuc#define YES __objc_yes 15*f4a2713aSLionel Sambuc#define NO __objc_no 16*f4a2713aSLionel Sambuc#else 17*f4a2713aSLionel Sambuc#define YES ((BOOL)1) 18*f4a2713aSLionel Sambuc#define NO ((BOOL)0) 19*f4a2713aSLionel Sambuc#endif 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc@interface NSNumber 22*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithChar:(char)value; 23*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; 24*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithShort:(short)value; 25*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; 26*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithInt:(int)value; 27*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; 28*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithLong:(long)value; 29*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; 30*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithLongLong:(long long)value; 31*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; 32*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithFloat:(float)value; 33*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithDouble:(double)value; 34*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithBool:(BOOL)value; 35*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithInteger:(NSInteger)value ; 36*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ; 37*f4a2713aSLionel Sambuc@end 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel Sambuc@interface NSString 40*f4a2713aSLionel Sambuc+ (id)stringWithUTF8String:(const char *)str; 41*f4a2713aSLionel Sambuc@end 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambucint main(int argc, const char *argv[]) { 44*f4a2713aSLionel Sambuc // character. 45*f4a2713aSLionel Sambuc NSNumber *theLetterZ = @('Z'); // equivalent to [NSNumber numberWithChar:('Z')] 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc // integral. 48*f4a2713aSLionel Sambuc NSNumber *fortyTwo = @(42); // equivalent to [NSNumber numberWithInt:(42)] 49*f4a2713aSLionel Sambuc NSNumber *fortyTwoUnsigned = @(42U); // equivalent to [NSNumber numberWithUnsignedInt:(42U)] 50*f4a2713aSLionel Sambuc NSNumber *fortyTwoLong = @(42L); // equivalent to [NSNumber numberWithLong:(42L)] 51*f4a2713aSLionel Sambuc NSNumber *fortyTwoLongLong = @(42LL); // equivalent to [NSNumber numberWithLongLong:(42LL)] 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc // floating point. 54*f4a2713aSLionel Sambuc NSNumber *piFloat = @(3.141592654F); // equivalent to [NSNumber numberWithFloat:(3.141592654F)] 55*f4a2713aSLionel Sambuc NSNumber *piDouble = @(3.1415926535); // equivalent to [NSNumber numberWithDouble:(3.1415926535)] 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc BOOL b; 58*f4a2713aSLionel Sambuc NSNumber *nsb = @(b); 59*f4a2713aSLionel Sambuc 60*f4a2713aSLionel Sambuc // Strings. 61*f4a2713aSLionel Sambuc NSString *duplicateString = @(strdup("Hello")); 62*f4a2713aSLionel Sambuc} 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc// CHECK: NSNumber *theLetterZ = ((NSNumber *(*)(id, SEL, char))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithChar:"), ('Z')); 65*f4a2713aSLionel Sambuc// CHECK: NSNumber *fortyTwo = ((NSNumber *(*)(id, SEL, int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithInt:"), (42)); 66*f4a2713aSLionel Sambuc// CHECK: NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(id, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), (42U)); 67*f4a2713aSLionel Sambuc// CHECK: NSNumber *fortyTwoLong = ((NSNumber *(*)(id, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), (42L)); 68*f4a2713aSLionel Sambuc// CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), (42LL)); 69*f4a2713aSLionel Sambuc// CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), (3.14159274F)); 70*f4a2713aSLionel Sambuc// CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), (3.1415926535000001)); 71*f4a2713aSLionel Sambuc// CHECK: NSNumber *nsb = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)(b)); 72*f4a2713aSLionel Sambuc// CHECK: NSString *duplicateString = ((NSString *(*)(id, SEL, const char *))(void *)objc_msgSend)(objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), (const char *)(strdup("Hello"))); 73