зеркало из https://github.com/microsoft/clang-1.git
Give a slight preference to functions returning "void" when we're
performing code completion at the statement level (rather than in an arbitrary expression). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112001 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
124300e428
Коммит
eb0d014591
|
@ -59,7 +59,12 @@ enum {
|
|||
/// based on the context of the result.
|
||||
enum {
|
||||
/// \brief The result is in a base class.
|
||||
CCD_InBaseClass = 2
|
||||
CCD_InBaseClass = 2,
|
||||
/// \brief The result is a type match against void.
|
||||
///
|
||||
/// Since everything converts to "void", we don't give as drastic an
|
||||
/// adjustment for matching void.
|
||||
CCD_VoidMatch = -5
|
||||
};
|
||||
|
||||
/// \brief Priority value factors by which we will divide or multiply the
|
||||
|
|
|
@ -593,9 +593,12 @@ void ResultBuilder::AdjustResultPriorityForPreferredType(Result &R) {
|
|||
|
||||
CanQualType TC = SemaRef.Context.getCanonicalType(T);
|
||||
// Check for exactly-matching types (modulo qualifiers).
|
||||
if (SemaRef.Context.hasSameUnqualifiedType(PreferredType, TC))
|
||||
R.Priority /= CCF_ExactTypeMatch;
|
||||
// Check for nearly-matching types, based on classification of each.
|
||||
if (SemaRef.Context.hasSameUnqualifiedType(PreferredType, TC)) {
|
||||
if (PreferredType->isVoidType())
|
||||
R.Priority += CCD_VoidMatch;
|
||||
else
|
||||
R.Priority /= CCF_ExactTypeMatch;
|
||||
} // Check for nearly-matching types, based on classification of each.
|
||||
else if ((getSimplifiedTypeClass(PreferredType)
|
||||
== getSimplifiedTypeClass(TC)) &&
|
||||
!(PreferredType->isEnumeralType() && TC->isEnumeralType()))
|
||||
|
@ -2400,8 +2403,14 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,
|
|||
Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
|
||||
break;
|
||||
|
||||
case PCC_Expression:
|
||||
case PCC_Statement:
|
||||
// For statements that are expressions, we prefer to call 'void' functions
|
||||
// rather than functions that return a result, since then the result would
|
||||
// be ignored.
|
||||
Results.setPreferredType(Context.VoidTy);
|
||||
// Fall through
|
||||
|
||||
case PCC_Expression:
|
||||
case PCC_ForInit:
|
||||
case PCC_Condition:
|
||||
if (WantTypesInContext(CompletionContext, getLangOptions()))
|
||||
|
|
|
@ -17,8 +17,8 @@ void test_A(A *a) {
|
|||
[a method:0];
|
||||
}
|
||||
// RUN: c-index-test -code-completion-at=%s:8:1 %s | FileCheck -check-prefix=CHECK-CC1 %s
|
||||
// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder int (^)(int x, int y)}{RightParen )} (50)
|
||||
// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText g}{LeftParen (}{Placeholder void (^)(float f, double d)}{RightParen )} (50)
|
||||
// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder int (^)(int x, int y)}{RightParen )} (45)
|
||||
// CHECK-CC1: FunctionDecl:{ResultType void}{TypedText g}{LeftParen (}{Placeholder void (^)(float f, double d)}{RightParen )} (45)
|
||||
// RUN: c-index-test -code-completion-at=%s:17:6 %s | FileCheck -check-prefix=CHECK-CC2 %s
|
||||
// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method2:}{Placeholder void (^)(float f, double d)} (20)
|
||||
// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType id}{TypedText method:}{Placeholder int (^)(int x, int y)} (20)
|
||||
|
|
|
@ -57,6 +57,6 @@ void f4(const char* str) {
|
|||
// CHECK-CC5: NotImplemented:{TypedText volatile} (65)
|
||||
|
||||
// RUN: c-index-test -code-completion-at=%s:19:3 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s
|
||||
// CHECK-CC6: FunctionDecl:{ResultType void}{TypedText f3}{LeftParen (}{Placeholder char const *}{Placeholder , ...}{Text , NULL}{RightParen )} (50)
|
||||
// CHECK-CC6: FunctionDecl:{ResultType void}{TypedText f3}{LeftParen (}{Placeholder char const *}{Placeholder , ...}{Text , NULL}{RightParen )} (45)
|
||||
// CHECK-CC6: NotImplemented:{TypedText void} (65)
|
||||
// CHECK-CC6: NotImplemented:{TypedText volatile} (65)
|
||||
|
|
|
@ -23,6 +23,6 @@ void f(int x) {
|
|||
// CHECK-DIAG: preamble.h:4:7:{4:9-4:13}: warning: incompatible pointer types assigning to 'int *' from 'float *'
|
||||
// RUN: env CINDEXTEST_EDITING=1 c-index-test -code-completion-at=%s:6:1 -I %S/Inputs -include %t %s 2> %t.stderr.txt | FileCheck -check-prefix CHECK-CC %s
|
||||
// CHECK-CC: FunctionDecl:{ResultType int}{TypedText bar}{LeftParen (}{Placeholder int i}{RightParen )} (50)
|
||||
// CHECK-CC: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder int x}{RightParen )} (50)
|
||||
// CHECK-CC: FunctionDecl:{ResultType void}{TypedText f}{LeftParen (}{Placeholder int x}{RightParen )} (45)
|
||||
// CHECK-CC: FunctionDecl:{ResultType int}{TypedText foo}{LeftParen (}{Placeholder int}{RightParen )} (50)
|
||||
// CHECK-CC: FunctionDecl:{ResultType int}{TypedText wibble}{LeftParen (}{Placeholder int}{RightParen )} (50)
|
||||
|
|
Загрузка…
Ссылка в новой задаче