[cfe-commits] r91133 - in /cfe/trunk: lib/Sema/SemaCodeComplete.cpp test/CodeCompletion/member-access.cpp test/Index/code-completion.cpp

Douglas Gregor dgregor at apple.com
Fri Dec 11 09:31:06 PST 2009


Author: dgregor
Date: Fri Dec 11 11:31:05 2009
New Revision: 91133

URL: http://llvm.org/viewvc/llvm-project?rev=91133&view=rev
Log:
Tweak code-completion results by suppressing class template
specializations and class template partial specializations (they're
never named directly). Also, member access expressions only refer to
value declarations (fields, functions, enumerators, etc.) and
Objective-C property declarations; filter out everything else.


Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/CodeCompletion/member-access.cpp
    cfe/trunk/test/Index/code-completion.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Dec 11 11:31:05 2009
@@ -364,11 +364,15 @@
       (IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend)))
     return;
 
-  // Class template (partial) specializations are never added as results
+  // Class template (partial) specializations are never added as results.
   if (isa<ClassTemplateSpecializationDecl>(CanonDecl) ||
       isa<ClassTemplatePartialSpecializationDecl>(CanonDecl))
     return;
   
+  // Using declarations themselves are never added as results.
+  if (isa<UsingDecl>(CanonDecl))
+    return;
+
   if (const IdentifierInfo *Id = R.Declaration->getIdentifier()) {
     // __va_list_tag is a freak of nature. Find it and skip it.
     if (Id->isStr("__va_list_tag") || Id->isStr("__builtin_va_list"))
@@ -571,18 +575,19 @@
   return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND);
 }
 
-/// \brief Brief determines whether the given declaration is a namespace or
-/// namespace alias.
+/// \brief Determines whether the given declaration is a type.
 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.
+/// \brief Determines which members of a class should be visible via
+/// "." or "->".  Only value declarations, nested name specifiers, and
+/// using declarations thereof should show up.
 bool ResultBuilder::IsMember(NamedDecl *ND) const {
-  return true;
+  if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND))
+    ND = Using->getTargetDecl();
+
+  return isa<ValueDecl>(ND) || isa<ObjCPropertyDecl>(ND);
 }
 
 // Find the next outer declaration context corresponding to this scope.
@@ -1479,6 +1484,8 @@
 
       // We could have the start of a nested-name-specifier. Add those
       // results as well.
+      // FIXME: We should really walk base classes to produce
+      // nested-name-specifiers so that we produce more-precise results.
       Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
       CollectLookupResults(S, Context.getTranslationUnitDecl(), NextRank,
                            CurContext, Results);

Modified: cfe/trunk/test/CodeCompletion/member-access.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/member-access.cpp?rev=91133&r1=91132&r2=91133&view=diff

==============================================================================
--- cfe/trunk/test/CodeCompletion/member-access.cpp (original)
+++ cfe/trunk/test/CodeCompletion/member-access.cpp Fri Dec 11 11:31:05 2009
@@ -37,6 +37,6 @@
   // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#double#>)
   // CHECK-CC1: memfun2 : 0 : [#Base3::#]memfun2(<#int#>)
   // CHECK-CC1: memfun3 : 0 : memfun3(<#int#>)
-  // CHECK-CC1: Base1 : 0 : Base1::
   // CHECK-CC1: memfun1 : 0 (Hidden) : Base2::memfun1(<#int#>)
+  // CHECK-CC1: Base1 : 3 : Base1::
   

Modified: cfe/trunk/test/Index/code-completion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/code-completion.cpp?rev=91133&r1=91132&r2=91133&view=diff

==============================================================================
--- cfe/trunk/test/Index/code-completion.cpp (original)
+++ cfe/trunk/test/Index/code-completion.cpp Fri Dec 11 11:31:05 2009
@@ -33,20 +33,19 @@
   overloaded(Z(), 0);
 }
 
-// CHECK-MEMBER: EnumDecl:{Informative X::}{TypedText E}
 // CHECK-MEMBER: FieldDecl:{TypedText member}
 // CHECK-MEMBER: FunctionDecl:{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )}
 // CHECK-MEMBER: EnumConstantDecl:{Informative E::}{TypedText Val1}
 // CHECK-MEMBER: FunctionDecl:{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )}
 // CHECK-MEMBER: FunctionDecl:{TypedText operator int}{LeftParen (}{RightParen )}
 // CHECK-MEMBER: FunctionDecl:{TypedText operator=}{LeftParen (}{Placeholder struct Z const &}{RightParen )}
-// CHECK-MEMBER: StructDecl:{TypedText X}{Text ::}
-// CHECK-MEMBER: StructDecl:{TypedText Y}{Text ::}
-// CHECK-MEMBER: StructDecl:{TypedText Z}{Text ::}
 // CHECK-MEMBER: FieldDecl:{Text X::}{TypedText member}
 // CHECK-MEMBER: FieldDecl:{Text Y::}{TypedText member}
 // CHECK-MEMBER: FunctionDecl:{Text X::}{TypedText operator=}{LeftParen (}{Placeholder struct X const &}{RightParen )}
 // CHECK-MEMBER: FunctionDecl:{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder struct Y const &}{RightParen )}
+// CHECK-MEMBER: StructDecl:{TypedText X}{Text ::}
+// CHECK-MEMBER: StructDecl:{TypedText Y}{Text ::}
+// CHECK-MEMBER: StructDecl:{TypedText Z}{Text ::}
 
 // CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text struct Z z}{Comma , }{CurrentParameter int second}{RightParen )}
 // CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text int i}{Comma , }{CurrentParameter long second}{RightParen )}





More information about the cfe-commits mailing list