[cfe-commits] r112001 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h lib/Sema/SemaCodeComplete.cpp test/Index/complete-blocks.m test/Index/complete-exprs.c test/Index/preamble.c
Douglas Gregor
dgregor at apple.com
Tue Aug 24 16:58:17 PDT 2010
Author: dgregor
Date: Tue Aug 24 18:58:17 2010
New Revision: 112001
URL: http://llvm.org/viewvc/llvm-project?rev=112001&view=rev
Log:
Give a slight preference to functions returning "void" when we're
performing code completion at the statement level (rather than in an
arbitrary expression).
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-blocks.m
cfe/trunk/test/Index/complete-exprs.c
cfe/trunk/test/Index/preamble.c
Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=112001&r1=112000&r2=112001&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Tue Aug 24 18:58:17 2010
@@ -59,7 +59,12 @@
/// 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
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=112001&r1=112000&r2=112001&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Aug 24 18:58:17 2010
@@ -593,9 +593,12 @@
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 @@
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()))
Modified: cfe/trunk/test/Index/complete-blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-blocks.m?rev=112001&r1=112000&r2=112001&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-blocks.m (original)
+++ cfe/trunk/test/Index/complete-blocks.m Tue Aug 24 18:58:17 2010
@@ -17,8 +17,8 @@
[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)
Modified: cfe/trunk/test/Index/complete-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-exprs.c?rev=112001&r1=112000&r2=112001&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-exprs.c (original)
+++ cfe/trunk/test/Index/complete-exprs.c Tue Aug 24 18:58:17 2010
@@ -57,6 +57,6 @@
// 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)
Modified: cfe/trunk/test/Index/preamble.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble.c?rev=112001&r1=112000&r2=112001&view=diff
==============================================================================
--- cfe/trunk/test/Index/preamble.c (original)
+++ cfe/trunk/test/Index/preamble.c Tue Aug 24 18:58:17 2010
@@ -23,6 +23,6 @@
// 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)
More information about the cfe-commits
mailing list