diff options
| author | Douglas Gregor <dgregor@apple.com> | 2012-04-10 18:35:07 +0000 | 
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2012-04-10 18:35:07 +0000 | 
| commit | 2997914ed0d4a6653b277668a47104b20fbf84fe (patch) | |
| tree | 341fc65747e7356435274b412f6635b4bb147a47 | |
| parent | 0241e32304d290768662748b221146ea7e8380f1 (diff) | |
| download | bcm5719-llvm-2997914ed0d4a6653b277668a47104b20fbf84fe.tar.gz bcm5719-llvm-2997914ed0d4a6653b277668a47104b20fbf84fe.zip  | |
Include the Objective-C parameter- and return-passing qualifiers when
providing code completions for Objective-C method declarations. Fixes
<rdar://problem/11164498>.
llvm-svn: 154421
| -rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 20 | ||||
| -rw-r--r-- | clang/test/Index/complete-method-decls.m | 24 | 
2 files changed, 31 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 2a8a7166246..1ee75329e08 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -6033,10 +6033,14 @@ static void FindImplementableMethods(ASTContext &Context,  /// \brief Add the parenthesized return or parameter type chunk to a code   /// completion string.  static void AddObjCPassingTypeChunk(QualType Type, +                                    unsigned ObjCDeclQuals,                                      ASTContext &Context,                                      const PrintingPolicy &Policy,                                      CodeCompletionBuilder &Builder) {    Builder.AddChunk(CodeCompletionString::CK_LeftParen); +  std::string Quals = formatObjCParamQualifiers(ObjCDeclQuals); +  if (!Quals.empty()) +    Builder.AddTextChunk(Builder.getAllocator().CopyString(Quals));    Builder.AddTextChunk(GetCompletionTypeString(Type, Context, Policy,                                                 Builder.getAllocator()));    Builder.AddChunk(CodeCompletionString::CK_RightParen); @@ -6111,7 +6115,8 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,        KnownSelectors.insert(Selectors.getNullarySelector(PropName)) &&        ReturnTypeMatchesProperty && !Property->getGetterMethodDecl()) {      if (ReturnType.isNull()) -      AddObjCPassingTypeChunk(Property->getType(), Context, Policy, Builder); +      AddObjCPassingTypeChunk(Property->getType(), /*Quals=*/0, +                              Context, Policy, Builder);      Builder.AddTypedTextChunk(Key);      Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern,  @@ -6157,7 +6162,8 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property,        Builder.AddTypedTextChunk(                                  Allocator.CopyString(SelectorId->getName()));        Builder.AddTypedTextChunk(":"); -      AddObjCPassingTypeChunk(Property->getType(), Context, Policy, Builder); +      AddObjCPassingTypeChunk(Property->getType(), /*Quals=*/0, +                              Context, Policy, Builder);        Builder.AddTextChunk(Key);        Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern,                                  CXCursor_ObjCInstanceMethodDecl)); @@ -6740,8 +6746,10 @@ 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->getResultType(), Context, Policy,  -                              Builder); +      AddObjCPassingTypeChunk(Method->getResultType(), +                              Method->getObjCDeclQualifier(), +                              Context, Policy, +                              Builder);       Selector Sel = Method->getSelector(); @@ -6765,7 +6773,9 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,          break;        // Add the parameter type. -      AddObjCPassingTypeChunk((*P)->getOriginalType(), Context, Policy,  +      AddObjCPassingTypeChunk((*P)->getOriginalType(), +                              (*P)->getObjCDeclQualifier(), +                              Context, Policy,                                Builder);        if (IdentifierInfo *Id = (*P)->getIdentifier()) diff --git a/clang/test/Index/complete-method-decls.m b/clang/test/Index/complete-method-decls.m index e26359cabb7..becb7de6eb8 100644 --- a/clang/test/Index/complete-method-decls.m +++ b/clang/test/Index/complete-method-decls.m @@ -4,7 +4,7 @@  @protocol P1  - (id)abc;  - (id)initWithInt:(int)x; -- (id)initWithTwoInts:(int)x second:(int)y; +- (id)initWithTwoInts:(inout int)x second:(int)y;  - (int)getInt;  - (id)getSelf;  @end @@ -57,7 +57,7 @@  @end  @interface Passing -- (oneway void)method:(in id x); +- (oneway void)method:(in id)x;  @end  @interface Gaps @@ -65,7 +65,11 @@  @end  @implementation Gaps -- (void)method:(int)x :(int)y; +- (void)method:(int)x :(int)y {} +@end + +@implementation Passing +- (oneway void)method:(in id x) {}  @end  // RUN: c-index-test -code-completion-at=%s:17:3 %s | FileCheck -check-prefix=CHECK-CC1 %s @@ -73,25 +77,25 @@  // CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text int}{RightParen )}{TypedText getInt} (40) (parent: ObjCProtocolDecl 'P1')  // CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText getSelf} (40) (parent: ObjCProtocolDecl 'P1')  // CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText initWithInt}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x} (40) (parent: ObjCProtocolDecl 'P1') -// CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y} (40) (parent: ObjCProtocolDecl 'P1') +// CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text inout }{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y} (40) (parent: ObjCProtocolDecl 'P1')  // RUN: c-index-test -code-completion-at=%s:17:7 %s | FileCheck -check-prefix=CHECK-CC2 %s  // CHECK-CC2: ObjCInstanceMethodDecl:{TypedText abc}  // CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{TypedText getSelf}  // CHECK-CC2: ObjCInstanceMethodDecl:{TypedText initWithInt}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x} -// CHECK-CC2: ObjCInstanceMethodDecl:{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y} +// CHECK-CC2: ObjCInstanceMethodDecl:{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text inout }{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y}  // RUN: c-index-test -code-completion-at=%s:24:7 %s | FileCheck -check-prefix=CHECK-CC3 %s  // CHECK-CC3: ObjCInstanceMethodDecl:{TypedText abc}  // CHECK-CC3-NEXT: ObjCInstanceMethodDecl:{TypedText getSelf}  // CHECK-CC3: ObjCInstanceMethodDecl:{TypedText init}  // CHECK-CC3: ObjCInstanceMethodDecl:{TypedText initWithInt}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x} -// CHECK-CC3: ObjCInstanceMethodDecl:{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y} +// CHECK-CC3: ObjCInstanceMethodDecl:{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text inout }{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y}  // RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:33:3 %s | FileCheck -check-prefix=CHECK-CC4 %s  // CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText abc}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  }{Text return}{HorizontalSpace  }{Placeholder expression}{SemiColon ;}{VerticalSpace  }{RightBrace }} (42)  // CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text int}{RightParen )}{TypedText getInt}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  // CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text int}{RightParen )}{TypedText getSecondValue}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  // CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText getSelf}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  }{Text return}{HorizontalSpace  }{Placeholder expression}{SemiColon ;}{VerticalSpace  }{RightBrace }} (40)  // CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText initWithInt}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{LeftBrace {}{VerticalSpace -// CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y}{HorizontalSpace  }{LeftBrace {}{VerticalSpace +// CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text inout }{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  // CHECK-CC4: ObjCInstanceMethodDecl:{LeftParen (}{Text int}{RightParen )}{TypedText setValue}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  // RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:33:8 %s | FileCheck -check-prefix=CHECK-CC5 %s  // CHECK-CC5: ObjCInstanceMethodDecl:{TypedText getInt}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  }{Text return}{HorizontalSpace  }{Placeholder expression}{SemiColon ;}{VerticalSpace  }{RightBrace }} (42) (parent: ObjCProtocolDecl 'P1') @@ -102,7 +106,7 @@  // CHECK-CC6: ObjCInstanceMethodDecl:{TypedText abc}{HorizontalSpace  }{LeftBrace {}{VerticalSpace   // CHECK-CC6: ObjCInstanceMethodDecl:{TypedText getSelf}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  }{Text return}{HorizontalSpace  }{Placeholder expression}{SemiColon ;}{VerticalSpace  }{RightBrace }} (40)  // CHECK-CC6: ObjCInstanceMethodDecl:{TypedText initWithInt}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  -// CHECK-CC6: ObjCInstanceMethodDecl:{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  +// CHECK-CC6: ObjCInstanceMethodDecl:{TypedText initWithTwoInts}{TypedText :}{LeftParen (}{Text inout }{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText second:}{LeftParen (}{Text int}{RightParen )}{Text y}{HorizontalSpace  }{LeftBrace {}{VerticalSpace   // RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:42:3 %s | FileCheck -check-prefix=CHECK-CC7 %s  // CHECK-CC7: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText abc}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  }{Text return}{HorizontalSpace  }{Placeholder expression}{SemiColon ;}{VerticalSpace  }{RightBrace }} (42)  // CHECK-CC7: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText categoryFunction}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{LeftBrace {}{VerticalSpace  @@ -174,3 +178,7 @@  // <rdar://problem/8939352>  // RUN: c-index-test -code-completion-at=%s:68:9 %s | FileCheck -check-prefix=CHECK-8939352 %s  // CHECK-8939352: ObjCInstanceMethodDecl:{TypedText method}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace  }{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text y} (40) + + +// RUN: c-index-test -code-completion-at=%s:72:2 %s | FileCheck -check-prefix=CHECK-ONEWAY %s +// CHECK-ONEWAY: ObjCInstanceMethodDecl:{LeftParen (}{Text oneway }{Text void}{RightParen )}{TypedText method}{TypedText :}{LeftParen (}{Text in }{Text id}{RightParen )}{Text x} (40) (parent: ObjCInterfaceDecl 'Passing')  | 

