aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/CodeCompleteConsumer.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-18 17:42:29 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-18 17:42:29 +0000
commit33224e61bfca370850abae89bbd415a4dabe07fa (patch)
tree2ecd0a1991f2e7494615d765d8f8e625fa7d8a7d /lib/Sema/CodeCompleteConsumer.cpp
parent9436ed50b0923368d5ae7a97f1b67c56b6837430 (diff)
For code completion in C++ member access expressions and tag names,
look into the current scope for anything that could start a nested-names-specifier. These results are ranked worse than any of the results actually found in the lexical scope. Perform a little more pruning of the result set, eliminating constructors, __va_list_tag, and any duplication of declarations in the result set. For the latter, implemented NamespaceDecl::getCanonicalDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82231 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/CodeCompleteConsumer.cpp')
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index fb82a6c331..7dee12a3dc 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -53,8 +53,10 @@ CodeCompleteConsumer::CodeCompleteMemberReferenceExpr(Scope *S,
// The "template" keyword can follow "->" or "." in the grammar.
Results.MaybeAddResult(Result("template", NextRank++));
- // FIXME: For C++, we also need to look into the current scope, since
- // we could have the start of a nested-name-specifier.
+ // We could have the start of a nested-name-specifier. Add those
+ // results as well.
+ Results.setFilter(&CodeCompleteConsumer::IsNestedNameSpecifier);
+ CollectLookupResults(S, NextRank, Results);
}
// Hand off the results found for code completion.
@@ -83,10 +85,14 @@ void CodeCompleteConsumer::CodeCompleteTag(Scope *S, ElaboratedType::TagKind TK)
}
ResultSet Results(*this, Filter);
- CollectLookupResults(S, 0, Results);
+ unsigned NextRank = CollectLookupResults(S, 0, Results);
- // FIXME: In C++, we could have the start of a nested-name-specifier.
- // Add those results (with a poorer rank, naturally).
+ if (getSema().getLangOptions().CPlusPlus) {
+ // We could have the start of a nested-name-specifier. Add those
+ // results as well.
+ Results.setFilter(&CodeCompleteConsumer::IsNestedNameSpecifier);
+ CollectLookupResults(S, NextRank, Results);
+ }
ProcessCodeCompleteResults(Results.data(), Results.size());
}
@@ -121,10 +127,6 @@ void CodeCompleteConsumer::ResultSet::MaybeAddResult(Result R) {
// FIXME: Using declarations
// FIXME: Separate overload sets
- // Filter out any unwanted results.
- if (Filter && !(Completer.*Filter)(R.Declaration))
- return;
-
Decl *CanonDecl = R.Declaration->getCanonicalDecl();
unsigned IDNS = CanonDecl->getIdentifierNamespace();
@@ -134,6 +136,23 @@ void CodeCompleteConsumer::ResultSet::MaybeAddResult(Result R) {
(IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend)))
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"))
+ return;
+
+ // FIXME: Should we filter out other names in the implementation's
+ // namespace, e.g., those containing a __ or that start with _[A-Z]?
+ }
+
+ // C++ constructors are never found by name lookup.
+ if (isa<CXXConstructorDecl>(CanonDecl))
+ return;
+
+ // Filter out any unwanted results.
+ if (Filter && !(Completer.*Filter)(R.Declaration))
+ return;
+
ShadowMap &SMap = ShadowMaps.back();
ShadowMap::iterator I, IEnd;
for (llvm::tie(I, IEnd) = SMap.equal_range(R.Declaration->getDeclName());
@@ -187,6 +206,10 @@ void CodeCompleteConsumer::ResultSet::MaybeAddResult(Result R) {
}
}
+ // Make sure that any given declaration only shows up in the result set once.
+ if (!AllDeclsFound.insert(CanonDecl))
+ return;
+
// Insert this result into the set of results and into the current shadow
// map.
SMap.insert(std::make_pair(R.Declaration->getDeclName(),