]> granicus.if.org Git - clang/commitdiff
Code completion after @property, providing the names of forward-declared properties
authorDouglas Gregor <dgregor@apple.com>
Wed, 18 Nov 2009 04:49:41 +0000 (04:49 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 18 Nov 2009 04:49:41 +0000 (04:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89196 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Action.h
lib/Parse/ParseObjc.cpp
lib/Sema/Sema.h
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-protocols.m

index ee852ff95cac21359810d2277db5db7df9cf7e22..a9b32133234a0c90bd7f889bf800edfa9825cc3c 100644 (file)
@@ -2365,6 +2365,12 @@ public:
   /// 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) { }
   //@}
 };
 
index dc173eaf4de7a17507fda06677a32a0ae7bab015..65bd79d6b4f2ebac8c82b46a21ea5e131315d556 100644 (file)
@@ -994,6 +994,11 @@ Parser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
          "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();
index 333cc00069ae98cc8f8ca5556fa3c7fc143393c5..e16bfaa57c8b700137eb9929d867e8b452a908ee 100644 (file)
@@ -4017,7 +4017,8 @@ public:
   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
index be1ddddd69953b51a3d02984a29faf2f54ac1c3f..9cecdadc867edb4d082108d751e98522049e34a0 100644 (file)
@@ -1830,6 +1830,7 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver) {
 /// \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 @@ static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
        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 @@ static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
              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 @@ void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
       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());
index f84b6248b8e6affe88364e0ba7c1301b49be492b..89f61bcf9ac9e4a2d73b82362c3316e143db7734 100644 (file)
@@ -8,9 +8,18 @@
 
 void f(id<Protocol1,Protocol2>);
 
+@protocol Protocol0;
+@protocol NewProtocol 
+{
+}
+@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}