]> granicus.if.org Git - clang/commitdiff
When providing a block literal as a code completion for a
authorDouglas Gregor <dgregor@apple.com>
Sat, 2 Oct 2010 23:49:58 +0000 (23:49 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 2 Oct 2010 23:49:58 +0000 (23:49 +0000)
function/method argument, include the parameter name and always
include parentheses (even for zero-parameter blocks). Otherwise, the
block literal placeholder '^' can look very weird.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115444 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCodeComplete.cpp
test/Index/complete-blocks.m

index 64a96dbff7a42d09192d6baf86f9c36080bf71e1..ae82ceb334afcb61dbc24e8fade35db6a19d9ad1 100644 (file)
@@ -1910,6 +1910,8 @@ static std::string FormatFunctionParameter(ASTContext &Context,
   if (Block->getNumArgs() == 0) {
     if (Block->getTypePtr()->isVariadic())
       Result += "(...)";
+    else
+      Result += "(void)";
   } else {
     Result += "(";
     for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) {
@@ -1923,6 +1925,9 @@ static std::string FormatFunctionParameter(ASTContext &Context,
     Result += ")";
   }
   
+  if (Param->getIdentifier())
+    Result += Param->getIdentifier()->getName();
+
   return Result;
 }
 
index 281b5e63f0ba84229ba693935835e5ad2dc517fc..61e363e37529a7677e781dfd027b5eda5fdaa275 100644 (file)
@@ -25,11 +25,21 @@ void test_B(B *b) {
   [b method3:^int(void){ return 0; }];
 }
 
+@interface C
+- method4:(void(^)(void))arg { };
+@end
+
+void test_C(C *c) {
+  [c method4:^{}];
+}
+
 // RUN: c-index-test -code-completion-at=%s:8:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
-// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder ^int(int x, int y)}{RightParen )} (50)
-// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText g}{LeftParen (}{Placeholder ^(float f, double d)}{RightParen )} (50)
+// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder ^int(int x, int y)block}{RightParen )} (50)
+// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText g}{LeftParen (}{Placeholder ^(float f, double d)b}{RightParen )} (50)
 // RUN: c-index-test -code-completion-at=%s:17:6 %s | FileCheck -check-prefix=CHECK-CC2 %s
-// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method2:}{Placeholder ^(float f, double d)} (20)
-// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method:}{Placeholder ^int(int x, int y)} (20)
+// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method2:}{Placeholder ^(float f, double d)b} (20)
+// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method:}{Placeholder ^int(int x, int y)b} (20)
 // RUN: c-index-test -code-completion-at=%s:25:6 %s | FileCheck -check-prefix=CHECK-CC3 %s
-// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType id}{TypedText method3:}{Placeholder ^int} (20)
+// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType id}{TypedText method3:}{Placeholder ^int(void)b} (20)
+// RUN: c-index-test -code-completion-at=%s:33:6 %s | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType id}{TypedText method4:}{Placeholder ^(void)arg} (20)