[cfe-commits] r158533 - in /cfe/trunk: lib/Sema/SemaCodeComplete.cpp test/CodeCompletion/objc-expr.m test/Index/complete-exprs.m

Jordan Rose jordan_rose at apple.com
Fri Jun 15 11:19:56 PDT 2012


Author: jrose
Date: Fri Jun 15 13:19:56 2012
New Revision: 158533

URL: http://llvm.org/viewvc/llvm-project?rev=158533&view=rev
Log:
[completion] Add completions for @"..." and @(...), and tidy up @[] and @{}.

Specifically, @[] and @{} didn't have a type associated with them; we now
use "NSArray *" and "NSDictionary *", respectively. @"" has the type
"NSString *". @(), unfortunately, has type "id", since it (currently) may
be either an NSNumber or an NSString.

Add a test for all the Objective-C at-expression completions.

<rdar://problem/11507708&11507668&11507711>

Added:
    cfe/trunk/test/CodeCompletion/objc-expr.m
Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-exprs.m

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=158533&r1=158532&r2=158533&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Jun 15 13:19:56 2012
@@ -4411,7 +4411,7 @@
   const char *EncodeType = "char[]";
   if (Results.getSema().getLangOpts().CPlusPlus ||
       Results.getSema().getLangOpts().ConstStrings)
-    EncodeType = " const char[]";
+    EncodeType = "const char[]";
   Builder.AddResultTypeChunk(EncodeType);
   Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"encode"));
   Builder.AddChunk(CodeCompletionString::CK_LeftParen);
@@ -4434,8 +4434,16 @@
   Builder.AddPlaceholderChunk("selector");
   Builder.AddChunk(CodeCompletionString::CK_RightParen);
   Results.AddResult(Result(Builder.TakeString()));
-  
+
+  // @"string"
+  Builder.AddResultTypeChunk("NSString *");
+  Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"\""));
+  Builder.AddPlaceholderChunk("string");
+  Builder.AddTextChunk("\"");
+  Results.AddResult(Result(Builder.TakeString()));
+
   // @[ objects, ... ]
+  Builder.AddResultTypeChunk("NSArray *");
   Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"["));
   Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
   Builder.AddPlaceholderChunk("objects, ...");
@@ -4444,6 +4452,7 @@
   Results.AddResult(Result(Builder.TakeString()));
 
   // @{ key : object, ... }
+  Builder.AddResultTypeChunk("NSDictionary *");
   Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"{"));
   Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
   Builder.AddPlaceholderChunk("key");
@@ -4454,6 +4463,15 @@
   Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
   Builder.AddChunk(CodeCompletionString::CK_RightBrace);
   Results.AddResult(Result(Builder.TakeString()));
+
+  // @( expression )
+  Builder.AddResultTypeChunk("id");
+  Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt, "("));
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddPlaceholderChunk("expression");
+  Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Builder.AddChunk(CodeCompletionString::CK_RightParen);
+  Results.AddResult(Result(Builder.TakeString()));
 }
 
 static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt) {

Added: cfe/trunk/test/CodeCompletion/objc-expr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/objc-expr.m?rev=158533&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/objc-expr.m (added)
+++ cfe/trunk/test/CodeCompletion/objc-expr.m Fri Jun 15 13:19:56 2012
@@ -0,0 +1,17 @@
+// Note: the run lines follow all tests, since line/column matter here
+
+id testCompleteAfterAtSign() {
+  return @"";
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:4:11 %s -fno-const-strings -o - | FileCheck -check-prefix=AT %s
+// CHECK-AT: COMPLETION: Pattern : [#NSString *#]"<#string#>"
+// CHECK-AT: COMPLETION: Pattern : [#id#]( <#expression#> )
+// CHECK-AT: COMPLETION: Pattern : [#NSArray *#][ <#objects, ...#> ]
+// CHECK-AT: COMPLETION: Pattern : [#char[]#]encode(<#type-name#>)
+// CHECK-AT: COMPLETION: Pattern : [#Protocol *#]protocol(<#protocol-name#>)
+// CHECK-AT: COMPLETION: Pattern : [#SEL#]selector(<#selector#>)
+// CHECK-AT: COMPLETION: Pattern : [#NSDictionary *#]{ <#key#> : <#object, ...#> }
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:4:11 %s -fconst-strings -o - | FileCheck -check-prefix=CONST-STRINGS %s
+// CHECK-CONST-STRINGS: COMPLETION: Pattern : [#const char[]#]encode(<#type-name#>)

Modified: cfe/trunk/test/Index/complete-exprs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.m?rev=158533&r1=158532&r2=158533&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-exprs.m (original)
+++ cfe/trunk/test/Index/complete-exprs.m Fri Jun 15 13:19:56 2012
@@ -18,8 +18,10 @@
 @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 NSString *}{TypedText @"}{Placeholder string}{Text "} (40)
+// CHECK-CC1: NotImplemented:{ResultType id}{TypedText @(}{HorizontalSpace  }{Placeholder expression}{HorizontalSpace  }{RightParen )} (40)
+// CHECK-CC1: NotImplemented:{ResultType NSArray *}{TypedText @[}{HorizontalSpace  }{Placeholder objects, ...}{HorizontalSpace  }{RightBracket ]} (40)
+// CHECK-CC1: NotImplemented:{ResultType NSDictionary *}{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)
@@ -40,8 +42,8 @@
 // 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 NSArray *}{TypedText @[}{HorizontalSpace  }{Placeholder objects, ...}{HorizontalSpace  }{RightBracket ]} (40)
+// CHECK-CC4: NotImplemented:{ResultType NSDictionary *}{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)





More information about the cfe-commits mailing list