]> granicus.if.org Git - clang/commitdiff
Teach code completion to cope with block types written without a
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 22:37:09 +0000 (22:37 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 22:37:09 +0000 (22:37 +0000)
prototype, e.g., ^() rather than ^(void). Fixes
<rdar://problem/8875712>.

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

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

index 1d7cf98264957f372f7b8a472b7046e2c5f01eb3..3a07ef6783ea90a00e3c08d3fd6464c3d49f9046 100644 (file)
@@ -1894,7 +1894,8 @@ static std::string FormatFunctionParameter(ASTContext &Context,
   
   // The argument for a block pointer parameter is a block literal with
   // the appropriate type.
-  FunctionProtoTypeLoc *Block = 0;
+  FunctionTypeLoc *Block = 0;
+  FunctionProtoTypeLoc *BlockProto = 0;
   TypeLoc TL;
   if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) {
     TL = TSInfo->getTypeLoc().getUnqualifiedLoc();
@@ -1919,7 +1920,8 @@ static std::string FormatFunctionParameter(ASTContext &Context,
       if (BlockPointerTypeLoc *BlockPtr
           = dyn_cast<BlockPointerTypeLoc>(&TL)) {
         TL = BlockPtr->getPointeeLoc().IgnoreParens();
-        Block = dyn_cast<FunctionProtoTypeLoc>(&TL);
+        Block = dyn_cast<FunctionTypeLoc>(&TL);
+        BlockProto = dyn_cast<FunctionProtoTypeLoc>(&TL);
       }
       break;
     }
@@ -1950,8 +1952,8 @@ static std::string FormatFunctionParameter(ASTContext &Context,
     ResultType.getAsStringInternal(Result, Context.PrintingPolicy);
   
   Result = '^' + Result;
-  if (Block->getNumArgs() == 0) {
-    if (Block->getTypePtr()->isVariadic())
+  if (!BlockProto || Block->getNumArgs() == 0) {
+    if (BlockProto && BlockProto->getTypePtr()->isVariadic())
       Result += "(...)";
     else
       Result += "(void)";
@@ -1962,7 +1964,7 @@ static std::string FormatFunctionParameter(ASTContext &Context,
         Result += ", ";
       Result += FormatFunctionParameter(Context, Block->getArg(I));
       
-      if (I == N - 1 && Block->getTypePtr()->isVariadic())
+      if (I == N - 1 && BlockProto->getTypePtr()->isVariadic())
         Result += ", ...";
     }
     Result += ")";
index 6522e54d8eb3a989bf38695925c553c82d879845..e7919efb0eb8dd63b69070ac36aa5777c37c6f25 100644 (file)
@@ -27,6 +27,7 @@ void test_B(B *b) {
 
 @interface C
 - method4:(void(^)(void))arg { };
+- method5:(void(^)())arg5 { };
 @end
 
 void test_C(C *c) {
@@ -41,8 +42,9 @@ void test_C(C *c) {
 // CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method:}{Placeholder ^int(int x, int y)b} (35)
 // 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(void)b} (35)
-// RUN: c-index-test -code-completion-at=%s:33:6 %s | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: c-index-test -code-completion-at=%s:34:6 %s | FileCheck -check-prefix=CHECK-CC4 %s
 // CHECK-CC4: ObjCInstanceMethodDecl:{ResultType id}{TypedText method4:}{Placeholder ^(void)arg} (35)
+// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType id}{TypedText method5:}{Placeholder ^(void)arg5} (35)
 // RUN: c-index-test -code-completion-at=%s:25:15 %s | FileCheck -check-prefix=CHECK-CC5 %s
 // CHECK-CC5: TypedefDecl:{TypedText block_t} (50)
 // CHECK-CC5: TypedefDecl:{TypedText Class} (50)