[cfe-commits] r152138 - in /cfe/trunk: include/clang-c/Index.h test/FixIt/objc-literals.m test/Index/annotate-literals.m test/Index/annotate-subscripting.m test/Index/complete-exprs.m test/Index/file-refs-subscripting.m test/Index/fix-its.c test/Index/index-subscripting-literals.m tools/libclang/CIndex.cpp tools/libclang/CXCursor.cpp tools/libclang/IndexBody.cpp

Ted Kremenek kremenek at apple.com
Tue Mar 6 12:06:06 PST 2012


Author: kremenek
Date: Tue Mar  6 14:06:06 2012
New Revision: 152138

URL: http://llvm.org/viewvc/llvm-project?rev=152138&view=rev
Log:
And libclang cursor/indexing support for new Objective-C NSArray/NSDictionary/NSNumber literals.

Added:
    cfe/trunk/test/FixIt/objc-literals.m
    cfe/trunk/test/Index/annotate-literals.m
    cfe/trunk/test/Index/annotate-subscripting.m
    cfe/trunk/test/Index/file-refs-subscripting.m
    cfe/trunk/test/Index/index-subscripting-literals.m
Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/complete-exprs.m
    cfe/trunk/test/Index/fix-its.c
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CXCursor.cpp
    cfe/trunk/tools/libclang/IndexBody.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=152138&r1=152137&r2=152138&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Mar  6 14:06:06 2012
@@ -1745,7 +1745,11 @@
    */
   CXCursor_LambdaExpr                    = 144,
   
-  CXCursor_LastExpr                      = CXCursor_LambdaExpr,
+  /** \brief Objective-c Boolean Literal.
+   */
+  CXCursor_ObjCBoolLiteralExpr           = 145,
+
+  CXCursor_LastExpr                      = CXCursor_ObjCBoolLiteralExpr,
 
   /* Statements */
   CXCursor_FirstStmt                     = 200,

Added: cfe/trunk/test/FixIt/objc-literals.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/objc-literals.m?rev=152138&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/objc-literals.m (added)
+++ cfe/trunk/test/FixIt/objc-literals.m Tue Mar  6 14:06:06 2012
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -fsyntax-only -fixit -x objective-c %t
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x objective-c %t
+// RUN: grep arrayWithObjects %t
+
+typedef unsigned char BOOL;
+
+ at interface NSNumber @end
+
+ at interface NSNumber (NSNumberCreation)
++ (NSNumber *)numberWithChar:(char)value;
++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
++ (NSNumber *)numberWithShort:(short)value;
++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
++ (NSNumber *)numberWithInt:(int)value;
++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
++ (NSNumber *)numberWithLong:(long)value;
++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
++ (NSNumber *)numberWithLongLong:(long long)value;
++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
++ (NSNumber *)numberWithFloat:(float)value;
++ (NSNumber *)numberWithDouble:(double)value;
++ (NSNumber *)numberWithBool:(BOOL)value;
+ at end
+
+ at interface NSArray
+ at end
+
+ at interface NSArray (NSArrayCreation)
++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
+ at end
+
+ at interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
+ at end
+
+void fixes() {
+  id arr = @[
+    17, // expected-error{{numeric literal must be prefixed by '@' in a collection}}
+    'a', // expected-error{{character literal must be prefixed by '@'}}
+    "blah" // expected-error{{string literal must be prefixed by '@'}}
+  ];
+}

Added: cfe/trunk/test/Index/annotate-literals.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-literals.m?rev=152138&view=auto
==============================================================================
--- cfe/trunk/test/Index/annotate-literals.m (added)
+++ cfe/trunk/test/Index/annotate-literals.m Tue Mar  6 14:06:06 2012
@@ -0,0 +1,72 @@
+typedef unsigned char BOOL;
+
+ at interface NSNumber @end
+
+ at interface NSNumber (NSNumberCreation)
++ (NSNumber *)numberWithChar:(char)value;
++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
++ (NSNumber *)numberWithShort:(short)value;
++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
++ (NSNumber *)numberWithInt:(int)value;
++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
++ (NSNumber *)numberWithLong:(long)value;
++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
++ (NSNumber *)numberWithLongLong:(long long)value;
++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
++ (NSNumber *)numberWithFloat:(float)value;
++ (NSNumber *)numberWithDouble:(double)value;
++ (NSNumber *)numberWithBool:(BOOL)value;
+ at end
+
+ at interface NSArray
+ at end
+
+ at interface NSArray (NSArrayCreation)
++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
+ at end
+
+ at interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
+ at end
+
+void test_literals(id k1, id o1, id k2, id o2, id k3) {
+  id objects = @[ o1, o2 ];
+  id dict = @{ k1 : o1,
+               k2 : o2,
+               k3 : @17 };
+}
+
+
+// RUN: c-index-test -test-annotate-tokens=%s:33:1:37:1 %s | FileCheck -check-prefix=CHECK-LITERALS %s
+
+// CHECK-LITERALS: Identifier: "id" [33:3 - 33:5] TypeRef=id:0:0
+// CHECK-LITERALS: Identifier: "objects" [33:6 - 33:13] VarDecl=objects:33:6 (Definition)
+// CHECK-LITERALS: Punctuation: "=" [33:14 - 33:15] VarDecl=objects:33:6 (Definition)
+// CHECK-LITERALS: Punctuation: "@" [33:16 - 33:17] UnexposedExpr=
+// CHECK-LITERALS: Punctuation: "[" [33:17 - 33:18] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "o1" [33:19 - 33:21] DeclRefExpr=o1:32:30
+// CHECK-LITERALS: Punctuation: "," [33:21 - 33:22] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "o2" [33:23 - 33:25] DeclRefExpr=o2:32:44
+// CHECK-LITERALS: Punctuation: "]" [33:26 - 33:27] UnexposedExpr=
+// CHECK-LITERALS: Punctuation: ";" [33:27 - 33:28] DeclStmt=
+// CHECK-LITERALS: Identifier: "id" [34:3 - 34:5] TypeRef=id:0:0
+// CHECK-LITERALS: Identifier: "dict" [34:6 - 34:10] VarDecl=dict:34:6 (Definition)
+// CHECK-LITERALS: Punctuation: "=" [34:11 - 34:12] VarDecl=dict:34:6 (Definition)
+// CHECK-LITERALS: Punctuation: "@" [34:13 - 34:14] UnexposedExpr=
+// CHECK-LITERALS: Punctuation: "{" [34:14 - 34:15] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "k1" [34:16 - 34:18] DeclRefExpr=k1:32:23
+// CHECK-LITERALS: Punctuation: ":" [34:19 - 34:20] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "o1" [34:21 - 34:23] DeclRefExpr=o1:32:30
+// CHECK-LITERALS: Punctuation: "," [34:23 - 34:24] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "k2" [35:16 - 35:18] DeclRefExpr=k2:32:37
+// CHECK-LITERALS: Punctuation: ":" [35:19 - 35:20] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "o2" [35:21 - 35:23] DeclRefExpr=o2:32:44
+// CHECK-LITERALS: Punctuation: "," [35:23 - 35:24] UnexposedExpr=
+// CHECK-LITERALS: Identifier: "k3" [36:16 - 36:18] DeclRefExpr=k3:32:51
+// CHECK-LITERALS: Punctuation: ":" [36:19 - 36:20] UnexposedExpr=
+// CHECK-LITERALS: Punctuation: "@" [36:21 - 36:22] UnexposedExpr=
+// CHECK-LITERALS: Literal: "17" [36:22 - 36:24] IntegerLiteral=
+// CHECK-LITERALS: Punctuation: "}" [36:25 - 36:26] UnexposedExpr=
+// CHECK-LITERALS: Punctuation: ";" [36:26 - 36:27] DeclStmt=
+// CHECK-LITERALS: Punctuation: "}" [37:1 - 37:2] CompoundStmt=
+

Added: cfe/trunk/test/Index/annotate-subscripting.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-subscripting.m?rev=152138&view=auto
==============================================================================
--- cfe/trunk/test/Index/annotate-subscripting.m (added)
+++ cfe/trunk/test/Index/annotate-subscripting.m Tue Mar  6 14:06:06 2012
@@ -0,0 +1,92 @@
+ at interface NSArray
+- (id)objectAtIndexedSubscript:(int)index;
++ (id)arrayWithObjects:(id *)objects count:(unsigned)count;
+ at end
+
+ at interface NSMutableArray : NSArray
+- (id)objectAtIndexedSubscript:(int)index;
+- (void)setObject:(id)object atIndexedSubscript:(int)index;
+ at end
+
+ at interface NSDictionary
+- (id)objectForKeyedSubscript:(id)key;
++ (id)dictionaryWithObjects:(id *)objects forKeys:(id *)keys count:(unsigned)count;
+ at end
+
+ at interface NSMutableDictionary : NSDictionary
+- (void)setObject:(id)object forKeyedSubscript:(id)key;
+ at end
+
+ at class NSString;
+
+id testArray(int index, id p) {
+  NSMutableArray *array;
+  array[3] = 0;
+  NSArray *arr = @[ p, p ];
+  return array[index];
+}
+
+void testDict() {
+  NSMutableDictionary *dictionary;
+  NSString *key;
+  id newObject, oldObject;
+  oldObject = dictionary[key];
+  dictionary[key] = newObject;
+  NSDictionary *dict = @{ key: newObject, key: oldObject };
+}
+
+// RUN: c-index-test -test-annotate-tokens=%s:22:1:36:1 -target x86_64-apple-macosx10.7 %s | FileCheck %s
+// CHECK: Identifier: "array" [24:3 - 24:8] DeclRefExpr=array:23:19
+// CHECK: Punctuation: "[" [24:8 - 24:9] UnexposedExpr=
+// CHECK: Literal: "3" [24:9 - 24:10] IntegerLiteral=
+// CHECK: Punctuation: "]" [24:10 - 24:11] UnexposedExpr=
+// CHECK: Punctuation: "=" [24:12 - 24:13] BinaryOperator=
+// CHECK: Literal: "0" [24:14 - 24:15] IntegerLiteral=
+// CHECK: Punctuation: ";" [24:15 - 24:16] CompoundStmt=
+// CHECK: Identifier: "NSArray" [25:3 - 25:10] ObjCClassRef=NSArray:1:12
+// CHECK: Punctuation: "*" [25:11 - 25:12] VarDecl=arr:25:12 (Definition)
+// CHECK: Identifier: "arr" [25:12 - 25:15] VarDecl=arr:25:12 (Definition)
+// CHECK: Punctuation: "=" [25:16 - 25:17] VarDecl=arr:25:12 (Definition)
+// CHECK: Punctuation: "@" [25:18 - 25:19] UnexposedExpr=
+// CHECK: Punctuation: "[" [25:19 - 25:20] UnexposedExpr=
+// CHECK: Identifier: "p" [25:21 - 25:22] DeclRefExpr=p:22:28
+// CHECK: Punctuation: "," [25:22 - 25:23] UnexposedExpr=
+// CHECK: Identifier: "p" [25:24 - 25:25] DeclRefExpr=p:22:28
+// CHECK: Punctuation: "]" [25:26 - 25:27] UnexposedExpr=
+// CHECK: Punctuation: ";" [25:27 - 25:28] DeclStmt=
+// CHECK: Keyword: "return" [26:3 - 26:9] ReturnStmt=
+// CHECK: Identifier: "array" [26:10 - 26:15] DeclRefExpr=array:23:19
+// CHECK: Punctuation: "[" [26:15 - 26:16] UnexposedExpr=
+// CHECK: Identifier: "index" [26:16 - 26:21] DeclRefExpr=index:22:18
+// CHECK: Punctuation: "]" [26:21 - 26:22] UnexposedExpr=
+// CHECK: Punctuation: ";" [26:22 - 26:23] CompoundStmt=
+
+// CHECK: Identifier: "oldObject" [33:3 - 33:12] DeclRefExpr=oldObject:32:17
+// CHECK: Punctuation: "=" [33:13 - 33:14] BinaryOperator=
+// CHECK: Identifier: "dictionary" [33:15 - 33:25] DeclRefExpr=dictionary:30:24
+// CHECK: Punctuation: "[" [33:25 - 33:26] UnexposedExpr=
+// CHECK: Identifier: "key" [33:26 - 33:29] DeclRefExpr=key:31:13
+// CHECK: Punctuation: "]" [33:29 - 33:30] UnexposedExpr=
+// CHECK: Punctuation: ";" [33:30 - 33:31] CompoundStmt=
+// CHECK: Identifier: "dictionary" [34:3 - 34:13] DeclRefExpr=dictionary:30:24
+// CHECK: Punctuation: "[" [34:13 - 34:14] UnexposedExpr=
+// CHECK: Identifier: "key" [34:14 - 34:17] DeclRefExpr=key:31:13
+// CHECK: Punctuation: "]" [34:17 - 34:18] UnexposedExpr=
+// CHECK: Punctuation: "=" [34:19 - 34:20] BinaryOperator=
+// CHECK: Identifier: "newObject" [34:21 - 34:30] DeclRefExpr=newObject:32:6
+// CHECK: Punctuation: ";" [34:30 - 34:31] CompoundStmt=
+// CHECK: Identifier: "NSDictionary" [35:3 - 35:15] ObjCClassRef=NSDictionary:11:12
+// CHECK: Punctuation: "*" [35:16 - 35:17] VarDecl=dict:35:17 (Definition)
+// CHECK: Identifier: "dict" [35:17 - 35:21] VarDecl=dict:35:17 (Definition)
+// CHECK: Punctuation: "=" [35:22 - 35:23] VarDecl=dict:35:17 (Definition)
+// CHECK: Punctuation: "@" [35:24 - 35:25] UnexposedExpr=
+// CHECK: Punctuation: "{" [35:25 - 35:26] UnexposedExpr=
+// CHECK: Identifier: "key" [35:27 - 35:30] DeclRefExpr=key:31:13
+// CHECK: Punctuation: ":" [35:30 - 35:31] UnexposedExpr=
+// CHECK: Identifier: "newObject" [35:32 - 35:41] DeclRefExpr=newObject:32:6
+// CHECK: Punctuation: "," [35:41 - 35:42] UnexposedExpr=
+// CHECK: Identifier: "key" [35:43 - 35:46] DeclRefExpr=key:31:13
+// CHECK: Punctuation: ":" [35:46 - 35:47] UnexposedExpr=
+// CHECK: Identifier: "oldObject" [35:48 - 35:57] DeclRefExpr=oldObject:32:17
+// CHECK: Punctuation: "}" [35:58 - 35:59] UnexposedExpr=
+// CHECK: Punctuation: ";" [35:59 - 35:60] DeclStmt=

Modified: cfe/trunk/test/Index/complete-exprs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.m?rev=152138&r1=152137&r2=152138&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-exprs.m (original)
+++ cfe/trunk/test/Index/complete-exprs.m Tue Mar  6 14:06:06 2012
@@ -2,9 +2,9 @@
 #define YES ((BOOL)1)
 #define NO ((BOOL)0)
 #define bool _Bool
+ at interface NSArray + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; @end
 @interface A
 - (int)method:(id)param1;
-
 @property int prop1;
 @end
 __strong id global;
@@ -12,10 +12,14 @@
 - (int)method:(id)param1 {
   void foo(bool (^block)(id x, A* y));
   for(BOOL B = YES; ; ) { }
+  @[ global ];
+  @{ global : global };
 }
 @end
 
 // RUN: c-index-test -code-completion-at=%s:13:2 %s | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: NotImplemented:{TypedText @[}{HorizontalSpace  }{Placeholder objects, ...}{HorizontalSpace  }{RightBracket ]} (40)
+// CHECK-CC1: NotImplemented:{TypedText @{}{HorizontalSpace  }{Placeholder key}{HorizontalSpace  }{Colon :}{HorizontalSpace  }{Placeholder object, ...}{HorizontalSpace  }{RightBrace }} (40)
 // CHECK-CC1: NotImplemented:{ResultType SEL}{TypedText _cmd} (80)
 // CHECK-CC1: TypedefDecl:{TypedText BOOL} (50)
 // CHECK-CC1: macro definition:{TypedText bool} (51)
@@ -32,3 +36,14 @@
 // CHECK-CC3: FunctionDecl:{ResultType void}{TypedText foo}{LeftParen (}{Placeholder ^bool(id x, A *y)block}{RightParen )} (34)
 // CHECK-CC3: VarDecl:{ResultType id}{TypedText global} (50)
 // CHECK-CC3: ParmDecl:{ResultType id}{TypedText param1} (34)
+
+// RUN: c-index-test -code-completion-at=%s:15:5 %s | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: c-index-test -code-completion-at=%s:16:5 %s | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: c-index-test -code-completion-at=%s:16:14 %s | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: NotImplemented:{TypedText @[}{HorizontalSpace  }{Placeholder objects, ...}{HorizontalSpace  }{RightBracket ]} (40)
+// CHECK-CC4: NotImplemented:{TypedText @{}{HorizontalSpace  }{Placeholder key}{HorizontalSpace  }{Colon :}{HorizontalSpace  }{Placeholder object, ...}{HorizontalSpace  }{RightBrace }} (40)
+// CHECK-CC4: NotImplemented:{ResultType SEL}{TypedText _cmd} (80)
+// CHECK-CC4: macro definition:{TypedText bool} (51)
+// CHECK-CC4: macro definition:{TypedText NO} (65)
+// CHECK-CC4: NotImplemented:{ResultType A *}{TypedText self} (34)
+// CHECK-CC4: macro definition:{TypedText YES} (65)

Added: cfe/trunk/test/Index/file-refs-subscripting.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/file-refs-subscripting.m?rev=152138&view=auto
==============================================================================
--- cfe/trunk/test/Index/file-refs-subscripting.m (added)
+++ cfe/trunk/test/Index/file-refs-subscripting.m Tue Mar  6 14:06:06 2012
@@ -0,0 +1,65 @@
+ at interface NSArray
+- (id)objectAtIndexedSubscript:(int)index;
++ (id)arrayWithObjects:(id *)objects count:(unsigned)count;
+ at end
+
+ at interface NSMutableArray : NSArray
+- (id)objectAtIndexedSubscript:(int)index;
+- (void)setObject:(id)object atIndexedSubscript:(int)index;
+ at end
+
+ at interface NSDictionary
+- (id)objectForKeyedSubscript:(id)key;
++ (id)dictionaryWithObjects:(id *)objects forKeys:(id *)keys count:(unsigned)count;
+ at end
+
+ at interface NSMutableDictionary : NSDictionary
+- (void)setObject:(id)object forKeyedSubscript:(id)key;
+ at end
+
+ at class NSString;
+
+id testArray(int index, id p) {
+  NSMutableArray *array;
+  array[3] = 0;
+  NSArray *arr = @[ p, p ];
+  return array[index];
+}
+
+void testDict() {
+  NSMutableDictionary *dictionary;
+  NSString *key;
+  id newObject, oldObject;
+  oldObject = dictionary[key];
+  dictionary[key] = newObject;
+  NSDictionary *dict = @{ key: newObject, key: oldObject };
+}
+
+// RUN: c-index-test \
+
+// RUN:  -file-refs-at=%s:22:21 \
+// CHECK:      ParmDecl=index:22:18
+// CHECK-NEXT: ParmDecl=index:22:18 (Definition) =[22:18 - 22:23]
+// CHECK-NEXT: DeclRefExpr=index:22:18 =[26:16 - 26:21]
+
+// RUN:  -file-refs-at=%s:22:28 \
+// CHECK-NEXT: ParmDecl=p:22:28
+// CHECK-NEXT: ParmDecl=p:22:28 (Definition) =[22:28 - 22:29]
+// CHECK-NEXT: DeclRefExpr=p:22:28 =[25:21 - 25:22]
+// CHECK-NEXT: DeclRefExpr=p:22:28 =[25:24 - 25:25]
+
+// RUN:  -file-refs-at=%s:34:16 \
+// CHECK-NEXT: DeclRefExpr=key:31:13
+// CHECK-NEXT: VarDecl=key:31:13 (Definition) =[31:13 - 31:16]
+// CHECK-NEXT: DeclRefExpr=key:31:13 =[33:26 - 33:29]
+// CHECK-NEXT: DeclRefExpr=key:31:13 =[34:14 - 34:17]
+// CHECK-NEXT: DeclRefExpr=key:31:13 =[35:27 - 35:30]
+// CHECK-NEXT: DeclRefExpr=key:31:13 =[35:43 - 35:46]
+
+// RUN:  -file-refs-at=%s:35:35 \
+// CHECK-NEXT: DeclRefExpr=newObject:32:6
+// CHECK-NEXT: VarDecl=newObject:32:6 (Definition) =[32:6 - 32:15]
+// CHECK-NEXT: DeclRefExpr=newObject:32:6 =[34:21 - 34:30]
+// CHECK-NEXT: DeclRefExpr=newObject:32:6 =[35:32 - 35:41]
+
+// RUN:   -target x86_64-apple-macosx10.7 %s | FileCheck %s

Modified: cfe/trunk/test/Index/fix-its.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/fix-its.c?rev=152138&r1=152137&r2=152138&view=diff
==============================================================================
--- cfe/trunk/test/Index/fix-its.c (original)
+++ cfe/trunk/test/Index/fix-its.c Tue Mar  6 14:06:06 2012
@@ -8,7 +8,7 @@
 
 void f(struct X *x) {
   // CHECK: error: no member named 'wobble' in 'struct X'; did you mean 'wibble'?
-  // CHECK-NOT: FIX-IT
+  // CHECK: FIX-IT: Replace [13:12 - 13:24] with "wibble"
   // CHECK: note: 'wibble' declared here
   MACRO(x->wobble = 17);
   // CHECK: error: no member named 'wabble' in 'struct X'; did you mean 'wibble'?

Added: cfe/trunk/test/Index/index-subscripting-literals.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-subscripting-literals.m?rev=152138&view=auto
==============================================================================
--- cfe/trunk/test/Index/index-subscripting-literals.m (added)
+++ cfe/trunk/test/Index/index-subscripting-literals.m Tue Mar  6 14:06:06 2012
@@ -0,0 +1,66 @@
+ at interface NSArray
+- (id)objectAtIndexedSubscript:(int)index;
++ (id)arrayWithObjects:(id *)objects count:(unsigned)count;
+ at end
+
+ at interface NSMutableArray : NSArray
+- (id)objectAtIndexedSubscript:(int)index;
+- (void)setObject:(id)object atIndexedSubscript:(int)index;
+ at end
+
+ at interface NSDictionary
+- (id)objectForKeyedSubscript:(id)key;
++ (id)dictionaryWithObjects:(id *)objects forKeys:(id *)keys count:(unsigned)count;
+ at end
+
+ at interface NSMutableDictionary : NSDictionary
+- (void)setObject:(id)object forKeyedSubscript:(id)key;
+ at end
+
+ at class NSString;
+
+int idx;
+id p;
+
+id testArray() {
+  NSMutableArray *array;
+  array[idx] = p;
+  NSArray *arr = @[ p, p ];
+  return array[idx];
+}
+
+NSString *key;
+id newObject, oldObject;
+
+void testDict() {
+  NSMutableDictionary *dictionary;
+  oldObject = dictionary[key];
+  dictionary[key] = newObject;
+  NSDictionary *dict = @{ key: newObject, key: oldObject };
+}
+
+// RUN: c-index-test -index-file -target x86_64-apple-macosx10.7 %s | FileCheck %s
+
+// CHECK:      [indexEntityReference]: kind: variable | name: idx | USR: c:@idx | lang: C | cursor: DeclRefExpr=idx:22:5 | loc: 27:9
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: p | USR: c:@p | lang: C | cursor: DeclRefExpr=p:23:4 | loc: 27:16 | <parent>:: kind: function | name: testArray | USR: c:@F at testArray | lang: C | container: [testArray:25:4] | refkind: direct
+// CHECK-NEXT: [indexEntityReference]: kind: objc-instance-method | name: setObject:atIndexedSubscript:
+// CHECK-NEXT: [indexEntityReference]: kind: objc-class | name: NSArray
+// CHECK-NEXT: [indexEntityReference]: kind: objc-class-method | name: arrayWithObjects:count: 
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: p | USR: c:@p | lang: C | cursor: DeclRefExpr=p:23:4 | loc: 28:21
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: p | USR: c:@p | lang: C | cursor: DeclRefExpr=p:23:4 | loc: 28:24
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: idx | USR: c:@idx | lang: C | cursor: DeclRefExpr=idx:22:5 | loc: 29:16
+// CHECK-NEXT: [indexEntityReference]: kind: objc-instance-method | name: objectAtIndexedSubscript:
+// CHECK-NEXT: [indexDeclaration]: kind: variable | name: key
+
+// CHECK:      [indexEntityReference]: kind: variable | name: oldObject
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: key | USR: c:@key | lang: C | cursor: DeclRefExpr=key:32:11 | loc: 37:26
+// CHECK-NEXT: [indexEntityReference]: kind: objc-instance-method | name: objectForKeyedSubscript:
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: key | USR: c:@key | lang: C | cursor: DeclRefExpr=key:32:11 | loc: 38:14
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: newObject | USR: c:@newObject | lang: C | cursor: DeclRefExpr=newObject:33:4 | loc: 38:21
+// CHECK-NEXT: [indexEntityReference]: kind: objc-instance-method | name: setObject:forKeyedSubscript:
+// CHECK-NEXT: [indexEntityReference]: kind: objc-class | name: NSDictionary
+// CHECK-NEXT: [indexEntityReference]: kind: objc-class-method | name: dictionaryWithObjects:forKeys:count: 
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: key | USR: c:@key | lang: C | cursor: DeclRefExpr=key:32:11 | loc: 39:27
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: newObject | USR: c:@newObject | lang: C | cursor: DeclRefExpr=newObject:33:4 | loc: 39:32
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: key | USR: c:@key | lang: C | cursor: DeclRefExpr=key:32:11 | loc: 39:43
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: oldObject | USR: c:@oldObject | lang: C | cursor: DeclRefExpr=oldObject:33:15 | loc: 39:48

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=152138&r1=152137&r2=152138&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Mar  6 14:06:06 2012
@@ -3291,6 +3291,8 @@
       return createCXString("UnaryExpr");
   case CXCursor_ObjCStringLiteral:
       return createCXString("ObjCStringLiteral");
+  case CXCursor_ObjCBoolLiteralExpr:
+      return createCXString("ObjCBoolLiteralExpr");
   case CXCursor_ObjCEncodeExpr:
       return createCXString("ObjCEncodeExpr");
   case CXCursor_ObjCSelectorExpr:

Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=152138&r1=152137&r2=152138&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Tue Mar  6 14:06:06 2012
@@ -227,6 +227,10 @@
   case Stmt::UnaryExprOrTypeTraitExprClass:
   case Stmt::UnaryTypeTraitExprClass:
   case Stmt::VAArgExprClass:
+  case Stmt::ObjCArrayLiteralClass:
+  case Stmt::ObjCDictionaryLiteralClass:
+  case Stmt::ObjCNumericLiteralClass:
+  case Stmt::ObjCSubscriptRefExprClass:
     K = CXCursor_UnexposedExpr;
     break;
 
@@ -395,7 +399,11 @@
   case Stmt::ObjCProtocolExprClass:
     K = CXCursor_ObjCProtocolExpr;
     break;
-
+      
+  case Stmt::ObjCBoolLiteralExprClass:
+    K = CXCursor_ObjCBoolLiteralExpr;
+    break;
+      
   case Stmt::ObjCBridgedCastExprClass:
     K = CXCursor_ObjCBridgedCastExpr;
     break;

Modified: cfe/trunk/tools/libclang/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexBody.cpp?rev=152138&r1=152137&r2=152138&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexBody.cpp (original)
+++ cfe/trunk/tools/libclang/IndexBody.cpp Tue Mar  6 14:06:06 2012
@@ -81,17 +81,33 @@
   }
 
   bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
-    if (E->isImplicitProperty()) {
-      if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter())
-        IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E,
-                                 CXIdxEntityRef_Implicit);
-      if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
-        IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E,
-                                 CXIdxEntityRef_Implicit);
-    } else {
+    if (E->isExplicitProperty())
       IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(),
                                Parent, ParentDC, E);
-    }
+
+    // No need to do a handleReference for the objc method, because there will
+    // be a message expr as part of PseudoObjectExpr.
+    return true;
+  }
+
+  bool VisitObjCNumericLiteral(ObjCNumericLiteral *E) {
+    if (ObjCMethodDecl *MD = E->getObjCNumericLiteralMethod())
+      IndexCtx.handleReference(MD, E->getLocStart(),
+                               Parent, ParentDC, E, CXIdxEntityRef_Implicit);
+    return true;
+  }
+
+  bool VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
+    if (ObjCMethodDecl *MD = E->getDictWithObjectsMethod())
+      IndexCtx.handleReference(MD, E->getLocStart(),
+                               Parent, ParentDC, E, CXIdxEntityRef_Implicit);
+    return true;
+  }
+
+  bool VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
+    if (ObjCMethodDecl *MD = E->getArrayWithObjectsMethod())
+      IndexCtx.handleReference(MD, E->getLocStart(),
+                               Parent, ParentDC, E, CXIdxEntityRef_Implicit);
     return true;
   }
 





More information about the cfe-commits mailing list