Home | History | Annotate | Download | only in ARCMT
      1 // RUN: rm -rf %t
      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 
      5 typedef signed char BOOL;
      6 #define nil ((void*) 0)
      7 
      8 @interface NSObject
      9 + (id)alloc;
     10 @end
     11 
     12 @interface NSString : NSObject
     13 + (id)stringWithString:(NSString *)string;
     14 - (id)initWithString:(NSString *)aString;
     15 @end
     16 
     17 @interface NSArray : NSObject
     18 - (id)objectAtIndex:(unsigned long)index;
     19 - (id)objectAtIndexedSubscript:(int)index;
     20 @end
     21 
     22 @interface NSArray (NSArrayCreation)
     23 + (id)array;
     24 + (id)arrayWithObject:(id)anObject;
     25 + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
     26 + (id)arrayWithObjects:(id)firstObj, ...;
     27 + (id)arrayWithArray:(NSArray *)array;
     28 
     29 - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
     30 - (id)initWithObjects:(id)firstObj, ...;
     31 - (id)initWithArray:(NSArray *)array;
     32 
     33 - (id)objectAtIndex:(unsigned long)index;
     34 @end
     35 
     36 @interface NSMutableArray : NSArray
     37 - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
     38 - (void)setObject:(id)object atIndexedSubscript:(int)index;
     39 @end
     40 
     41 @interface NSDictionary : NSObject
     42 - (id)objectForKeyedSubscript:(id)key;
     43 @end
     44 
     45 @interface NSDictionary (NSDictionaryCreation)
     46 + (id)dictionary;
     47 + (id)dictionaryWithObject:(id)object forKey:(id)key;
     48 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
     49 + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
     50 + (id)dictionaryWithDictionary:(NSDictionary *)dict;
     51 + (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
     52 
     53 - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
     54 - (id)initWithObjectsAndKeys:(id)firstObject, ...;
     55 - (id)initWithDictionary:(NSDictionary *)otherDictionary;
     56 - (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
     57 
     58 - (id)objectForKey:(id)aKey;
     59 @end
     60 
     61 @interface NSMutableDictionary : NSDictionary
     62 - (void)setObject:(id)anObject forKey:(id)aKey;
     63 - (void)setObject:(id)object forKeyedSubscript:(id)key;
     64 @end
     65 
     66 @interface NSNumber : NSObject
     67 @end
     68 
     69 @interface NSNumber (NSNumberCreation)
     70 + (NSNumber *)numberWithInt:(int)value;
     71 @end
     72 
     73 #define M(x) (x)
     74 #define PAIR(x) @#x, [NSNumber numberWithInt:(x)]
     75 #define TWO(x) ((x), (x))
     76 
     77 @interface I
     78 @end
     79 @implementation I
     80 -(void) foo {
     81   NSString *str;
     82   NSArray *arr;
     83   NSDictionary *dict;
     84 
     85   arr = @[];
     86   arr = @[str];
     87   arr = @[str, str];
     88   dict = @{};
     89   dict = @{str: arr};
     90   dict = @{@"key1": @"value1", @"key2": @"value2"};
     91   dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil];
     92   dict = [NSDictionary dictionaryWithObjectsAndKeys:
     93                                                @"value1", @"key1",
     94 #ifdef BLAH
     95                                                @"value2", @"key2",
     96 #else
     97                                                @"value3", @"key3",
     98 #endif
     99                                                nil ];
    100 
    101   id o = arr[2];
    102   o = dict[@"key"];
    103   o = TWO(dict[@"key"]);
    104   o = @{@"key": @{}};
    105   NSMutableArray *marr = 0;
    106   NSMutableDictionary *mdict = 0;
    107   marr[2] = @"val";
    108   mdict[@"key"] = @"value";
    109   marr[2] = arr[4];
    110   mdict[@"key"] = dict[@"key2"];
    111   [mdict setObject:dict[@"key2"] forKey:
    112 #if 1
    113                      @"key1"
    114 #else
    115                      @"key2"
    116 #endif
    117                     ];
    118   mdict[@"key"] = [dict objectForKey:
    119 #if 2
    120                      @"key3"
    121 #else
    122                      @"key4"
    123 #endif
    124                    ];
    125   mdict[[dict objectForKey:
    126 #if 3
    127                      @"key5"
    128 #else
    129                      @"key6"
    130 #endif
    131                    ]] = @"value";
    132   mdict[dict[@"key2"]] = @"val";
    133   mdict[dict[@[@"arrkey"]]] = dict[@"key1"];
    134   __strong NSArray **parr = 0;
    135   o = (*parr)[2];
    136 }
    137 @end
    138