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

Douglas Gregor dgregor at apple.com
Mon Aug 30 22:13:43 PDT 2010


Author: dgregor
Date: Tue Aug 31 00:13:43 2010
New Revision: 112579

URL: http://llvm.org/viewvc/llvm-project?rev=112579&view=rev
Log:
When provide code completions for a variadic Objective-C method
declaration send or a variadic function call, collapse the ", ..."
into the parameter before it, so that we don't get a second
placeholder.

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/CodeCompletion/functions.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=112579&r1=112578&r2=112579&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Aug 31 00:13:43 2010
@@ -1839,13 +1839,13 @@
     if (I)
       Result += ", ";
     Result += FormatFunctionParameter(Context, Block->getArg(I));
-  }
-  if (Block->getTypePtr()->isVariadic()) {
-    if (Block->getNumArgs() > 0)
+    
+    if (I == N - 1 && Block->getTypePtr()->isVariadic())
       Result += ", ...";
-    else
-      Result += "...";
-  } else if (Block->getNumArgs() == 0 && !Context.getLangOptions().CPlusPlus)
+  }
+  if (Block->getTypePtr()->isVariadic() && Block->getNumArgs() == 0)
+    Result += "...";
+  else if (Block->getNumArgs() == 0 && !Context.getLangOptions().CPlusPlus)
     Result += "void";
              
   Result += ")";
@@ -1879,6 +1879,9 @@
     // Format the placeholder string.
     std::string PlaceholderStr = FormatFunctionParameter(Context, Param);
         
+    if (Function->isVariadic() && P == N - 1)
+      PlaceholderStr += ", ...";
+
     // Add the placeholder string.
     CCStr->AddPlaceholderChunk(PlaceholderStr);
   }
@@ -1886,7 +1889,8 @@
   if (const FunctionProtoType *Proto 
         = Function->getType()->getAs<FunctionProtoType>())
     if (Proto->isVariadic()) {
-      CCStr->AddPlaceholderChunk(", ...");
+      if (Proto->getNumArgs() == 0)
+        CCStr->AddPlaceholderChunk("...");
 
       MaybeAddSentinel(Context, Function, CCStr);
     }
@@ -2198,6 +2202,9 @@
             Arg += II->getName().str();
       }
       
+      if (Method->isVariadic() && (P + 1) == PEnd)
+        Arg += ", ...";
+      
       if (DeclaringEntity)
         Result->AddTextChunk(Arg);
       else if (AllParametersAreInformative)
@@ -2207,12 +2214,14 @@
     }
 
     if (Method->isVariadic()) {
-      if (DeclaringEntity)
-        Result->AddTextChunk(", ...");
-      else if (AllParametersAreInformative)
-        Result->AddInformativeChunk(", ...");
-      else
-        Result->AddPlaceholderChunk(", ...");
+      if (Method->param_size() == 0) {
+        if (DeclaringEntity)
+          Result->AddTextChunk(", ...");
+        else if (AllParametersAreInformative)
+          Result->AddInformativeChunk(", ...");
+        else
+          Result->AddPlaceholderChunk(", ...");
+      }
       
       MaybeAddSentinel(S.Context, Method, Result);
     }
@@ -4955,14 +4964,14 @@
       Pattern->AddChunk(CodeCompletionString::CK_RightParen);
       
       if (IdentifierInfo *Id = (*P)->getIdentifier())
-        Pattern->AddTextChunk(Id->getName());
+        Pattern->AddTextChunk(Id->getName());      
     }
 
     if (Method->isVariadic()) {
       if (Method->param_size() > 0)
         Pattern->AddChunk(CodeCompletionString::CK_Comma);
       Pattern->AddTextChunk("...");
-    }
+    }        
 
     if (IsInImplementation && Results.includeCodePatterns()) {
       // We will be defining the method here, so add a compound statement.

Modified: cfe/trunk/test/CodeCompletion/functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/functions.cpp?rev=112579&r1=112578&r2=112579&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/functions.cpp (original)
+++ cfe/trunk/test/CodeCompletion/functions.cpp Tue Aug 31 00:13:43 2010
@@ -5,4 +5,4 @@
   ::
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:5:5 %s -o - | FileCheck -check-prefix=CC1 %s
   // CHECK-CC1: f(<#int i#>{#, <#int j#>{#, <#int k#>#}#})
-  // CHECK-CC1: f(<#float x#>, <#float y#><#, ...#>)
+  // CHECK-CC1: f(<#float x#>, <#float y, ...#>)

Modified: cfe/trunk/test/Index/complete-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.c?rev=112579&r1=112578&r2=112579&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-exprs.c (original)
+++ cfe/trunk/test/Index/complete-exprs.c Tue Aug 31 00:13:43 2010
@@ -48,6 +48,6 @@
 // CHECK-CC4: VarDecl:{ResultType struct X}{TypedText f1} (50) (deprecated)
 
 // 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 )} (45)
+// CHECK-CC6: FunctionDecl:{ResultType void}{TypedText f3}{LeftParen (}{Placeholder char const *, ...}{Text , NULL}{RightParen )} (45)
 // CHECK-CC6: NotImplemented:{TypedText void} (65)
 // CHECK-CC6: NotImplemented:{TypedText volatile} (65)

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=112579&r1=112578&r2=112579&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-objc-message.m (original)
+++ cfe/trunk/test/Index/complete-objc-message.m Tue Aug 31 00:13:43 2010
@@ -182,8 +182,8 @@
 // CHECK-CCA: {ResultType Class}{TypedText self}
 // 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)}{Placeholder , ...}
-// CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText SentinelMethod:}{Placeholder (int)}{Placeholder , ...}{Text , nil}
+// CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int), ...}
+// CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText SentinelMethod:}{Placeholder (int), ...}{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)}





More information about the cfe-commits mailing list