summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Sema/CodeCompleteTest.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2019-01-31 20:20:32 +0000
committerIlya Biryukov <ibiryukov@google.com>2019-01-31 20:20:32 +0000
commit4f9543b4d6152a5ee574246a645c7a3ec1db2c4f (patch)
tree30f0dd5daaa87f4663c6637e9b22140357937b59 /clang/unittests/Sema/CodeCompleteTest.cpp
parent240a90a57e3f313914dfb08c881fe7b079137c84 (diff)
downloadbcm5719-llvm-4f9543b4d6152a5ee574246a645c7a3ec1db2c4f.tar.gz
bcm5719-llvm-4f9543b4d6152a5ee574246a645c7a3ec1db2c4f.zip
[CodeComplete] Propagate preferred types through parser in more cases
Preferred types are used by code completion for ranking. This commit considerably increases the number of points in code where those types are propagated. In order to avoid complicating signatures of Parser's methods, a preferred type is kept as a member variable in the parser and updated during parsing. Differential revision: https://reviews.llvm.org/D56723 llvm-svn: 352788
Diffstat (limited to 'clang/unittests/Sema/CodeCompleteTest.cpp')
-rw-r--r--clang/unittests/Sema/CodeCompleteTest.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/clang/unittests/Sema/CodeCompleteTest.cpp b/clang/unittests/Sema/CodeCompleteTest.cpp
index d44e0ece55d..3bec79dc9ad 100644
--- a/clang/unittests/Sema/CodeCompleteTest.cpp
+++ b/clang/unittests/Sema/CodeCompleteTest.cpp
@@ -339,4 +339,103 @@ TEST(PreferredTypeTest, BinaryExpr) {
EXPECT_THAT(collectPreferredTypes(Code), Each("NULL TYPE"));
}
+TEST(PreferredTypeTest, Members) {
+ StringRef Code = R"cpp(
+ struct vector {
+ int *begin();
+ vector clone();
+ };
+
+ void test(int *a) {
+ a = ^vector().^clone().^begin();
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("int *"));
+}
+
+TEST(PreferredTypeTest, Conditions) {
+ StringRef Code = R"cpp(
+ struct vector {
+ bool empty();
+ };
+
+ void test() {
+ if (^vector().^empty()) {}
+ while (^vector().^empty()) {}
+ for (; ^vector().^empty();) {}
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("_Bool"));
+}
+
+TEST(PreferredTypeTest, InitAndAssignment) {
+ StringRef Code = R"cpp(
+ struct vector {
+ int* begin();
+ };
+
+ void test() {
+ const int* x = ^vector().^begin();
+ x = ^vector().^begin();
+
+ if (const int* y = ^vector().^begin()) {}
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("const int *"));
+}
+
+TEST(PreferredTypeTest, UnaryExprs) {
+ StringRef Code = R"cpp(
+ void test(long long a) {
+ a = +^a;
+ a = -^a
+ a = ++^a;
+ a = --^a;
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("long long"));
+
+ Code = R"cpp(
+ void test(int a, int *ptr) {
+ !^a;
+ !^ptr;
+ !!!^a;
+
+ a = !^a;
+ a = !^ptr;
+ a = !!!^a;
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("_Bool"));
+
+ Code = R"cpp(
+ void test(int a) {
+ const int* x = &^a;
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("const int"));
+
+ Code = R"cpp(
+ void test(int *a) {
+ int x = *^a;
+ int &r = *^a;
+ }
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("int *"));
+
+ Code = R"cpp(
+ void test(int a) {
+ *^a;
+ &^a;
+ }
+
+ )cpp";
+}
+
+TEST(PreferredTypeTest, ParenExpr) {
+ StringRef Code = R"cpp(
+ const int *i = ^(^(^(^10)));
+ )cpp";
+ EXPECT_THAT(collectPreferredTypes(Code), Each("const int *"));
+}
} // namespace
OpenPOWER on IntegriCloud