[cfe-commits] r82223 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h lib/Sema/CodeCompleteConsumer.cpp test/CodeCompletion/tag.c

Douglas Gregor dgregor at apple.com
Fri Sep 18 08:51:54 PDT 2009


Author: dgregor
Date: Fri Sep 18 10:51:54 2009
New Revision: 82223

URL: http://llvm.org/viewvc/llvm-project?rev=82223&view=rev
Log:
When gathering results for code completion, only include hidden
results when there is some way to refer to them in the language, such
as with a qualified name in C++.


Modified:
    cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
    cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
    cfe/trunk/test/CodeCompletion/tag.c

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=82223&r1=82222&r2=82223&view=diff

==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Fri Sep 18 10:51:54 2009
@@ -204,6 +204,14 @@
   bool IsClassOrStruct(NamedDecl *ND) const;
   bool IsUnion(NamedDecl *ND) const;
   //@}
+  
+  /// \name Utility functions
+  ///
+  //@{
+  
+  bool canHiddenResultBeFound(NamedDecl *Hidden, NamedDecl *Visible);
+  
+  //@}
 };
   
 /// \brief A simple code-completion consumer that prints the results it 

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

==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Fri Sep 18 10:51:54 2009
@@ -174,7 +174,15 @@
         continue;
       
       // The newly-added result is hidden by an entry in the shadow map.
-      R.Hidden = true;
+      if (Completer.canHiddenResultBeFound(R.Declaration, I->second.first)) {
+        // Note that this result was hidden.
+        R.Hidden = true;
+      } else {
+        // This result was hidden and cannot be found; don't bother adding
+        // it.
+        return;
+      }
+      
       break;
     }
   }
@@ -420,6 +428,35 @@
   };
 }
 
+/// \brief Determines whether the given hidden result could be found with
+/// some extra work, e.g., by qualifying the name.
+///
+/// \param Hidden the declaration that is hidden by the currenly \p Visible
+/// declaration.
+///
+/// \param Visible the declaration with the same name that is already visible.
+///
+/// \returns true if the hidden result can be found by some mechanism,
+/// false otherwise.
+bool CodeCompleteConsumer::canHiddenResultBeFound(NamedDecl *Hidden, 
+                                                  NamedDecl *Visible) {
+  // In C, there is no way to refer to a hidden name.
+  if (!getSema().getLangOptions().CPlusPlus)
+    return false;
+  
+  DeclContext *HiddenCtx = Hidden->getDeclContext()->getLookupContext();
+  
+  // There is no way to qualify a name declared in a function or method.
+  if (HiddenCtx->isFunctionOrMethod())
+    return false;
+
+  // If the hidden and visible declarations are in different name-lookup
+  // contexts, then we can qualify the name of the hidden declaration.
+  // FIXME: Optionally compute the string needed to refer to the hidden
+  // name.
+  return HiddenCtx != Visible->getDeclContext()->getLookupContext();
+}
+
 void 
 PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Result *Results, 
                                                          unsigned NumResults) {

Modified: cfe/trunk/test/CodeCompletion/tag.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/tag.c?rev=82223&r1=82222&r2=82223&view=diff

==============================================================================
--- cfe/trunk/test/CodeCompletion/tag.c (original)
+++ cfe/trunk/test/CodeCompletion/tag.c Fri Sep 18 10:51:54 2009
@@ -11,5 +11,4 @@
   enum X { x };
   // CHECK-CC1: X : 0
   // CHECK-CC1: Y : 2
-  // CHECK-CC1: X : 2 (Hidden)
   enum





More information about the cfe-commits mailing list