r349050 - [CodeComplete] Set preferred type to bool on conditions
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 13 07:36:32 PST 2018
Author: ibiryukov
Date: Thu Dec 13 07:36:32 2018
New Revision: 349050
URL: http://llvm.org/viewvc/llvm-project?rev=349050&view=rev
Log:
[CodeComplete] Set preferred type to bool on conditions
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D55431
Added:
cfe/trunk/test/CodeCompletion/preferred-type.cpp
Modified:
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=349050&r1=349049&r2=349050&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Thu Dec 13 07:36:32 2018
@@ -539,9 +539,12 @@ void PrintingCodeCompleteConsumer::Proce
unsigned NumResults) {
std::stable_sort(Results, Results + NumResults);
- StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter();
+ if (!Context.getPreferredType().isNull())
+ OS << "PREFERRED-TYPE: " << Context.getPreferredType().getAsString()
+ << "\n";
- // Print the results.
+ StringRef Filter = SemaRef.getPreprocessor().getCodeCompletionFilter();
+ // Print the completions.
for (unsigned I = 0; I != NumResults; ++I) {
if (!Filter.empty() && isResultFilteredOut(Filter, Results[I]))
continue;
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=349050&r1=349049&r2=349050&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Dec 13 07:36:32 2018
@@ -3521,7 +3521,7 @@ static void HandleCodeCompleteResults(Se
CodeCompleter->ProcessCodeCompleteResults(*S, Context, Results, NumResults);
}
-static enum CodeCompletionContext::Kind
+static CodeCompletionContext
mapCodeCompletionContext(Sema &S, Sema::ParserCompletionContext PCC) {
switch (PCC) {
case Sema::PCC_Namespace:
@@ -3558,8 +3558,10 @@ mapCodeCompletionContext(Sema &S, Sema::
return CodeCompletionContext::CCC_Expression;
case Sema::PCC_Expression:
- case Sema::PCC_Condition:
return CodeCompletionContext::CCC_Expression;
+ case Sema::PCC_Condition:
+ return CodeCompletionContext(CodeCompletionContext::CCC_Expression,
+ S.getASTContext().BoolTy);
case Sema::PCC_Statement:
return CodeCompletionContext::CCC_Statement;
Added: cfe/trunk/test/CodeCompletion/preferred-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/preferred-type.cpp?rev=349050&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/preferred-type.cpp (added)
+++ cfe/trunk/test/CodeCompletion/preferred-type.cpp Thu Dec 13 07:36:32 2018
@@ -0,0 +1,15 @@
+void test(bool x) {
+ if (x) {}
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:2:7 %s | FileCheck %s
+ // CHECK: PREFERRED-TYPE: _Bool
+
+ while (x) {}
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:6:10 %s | FileCheck %s
+
+ for (; x;) {}
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:9:10 %s | FileCheck %s
+
+ // FIXME(ibiryukov): the condition in do-while is parsed as expression, so we
+ // fail to detect it should be converted to bool.
+ // do {} while (x);
+}
More information about the cfe-commits
mailing list