]> granicus.if.org Git - clang/commitdiff
For code completion, note that injected-class-names found as part of
authorDouglas Gregor <dgregor@apple.com>
Wed, 23 Sep 2009 22:26:46 +0000 (22:26 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 23 Sep 2009 22:26:46 +0000 (22:26 +0000)
lookup in a member access expression always start a
nested-name-specifier. Additionally, rank names that start
nested-name-specifiers after other names.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82663 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/member-access.cpp

index f879dae6961bf0c5444d0a2445626e96faed4977..4c46696d1df001884112b37635506a1e5683230b 100644 (file)
@@ -112,6 +112,7 @@ namespace {
     bool IsNamespace(NamedDecl *ND) const;
     bool IsNamespaceOrAlias(NamedDecl *ND) const;
     bool IsType(NamedDecl *ND) const;
+    bool IsMember(NamedDecl *ND) const;
     //@}    
   };  
 }
@@ -303,8 +304,17 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) {
   if (!AllDeclsFound.insert(CanonDecl))
     return;
   
+  // If the filter is for nested-name-specifiers, then this result starts a
+  // nested-name-specifier.
+  if ((Filter == &ResultBuilder::IsNestedNameSpecifier) ||
+      (Filter == &ResultBuilder::IsMember &&
+       isa<CXXRecordDecl>(R.Declaration) &&
+       cast<CXXRecordDecl>(R.Declaration)->isInjectedClassName()))
+    R.StartsNestedNameSpecifier = true;
+  
   // If this result is supposed to have an informative qualifier, add one.
-  if (R.QualifierIsInformative && !R.Qualifier) {
+  if (R.QualifierIsInformative && !R.Qualifier &&
+      !R.StartsNestedNameSpecifier) {
     DeclContext *Ctx = R.Declaration->getDeclContext();
     if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
       R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace);
@@ -314,12 +324,7 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) {
     else
       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(),
@@ -404,6 +409,14 @@ bool ResultBuilder::IsType(NamedDecl *ND) const {
   return isa<TypeDecl>(ND);
 }
 
+/// \brief Since every declaration found within a class is a member that we
+/// care about, always returns true. This predicate exists mostly to 
+/// communicate to the result builder that we are performing a lookup for
+/// member access.
+bool ResultBuilder::IsMember(NamedDecl *ND) const {
+  return true;
+}
+
 // Find the next outer declaration context corresponding to this scope.
 static DeclContext *findOuterContext(Scope *S) {
   for (S = S->getParent(); S; S = S->getParent())
@@ -952,6 +965,10 @@ namespace {
       if (X.Hidden != Y.Hidden)
         return !X.Hidden;
       
+      // Non-nested-name-specifiers precede nested-name-specifiers.
+      if (X.StartsNestedNameSpecifier != Y.StartsNestedNameSpecifier)
+        return !X.StartsNestedNameSpecifier;
+      
       // Ordering depends on the kind of result.
       switch (X.Kind) {
         case Result::RK_Declaration:
@@ -1005,7 +1022,7 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *BaseE,
       return;
   }
   
-  ResultBuilder Results(*this);
+  ResultBuilder Results(*this, &ResultBuilder::IsMember);
   unsigned NextRank = 0;
   
   if (const RecordType *Record = BaseType->getAs<RecordType>()) {
index b23436d8c8e4ce1610fbfff37e36a6c0cac0a5bb..b0c1cf675bbdce5cc23a2ec94344cd6c01b809cc 100644 (file)
@@ -37,6 +37,7 @@ void test(const Proxy &p) {
   // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#double#>)
   // CHECK-CC1: memfun2 : 0 : [#Base3::#]memfun2(<#int#>)
   // CHECK-CC1: memfun3 : 0 : memfun3(<#int#>)
+  // CHECK-CC1-NEXT: Base1 : 0 : Base1::
   // CHECK-CC1: memfun1 : 0 (Hidden) : Base2::memfun1(<#int#>)
   // RUN: true