Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -E %s -o %t.mm |
| 2 | // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s |
| 3 | // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o %t-rw.cpp |
NAKAMURA Takumi | 9ff009f | 2012-05-01 10:52:06 +0000 | [diff] [blame] | 4 | // 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 |
NAKAMURA Takumi | 88442c9 | 2012-04-24 01:19:04 +0000 | [diff] [blame] | 5 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 6 | extern char *strdup(const char *str); |
| 7 | extern "C" void *sel_registerName(const char *); |
| 8 | |
| 9 | typedef signed char BOOL; |
| 10 | typedef long NSInteger; |
| 11 | typedef unsigned long NSUInteger; |
| 12 | |
| 13 | #if __has_feature(objc_bool) |
| 14 | #define YES __objc_yes |
| 15 | #define NO __objc_no |
| 16 | #else |
| 17 | #define YES ((BOOL)1) |
| 18 | #define NO ((BOOL)0) |
| 19 | #endif |
| 20 | |
| 21 | @interface NSNumber |
| 22 | + (NSNumber *)numberWithChar:(char)value; |
| 23 | + (NSNumber *)numberWithUnsignedChar:(unsigned char)value; |
| 24 | + (NSNumber *)numberWithShort:(short)value; |
| 25 | + (NSNumber *)numberWithUnsignedShort:(unsigned short)value; |
| 26 | + (NSNumber *)numberWithInt:(int)value; |
| 27 | + (NSNumber *)numberWithUnsignedInt:(unsigned int)value; |
| 28 | + (NSNumber *)numberWithLong:(long)value; |
| 29 | + (NSNumber *)numberWithUnsignedLong:(unsigned long)value; |
| 30 | + (NSNumber *)numberWithLongLong:(long long)value; |
| 31 | + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; |
| 32 | + (NSNumber *)numberWithFloat:(float)value; |
| 33 | + (NSNumber *)numberWithDouble:(double)value; |
| 34 | + (NSNumber *)numberWithBool:(BOOL)value; |
| 35 | + (NSNumber *)numberWithInteger:(NSInteger)value ; |
| 36 | + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ; |
| 37 | @end |
| 38 | |
| 39 | @interface NSString |
| 40 | + (id)stringWithUTF8String:(const char *)str; |
| 41 | @end |
| 42 | |
| 43 | int main(int argc, const char *argv[]) { |
| 44 | // character. |
| 45 | NSNumber *theLetterZ = @('Z'); // equivalent to [NSNumber numberWithChar:('Z')] |
| 46 | |
| 47 | // integral. |
| 48 | NSNumber *fortyTwo = @(42); // equivalent to [NSNumber numberWithInt:(42)] |
| 49 | NSNumber *fortyTwoUnsigned = @(42U); // equivalent to [NSNumber numberWithUnsignedInt:(42U)] |
| 50 | NSNumber *fortyTwoLong = @(42L); // equivalent to [NSNumber numberWithLong:(42L)] |
| 51 | NSNumber *fortyTwoLongLong = @(42LL); // equivalent to [NSNumber numberWithLongLong:(42LL)] |
| 52 | |
| 53 | // floating point. |
| 54 | NSNumber *piFloat = @(3.141592654F); // equivalent to [NSNumber numberWithFloat:(3.141592654F)] |
| 55 | NSNumber *piDouble = @(3.1415926535); // equivalent to [NSNumber numberWithDouble:(3.1415926535)] |
| 56 | |
Argyrios Kyrtzidis | 2df1a58 | 2012-05-10 23:12:03 +0000 | [diff] [blame] | 57 | BOOL b; |
| 58 | NSNumber *nsb = @(b); |
| 59 | |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 60 | // Strings. |
| 61 | NSString *duplicateString = @(strdup("Hello")); |
| 62 | } |
| 63 | |
| 64 | // CHECK: NSNumber *theLetterZ = ((NSNumber *(*)(id, SEL, char))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithChar:"), ('Z')); |
| 65 | // CHECK: NSNumber *fortyTwo = ((NSNumber *(*)(id, SEL, int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithInt:"), (42)); |
| 66 | // CHECK: NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(id, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), (42U)); |
| 67 | // CHECK: NSNumber *fortyTwoLong = ((NSNumber *(*)(id, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), (42L)); |
| 68 | // CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), (42LL)); |
Benjamin Kramer | a0a3c90 | 2012-09-20 14:07:17 +0000 | [diff] [blame] | 69 | // CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), (3.1415927F)); |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 70 | // CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), (3.1415926535)); |
Argyrios Kyrtzidis | 2df1a58 | 2012-05-10 23:12:03 +0000 | [diff] [blame] | 71 | // CHECK: NSNumber *nsb = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)(b)); |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 72 | // CHECK: NSString *duplicateString = ((NSString *(*)(id, SEL, const char *))(void *)objc_msgSend)(objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), (const char *)(strdup("Hello"))); |