Skip to content

Commit

Permalink
[libclang] Replace ObjC generic parameters when code-completing metho…
Browse files Browse the repository at this point in the history
…d implementations.

rdar://20643768

llvm-svn: 241559
  • Loading branch information
DougGregor committed Jul 7, 2015
1 parent 4c850f3 commit 9b7b3e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 1 addition & 3 deletions clang/include/clang/AST/DeclObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext {

/// \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.
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/AST/DeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion clang/test/Index/complete-parameterized-classes.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ @interface Test<T : id, U : NSObject *> : NSObject
}
-(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
Expand All @@ -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)
Expand All @@ -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)

0 comments on commit 9b7b3e9

Please sign in to comment.