2 // RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11
3 // RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result
6 typedef signed char BOOL;
7 #define nil ((void*) 0)
9 typedef const struct __CFString * CFStringRef;
18 @interface NSString : NSObject
19 + (id)stringWithString:(NSString *)string;
20 - (id)initWithString:(NSString *)aString;
23 @interface NSArray : NSObject
24 - (id)objectAtIndex:(unsigned long)index;
27 @interface NSArray (NSExtendedArray)
28 - (id)objectAtIndexedSubscript:(unsigned)idx;
31 @interface NSArray (NSArrayCreation)
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;
38 - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
39 - (id)initWithObjects:(id)firstObj, ...;
40 - (id)initWithArray:(NSArray *)array;
43 @interface NSMutableArray : NSArray
44 - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
47 @interface NSMutableArray (NSExtendedMutableArray)
48 - (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx;
51 @interface NSDictionary : NSObject
52 - (id)objectForKey:(id)aKey;
55 @interface NSDictionary (NSExtendedDictionary)
56 - (id)objectForKeyedSubscript:(id)key;
59 @interface NSDictionary (NSDictionaryCreation)
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;
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;
73 @interface NSMutableDictionary : NSDictionary
74 - (void)setObject:(id)anObject forKey:(id)aKey;
77 @interface NSMutableDictionary (NSExtendedMutableDictionary)
78 - (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
81 @interface NSNumber : NSObject
84 @interface NSNumber (NSNumberCreation)
85 + (NSNumber *)numberWithInt:(int)value;
89 #define PAIR(x) @#x, [NSNumber numberWithInt:(x)]
90 #define TWO(x) ((x), (x))
91 #define TWO_SEP(x,y) ((x), (y))
108 dict = @{@"key1": @"value1", @"key2": @"value2"};
109 dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil];
110 dict = [NSDictionary dictionaryWithObjectsAndKeys:
121 o = TWO(dict[@"key"]);
122 o = TWO_SEP(dict[@"key"], arr[2]);
124 NSMutableArray *marr = 0;
125 NSMutableDictionary *mdict = 0;
127 mdict[@"key"] = @"value";
129 mdict[@"key"] = dict[@"key2"];
130 [mdict setObject:dict[@"key2"] forKey:
137 mdict[@"key"] = [dict objectForKey:
144 mdict[[dict objectForKey:
151 mdict[dict[@"key2"]] = @"val";
152 mdict[dict[@[@"arrkey"]]] = dict[@"key1"];
153 __strong NSArray **parr = 0;
156 o = ((NSArray*)hd)[2];
159 dict = @{@"A": @"1", arr[2]: @[]};
160 dict = [NSDictionary dictionaryWithObjects:@[@"1", @"2"] forKeys:arr];
161 dict = @{@"A": @"1", @"B": @"2"};
162 dict = @{@"A": @[], @"B": @[]};
166 extern const CFStringRef globStr;
168 void test1(NSString *str) {
169 NSDictionary *dict = @{(id)globStr: str};
170 dict = @{str: (id)globStr};
171 dict = @{(id)globStr: str};
172 dict = @{str: (id)globStr};
174 NSArray *arr = @[(id)globStr, (id)globStr];
175 arr = @[str, (id)globStr];
176 arr = @[(id)globStr, str];
177 arr = @[(id)globStr];
180 @interface Custom : NSObject
181 - (id)objectAtIndex:(unsigned long)index;
184 @interface Custom (Extended)
185 - (id)objectAtIndexedSubscript:(unsigned)idx;
188 @interface MutableCustom : Custom
189 - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
192 @interface MutableCustom (Extended)
193 - (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx;
196 @interface CustomUnavail : NSObject
197 - (id)objectAtIndex:(unsigned long)index;
200 @interface CustomUnavail (Extended)
201 - (id)objectAtIndexedSubscript:(unsigned)idx __attribute__((unavailable));
204 @interface MutableCustomUnavail : CustomUnavail
205 - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
208 @interface MutableCustomUnavail (Extended)
209 - (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx __attribute__((unavailable));
217 MutableCustomUnavail *mutcunaval;
218 o = [mutcunaval objectAtIndex:4];
219 [mutcunaval replaceObjectAtIndex:2 withObject:@"val"];
222 @interface NSLocale : NSObject
225 - (id)objectForKey:(id)key;
229 id o = [[NSLocale currentLocale] objectForKey:key];