r241559 - [libclang] Replace ObjC generic parameters when code-completing method implementations.

Douglas Gregor dgregor at apple.com
Mon Jul 6 23:20:27 PDT 2015


Author: dgregor
Date: Tue Jul  7 01:20:27 2015
New Revision: 241559

URL: http://llvm.org/viewvc/llvm-project?rev=241559&view=rev
Log:
[libclang] Replace ObjC generic parameters when code-completing method implementations.

rdar://20643768

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

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=241559&r1=241558&r2=241559&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Jul  7 01:20:27 2015
@@ -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.

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=241559&r1=241558&r2=241559&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Jul  7 01:20:27 2015
@@ -1022,6 +1022,12 @@ SourceRange ObjCMethodDecl::getReturnTyp
   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.
 

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=241559&r1=241558&r2=241559&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Jul  7 01:20:27 2015
@@ -7076,7 +7076,8 @@ void Sema::CodeCompleteObjCMethodDecl(Sc
     // 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(Sc
         ParamType = (*P)->getType();
       else
         ParamType = (*P)->getOriginalType();
+      ParamType = ParamType.substObjCTypeArgs(Context, {},
+                                            ObjCSubstitutionContext::Parameter);
       AddObjCPassingTypeChunk(ParamType,
                               (*P)->getObjCDeclQualifier(),
                               Context, Policy,

Modified: cfe/trunk/test/Index/complete-parameterized-classes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-parameterized-classes.m?rev=241559&r1=241558&r2=241559&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-parameterized-classes.m (original)
+++ cfe/trunk/test/Index/complete-parameterized-classes.m Tue Jul  7 01:20:27 2015
@@ -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->;
 }
 
+ at implementation Test
+-(id)getit:(id)val {}
+ at 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)





More information about the cfe-commits mailing list