xref: /aosp_15_r20/external/clang/test/Index/annotate-subscripting.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li@interface NSArray
2*67e74705SXin Li- (id)objectAtIndexedSubscript:(int)index;
3*67e74705SXin Li+ (id)arrayWithObjects:(id *)objects count:(unsigned)count;
4*67e74705SXin Li@end
5*67e74705SXin Li
6*67e74705SXin Li@interface NSMutableArray : NSArray
7*67e74705SXin Li- (id)objectAtIndexedSubscript:(int)index;
8*67e74705SXin Li- (void)setObject:(id)object atIndexedSubscript:(int)index;
9*67e74705SXin Li@end
10*67e74705SXin Li
11*67e74705SXin Li@interface NSDictionary
12*67e74705SXin Li- (id)objectForKeyedSubscript:(id)key;
13*67e74705SXin Li+ (id)dictionaryWithObjects:(id *)objects forKeys:(id *)keys count:(unsigned)count;
14*67e74705SXin Li@end
15*67e74705SXin Li
16*67e74705SXin Li@interface NSMutableDictionary : NSDictionary
17*67e74705SXin Li- (void)setObject:(id)object forKeyedSubscript:(id)key;
18*67e74705SXin Li@end
19*67e74705SXin Li
20*67e74705SXin Li@class NSString;
21*67e74705SXin Li
22*67e74705SXin Liid testArray(int index, id p) {
23*67e74705SXin Li  NSMutableArray *array;
24*67e74705SXin Li  array[3] = 0;
25*67e74705SXin Li  NSArray *arr = @[ p, p ];
26*67e74705SXin Li  return array[index];
27*67e74705SXin Li}
28*67e74705SXin Li
29*67e74705SXin Livoid testDict() {
30*67e74705SXin Li  NSMutableDictionary *dictionary;
31*67e74705SXin Li  NSString *key;
32*67e74705SXin Li  id newObject, oldObject;
33*67e74705SXin Li  oldObject = dictionary[key];
34*67e74705SXin Li  dictionary[key] = newObject;
35*67e74705SXin Li  NSDictionary *dict = @{ key: newObject, key: oldObject };
36*67e74705SXin Li}
37*67e74705SXin Li
38*67e74705SXin Li// RUN: c-index-test -test-annotate-tokens=%s:22:1:36:1 -target x86_64-apple-macosx10.7 %s | FileCheck %s
39*67e74705SXin Li// CHECK: Identifier: "array" [24:3 - 24:8] DeclRefExpr=array:23:19
40*67e74705SXin Li// CHECK: Punctuation: "[" [24:8 - 24:9] UnexposedExpr=
41*67e74705SXin Li// CHECK: Literal: "3" [24:9 - 24:10] IntegerLiteral=
42*67e74705SXin Li// CHECK: Punctuation: "]" [24:10 - 24:11] UnexposedExpr=
43*67e74705SXin Li// CHECK: Punctuation: "=" [24:12 - 24:13] BinaryOperator=
44*67e74705SXin Li// CHECK: Literal: "0" [24:14 - 24:15] IntegerLiteral=
45*67e74705SXin Li// CHECK: Punctuation: ";" [24:15 - 24:16] CompoundStmt=
46*67e74705SXin Li// CHECK: Identifier: "NSArray" [25:3 - 25:10] ObjCClassRef=NSArray:1:12
47*67e74705SXin Li// CHECK: Punctuation: "*" [25:11 - 25:12] VarDecl=arr:25:12 (Definition)
48*67e74705SXin Li// CHECK: Identifier: "arr" [25:12 - 25:15] VarDecl=arr:25:12 (Definition)
49*67e74705SXin Li// CHECK: Punctuation: "=" [25:16 - 25:17] VarDecl=arr:25:12 (Definition)
50*67e74705SXin Li// CHECK: Punctuation: "@" [25:18 - 25:19] UnexposedExpr=
51*67e74705SXin Li// CHECK: Punctuation: "[" [25:19 - 25:20] UnexposedExpr=
52*67e74705SXin Li// CHECK: Identifier: "p" [25:21 - 25:22] DeclRefExpr=p:22:28
53*67e74705SXin Li// CHECK: Punctuation: "," [25:22 - 25:23] UnexposedExpr=
54*67e74705SXin Li// CHECK: Identifier: "p" [25:24 - 25:25] DeclRefExpr=p:22:28
55*67e74705SXin Li// CHECK: Punctuation: "]" [25:26 - 25:27] UnexposedExpr=
56*67e74705SXin Li// CHECK: Punctuation: ";" [25:27 - 25:28] DeclStmt=
57*67e74705SXin Li// CHECK: Keyword: "return" [26:3 - 26:9] ReturnStmt=
58*67e74705SXin Li// CHECK: Identifier: "array" [26:10 - 26:15] DeclRefExpr=array:23:19
59*67e74705SXin Li// CHECK: Punctuation: "[" [26:15 - 26:16] UnexposedExpr=
60*67e74705SXin Li// CHECK: Identifier: "index" [26:16 - 26:21] DeclRefExpr=index:22:18
61*67e74705SXin Li// CHECK: Punctuation: "]" [26:21 - 26:22] UnexposedExpr=
62*67e74705SXin Li// CHECK: Punctuation: ";" [26:22 - 26:23] CompoundStmt=
63*67e74705SXin Li
64*67e74705SXin Li// CHECK: Identifier: "oldObject" [33:3 - 33:12] DeclRefExpr=oldObject:32:17
65*67e74705SXin Li// CHECK: Punctuation: "=" [33:13 - 33:14] BinaryOperator=
66*67e74705SXin Li// CHECK: Identifier: "dictionary" [33:15 - 33:25] DeclRefExpr=dictionary:30:24
67*67e74705SXin Li// CHECK: Punctuation: "[" [33:25 - 33:26] UnexposedExpr=
68*67e74705SXin Li// CHECK: Identifier: "key" [33:26 - 33:29] DeclRefExpr=key:31:13
69*67e74705SXin Li// CHECK: Punctuation: "]" [33:29 - 33:30] UnexposedExpr=
70*67e74705SXin Li// CHECK: Punctuation: ";" [33:30 - 33:31] CompoundStmt=
71*67e74705SXin Li// CHECK: Identifier: "dictionary" [34:3 - 34:13] DeclRefExpr=dictionary:30:24
72*67e74705SXin Li// CHECK: Punctuation: "[" [34:13 - 34:14] UnexposedExpr=
73*67e74705SXin Li// CHECK: Identifier: "key" [34:14 - 34:17] DeclRefExpr=key:31:13
74*67e74705SXin Li// CHECK: Punctuation: "]" [34:17 - 34:18] UnexposedExpr=
75*67e74705SXin Li// CHECK: Punctuation: "=" [34:19 - 34:20] BinaryOperator=
76*67e74705SXin Li// CHECK: Identifier: "newObject" [34:21 - 34:30] DeclRefExpr=newObject:32:6
77*67e74705SXin Li// CHECK: Punctuation: ";" [34:30 - 34:31] CompoundStmt=
78*67e74705SXin Li// CHECK: Identifier: "NSDictionary" [35:3 - 35:15] ObjCClassRef=NSDictionary:11:12
79*67e74705SXin Li// CHECK: Punctuation: "*" [35:16 - 35:17] VarDecl=dict:35:17 (Definition)
80*67e74705SXin Li// CHECK: Identifier: "dict" [35:17 - 35:21] VarDecl=dict:35:17 (Definition)
81*67e74705SXin Li// CHECK: Punctuation: "=" [35:22 - 35:23] VarDecl=dict:35:17 (Definition)
82*67e74705SXin Li// CHECK: Punctuation: "@" [35:24 - 35:25] UnexposedExpr=
83*67e74705SXin Li// CHECK: Punctuation: "{" [35:25 - 35:26] UnexposedExpr=
84*67e74705SXin Li// CHECK: Identifier: "key" [35:27 - 35:30] DeclRefExpr=key:31:13
85*67e74705SXin Li// CHECK: Punctuation: ":" [35:30 - 35:31] UnexposedExpr=
86*67e74705SXin Li// CHECK: Identifier: "newObject" [35:32 - 35:41] DeclRefExpr=newObject:32:6
87*67e74705SXin Li// CHECK: Punctuation: "," [35:41 - 35:42] UnexposedExpr=
88*67e74705SXin Li// CHECK: Identifier: "key" [35:43 - 35:46] DeclRefExpr=key:31:13
89*67e74705SXin Li// CHECK: Punctuation: ":" [35:46 - 35:47] UnexposedExpr=
90*67e74705SXin Li// CHECK: Identifier: "oldObject" [35:48 - 35:57] DeclRefExpr=oldObject:32:17
91*67e74705SXin Li// CHECK: Punctuation: "}" [35:58 - 35:59] UnexposedExpr=
92*67e74705SXin Li// CHECK: Punctuation: ";" [35:59 - 35:60] DeclStmt=
93