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

Douglas Gregor dgregor at apple.com
Tue Sep 22 16:22:24 PDT 2009


Author: dgregor
Date: Tue Sep 22 18:22:24 2009
New Revision: 82587

URL: http://llvm.org/viewvc/llvm-project?rev=82587&view=rev
Log:
When code-completion finds a declaration only because it is usable as
the start of a nested-name-specifier, add the "::" after the
nested-name-specifier to the code-completion string.

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

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

==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Tue Sep 22 18:22:24 2009
@@ -173,6 +173,10 @@
     /// \brief Whether this result was found via lookup into a base class.
     bool QualifierIsInformative : 1;
     
+    /// \brief Whether this declaration is the beginning of a 
+    /// nested-name-specifier and, therefore, should be followed by '::'.
+    bool StartsNestedNameSpecifier : 1;
+    
     /// \brief If the result should have a nested-name-specifier, this is it.
     /// When \c QualifierIsInformative, the nested-name-specifier is 
     /// informative rather than required.
@@ -183,13 +187,14 @@
            NestedNameSpecifier *Qualifier = 0,
            bool QualifierIsInformative = false)
       : Kind(RK_Declaration), Declaration(Declaration), Rank(Rank), 
-        Hidden(false), QualifierIsInformative(QualifierIsInformative), 
-        Qualifier(Qualifier) { }
+        Hidden(false), QualifierIsInformative(QualifierIsInformative),
+        StartsNestedNameSpecifier(false), Qualifier(Qualifier) { }
     
     /// \brief Build a result that refers to a keyword or symbol.
     Result(const char *Keyword, unsigned Rank)
       : Kind(RK_Keyword), Keyword(Keyword), Rank(Rank), Hidden(false),
-        QualifierIsInformative(0), Qualifier(0) { }
+        QualifierIsInformative(0), StartsNestedNameSpecifier(false), 
+        Qualifier(0) { }
     
     /// \brief Retrieve the declaration stored in this result.
     NamedDecl *getDeclaration() const {

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Sep 22 18:22:24 2009
@@ -313,6 +313,11 @@
       R.QualifierIsInformative = false;
   }
   
+  // If the filter is for nested-name-specifiers, then this result starts a
+  // nested-name-specifier.
+  if (Filter == &ResultBuilder::IsNestedNameSpecifier)
+    R.StartsNestedNameSpecifier = true;
+  
   // Insert this result into the set of results and into the current shadow
   // map.
   SMap.insert(std::make_pair(R.Declaration->getDeclName(),
@@ -849,11 +854,13 @@
     return Result;
   }
   
-  if (Qualifier) {
+  if (Qualifier || StartsNestedNameSpecifier) {
     CodeCompletionString *Result = new CodeCompletionString;
     AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, 
                                    S.Context);
     Result->AddTextChunk(ND->getNameAsString().c_str());
+    if (StartsNestedNameSpecifier)
+      Result->AddTextChunk("::");
     return Result;
   }
   

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

==============================================================================
--- cfe/trunk/test/CodeCompletion/tag.cpp (original)
+++ cfe/trunk/test/CodeCompletion/tag.cpp Tue Sep 22 18:22:24 2009
@@ -21,6 +21,6 @@
     // CHECK-CC1: A : 4
     // CHECK-CC1: X : 4
     // CHECK-CC1: Y : 4
-    // CHECK-CC1: M : 9
-    // CHECK-CC1: N : 9
+    // CHECK-CC1: M : 9 : M::
+    // CHECK-CC1: N : 9 : N::
     // RUN: true





More information about the cfe-commits mailing list