[cfe-commits] r89196 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaCodeComplete.cpp test/Index/complete-protocols.m

Douglas Gregor dgregor at apple.com
Tue Nov 17 20:49:41 PST 2009


Author: dgregor
Date: Tue Nov 17 22:49:41 2009
New Revision: 89196

URL: http://llvm.org/viewvc/llvm-project?rev=89196&view=rev
Log:
Code completion after @property, providing the names of forward-declared properties

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-protocols.m

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=89196&r1=89195&r2=89196&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Nov 17 22:49:41 2009
@@ -2365,6 +2365,12 @@
   /// parsed.
   virtual void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
                                                   unsigned NumProtocols) { }
+
+  /// \brief Code completion for a protocol declaration or definition, after
+  /// the @protocol but before any identifier.
+  ///
+  /// \param S the scope in which the protocol declaration occurs.
+  virtual void CodeCompleteObjCProtocolDecl(Scope *S) { }
   //@}
 };
 

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=89196&r1=89195&r2=89196&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Nov 17 22:49:41 2009
@@ -994,6 +994,11 @@
          "ParseObjCAtProtocolDeclaration(): Expected @protocol");
   ConsumeToken(); // the "protocol" identifier
 
+  if (Tok.is(tok::code_completion)) {
+    Actions.CodeCompleteObjCProtocolDecl(CurScope);
+    ConsumeToken();
+  }
+
   if (Tok.isNot(tok::identifier)) {
     Diag(Tok, diag::err_expected_ident); // missing protocol name.
     return DeclPtrTy();

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=89196&r1=89195&r2=89196&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Nov 17 22:49:41 2009
@@ -4017,7 +4017,8 @@
   virtual void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver);
   virtual void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
                                                   unsigned NumProtocols);
-  //@}
+  virtual void CodeCompleteObjCProtocolDecl(Scope *S);
+ //@}
   
   //===--------------------------------------------------------------------===//
   // Extra semantic analysis beyond the C type system

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=89196&r1=89195&r2=89196&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Nov 17 22:49:41 2009
@@ -1830,6 +1830,7 @@
 /// \brief Add all of the protocol declarations that we find in the given
 /// (translation unit) context.
 static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
+                               bool OnlyForwardDeclarations,
                                ResultBuilder &Results) {
   typedef CodeCompleteConsumer::Result Result;
   
@@ -1838,7 +1839,8 @@
        D != DEnd; ++D) {
     // Record any protocols we find.
     if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(*D))
-      Results.MaybeAddResult(Result(Proto, 0), CurContext);
+      if (!OnlyForwardDeclarations || Proto->isForwardDecl())
+        Results.MaybeAddResult(Result(Proto, 0), CurContext);
 
     // Record any forward-declared protocols we find.
     if (ObjCForwardProtocolDecl *Forward
@@ -1847,7 +1849,8 @@
              P = Forward->protocol_begin(),
              PEnd = Forward->protocol_end();
            P != PEnd; ++P)
-        Results.MaybeAddResult(Result(*P, 0), CurContext);
+        if (!OnlyForwardDeclarations || (*P)->isForwardDecl())
+          Results.MaybeAddResult(Result(*P, 0), CurContext);
     }
   }
 }
@@ -1864,7 +1867,20 @@
       Results.Ignore(Protocol);
 
   // Add all protocols.
-  AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, Results);
+  AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, false,
+                     Results);
+
+  Results.ExitScope();
+  HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
+}
+
+void Sema::CodeCompleteObjCProtocolDecl(Scope *) {
+  ResultBuilder Results(*this);
+  Results.EnterNewScope();
+  
+  // Add all protocols.
+  AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true,
+                     Results);
 
   Results.ExitScope();
   HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());

Modified: cfe/trunk/test/Index/complete-protocols.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-protocols.m?rev=89196&r1=89195&r2=89196&view=diff

==============================================================================
--- cfe/trunk/test/Index/complete-protocols.m (original)
+++ cfe/trunk/test/Index/complete-protocols.m Tue Nov 17 22:49:41 2009
@@ -8,9 +8,18 @@
 
 void f(id<Protocol1,Protocol2>);
 
+ at protocol Protocol0;
+ at protocol NewProtocol 
+{
+}
+ at end
+
 // 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}
+// RUN: c-index-test -code-completion-at=%s:12:11 %s | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: ObjCProtocolDecl:{TypedText Protocol0}
+// CHECK-CC3-NEXT: ObjCProtocolDecl:{TypedText Protocol2}





More information about the cfe-commits mailing list