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