[cfe-commits] r111867 - in /cfe/trunk: lib/Sema/SemaCodeComplete.cpp test/Index/complete-exprs.c test/Index/complete-objc-message.m

Douglas Gregor dgregor at apple.com
Mon Aug 23 16:51:41 PDT 2010


Author: dgregor
Date: Mon Aug 23 18:51:41 2010
New Revision: 111867

URL: http://llvm.org/viewvc/llvm-project?rev=111867&view=rev
Log:
When calling a function or messaging a method marked "sentinel", add
the ", nil", ", NULL", or ", (void*)0" to the end of the code
completion, since it always has to be there anyway.

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-exprs.c
    cfe/trunk/test/Index/complete-objc-message.m

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=111867&r1=111866&r2=111867&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Aug 23 18:51:41 2010
@@ -1666,6 +1666,20 @@
   Result->AddResultTypeChunk(TypeStr);
 }
 
+static void MaybeAddSentinel(ASTContext &Context, NamedDecl *FunctionOrMethod,
+                             CodeCompletionString *Result) {
+  if (SentinelAttr *Sentinel = FunctionOrMethod->getAttr<SentinelAttr>())
+    if (Sentinel->getSentinel() == 0) {
+      if (Context.getLangOptions().ObjC1 &&
+          Context.Idents.get("nil").hasMacroDefinition())
+        Result->AddTextChunk(", nil");
+      else if (Context.Idents.get("NULL").hasMacroDefinition())
+        Result->AddTextChunk(", NULL");
+      else
+        Result->AddTextChunk(", (void*)0");
+    }
+}
+
 /// \brief Add function parameter chunks to the given code completion string.
 static void AddFunctionParameterChunks(ASTContext &Context,
                                        FunctionDecl *Function,
@@ -1702,8 +1716,11 @@
   
   if (const FunctionProtoType *Proto 
         = Function->getType()->getAs<FunctionProtoType>())
-    if (Proto->isVariadic())
+    if (Proto->isVariadic()) {
       CCStr->AddPlaceholderChunk(", ...");
+
+      MaybeAddSentinel(Context, Function, CCStr);
+    }
 }
 
 /// \brief Add template parameter chunks to the given code completion string.
@@ -2020,6 +2037,8 @@
         Result->AddInformativeChunk(", ...");
       else
         Result->AddPlaceholderChunk(", ...");
+      
+      MaybeAddSentinel(S.Context, Method, Result);
     }
     
     return Result;

Modified: cfe/trunk/test/Index/complete-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.c?rev=111867&r1=111866&r2=111867&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-exprs.c (original)
+++ cfe/trunk/test/Index/complete-exprs.c Mon Aug 23 18:51:41 2010
@@ -12,6 +12,12 @@
 
 const char *str = "Hello, \nWorld";
 
+void f3(const char*, ...) __attribute__((sentinel(0)));
+
+#define NULL __null
+void f4(const char* str) {
+  f3(str, NULL);
+}
 // RUN: c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: env CINDEXTEST_EDITING=1 c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: NotImplemented:{TypedText __PRETTY_FUNCTION__} (60)
@@ -49,3 +55,8 @@
 // RUN: c-index-test -code-completion-at=%s:13:28 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC5 %s
 // CHECK-CC5: NotImplemented:{TypedText void} (40)
 // CHECK-CC5: NotImplemented:{TypedText volatile} (40)
+
+// RUN: c-index-test -code-completion-at=%s:19:3 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s
+// CHECK-CC6: FunctionDecl:{ResultType void}{TypedText f3}{LeftParen (}{Placeholder char const *}{Placeholder , ...}{Text , NULL}{RightParen )} (50)
+// CHECK-CC6: NotImplemented:{TypedText void} (40)
+// CHECK-CC6: NotImplemented:{TypedText volatile} (40)

Modified: cfe/trunk/test/Index/complete-objc-message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-objc-message.m?rev=111867&r1=111866&r2=111867&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-objc-message.m (original)
+++ cfe/trunk/test/Index/complete-objc-message.m Mon Aug 23 18:51:41 2010
@@ -1,6 +1,6 @@
 // Note: the run lines follow their respective tests, since line/column
 // matter in this test.
-
+#define nil (void*)0
 @protocol FooTestProtocol
 + protocolClassMethod;
 - protocolInstanceMethod : (int)value;
@@ -96,9 +96,9 @@
 }
 
 @interface Ellipsis
-- (int)Method:(int)i, ...;
+- (int)Method:(int)i, ...; 
+- (int)SentinelMethod:(int)i, ... __attribute__((sentinel(0,1)));
 @end
-
 void f(Ellipsis *e) {
   [e Method:1, 2, 3];
 }
@@ -171,6 +171,7 @@
 // CHECK-CCA: {TypedText super}
 // RUN: c-index-test -code-completion-at=%s:103:6 %s | FileCheck -check-prefix=CHECK-CCB %s
 // CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)i}{Placeholder , ...}
+// CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText SentinelMethod:}{Placeholder (int)i}{Placeholder , ...}{Text , nil}
 // RUN: c-index-test -code-completion-at=%s:116:14 %s | FileCheck -check-prefix=CHECK-CCC %s
 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method}
 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)i}





More information about the cfe-commits mailing list