]> granicus.if.org Git - clang/commitdiff
[libclang] Replace ObjC generic parameters when code-completing method implementations.
authorDouglas Gregor <dgregor@apple.com>
Tue, 7 Jul 2015 06:20:27 +0000 (06:20 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 7 Jul 2015 06:20:27 +0000 (06:20 +0000)
rdar://20643768

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

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-parameterized-classes.m

index 7262253115799626f1bd6a3587a3306d224c9039..ad037acbdf3d7fb85a79d1ab718d4b8739601831 100644 (file)
@@ -333,9 +333,7 @@ public:
 
   /// \brief Determine the type of an expression that sends a message to this
   /// function.
-  QualType getSendResultType() const {
-    return getReturnType().getNonLValueExprType(getASTContext());
-  }
+  QualType getSendResultType() const;
 
   /// Determine the type of an expression that sends a message to this
   /// function with the given receiver type.
index b540e37cd076dec6f3db6cf74e4acf24b66fae84..11a66c9c8cb2556fac1adb4b56789e3a372f961d 100644 (file)
@@ -1022,6 +1022,12 @@ SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const {
   return SourceRange();
 }
 
+QualType ObjCMethodDecl::getSendResultType() const {
+  ASTContext &Ctx = getASTContext();
+  return getReturnType().getNonLValueExprType(Ctx)
+           .substObjCTypeArgs(Ctx, {}, ObjCSubstitutionContext::Result);
+}
+
 QualType ObjCMethodDecl::getSendResultType(QualType receiverType) const {
   // FIXME: Handle related result types here.
 
index 7d898d8ac1a20938d2a99f0c1ee8f0c753fcdc77..252e30563e3a51d4e4068c06fb61f938b923f9c2 100644 (file)
@@ -7076,7 +7076,8 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
     // If the result type was not already provided, add it to the
     // pattern as (type).
     if (ReturnType.isNull())
-      AddObjCPassingTypeChunk(Method->getReturnType(),
+      AddObjCPassingTypeChunk(Method->getSendResultType()
+                                  .stripObjCKindOfType(Context),
                               Method->getObjCDeclQualifier(), Context, Policy,
                               Builder);
 
@@ -7107,6 +7108,8 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
         ParamType = (*P)->getType();
       else
         ParamType = (*P)->getOriginalType();
+      ParamType = ParamType.substObjCTypeArgs(Context, {},
+                                            ObjCSubstitutionContext::Parameter);
       AddObjCPassingTypeChunk(ParamType,
                               (*P)->getObjCDeclQualifier(),
                               Context, Policy,
index 978f42b4008bae9b48ed4de46e2e845eecddd9c6..c7d273ac1ef799d885c716dc46f56635e7a673fc 100644 (file)
@@ -11,7 +11,7 @@
 }
 -(U)getit:(T)val;
 -(void)apply:(void(^)(T, U))block;
--(void)apply2:(void(^__nonnull)(T, U))block;
+-(void)apply2:(void(^_Nonnull)(T, U))block;
 
 @property (strong) T prop;
 @end
@@ -33,6 +33,10 @@ void test2(Test *obj) {
   obj->;
 }
 
+@implementation Test
+-(id)getit:(id)val {}
+@end
+
 // RUN: c-index-test -code-completion-at=%s:25:8 %s | FileCheck -check-prefix=CHECK-CC0 %s
 // CHECK-CC0: ObjCInstanceMethodDecl:{ResultType void}{TypedText apply2:}{Placeholder ^(MyClsA *, MyClsB *)block} (35)
 // CHECK-CC0: ObjCInstanceMethodDecl:{ResultType void}{TypedText apply:}{Placeholder ^(MyClsA *, MyClsB *)block} (35)
@@ -54,3 +58,9 @@ void test2(Test *obj) {
 
 // RUN: c-index-test -code-completion-at=%s:33:8 %s | FileCheck -check-prefix=CHECK-CC5 %s
 // CHECK-CC5: ObjCIvarDecl:{ResultType __kindof NSObject *}{TypedText myVar} (35)
+
+// RUN: c-index-test -code-completion-at=%s:37:2 %s | FileCheck -check-prefix=CHECK-CC6 %s
+// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text void}{RightParen )}{TypedText apply2}{TypedText :}{LeftParen (}{Text void (^ _Nonnull)(id, NSObject *)}{RightParen )}{Text block} (40)
+// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text void}{RightParen )}{TypedText apply}{TypedText :}{LeftParen (}{Text void (^)(id, NSObject *)}{RightParen )}{Text block} (40)
+// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text NSObject *}{RightParen )}{TypedText getit}{TypedText :}{LeftParen (}{Text id}{RightParen )}{Text val} (40)
+// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText prop} (40)