[cfe-commits] r125991 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h lib/Frontend/ASTUnit.cpp lib/Sema/CodeCompleteConsumer.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-enums.c
Douglas Gregor
dgregor at apple.com
Fri Feb 18 15:30:37 PST 2011
Author: dgregor
Date: Fri Feb 18 17:30:37 2011
New Revision: 125991
URL: http://llvm.org/viewvc/llvm-project?rev=125991&view=rev
Log:
When code-completing a case statement for a switch on a value of
enumeration type, prioritize the enumeration constants and don't
provide completions for any other expressions. Fixes <rdar://problem/7283668>.
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-enums.c
Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=125991&r1=125990&r2=125991&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Fri Feb 18 17:30:37 2011
@@ -36,6 +36,9 @@
/// \brief Priority for the next initialization in a constructor initializer
/// list.
CCP_NextInitializer = 7,
+ /// \brief Priority for an enumeration constant inside a switch whose
+ /// condition is of the enumeration type.
+ CCP_EnumInCase = 7,
/// \brief Priority for a send-to-super completion.
CCP_SuperCompletion = 20,
/// \brief Priority for a declaration that is in the local scope.
@@ -153,6 +156,9 @@
enum Kind {
/// \brief An unspecified code-completion context.
CCC_Other,
+ /// \brief An unspecified code-completion context where we should also add
+ /// macro completions.
+ CCC_OtherWithMacros,
/// \brief Code completion occurred within a "top-level" completion context,
/// e.g., at namespace or global scope.
CCC_TopLevel,
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=125991&r1=125990&r2=125991&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Feb 18 17:30:37 2011
@@ -333,8 +333,8 @@
| (1 << (CodeCompletionContext::CCC_ObjCMessageReceiver - 1))
| (1 << (CodeCompletionContext::CCC_MacroNameUse - 1))
| (1 << (CodeCompletionContext::CCC_PreprocessorExpression - 1))
- | (1 << (CodeCompletionContext::CCC_ParenthesizedExpression - 1));
-
+ | (1 << (CodeCompletionContext::CCC_ParenthesizedExpression - 1))
+ | (1 << (CodeCompletionContext::CCC_OtherWithMacros - 1));
CachedResult.Priority = Results[I].Priority;
CachedResult.Kind = Results[I].CursorKind;
@@ -1790,6 +1790,7 @@
case CodeCompletionContext::CCC_SelectorName:
case CodeCompletionContext::CCC_TypeQualifiers:
case CodeCompletionContext::CCC_Other:
+ case CodeCompletionContext::CCC_OtherWithMacros:
// We're looking for nothing, or we're looking for names that cannot
// be hidden.
return;
Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=125991&r1=125990&r2=125991&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Fri Feb 18 17:30:37 2011
@@ -63,6 +63,7 @@
case CCC_SelectorName:
case CCC_TypeQualifiers:
case CCC_Other:
+ case CCC_OtherWithMacros:
return false;
}
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=125991&r1=125990&r2=125991&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Feb 18 17:30:37 2011
@@ -3331,15 +3331,16 @@
if (EnumeratorsSeen.count(*E))
continue;
- Results.AddResult(CodeCompletionResult(*E, Qualifier),
- CurContext, 0, false);
+ CodeCompletionResult R(*E, Qualifier);
+ R.Priority = CCP_EnumInCase;
+ Results.AddResult(R, CurContext, 0, false);
}
Results.ExitScope();
if (CodeCompleter->includeMacros())
AddMacroResults(PP, Results);
HandleCodeCompleteResults(this, CodeCompleter,
- CodeCompletionContext::CCC_Expression,
+ CodeCompletionContext::CCC_OtherWithMacros,
Results.data(),Results.size());
}
Modified: cfe/trunk/test/Index/complete-enums.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-enums.c?rev=125991&r1=125990&r2=125991&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-enums.c (original)
+++ cfe/trunk/test/Index/complete-enums.c Fri Feb 18 17:30:37 2011
@@ -1,15 +1,22 @@
// Note: the run lines follow their respective tests, since line/column
// matter in this test.
-enum {
- Red = 17,
- Green,
- Blue
+enum Color {
+ Color_Red = 17,
+ Color_Green,
+ Color_Blue
};
-
-void f() {
-
+int Greeby();
+void f(Color color) {
+ switch (color) {
+ case Red:
+ }
}
// RUN: c-index-test -code-completion-at=%s:11:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
-// CHECK-CC1: EnumConstantDecl:{ResultType enum <anonymous>}{TypedText Red}
+// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Red}
+
+// RUN: c-index-test -code-completion-at=%s:12:8 %s | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Blue} (7)
+// CHECK-CC2-NEXT: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Green} (7)
+// CHECK-CC2-NEXT: EnumConstantDecl:{ResultType enum Color}{TypedText Color_Red} (7)
More information about the cfe-commits
mailing list