• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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// rdar://10803676
4
5extern "C" void *sel_registerName(const char *);
6
7typedef bool BOOL;
8typedef long NSInteger;
9typedef unsigned long NSUInteger;
10
11#if __has_feature(objc_bool)
12#define YES             __objc_yes
13#define NO              __objc_no
14#else
15#define YES             ((BOOL)1)
16#define NO              ((BOOL)0)
17#endif
18
19@interface NSNumber
20+ (NSNumber *)numberWithChar:(char)value;
21+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
22+ (NSNumber *)numberWithShort:(short)value;
23+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
24+ (NSNumber *)numberWithInt:(int)value;
25+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
26+ (NSNumber *)numberWithLong:(long)value;
27+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
28+ (NSNumber *)numberWithLongLong:(long long)value;
29+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
30+ (NSNumber *)numberWithFloat:(float)value;
31+ (NSNumber *)numberWithDouble:(double)value;
32+ (NSNumber *)numberWithBool:(BOOL)value;
33+ (NSNumber *)numberWithInteger:(NSInteger)value ;
34+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ;
35@end
36
37int main(int argc, const char *argv[]) {
38  // character literals.
39  NSNumber *theLetterZ = @'Z';          // equivalent to [NSNumber numberWithChar:'Z']
40
41  // integral literals.
42  NSNumber *fortyTwo = @42;             // equivalent to [NSNumber numberWithInt:42]
43  NSNumber *fortyTwoUnsigned = @42U;    // equivalent to [NSNumber numberWithUnsignedInt:42U]
44  NSNumber *fortyTwoLong = @42L;        // equivalent to [NSNumber numberWithLong:42L]
45  NSNumber *fortyTwoLongLong = @42LL;   // equivalent to [NSNumber numberWithLongLong:42LL]
46
47  // floating point literals.
48  NSNumber *piFloat = @3.141592654F;    // equivalent to [NSNumber numberWithFloat:3.141592654F]
49  NSNumber *piDouble = @3.1415926535;   // equivalent to [NSNumber numberWithDouble:3.1415926535]
50
51  // BOOL literals.
52  NSNumber *yesNumber = @YES;           // equivalent to [NSNumber numberWithBool:YES]
53  NSNumber *noNumber = @NO;             // equivalent to [NSNumber numberWithBool:NO]
54
55  NSNumber *trueNumber = @true;         // equivalent to [NSNumber numberWithBool:(BOOL)true]
56  NSNumber *falseNumber = @false;       // equivalent to [NSNumber numberWithBool:(BOOL)false]
57}
58
59// CHECK:  NSNumber *theLetterZ = ((NSNumber *(*)(Class, SEL, char))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithChar:"), 'Z');
60// CHECK:  NSNumber *fortyTwo = ((NSNumber *(*)(Class, SEL, int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithInt:"), 42);
61// CHECK:  NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(Class, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), 42U);
62// CHECK:  NSNumber *fortyTwoLong = ((NSNumber *(*)(Class, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), 42L);
63// CHECK:  NSNumber *fortyTwoLongLong = ((NSNumber *(*)(Class, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), 42LL);
64// CHECK:  NSNumber *piFloat = ((NSNumber *(*)(Class, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), 3.14159274F);
65// CHECK:  NSNumber *piDouble = ((NSNumber *(*)(Class, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), 3.1415926535000001);
66// CHECK:  NSNumber *yesNumber = ((NSNumber *(*)(Class, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true);
67// CHECK:  NSNumber *noNumber = ((NSNumber *(*)(Class, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false);
68// CHECK:  NSNumber *trueNumber = ((NSNumber *(*)(Class, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true);
69// CHECK:  NSNumber *falseNumber = ((NSNumber *(*)(Class, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false);
70