blob: 147595182de57145138a86dedbc3f76a9ff26678 [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
80@interface I
81@end
82@implementation I
83-(void) foo {
84 NSString *str;
85 NSArray *arr;
86 NSDictionary *dict;
87
88 arr = [NSArray array];
89 arr = [NSArray arrayWithObject:str];
90 arr = [NSArray arrayWithObjects:str, str, nil];
91 dict = [NSDictionary dictionary];
92 dict = [NSDictionary dictionaryWithObject:arr forKey:str];
93 dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil];
94 dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil];
95 dict = [NSDictionary dictionaryWithObjectsAndKeys:
96 @"value1", @"key1",
97#ifdef BLAH
98 @"value2", @"key2",
99#else
100 @"value3", @"key3",
101#endif
102 nil ];
103
104 id o = [arr objectAtIndex:2];
105 o = [dict objectForKey:@"key"];
106 o = TWO([dict objectForKey:@"key"]);
107 o = [NSDictionary dictionaryWithObject:[NSDictionary dictionary] forKey:@"key"];
108 NSMutableArray *marr = 0;
109 NSMutableDictionary *mdict = 0;
110 [marr replaceObjectAtIndex:2 withObject:@"val"];
111 [mdict setObject:@"value" forKey:@"key"];
112 [marr replaceObjectAtIndex:2 withObject:[arr objectAtIndex:4]];
113 [mdict setObject:[dict objectForKey:@"key2"] forKey:@"key"];
114 [mdict setObject:[dict objectForKey:@"key2"] forKey:
115#if 1
116 @"key1"
117#else
118 @"key2"
119#endif
120 ];
121 [mdict setObject:[dict objectForKey:
122#if 2
123 @"key3"
124#else
125 @"key4"
126#endif
127 ] forKey:@"key"];
128 [mdict setObject:@"value" forKey:[dict objectForKey:
129#if 3
130 @"key5"
131#else
132 @"key6"
133#endif
134 ] ];
135 [mdict setObject:@"val" forKey:[dict objectForKey:@"key2"]];
136 [mdict setObject:[dict objectForKey:@"key1"] forKey:[dict objectForKey:[NSArray arrayWithObject:@"arrkey"]]];
137 __strong NSArray **parr = 0;
138 o = [*parr objectAtIndex:2];
139}
140@end
Argyrios Kyrtzidis055b3952012-05-14 22:01:53 +0000141
142extern const CFStringRef globStr;
143
144void test1(NSString *str) {
145 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: str, globStr, nil];
146 dict = [NSDictionary dictionaryWithObjectsAndKeys: globStr, str, nil];
147 dict = [NSDictionary dictionaryWithObject:str forKey:globStr];
148 dict = [NSDictionary dictionaryWithObject:globStr forKey:str];
149
150 NSArray *arr = [NSArray arrayWithObjects: globStr, globStr, nil];
151 arr = [NSArray arrayWithObjects: str, globStr, nil];
152 arr = [NSArray arrayWithObjects: globStr, str, nil];
153 arr = [NSArray arrayWithObject:globStr];
154}