diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-01-31 20:20:32 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-01-31 20:20:32 +0000 |
commit | d60b3870985efd980894c42db7a6721c5ef04a07 (patch) | |
tree | c0e66ab30277e1559691e2686320a983121a6d14 /unittests/Sema | |
parent | a87ff88c6466fbedd6281513b9480a2cad6c08c8 (diff) | |
download | clang-d60b3870985efd980894c42db7a6721c5ef04a07.tar.gz |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352788 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Sema')
-rw-r--r-- | unittests/Sema/CodeCompleteTest.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/unittests/Sema/CodeCompleteTest.cpp b/unittests/Sema/CodeCompleteTest.cpp index d44e0ece55..3bec79dc9a 100644 --- a/unittests/Sema/CodeCompleteTest.cpp +++ b/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 |