[cfe-commits] r107933 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaCodeComplete.cpp test/Index/complete-method-decls.m
Douglas Gregor
dgregor at apple.com
Thu Jul 8 16:37:41 PDT 2010
Author: dgregor
Date: Thu Jul 8 18:37:41 2010
New Revision: 107933
URL: http://llvm.org/viewvc/llvm-project?rev=107933&view=rev
Log:
Support code completion for parameter names in Objective-C method
declarations.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-method-decls.m
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=107933&r1=107932&r2=107933&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Jul 8 18:37:41 2010
@@ -3134,14 +3134,17 @@
DeclPtrTy IDecl) {
}
- /// \brief Code completion for a selector identifier within an Objective-C
- /// method declaration.
+ /// \brief Code completion for a selector identifier or argument name within
+ /// an Objective-C method declaration.
///
/// \param S The scope in which this code completion occurs.
///
/// \param IsInstanceMethod Whether we are parsing an instance method (or,
/// if false, a class method).
///
+ /// \param AtParameterName Whether the actual code completion point is at the
+ /// argument name.
+ ///
/// \param ReturnType If non-NULL, the specified return type of the method
/// being declared or defined.
///
@@ -3151,6 +3154,7 @@
/// \param NumSelIdents The number of identifiers provided by SelIdents.
virtual void CodeCompleteObjCMethodDeclSelector(Scope *S,
bool IsInstanceMethod,
+ bool AtParameterName,
TypeTy *ReturnType,
IdentifierInfo **SelIdents,
unsigned NumSelIdents) { }
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=107933&r1=107932&r2=107933&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Thu Jul 8 18:37:41 2010
@@ -856,6 +856,20 @@
if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
ArgInfo.ArgAttrs = ParseGNUAttributes();
+ // Code completion for the next piece of the selector.
+ if (Tok.is(tok::code_completion)) {
+ ConsumeCodeCompletionToken();
+ KeyIdents.push_back(SelIdent);
+ Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
+ mType == tok::minus,
+ /*AtParameterName=*/true,
+ ReturnType,
+ KeyIdents.data(),
+ KeyIdents.size());
+ KeyIdents.pop_back();
+ break;
+ }
+
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); // missing argument name.
break;
@@ -873,6 +887,7 @@
ConsumeCodeCompletionToken();
Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(),
mType == tok::minus,
+ /*AtParameterName=*/false,
ReturnType,
KeyIdents.data(),
KeyIdents.size());
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=107933&r1=107932&r2=107933&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Jul 8 18:37:41 2010
@@ -4574,6 +4574,7 @@
DeclPtrTy IDecl);
virtual void CodeCompleteObjCMethodDeclSelector(Scope *S,
bool IsInstanceMethod,
+ bool AtParameterName,
TypeTy *ReturnType,
IdentifierInfo **SelIdents,
unsigned NumSelIdents);
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=107933&r1=107932&r2=107933&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Jul 8 18:37:41 2010
@@ -4147,6 +4147,7 @@
void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S,
bool IsInstanceMethod,
+ bool AtParameterName,
TypeTy *ReturnTy,
IdentifierInfo **SelIdents,
unsigned NumSelIdents) {
@@ -4185,6 +4186,20 @@
NumSelIdents))
continue;
+ if (AtParameterName) {
+ // Suggest parameter names we've seen before.
+ if (NumSelIdents && NumSelIdents <= MethList->Method->param_size()) {
+ ParmVarDecl *Param = MethList->Method->param_begin()[NumSelIdents-1];
+ if (Param->getIdentifier()) {
+ CodeCompletionString *Pattern = new CodeCompletionString;
+ Pattern->AddTypedTextChunk(Param->getIdentifier()->getName());
+ Results.AddResult(Pattern);
+ }
+ }
+
+ continue;
+ }
+
Result R(MethList->Method, 0);
R.StartParameter = NumSelIdents;
R.AllParametersAreInformative = false;
Modified: cfe/trunk/test/Index/complete-method-decls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-method-decls.m?rev=107933&r1=107932&r2=107933&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-method-decls.m (original)
+++ cfe/trunk/test/Index/complete-method-decls.m Thu Jul 8 18:37:41 2010
@@ -44,12 +44,12 @@
@interface C
- (int)first:(int)x second:(float)y third:(double)z;
-- (id)first:(int)x second2:(float)y third:(double)z;
-- (void*)first:(int)x second3:(float)y third:(double)z;
+- (id)first:(int)xx second2:(float)y2 third:(double)z;
+- (void*)first:(int)xxx second3:(float)y3 third:(double)z;
@end
@interface D
-- (int)first:(int)x second4:(float)y third:(double)z;
+- (int)first:(int)x second2:(float)y third:(double)z;
@end
// RUN: c-index-test -code-completion-at=%s:17:3 %s | FileCheck -check-prefix=CHECK-CC1 %s
@@ -90,8 +90,14 @@
// RUN: c-index-test -code-completion-at=%s:42:3 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC7 %s
// CHECK-CC7: NotImplemented:{LeftParen (}{Text id}{RightParen )}{TypedText categoryFunction}{Colon :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{LeftBrace {}{VerticalSpace
// RUN: c-index-test -code-completion-at=%s:52:21 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC8 %s
-// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{Informative first:}{TypedText second2:}{Text (float)y}{HorizontalSpace }{Text third:}{Text (double)z} (20)
-// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType void *}{Informative first:}{TypedText second3:}{Text (float)y}{HorizontalSpace }{Text third:}{Text (double)z} (20)
+// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType id}{Informative first:}{TypedText second2:}{Text (float)y2}{HorizontalSpace }{Text third:}{Text (double)z} (20)
+// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType void *}{Informative first:}{TypedText second3:}{Text (float)y3}{HorizontalSpace }{Text third:}{Text (double)z} (20)
// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative first:}{TypedText second:}{Text (float)y}{HorizontalSpace }{Text third:}{Text (double)z} (5)
+// RUN: c-index-test -code-completion-at=%s:52:19 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC9 %s
+// CHECK-CC9: NotImplemented:{TypedText x} (30)
+// CHECK-CC9: NotImplemented:{TypedText xx} (30)
+// CHECK-CC9: NotImplemented:{TypedText xxx} (30)
+// RUN: c-index-test -code-completion-at=%s:52:36 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CCA %s
+// CHECK-CCA: NotImplemented:{TypedText y2} (30)
More information about the cfe-commits
mailing list