summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCodeComplete.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-07-28 21:50:18 +0000
committerDouglas Gregor <dgregor@apple.com>2010-07-28 21:50:18 +0000
commit85b5063f2ca7941861a30eeb8fafaea325cad7b0 (patch)
treee66ba9abd2dd2951fcb441ec860f401efe8e3cda /clang/lib/Sema/SemaCodeComplete.cpp
parent04f5c31e98108b5ab4dd5f5df98072191bdc2b00 (diff)
downloadbcm5719-llvm-85b5063f2ca7941861a30eeb8fafaea325cad7b0.tar.gz
bcm5719-llvm-85b5063f2ca7941861a30eeb8fafaea325cad7b0.zip
When performing code completion for a case statement in a switch whose
condition is not of enumeration type, provide code-completion results containing all values of integral or enumeral type. llvm-svn: 109677
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 55288750fd5..bc0335556f9 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -227,6 +227,7 @@ namespace {
//@{
bool IsOrdinaryName(NamedDecl *ND) const;
bool IsOrdinaryNonTypeName(NamedDecl *ND) const;
+ bool IsIntegralConstantValue(NamedDecl *ND) const;
bool IsOrdinaryNonValueName(NamedDecl *ND) const;
bool IsNestedNameSpecifier(NamedDecl *ND) const;
bool IsEnum(NamedDecl *ND) const;
@@ -821,6 +822,17 @@ bool ResultBuilder::IsOrdinaryNonTypeName(NamedDecl *ND) const {
return ND->getIdentifierNamespace() & IDNS;
}
+bool ResultBuilder::IsIntegralConstantValue(NamedDecl *ND) const {
+ if (!IsOrdinaryNonTypeName(ND))
+ return 0;
+
+ if (ValueDecl *VD = dyn_cast<ValueDecl>(ND->getUnderlyingDecl()))
+ if (VD->getType()->isIntegralOrEnumerationType())
+ return true;
+
+ return false;
+}
+
/// \brief Determines whether this given declaration will be found by
/// ordinary name lookup.
bool ResultBuilder::IsOrdinaryNonValueName(NamedDecl *ND) const {
@@ -2271,11 +2283,17 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,
/// \brief Perform code-completion in an expression context when we know what
/// type we're looking for.
-void Sema::CodeCompleteExpression(Scope *S, QualType T) {
+///
+/// \param IntegralConstantExpression Only permit integral constant
+/// expressions.
+void Sema::CodeCompleteExpression(Scope *S, QualType T,
+ bool IntegralConstantExpression) {
typedef CodeCompleteConsumer::Result Result;
ResultBuilder Results(*this);
- if (WantTypesInContext(CCC_Expression, getLangOptions()))
+ if (IntegralConstantExpression)
+ Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
+ else if (WantTypesInContext(CCC_Expression, getLangOptions()))
Results.setFilter(&ResultBuilder::IsOrdinaryName);
else
Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
@@ -2476,8 +2494,10 @@ void Sema::CodeCompleteCase(Scope *S) {
return;
SwitchStmt *Switch = getSwitchStack().back();
- if (!Switch->getCond()->getType()->isEnumeralType())
+ if (!Switch->getCond()->getType()->isEnumeralType()) {
+ CodeCompleteExpression(S, Switch->getCond()->getType(), true);
return;
+ }
// Code-complete the cases of a switch statement over an enumeration type
// by providing the list of
OpenPOWER on IntegriCloud