summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/CodeCompleteConsumer.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-18 15:51:54 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-18 15:51:54 +0000
commit2da11086f31368e630ec24638ceab94f280df70b (patch)
treeeba06dad814c2780160de48f562d5990e31c630d /clang/lib/Sema/CodeCompleteConsumer.cpp
parentf45b0cf38910ede9cfae839ce00d6b39a880fed8 (diff)
downloadbcm5719-llvm-2da11086f31368e630ec24638ceab94f280df70b.tar.gz
bcm5719-llvm-2da11086f31368e630ec24638ceab94f280df70b.zip
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++. llvm-svn: 82223
Diffstat (limited to 'clang/lib/Sema/CodeCompleteConsumer.cpp')
-rw-r--r--clang/lib/Sema/CodeCompleteConsumer.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp
index 707ad9a1434..fb82a6c3313 100644
--- a/clang/lib/Sema/CodeCompleteConsumer.cpp
+++ b/clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -174,7 +174,15 @@ void CodeCompleteConsumer::ResultSet::MaybeAddResult(Result R) {
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 @@ namespace {
};
}
+/// \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) {
OpenPOWER on IntegriCloud