2012-03-07 04:06:33 +08:00
|
|
|
// RUN: rm -rf %t
|
2012-03-07 06:03:39 +08:00
|
|
|
// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c -triple x86_64-apple-darwin11
|
2012-03-07 04:06:33 +08:00
|
|
|
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
|
2012-05-15 06:01:53 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s.result
|
2012-03-07 04:06:33 +08:00
|
|
|
|
|
|
|
typedef signed char BOOL;
|
|
|
|
#define nil ((void*) 0)
|
|
|
|
|
2012-05-15 06:01:53 +08:00
|
|
|
typedef const struct __CFString * CFStringRef;
|
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
@interface NSObject
|
|
|
|
+ (id)alloc;
|
|
|
|
@end
|
|
|
|
|
2012-06-19 10:22:02 +08:00
|
|
|
@protocol NSCopying
|
|
|
|
@end
|
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
@interface NSString : NSObject
|
|
|
|
+ (id)stringWithString:(NSString *)string;
|
|
|
|
- (id)initWithString:(NSString *)aString;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSArray : NSObject
|
|
|
|
- (id)objectAtIndex:(unsigned long)index;
|
2012-06-19 10:22:02 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSArray (NSExtendedArray)
|
|
|
|
- (id)objectAtIndexedSubscript:(unsigned)idx;
|
2012-03-07 04:06:33 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSArray (NSArrayCreation)
|
|
|
|
+ (id)array;
|
|
|
|
+ (id)arrayWithObject:(id)anObject;
|
|
|
|
+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
|
|
|
|
+ (id)arrayWithObjects:(id)firstObj, ...;
|
|
|
|
+ (id)arrayWithArray:(NSArray *)array;
|
|
|
|
|
|
|
|
- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
|
|
|
|
- (id)initWithObjects:(id)firstObj, ...;
|
|
|
|
- (id)initWithArray:(NSArray *)array;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSMutableArray : NSArray
|
|
|
|
- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
|
2012-06-19 10:22:02 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSMutableArray (NSExtendedMutableArray)
|
|
|
|
- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx;
|
2012-03-07 04:06:33 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSDictionary : NSObject
|
2012-06-19 10:22:02 +08:00
|
|
|
- (id)objectForKey:(id)aKey;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSDictionary (NSExtendedDictionary)
|
2012-03-07 04:06:33 +08:00
|
|
|
- (id)objectForKeyedSubscript:(id)key;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSDictionary (NSDictionaryCreation)
|
|
|
|
+ (id)dictionary;
|
|
|
|
+ (id)dictionaryWithObject:(id)object forKey:(id)key;
|
|
|
|
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
|
|
|
|
+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
|
|
|
|
+ (id)dictionaryWithDictionary:(NSDictionary *)dict;
|
|
|
|
+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
|
|
|
|
|
|
|
|
- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
|
|
|
|
- (id)initWithObjectsAndKeys:(id)firstObject, ...;
|
|
|
|
- (id)initWithDictionary:(NSDictionary *)otherDictionary;
|
|
|
|
- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSMutableDictionary : NSDictionary
|
|
|
|
- (void)setObject:(id)anObject forKey:(id)aKey;
|
2012-06-19 10:22:02 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSMutableDictionary (NSExtendedMutableDictionary)
|
|
|
|
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
|
2012-03-07 04:06:33 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSNumber : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSNumber (NSNumberCreation)
|
|
|
|
+ (NSNumber *)numberWithInt:(int)value;
|
|
|
|
@end
|
|
|
|
|
|
|
|
#define M(x) (x)
|
|
|
|
#define PAIR(x) @#x, [NSNumber numberWithInt:(x)]
|
|
|
|
#define TWO(x) ((x), (x))
|
2015-09-12 04:09:11 +08:00
|
|
|
#define TWO_SEP(x,y) ((x), (y))
|
2012-03-07 04:06:33 +08:00
|
|
|
|
2012-05-22 08:47:53 +08:00
|
|
|
@interface I {
|
|
|
|
NSArray *ivarArr;
|
|
|
|
}
|
2012-03-07 04:06:33 +08:00
|
|
|
@end
|
|
|
|
@implementation I
|
|
|
|
-(void) foo {
|
|
|
|
NSString *str;
|
|
|
|
NSArray *arr;
|
|
|
|
NSDictionary *dict;
|
|
|
|
|
|
|
|
arr = @[];
|
|
|
|
arr = @[str];
|
|
|
|
arr = @[str, str];
|
|
|
|
dict = @{};
|
|
|
|
dict = @{str: arr};
|
|
|
|
dict = @{@"key1": @"value1", @"key2": @"value2"};
|
|
|
|
dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil];
|
|
|
|
dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"value1", @"key1",
|
|
|
|
#ifdef BLAH
|
|
|
|
@"value2", @"key2",
|
|
|
|
#else
|
|
|
|
@"value3", @"key3",
|
|
|
|
#endif
|
|
|
|
nil ];
|
|
|
|
|
|
|
|
id o = arr[2];
|
|
|
|
o = dict[@"key"];
|
|
|
|
o = TWO(dict[@"key"]);
|
2015-09-12 04:09:11 +08:00
|
|
|
o = TWO_SEP(dict[@"key"], arr[2]);
|
2012-03-07 04:06:33 +08:00
|
|
|
o = @{@"key": @{}};
|
|
|
|
NSMutableArray *marr = 0;
|
|
|
|
NSMutableDictionary *mdict = 0;
|
|
|
|
marr[2] = @"val";
|
|
|
|
mdict[@"key"] = @"value";
|
|
|
|
marr[2] = arr[4];
|
|
|
|
mdict[@"key"] = dict[@"key2"];
|
|
|
|
[mdict setObject:dict[@"key2"] forKey:
|
|
|
|
#if 1
|
|
|
|
@"key1"
|
|
|
|
#else
|
|
|
|
@"key2"
|
|
|
|
#endif
|
|
|
|
];
|
|
|
|
mdict[@"key"] = [dict objectForKey:
|
|
|
|
#if 2
|
|
|
|
@"key3"
|
|
|
|
#else
|
|
|
|
@"key4"
|
|
|
|
#endif
|
|
|
|
];
|
|
|
|
mdict[[dict objectForKey:
|
|
|
|
#if 3
|
|
|
|
@"key5"
|
|
|
|
#else
|
|
|
|
@"key6"
|
|
|
|
#endif
|
|
|
|
]] = @"value";
|
|
|
|
mdict[dict[@"key2"]] = @"val";
|
|
|
|
mdict[dict[@[@"arrkey"]]] = dict[@"key1"];
|
|
|
|
__strong NSArray **parr = 0;
|
|
|
|
o = (*parr)[2];
|
2012-05-15 07:33:49 +08:00
|
|
|
void *hd;
|
|
|
|
o = ((NSArray*)hd)[2];
|
2012-05-22 08:47:53 +08:00
|
|
|
o = ivarArr[2];
|
2013-01-17 07:54:48 +08:00
|
|
|
|
|
|
|
dict = @{@"A": @"1", arr[2]: @[]};
|
|
|
|
dict = [NSDictionary dictionaryWithObjects:@[@"1", @"2"] forKeys:arr];
|
|
|
|
dict = @{@"A": @"1", @"B": @"2"};
|
2013-04-06 09:13:17 +08:00
|
|
|
dict = @{@"A": @[], @"B": @[]};
|
2012-03-07 04:06:33 +08:00
|
|
|
}
|
|
|
|
@end
|
2012-05-15 06:01:53 +08:00
|
|
|
|
|
|
|
extern const CFStringRef globStr;
|
|
|
|
|
|
|
|
void test1(NSString *str) {
|
|
|
|
NSDictionary *dict = @{(id)globStr: str};
|
|
|
|
dict = @{str: (id)globStr};
|
|
|
|
dict = @{(id)globStr: str};
|
|
|
|
dict = @{str: (id)globStr};
|
|
|
|
|
|
|
|
NSArray *arr = @[(id)globStr, (id)globStr];
|
|
|
|
arr = @[str, (id)globStr];
|
|
|
|
arr = @[(id)globStr, str];
|
|
|
|
arr = @[(id)globStr];
|
|
|
|
}
|
2012-07-06 05:49:51 +08:00
|
|
|
|
|
|
|
@interface Custom : NSObject
|
|
|
|
- (id)objectAtIndex:(unsigned long)index;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface Custom (Extended)
|
|
|
|
- (id)objectAtIndexedSubscript:(unsigned)idx;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MutableCustom : Custom
|
|
|
|
- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MutableCustom (Extended)
|
|
|
|
- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface CustomUnavail : NSObject
|
|
|
|
- (id)objectAtIndex:(unsigned long)index;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface CustomUnavail (Extended)
|
|
|
|
- (id)objectAtIndexedSubscript:(unsigned)idx __attribute__((unavailable));
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MutableCustomUnavail : CustomUnavail
|
|
|
|
- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MutableCustomUnavail (Extended)
|
|
|
|
- (void)setObject:(id)obj atIndexedSubscript:(unsigned)idx __attribute__((unavailable));
|
|
|
|
@end
|
|
|
|
|
|
|
|
void test2() {
|
|
|
|
MutableCustom *mutc;
|
|
|
|
id o = mutc[4];
|
|
|
|
mutc[2] = @"val";
|
|
|
|
|
|
|
|
MutableCustomUnavail *mutcunaval;
|
|
|
|
o = [mutcunaval objectAtIndex:4];
|
|
|
|
[mutcunaval replaceObjectAtIndex:2 withObject:@"val"];
|
|
|
|
}
|
2012-07-06 08:07:09 +08:00
|
|
|
|
|
|
|
@interface NSLocale : NSObject
|
|
|
|
+ (id)systemLocale;
|
|
|
|
+ (id)currentLocale;
|
|
|
|
- (id)objectForKey:(id)key;
|
|
|
|
@end
|
|
|
|
|
|
|
|
void test3(id key) {
|
|
|
|
id o = [[NSLocale currentLocale] objectForKey:key];
|
|
|
|
}
|