Teach code completion to adjust its completion priorities based on the
type that we expect to see at a given point in the grammar, e.g., when
initializing a variable, returning a result, or calling a function. We
don't prune the candidate set at all, just adjust priorities to favor
things that should type-check, using an ultra-simplified type system.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105128 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Index/complete-type-factors.m b/test/Index/complete-type-factors.m
new file mode 100644
index 0000000..3f56b38
--- /dev/null
+++ b/test/Index/complete-type-factors.m
@@ -0,0 +1,117 @@
+/* Run lines are at the end, since line/column matter in this test. */
+
+enum Color {
+ Red, Green, Blue
+};
+
+enum Priority {
+ Low,
+ High
+};
+
+int func1(enum Color);
+enum Priority func2(int);
+void func3(float);
+enum Priority test1(enum Priority priority, enum Color color, int integer) {
+ int i = integer;
+ enum Color c = color;
+ return priority;
+ func1(c);
+ void (^block)(enum Color, int);
+ block(c, 17);
+ c = color;
+}
+
+// FIXME: It would be great for message sends to have the same
+// benefits as function calls, but we don't quite have the
+// infrastructure yet.
+
+// RUN: c-index-test -code-completion-at=%s:16:11 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (30)
+// CHECK-CC1: ParmDecl:{ResultType enum Color}{TypedText color} (4)
+// CHECK-CC1: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (12)
+// CHECK-CC1: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (25)
+// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (30)
+// CHECK-CC1: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (30)
+// CHECK-CC1: VarDecl:{ResultType int}{TypedText i} (2)
+// CHECK-CC1: ParmDecl:{ResultType int}{TypedText integer} (2)
+// CHECK-CC1: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (30)
+// CHECK-CC1: macro definition:{TypedText OBJC_NEW_PROPERTIES} (70)
+// CHECK-CC1: macro definition:{TypedText OBJC_ZEROCOST_EXCEPTIONS} (70)
+// CHECK-CC1: ParmDecl:{ResultType enum Priority}{TypedText priority} (4)
+// CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (30)
+// CHECK-CC1: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)
+// CHECK-CC1: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (25)
+// RUN: c-index-test -code-completion-at=%s:17:18 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (15)
+// CHECK-CC2: VarDecl:{ResultType enum Color}{TypedText c} (2)
+// CHECK-CC2: ParmDecl:{ResultType enum Color}{TypedText color} (2)
+// CHECK-CC2: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25)
+// CHECK-CC2: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50)
+// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (15)
+// CHECK-CC2: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (60)
+// CHECK-CC2: VarDecl:{ResultType int}{TypedText i} (4)
+// CHECK-CC2: ParmDecl:{ResultType int}{TypedText integer} (4)
+// CHECK-CC2: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (60)
+// CHECK-CC2: macro definition:{TypedText OBJC_NEW_PROPERTIES} (70)
+// CHECK-CC2: macro definition:{TypedText OBJC_ZEROCOST_EXCEPTIONS} (70)
+// CHECK-CC2: ParmDecl:{ResultType enum Priority}{TypedText priority} (8)
+// CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (15)
+// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)
+// CHECK-CC2: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (50)
+// RUN: c-index-test -code-completion-at=%s:18:10 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (60)
+// CHECK-CC3: VarDecl:{ResultType enum Color}{TypedText c} (8)
+// CHECK-CC3: ParmDecl:{ResultType enum Color}{TypedText color} (8)
+// CHECK-CC3: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25)
+// CHECK-CC3: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (12)
+// CHECK-CC3: FunctionDecl:{ResultType void}{TypedText func3}{LeftParen (}{Placeholder float}{RightParen )} (50)
+// CHECK-CC3: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (60)
+// CHECK-CC3: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (15)
+// CHECK-CC3: VarDecl:{ResultType int}{TypedText i} (4)
+// CHECK-CC3: ParmDecl:{ResultType int}{TypedText integer} (4)
+// CHECK-CC3: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (15)
+// CHECK-CC3: macro definition:{TypedText OBJC_NEW_PROPERTIES} (70)
+// CHECK-CC3: macro definition:{TypedText OBJC_ZEROCOST_EXCEPTIONS} (70)
+// CHECK-CC3: ParmDecl:{ResultType enum Priority}{TypedText priority} (2)
+// CHECK-CC3: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (60)
+// CHECK-CC3: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)
+// CHECK-CC3: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (12)
+// RUN: c-index-test -code-completion-at=%s:19:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (15)
+// CHECK-CC4: VarDecl:{ResultType enum Color}{TypedText c} (2)
+// CHECK-CC4: ParmDecl:{ResultType enum Color}{TypedText color} (2)
+// CHECK-CC4: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25)
+// CHECK-CC4: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50)
+// CHECK-CC4: FunctionDecl:{ResultType void}{TypedText func3}{LeftParen (}{Placeholder float}{RightParen )} (50)
+// CHECK-CC4: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (15)
+// CHECK-CC4: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (60)
+// CHECK-CC4: VarDecl:{ResultType int}{TypedText i} (4)
+// CHECK-CC4: ParmDecl:{ResultType int}{TypedText integer} (4)
+// CHECK-CC4: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (60)
+// CHECK-CC4: macro definition:{TypedText OBJC_NEW_PROPERTIES} (70)
+// CHECK-CC4: macro definition:{TypedText OBJC_ZEROCOST_EXCEPTIONS} (70)
+// CHECK-CC4: ParmDecl:{ResultType enum Priority}{TypedText priority} (8)
+// CHECK-CC4: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (15)
+// CHECK-CC4: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)
+// CHECK-CC4: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (50)
+// RUN: c-index-test -code-completion-at=%s:21:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: c-index-test -code-completion-at=%s:22:7 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s
+// CHECK-CC6: VarDecl:{ResultType void (^)(enum Color, int)}{TypedText block} (8)
+// CHECK-CC6: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (15)
+// CHECK-CC6: VarDecl:{ResultType enum Color}{TypedText c} (2)
+// CHECK-CC6: ParmDecl:{ResultType enum Color}{TypedText color} (2)
+// CHECK-CC6: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25)
+// CHECK-CC6: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50)
+// CHECK-CC6: FunctionDecl:{ResultType void}{TypedText func3}{LeftParen (}{Placeholder float}{RightParen )} (50)
+// CHECK-CC6: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (15)
+// CHECK-CC6: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (60)
+// CHECK-CC6: VarDecl:{ResultType int}{TypedText i} (4)
+// CHECK-CC6: ParmDecl:{ResultType int}{TypedText integer} (4)
+// CHECK-CC6: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (60)
+// CHECK-CC6: macro definition:{TypedText OBJC_NEW_PROPERTIES} (70)
+// CHECK-CC6: macro definition:{TypedText OBJC_ZEROCOST_EXCEPTIONS} (70)
+// CHECK-CC6: ParmDecl:{ResultType enum Priority}{TypedText priority} (8)
+// CHECK-CC6: EnumConstantDecl:{ResultType enum Color}{TypedText Red} (15)
+// CHECK-CC6: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)
+// CHECK-CC6: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (50)