[llvm-branch-commits] [cfe-branch] r121569 - in /cfe/branches/Apple/whitney: lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaLookup.cpp test/Index/complete-protocols.m

Daniel Dunbar daniel at zuster.org
Fri Dec 10 13:38:33 PST 2010


Author: ddunbar
Date: Fri Dec 10 15:38:33 2010
New Revision: 121569

URL: http://llvm.org/viewvc/llvm-project?rev=121569&view=rev
Log:
Merge r121416:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Thu Dec 9 21:44:02 2010 +0000

    Don't walk the translation unit context to produce protocol names when
    global code completions are disabled (e.g., because they are
    cached). Also, make sure that forward-declared protocols are visited
    when we look for all visible names within a declaration context.

    Previously, we would end up with duplicate completions for protocols.

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
    cfe/branches/Apple/whitney/lib/Sema/SemaLookup.cpp
    cfe/branches/Apple/whitney/test/Index/complete-protocols.m

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp?rev=121569&r1=121568&r2=121569&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp Fri Dec 10 15:38:33 2010
@@ -4949,20 +4949,25 @@
 void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
                                               unsigned NumProtocols) {
   ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCProtocolName);
-  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,
-                                                    Protocols[I].second))
-      Results.Ignore(Protocol);
-
-  // Add all protocols.
-  AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, false,
-                     Results);
+  if (CodeCompleter && CodeCompleter->includeGlobals()) {
+    Results.EnterNewScope();
+    
+    // Tell the result set to ignore all of the protocols we have
+    // already seen.
+    // FIXME: This doesn't work when caching code-completion results.
+    for (unsigned I = 0; I != NumProtocols; ++I)
+      if (ObjCProtocolDecl *Protocol = LookupProtocol(Protocols[I].first,
+                                                      Protocols[I].second))
+        Results.Ignore(Protocol);
+
+    // Add all protocols.
+    AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, false,
+                       Results);
 
-  Results.ExitScope();
+    Results.ExitScope();
+  }
+  
   HandleCodeCompleteResults(this, CodeCompleter, 
                             CodeCompletionContext::CCC_ObjCProtocolName,
                             Results.data(),Results.size());
@@ -4970,13 +4975,17 @@
 
 void Sema::CodeCompleteObjCProtocolDecl(Scope *) {
   ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCProtocolName);
-  Results.EnterNewScope();
   
-  // Add all protocols.
-  AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true,
-                     Results);
+  if (CodeCompleter && CodeCompleter->includeGlobals()) {
+    Results.EnterNewScope();
+    
+    // Add all protocols.
+    AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true,
+                       Results);
 
-  Results.ExitScope();
+    Results.ExitScope();
+  }
+  
   HandleCodeCompleteResults(this, CodeCompleter, 
                             CodeCompletionContext::CCC_ObjCProtocolName,
                             Results.data(),Results.size());

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaLookup.cpp?rev=121569&r1=121568&r2=121569&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaLookup.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaLookup.cpp Fri Dec 10 15:38:33 2010
@@ -2465,12 +2465,24 @@
     for (DeclContext::decl_iterator D = CurCtx->decls_begin(), 
                                  DEnd = CurCtx->decls_end();
          D != DEnd; ++D) {
-      if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
+      if (NamedDecl *ND = dyn_cast<NamedDecl>(*D)) {
         if (Result.isAcceptableDecl(ND)) {
           Consumer.FoundDecl(ND, Visited.checkHidden(ND), InBaseClass);
           Visited.add(ND);
         }
-
+      } else if (ObjCForwardProtocolDecl *ForwardProto
+                                      = dyn_cast<ObjCForwardProtocolDecl>(*D)) {
+        for (ObjCForwardProtocolDecl::protocol_iterator
+                  P = ForwardProto->protocol_begin(),
+               PEnd = ForwardProto->protocol_end();
+             P != PEnd;
+             ++P) {
+          if (Result.isAcceptableDecl(*P)) {
+            Consumer.FoundDecl(*P, Visited.checkHidden(*P), InBaseClass);
+            Visited.add(*P);
+          }
+        }
+      }
       // Visit transparent contexts and inline namespaces inside this context.
       if (DeclContext *InnerCtx = dyn_cast<DeclContext>(*D)) {
         if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())

Modified: cfe/branches/Apple/whitney/test/Index/complete-protocols.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/complete-protocols.m?rev=121569&r1=121568&r2=121569&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/complete-protocols.m (original)
+++ cfe/branches/Apple/whitney/test/Index/complete-protocols.m Fri Dec 10 15:38:33 2010
@@ -16,10 +16,12 @@
 
 // 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}
+// CHECK-CC1-NEXT: 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}
+
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:9:11 %s | FileCheck -check-prefix=CHECK-CC1 %s





More information about the llvm-branch-commits mailing list