[cfe-commits] r89194 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaCodeComplete.cpp test/Index/complete-member-access.m test/Index/complete-property-list.m
Douglas Gregor
dgregor at apple.com
Tue Nov 17 20:19:13 PST 2009
Author: dgregor
Date: Tue Nov 17 22:19:12 2009
New Revision: 89194
URL: http://llvm.org/viewvc/llvm-project?rev=89194&view=rev
Log:
Code completion for Objective-C properly lists
Added:
cfe/trunk/test/Index/complete-property-list.m
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-member-access.m
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=89194&r1=89193&r2=89194&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Nov 17 22:19:12 2009
@@ -2352,6 +2352,19 @@
/// \param S the scope in which the operator keyword occurs.
/// \param Receiver an expression for the receiver of the message.
virtual void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver) { }
+
+ /// \brief Code completion for a list of protocol references in Objective-C,
+ /// such as P1 and P2 in \c id<P1,P2>.
+ ///
+ /// This code completion action is invoked prior to each identifier
+ /// in the protocol list.
+ ///
+ /// \param Protocols the set of protocols that have already been parsed.
+ ///
+ /// \param NumProtocols the number of protocols that have already been
+ /// parsed.
+ virtual void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
+ unsigned NumProtocols) { }
//@}
};
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=89194&r1=89193&r2=89194&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Nov 17 22:19:12 2009
@@ -834,6 +834,12 @@
llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
while (1) {
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(),
+ ProtocolIdents.size());
+ ConsumeToken();
+ }
+
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident);
SkipUntil(tok::greater);
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=89194&r1=89193&r2=89194&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Nov 17 22:19:12 2009
@@ -4015,6 +4015,8 @@
virtual void CodeCompleteObjCClassMessage(Scope *S, IdentifierInfo *FName,
SourceLocation FNameLoc);
virtual void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver);
+ virtual void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
+ unsigned NumProtocols);
//@}
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=89194&r1=89193&r2=89194&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Nov 17 22:19:12 2009
@@ -95,6 +95,9 @@
/// \brief Exit from the current scope.
void ExitScope();
+ /// \brief Ignore this declaration, if it is seen again.
+ void Ignore(Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); }
+
/// \name Name lookup predicates
///
/// These predicates can be passed to the name lookup functions to filter the
@@ -1823,3 +1826,46 @@
Results.ExitScope();
HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
}
+
+/// \brief Add all of the protocol declarations that we find in the given
+/// (translation unit) context.
+static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
+ ResultBuilder &Results) {
+ typedef CodeCompleteConsumer::Result Result;
+
+ for (DeclContext::decl_iterator D = Ctx->decls_begin(),
+ DEnd = Ctx->decls_end();
+ D != DEnd; ++D) {
+ // Record any protocols we find.
+ if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(*D))
+ Results.MaybeAddResult(Result(Proto, 0), CurContext);
+
+ // Record any forward-declared protocols we find.
+ if (ObjCForwardProtocolDecl *Forward
+ = dyn_cast<ObjCForwardProtocolDecl>(*D)) {
+ for (ObjCForwardProtocolDecl::protocol_iterator
+ P = Forward->protocol_begin(),
+ PEnd = Forward->protocol_end();
+ P != PEnd; ++P)
+ Results.MaybeAddResult(Result(*P, 0), CurContext);
+ }
+ }
+}
+
+void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
+ unsigned NumProtocols) {
+ ResultBuilder Results(*this);
+ Results.EnterNewScope();
+
+ // Tell the result set to ignore all of the protocols we have
+ // already seen.
+ for (unsigned I = 0; I != NumProtocols; ++I)
+ if (ObjCProtocolDecl *Protocol = LookupProtocol(Protocols[I].first))
+ Results.Ignore(Protocol);
+
+ // Add all protocols.
+ AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, Results);
+
+ Results.ExitScope();
+ HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
+}
Modified: cfe/trunk/test/Index/complete-member-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-member-access.m?rev=89194&r1=89193&r2=89194&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-member-access.m (original)
+++ cfe/trunk/test/Index/complete-member-access.m Tue Nov 17 22:19:12 2009
@@ -1,5 +1,5 @@
-// Note: the RUN lines are near the end of the file, since line/column
-// matter for this test.
+/* Note: the RUN lines are near the end of the file, since line/column
+ matter for this test. */
@protocol MyProtocol
@property float ProtoProp;
Added: cfe/trunk/test/Index/complete-property-list.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-property-list.m?rev=89194&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-property-list.m (added)
+++ cfe/trunk/test/Index/complete-property-list.m Tue Nov 17 22:19:12 2009
@@ -0,0 +1,16 @@
+/* Note: the RUN lines are near the end of the file, since line/column
+ matter for this test. */
+
+ at protocol Protocol1
+ at end
+
+ at protocol Protocol2;
+
+void f(id<Protocol1,Protocol2>);
+
+// RUN: c-index-test -code-completion-at=%s:9:11 %s | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: ObjCProtocolDecl:{TypedText Protocol1}
+// CHECK-CC1: ObjCProtocolDecl:{TypedText Protocol2}
+// RUN: c-index-test -code-completion-at=%s:9:21 %s | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2-NOT: ObjCProtocolDecl:{TypedText Protocol1}
+// CHECK-CC2: ObjCProtocolDecl:{TypedText Protocol2}
More information about the cfe-commits
mailing list