Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Argyrios Kyrtzidis | b82019b | 2012-03-06 22:03:39 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11 |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 3 | // RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result |
Argyrios Kyrtzidis | 055b395 | 2012-05-14 22:01:53 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 5 | |
| 6 | typedef signed char BOOL; |
| 7 | #define nil ((void*) 0) |
| 8 | |
Argyrios Kyrtzidis | 055b395 | 2012-05-14 22:01:53 +0000 | [diff] [blame] | 9 | typedef const struct __CFString * CFStringRef; |
| 10 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 11 | @interface NSObject |
| 12 | + (id)alloc; |
| 13 | @end |
| 14 | |
Argyrios Kyrtzidis | 12b732a | 2012-06-19 02:22:02 +0000 | [diff] [blame^] | 15 | @protocol NSCopying |
| 16 | @end |
| 17 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 18 | @interface NSString : NSObject |
| 19 | + (id)stringWithString:(NSString *)string; |
| 20 | - (id)initWithString:(NSString *)aString; |
| 21 | @end |
| 22 | |
| 23 | @interface NSArray : NSObject |
| 24 | - (id)objectAtIndex:(unsigned long)index; |
Argyrios Kyrtzidis | 12b732a | 2012-06-19 02:22:02 +0000 | [diff] [blame^] | 25 | @end |
| 26 | |
| 27 | @interface NSArray (NSExtendedArray) |
| 28 | - (id)objectAtIndexedSubscript:(unsigned)idx; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 29 | @end |
| 30 | |
| 31 | @interface NSArray (NSArrayCreation) |
| 32 | + (id)array; |
| 33 | + (id)arrayWithObject:(id)anObject; |
| 34 | + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; |
| 35 | + (id)arrayWithObjects:(id)firstObj, ...; |
| 36 | + (id)arrayWithArray:(NSArray *)array; |
| 37 | |
| 38 | - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt; |
| 39 | - (id)initWithObjects:(id)firstObj, ...; |
| 40 | - (id)initWithArray:(NSArray *)array; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 41 | @end |
| 42 | |
| 43 | @interface NSMutableArray : NSArray |
| 44 | - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject; |
Argyrios Kyrtzidis | 12b732a | 2012-06-19 02:22:02 +0000 | [diff] [blame^] | 45 | @end |
| 46 | |
| 47 | @interface NSMutableArray (NSExtendedMutableArray) |
| 48 | - (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 49 | @end |
| 50 | |
| 51 | @interface NSDictionary : NSObject |
Argyrios Kyrtzidis | 12b732a | 2012-06-19 02:22:02 +0000 | [diff] [blame^] | 52 | - (id)objectForKey:(id)aKey; |
| 53 | @end |
| 54 | |
| 55 | @interface NSDictionary (NSExtendedDictionary) |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 56 | - (id)objectForKeyedSubscript:(id)key; |
| 57 | @end |
| 58 | |
| 59 | @interface NSDictionary (NSDictionaryCreation) |
| 60 | + (id)dictionary; |
| 61 | + (id)dictionaryWithObject:(id)object forKey:(id)key; |
| 62 | + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; |
| 63 | + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...; |
| 64 | + (id)dictionaryWithDictionary:(NSDictionary *)dict; |
| 65 | + (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; |
| 66 | |
| 67 | - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; |
| 68 | - (id)initWithObjectsAndKeys:(id)firstObject, ...; |
| 69 | - (id)initWithDictionary:(NSDictionary *)otherDictionary; |
| 70 | - (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 71 | @end |
| 72 | |
| 73 | @interface NSMutableDictionary : NSDictionary |
| 74 | - (void)setObject:(id)anObject forKey:(id)aKey; |
Argyrios Kyrtzidis | 12b732a | 2012-06-19 02:22:02 +0000 | [diff] [blame^] | 75 | @end |
| 76 | |
| 77 | @interface NSMutableDictionary (NSExtendedMutableDictionary) |
| 78 | - (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 79 | @end |
| 80 | |
| 81 | @interface NSNumber : NSObject |
| 82 | @end |
| 83 | |
| 84 | @interface NSNumber (NSNumberCreation) |
| 85 | + (NSNumber *)numberWithInt:(int)value; |
| 86 | @end |
| 87 | |
| 88 | #define M(x) (x) |
| 89 | #define PAIR(x) @#x, [NSNumber numberWithInt:(x)] |
| 90 | #define TWO(x) ((x), (x)) |
| 91 | |
Argyrios Kyrtzidis | 2bddd43 | 2012-05-22 00:47:53 +0000 | [diff] [blame] | 92 | @interface I { |
| 93 | NSArray *ivarArr; |
| 94 | } |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 95 | @end |
| 96 | @implementation I |
| 97 | -(void) foo { |
| 98 | NSString *str; |
| 99 | NSArray *arr; |
| 100 | NSDictionary *dict; |
| 101 | |
| 102 | arr = @[]; |
| 103 | arr = @[str]; |
| 104 | arr = @[str, str]; |
| 105 | dict = @{}; |
| 106 | dict = @{str: arr}; |
| 107 | dict = @{@"key1": @"value1", @"key2": @"value2"}; |
| 108 | dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil]; |
| 109 | dict = [NSDictionary dictionaryWithObjectsAndKeys: |
| 110 | @"value1", @"key1", |
| 111 | #ifdef BLAH |
| 112 | @"value2", @"key2", |
| 113 | #else |
| 114 | @"value3", @"key3", |
| 115 | #endif |
| 116 | nil ]; |
| 117 | |
| 118 | id o = arr[2]; |
| 119 | o = dict[@"key"]; |
| 120 | o = TWO(dict[@"key"]); |
| 121 | o = @{@"key": @{}}; |
| 122 | NSMutableArray *marr = 0; |
| 123 | NSMutableDictionary *mdict = 0; |
| 124 | marr[2] = @"val"; |
| 125 | mdict[@"key"] = @"value"; |
| 126 | marr[2] = arr[4]; |
| 127 | mdict[@"key"] = dict[@"key2"]; |
| 128 | [mdict setObject:dict[@"key2"] forKey: |
| 129 | #if 1 |
| 130 | @"key1" |
| 131 | #else |
| 132 | @"key2" |
| 133 | #endif |
| 134 | ]; |
| 135 | mdict[@"key"] = [dict objectForKey: |
| 136 | #if 2 |
| 137 | @"key3" |
| 138 | #else |
| 139 | @"key4" |
| 140 | #endif |
| 141 | ]; |
| 142 | mdict[[dict objectForKey: |
| 143 | #if 3 |
| 144 | @"key5" |
| 145 | #else |
| 146 | @"key6" |
| 147 | #endif |
| 148 | ]] = @"value"; |
| 149 | mdict[dict[@"key2"]] = @"val"; |
| 150 | mdict[dict[@[@"arrkey"]]] = dict[@"key1"]; |
| 151 | __strong NSArray **parr = 0; |
| 152 | o = (*parr)[2]; |
Argyrios Kyrtzidis | 20119a8 | 2012-05-14 23:33:49 +0000 | [diff] [blame] | 153 | void *hd; |
| 154 | o = ((NSArray*)hd)[2]; |
Argyrios Kyrtzidis | 2bddd43 | 2012-05-22 00:47:53 +0000 | [diff] [blame] | 155 | o = ivarArr[2]; |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 156 | } |
| 157 | @end |
Argyrios Kyrtzidis | 055b395 | 2012-05-14 22:01:53 +0000 | [diff] [blame] | 158 | |
| 159 | extern const CFStringRef globStr; |
| 160 | |
| 161 | void test1(NSString *str) { |
| 162 | NSDictionary *dict = @{(id)globStr: str}; |
| 163 | dict = @{str: (id)globStr}; |
| 164 | dict = @{(id)globStr: str}; |
| 165 | dict = @{str: (id)globStr}; |
| 166 | |
| 167 | NSArray *arr = @[(id)globStr, (id)globStr]; |
| 168 | arr = @[str, (id)globStr]; |
| 169 | arr = @[(id)globStr, str]; |
| 170 | arr = @[(id)globStr]; |
| 171 | } |