Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 1 | //===- unittest/AST/ASTImporterTest.cpp - AST node import test ------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Type-parameterized tests for the correct import of Decls with different |
| 10 | // visibility. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | // Define this to have ::testing::Combine available. |
| 15 | // FIXME: Better solution for this? |
| 16 | #define GTEST_HAS_COMBINE 1 |
| 17 | |
| 18 | #include "ASTImporterFixtures.h" |
| 19 | |
| 20 | namespace clang { |
| 21 | namespace ast_matchers { |
| 22 | |
| 23 | using internal::BindableMatcher; |
| 24 | |
| 25 | // Type parameters for type-parameterized test fixtures. |
| 26 | struct GetFunPattern { |
| 27 | using DeclTy = FunctionDecl; |
| 28 | BindableMatcher<Decl> operator()() { return functionDecl(hasName("f")); } |
| 29 | }; |
| 30 | struct GetVarPattern { |
| 31 | using DeclTy = VarDecl; |
| 32 | BindableMatcher<Decl> operator()() { return varDecl(hasName("v")); } |
| 33 | }; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 34 | struct GetClassPattern { |
| 35 | using DeclTy = CXXRecordDecl; |
| 36 | BindableMatcher<Decl> operator()() { return cxxRecordDecl(hasName("X")); } |
| 37 | }; |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 38 | struct GetEnumPattern { |
| 39 | using DeclTy = EnumDecl; |
| 40 | BindableMatcher<Decl> operator()() { return enumDecl(hasName("E")); } |
| 41 | }; |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 42 | struct GetTypedefNamePattern { |
| 43 | using DeclTy = TypedefNameDecl; |
| 44 | BindableMatcher<Decl> operator()() { return typedefNameDecl(hasName("T")); } |
| 45 | }; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 46 | struct GetFunTemplPattern { |
| 47 | using DeclTy = FunctionTemplateDecl; |
| 48 | BindableMatcher<Decl> operator()() { |
| 49 | return functionTemplateDecl(hasName("f")); |
| 50 | } |
| 51 | }; |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 52 | struct GetVarTemplPattern { |
| 53 | using DeclTy = VarTemplateDecl; |
| 54 | BindableMatcher<Decl> operator()() { |
| 55 | return namedDecl(hasName("v"), has(templateTypeParmDecl())); |
| 56 | } |
| 57 | }; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 58 | struct GetClassTemplPattern { |
| 59 | using DeclTy = ClassTemplateDecl; |
| 60 | BindableMatcher<Decl> operator()() { return classTemplateDecl(hasName("X")); } |
| 61 | }; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 62 | |
| 63 | // Values for the value-parameterized test fixtures. |
| 64 | // FunctionDecl: |
| 65 | const auto *ExternF = "void f();"; |
| 66 | const auto *StaticF = "static void f();"; |
| 67 | const auto *AnonF = "namespace { void f(); }"; |
| 68 | // VarDecl: |
| 69 | const auto *ExternV = "extern int v;"; |
| 70 | const auto *StaticV = "static int v;"; |
| 71 | const auto *AnonV = "namespace { extern int v; }"; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 72 | // CXXRecordDecl: |
| 73 | const auto *ExternC = "class X;"; |
| 74 | const auto *AnonC = "namespace { class X; }"; |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 75 | // EnumDecl: |
| 76 | const auto *ExternE = "enum E {};"; |
| 77 | const auto *AnonE = "namespace { enum E {}; }"; |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 78 | const auto *ExternEC = "enum class E;"; |
| 79 | const auto *AnonEC = "namespace { enum class E; }"; |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 80 | // TypedefNameDecl: |
| 81 | const auto *ExternTypedef = "typedef int T;"; |
| 82 | const auto *AnonTypedef = "namespace { typedef int T; }"; |
| 83 | const auto *ExternUsing = "using T = int;"; |
| 84 | const auto *AnonUsing = "namespace { using T = int; }"; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 85 | // FunctionTemplateDecl: |
| 86 | const auto *ExternFT = "template <class> void f();"; |
| 87 | const auto *StaticFT = "template <class> static void f();"; |
| 88 | const auto *AnonFT = "namespace { template <class> void f(); }"; |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 89 | // VarTemplateDecl: |
| 90 | const auto *ExternVT = "template <class> extern int v;"; |
| 91 | const auto *StaticVT = "template <class> static int v;"; |
| 92 | const auto *AnonVT = "namespace { template <class> extern int v; }"; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 93 | // ClassTemplateDecl: |
| 94 | const auto *ExternCT = "template <class> class X;"; |
| 95 | const auto *AnonCT = "namespace { template <class> class X; }"; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 96 | |
| 97 | // First value in tuple: Compile options. |
| 98 | // Second value in tuple: Source code to be used in the test. |
| 99 | using ImportVisibilityChainParams = |
| 100 | ::testing::WithParamInterface<std::tuple<ArgVector, const char *>>; |
| 101 | // Fixture to test the redecl chain of Decls with the same visibility. Gtest |
| 102 | // makes it possible to have either value-parameterized or type-parameterized |
| 103 | // fixtures. However, we cannot have both value- and type-parameterized test |
| 104 | // fixtures. This is a value-parameterized test fixture in the gtest sense. We |
| 105 | // intend to mimic gtest's type-parameters via the PatternFactory template |
| 106 | // parameter. We manually instantiate the different tests with the each types. |
| 107 | template <typename PatternFactory> |
| 108 | class ImportVisibilityChain |
| 109 | : public ASTImporterTestBase, public ImportVisibilityChainParams { |
| 110 | protected: |
| 111 | using DeclTy = typename PatternFactory::DeclTy; |
| 112 | ArgVector getExtraArgs() const override { return std::get<0>(GetParam()); } |
| 113 | std::string getCode() const { return std::get<1>(GetParam()); } |
| 114 | BindableMatcher<Decl> getPattern() const { return PatternFactory()(); } |
| 115 | |
| 116 | // Type-parameterized test. |
| 117 | void TypedTest_ImportChain() { |
| 118 | std::string Code = getCode() + getCode(); |
| 119 | auto Pattern = getPattern(); |
| 120 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 121 | TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc"); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 122 | |
| 123 | auto *FromD0 = FirstDeclMatcher<DeclTy>().match(FromTu, Pattern); |
| 124 | auto *FromD1 = LastDeclMatcher<DeclTy>().match(FromTu, Pattern); |
| 125 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 126 | auto *ToD0 = Import(FromD0, Lang_CXX14); |
| 127 | auto *ToD1 = Import(FromD1, Lang_CXX14); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 128 | |
| 129 | EXPECT_TRUE(ToD0); |
| 130 | ASSERT_TRUE(ToD1); |
| 131 | EXPECT_NE(ToD0, ToD1); |
| 132 | EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | // Manual instantiation of the fixture with each type. |
| 137 | using ImportFunctionsVisibilityChain = ImportVisibilityChain<GetFunPattern>; |
| 138 | using ImportVariablesVisibilityChain = ImportVisibilityChain<GetVarPattern>; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 139 | using ImportClassesVisibilityChain = ImportVisibilityChain<GetClassPattern>; |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 140 | using ImportScopedEnumsVisibilityChain = ImportVisibilityChain<GetEnumPattern>; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 141 | using ImportFunctionTemplatesVisibilityChain = |
| 142 | ImportVisibilityChain<GetFunTemplPattern>; |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 143 | using ImportVariableTemplatesVisibilityChain = |
| 144 | ImportVisibilityChain<GetVarTemplPattern>; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 145 | using ImportClassTemplatesVisibilityChain = |
| 146 | ImportVisibilityChain<GetClassTemplPattern>; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 147 | |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 148 | // Value-parameterized test for functions. |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 149 | TEST_P(ImportFunctionsVisibilityChain, ImportChain) { |
| 150 | TypedTest_ImportChain(); |
| 151 | } |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 152 | // Value-parameterized test for variables. |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 153 | TEST_P(ImportVariablesVisibilityChain, ImportChain) { |
| 154 | TypedTest_ImportChain(); |
| 155 | } |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 156 | // Value-parameterized test for classes. |
| 157 | TEST_P(ImportClassesVisibilityChain, ImportChain) { |
| 158 | TypedTest_ImportChain(); |
| 159 | } |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 160 | // Value-parameterized test for scoped enums. |
| 161 | TEST_P(ImportScopedEnumsVisibilityChain, ImportChain) { |
| 162 | TypedTest_ImportChain(); |
| 163 | } |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 164 | // Value-parameterized test for function templates. |
| 165 | TEST_P(ImportFunctionTemplatesVisibilityChain, ImportChain) { |
| 166 | TypedTest_ImportChain(); |
| 167 | } |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 168 | // Value-parameterized test for variable templates. |
| 169 | TEST_P(ImportVariableTemplatesVisibilityChain, ImportChain) { |
| 170 | TypedTest_ImportChain(); |
| 171 | } |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 172 | // Value-parameterized test for class templates. |
| 173 | TEST_P(ImportClassTemplatesVisibilityChain, ImportChain) { |
| 174 | TypedTest_ImportChain(); |
| 175 | } |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 176 | |
| 177 | // Automatic instantiation of the value-parameterized tests. |
| 178 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctionsVisibilityChain, |
| 179 | ::testing::Combine( |
| 180 | DefaultTestValuesForRunOptions, |
| 181 | ::testing::Values(ExternF, StaticF, AnonF)), ); |
| 182 | INSTANTIATE_TEST_CASE_P( |
| 183 | ParameterizedTests, ImportVariablesVisibilityChain, |
| 184 | ::testing::Combine( |
| 185 | DefaultTestValuesForRunOptions, |
| 186 | // There is no point to instantiate with StaticV, because in C++ we can |
| 187 | // forward declare a variable only with the 'extern' keyword. |
| 188 | // Consequently, each fwd declared variable has external linkage. This |
| 189 | // is different in the C language where any declaration without an |
| 190 | // initializer is a tentative definition, subsequent definitions may be |
| 191 | // provided but they must have the same linkage. See also the test |
| 192 | // ImportVariableChainInC which test for this special C Lang case. |
| 193 | ::testing::Values(ExternV, AnonV)), ); |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 194 | INSTANTIATE_TEST_CASE_P( |
| 195 | ParameterizedTests, ImportClassesVisibilityChain, |
| 196 | ::testing::Combine( |
| 197 | DefaultTestValuesForRunOptions, |
| 198 | ::testing::Values(ExternC, AnonC)), ); |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 199 | INSTANTIATE_TEST_CASE_P( |
| 200 | ParameterizedTests, ImportScopedEnumsVisibilityChain, |
| 201 | ::testing::Combine( |
| 202 | DefaultTestValuesForRunOptions, |
| 203 | ::testing::Values(ExternEC, AnonEC)), ); |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 204 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, |
| 205 | ImportFunctionTemplatesVisibilityChain, |
| 206 | ::testing::Combine(DefaultTestValuesForRunOptions, |
| 207 | ::testing::Values(ExternFT, StaticFT, |
| 208 | AnonFT)), ); |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 209 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, |
| 210 | ImportVariableTemplatesVisibilityChain, |
| 211 | ::testing::Combine(DefaultTestValuesForRunOptions, |
| 212 | ::testing::Values(ExternVT, |
| 213 | AnonVT)), ); |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 214 | INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClassTemplatesVisibilityChain, |
| 215 | ::testing::Combine(DefaultTestValuesForRunOptions, |
| 216 | ::testing::Values(ExternCT, |
| 217 | AnonCT)), ); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 218 | |
| 219 | // First value in tuple: Compile options. |
| 220 | // Second value in tuple: Tuple with informations for the test. |
| 221 | // Code for first import (or initial code), code to import, whether the `f` |
| 222 | // functions are expected to be linked in a declaration chain. |
| 223 | // One value of this tuple is combined with every value of compile options. |
| 224 | // The test can have a single tuple as parameter only. |
| 225 | using ImportVisibilityParams = ::testing::WithParamInterface< |
| 226 | std::tuple<ArgVector, std::tuple<const char *, const char *, bool>>>; |
| 227 | |
| 228 | template <typename PatternFactory> |
| 229 | class ImportVisibility |
| 230 | : public ASTImporterTestBase, |
| 231 | public ImportVisibilityParams { |
| 232 | protected: |
| 233 | using DeclTy = typename PatternFactory::DeclTy; |
| 234 | ArgVector getExtraArgs() const override { return std::get<0>(GetParam()); } |
| 235 | std::string getCode0() const { return std::get<0>(std::get<1>(GetParam())); } |
| 236 | std::string getCode1() const { return std::get<1>(std::get<1>(GetParam())); } |
| 237 | bool shouldBeLinked() const { return std::get<2>(std::get<1>(GetParam())); } |
| 238 | BindableMatcher<Decl> getPattern() const { return PatternFactory()(); } |
| 239 | |
| 240 | void TypedTest_ImportAfter() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 241 | TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14); |
| 242 | TranslationUnitDecl *FromTu = |
| 243 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 244 | |
| 245 | auto *ToD0 = FirstDeclMatcher<DeclTy>().match(ToTu, getPattern()); |
| 246 | auto *FromD1 = FirstDeclMatcher<DeclTy>().match(FromTu, getPattern()); |
| 247 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 248 | auto *ToD1 = Import(FromD1, Lang_CXX14); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 249 | |
| 250 | ASSERT_TRUE(ToD0); |
| 251 | ASSERT_TRUE(ToD1); |
| 252 | EXPECT_NE(ToD0, ToD1); |
| 253 | |
| 254 | if (shouldBeLinked()) |
| 255 | EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); |
| 256 | else |
| 257 | EXPECT_FALSE(ToD1->getPreviousDecl()); |
| 258 | } |
| 259 | |
| 260 | void TypedTest_ImportAfterImport() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 261 | TranslationUnitDecl *FromTu0 = |
| 262 | getTuDecl(getCode0(), Lang_CXX14, "input0.cc"); |
| 263 | TranslationUnitDecl *FromTu1 = |
| 264 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 265 | auto *FromD0 = FirstDeclMatcher<DeclTy>().match(FromTu0, getPattern()); |
| 266 | auto *FromD1 = FirstDeclMatcher<DeclTy>().match(FromTu1, getPattern()); |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 267 | auto *ToD0 = Import(FromD0, Lang_CXX14); |
| 268 | auto *ToD1 = Import(FromD1, Lang_CXX14); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 269 | ASSERT_TRUE(ToD0); |
| 270 | ASSERT_TRUE(ToD1); |
| 271 | EXPECT_NE(ToD0, ToD1); |
| 272 | if (shouldBeLinked()) |
| 273 | EXPECT_EQ(ToD1->getPreviousDecl(), ToD0); |
| 274 | else |
| 275 | EXPECT_FALSE(ToD1->getPreviousDecl()); |
| 276 | } |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 277 | |
| 278 | void TypedTest_ImportAfterWithMerge() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 279 | TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14); |
| 280 | TranslationUnitDecl *FromTu = |
| 281 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 282 | |
| 283 | auto *ToF0 = FirstDeclMatcher<DeclTy>().match(ToTu, getPattern()); |
| 284 | auto *FromF1 = FirstDeclMatcher<DeclTy>().match(FromTu, getPattern()); |
| 285 | |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 286 | auto *ToF1 = Import(FromF1, Lang_CXX14); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 287 | |
| 288 | ASSERT_TRUE(ToF0); |
| 289 | ASSERT_TRUE(ToF1); |
| 290 | |
| 291 | if (shouldBeLinked()) |
| 292 | EXPECT_EQ(ToF0, ToF1); |
| 293 | else |
| 294 | EXPECT_NE(ToF0, ToF1); |
| 295 | |
| 296 | // We expect no (ODR) warning during the import. |
| 297 | EXPECT_EQ(0u, ToTu->getASTContext().getDiagnostics().getNumWarnings()); |
| 298 | } |
| 299 | |
| 300 | void TypedTest_ImportAfterImportWithMerge() { |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 301 | TranslationUnitDecl *FromTu0 = |
| 302 | getTuDecl(getCode0(), Lang_CXX14, "input0.cc"); |
| 303 | TranslationUnitDecl *FromTu1 = |
| 304 | getTuDecl(getCode1(), Lang_CXX14, "input1.cc"); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 305 | auto *FromF0 = FirstDeclMatcher<DeclTy>().match(FromTu0, getPattern()); |
| 306 | auto *FromF1 = FirstDeclMatcher<DeclTy>().match(FromTu1, getPattern()); |
Balazs Keri | 14d115f | 2019-07-15 12:16:30 +0000 | [diff] [blame] | 307 | auto *ToF0 = Import(FromF0, Lang_CXX14); |
| 308 | auto *ToF1 = Import(FromF1, Lang_CXX14); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 309 | ASSERT_TRUE(ToF0); |
| 310 | ASSERT_TRUE(ToF1); |
| 311 | if (shouldBeLinked()) |
| 312 | EXPECT_EQ(ToF0, ToF1); |
| 313 | else |
| 314 | EXPECT_NE(ToF0, ToF1); |
| 315 | |
| 316 | // We expect no (ODR) warning during the import. |
| 317 | EXPECT_EQ(0u, ToF0->getTranslationUnitDecl() |
| 318 | ->getASTContext() |
| 319 | .getDiagnostics() |
| 320 | .getNumWarnings()); |
| 321 | } |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 322 | }; |
| 323 | using ImportFunctionsVisibility = ImportVisibility<GetFunPattern>; |
| 324 | using ImportVariablesVisibility = ImportVisibility<GetVarPattern>; |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 325 | using ImportClassesVisibility = ImportVisibility<GetClassPattern>; |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 326 | using ImportEnumsVisibility = ImportVisibility<GetEnumPattern>; |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 327 | using ImportScopedEnumsVisibility = ImportVisibility<GetEnumPattern>; |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 328 | using ImportTypedefNameVisibility = ImportVisibility<GetTypedefNamePattern>; |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 329 | using ImportFunctionTemplatesVisibility = ImportVisibility<GetFunTemplPattern>; |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 330 | using ImportVariableTemplatesVisibility = ImportVisibility<GetVarTemplPattern>; |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 331 | using ImportClassTemplatesVisibility = ImportVisibility<GetClassTemplPattern>; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 332 | |
| 333 | // FunctionDecl. |
| 334 | TEST_P(ImportFunctionsVisibility, ImportAfter) { |
| 335 | TypedTest_ImportAfter(); |
| 336 | } |
| 337 | TEST_P(ImportFunctionsVisibility, ImportAfterImport) { |
| 338 | TypedTest_ImportAfterImport(); |
| 339 | } |
| 340 | // VarDecl. |
| 341 | TEST_P(ImportVariablesVisibility, ImportAfter) { |
| 342 | TypedTest_ImportAfter(); |
| 343 | } |
| 344 | TEST_P(ImportVariablesVisibility, ImportAfterImport) { |
| 345 | TypedTest_ImportAfterImport(); |
| 346 | } |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 347 | // CXXRecordDecl. |
| 348 | TEST_P(ImportClassesVisibility, ImportAfter) { |
| 349 | TypedTest_ImportAfter(); |
| 350 | } |
| 351 | TEST_P(ImportClassesVisibility, ImportAfterImport) { |
| 352 | TypedTest_ImportAfterImport(); |
| 353 | } |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 354 | // EnumDecl. |
| 355 | TEST_P(ImportEnumsVisibility, ImportAfter) { |
| 356 | TypedTest_ImportAfterWithMerge(); |
| 357 | } |
| 358 | TEST_P(ImportEnumsVisibility, ImportAfterImport) { |
| 359 | TypedTest_ImportAfterImportWithMerge(); |
| 360 | } |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 361 | TEST_P(ImportScopedEnumsVisibility, ImportAfter) { |
| 362 | TypedTest_ImportAfter(); |
| 363 | } |
| 364 | TEST_P(ImportScopedEnumsVisibility, ImportAfterImport) { |
| 365 | TypedTest_ImportAfterImport(); |
| 366 | } |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 367 | // TypedefNameDecl. |
| 368 | TEST_P(ImportTypedefNameVisibility, ImportAfter) { |
| 369 | TypedTest_ImportAfterWithMerge(); |
| 370 | } |
| 371 | TEST_P(ImportTypedefNameVisibility, ImportAfterImport) { |
| 372 | TypedTest_ImportAfterImportWithMerge(); |
| 373 | } |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 374 | // FunctionTemplateDecl. |
| 375 | TEST_P(ImportFunctionTemplatesVisibility, ImportAfter) { |
| 376 | TypedTest_ImportAfter(); |
| 377 | } |
| 378 | TEST_P(ImportFunctionTemplatesVisibility, ImportAfterImport) { |
| 379 | TypedTest_ImportAfterImport(); |
| 380 | } |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 381 | // VarTemplateDecl. |
| 382 | TEST_P(ImportVariableTemplatesVisibility, ImportAfter) { |
| 383 | TypedTest_ImportAfter(); |
| 384 | } |
| 385 | TEST_P(ImportVariableTemplatesVisibility, ImportAfterImport) { |
| 386 | TypedTest_ImportAfterImport(); |
| 387 | } |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 388 | // ClassTemplateDecl. |
| 389 | TEST_P(ImportClassTemplatesVisibility, ImportAfter) { TypedTest_ImportAfter(); } |
| 390 | TEST_P(ImportClassTemplatesVisibility, ImportAfterImport) { |
| 391 | TypedTest_ImportAfterImport(); |
| 392 | } |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 393 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 394 | const bool ExpectLinkedDeclChain = true; |
| 395 | const bool ExpectUnlinkedDeclChain = false; |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 396 | |
| 397 | INSTANTIATE_TEST_CASE_P( |
| 398 | ParameterizedTests, ImportFunctionsVisibility, |
| 399 | ::testing::Combine( |
| 400 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 401 | ::testing::Values( |
| 402 | std::make_tuple(ExternF, ExternF, ExpectLinkedDeclChain), |
| 403 | std::make_tuple(ExternF, StaticF, ExpectUnlinkedDeclChain), |
| 404 | std::make_tuple(ExternF, AnonF, ExpectUnlinkedDeclChain), |
| 405 | std::make_tuple(StaticF, ExternF, ExpectUnlinkedDeclChain), |
| 406 | std::make_tuple(StaticF, StaticF, ExpectUnlinkedDeclChain), |
| 407 | std::make_tuple(StaticF, AnonF, ExpectUnlinkedDeclChain), |
| 408 | std::make_tuple(AnonF, ExternF, ExpectUnlinkedDeclChain), |
| 409 | std::make_tuple(AnonF, StaticF, ExpectUnlinkedDeclChain), |
| 410 | std::make_tuple(AnonF, AnonF, ExpectUnlinkedDeclChain))), ); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 411 | INSTANTIATE_TEST_CASE_P( |
| 412 | ParameterizedTests, ImportVariablesVisibility, |
| 413 | ::testing::Combine( |
| 414 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 415 | ::testing::Values( |
| 416 | std::make_tuple(ExternV, ExternV, ExpectLinkedDeclChain), |
| 417 | std::make_tuple(ExternV, StaticV, ExpectUnlinkedDeclChain), |
| 418 | std::make_tuple(ExternV, AnonV, ExpectUnlinkedDeclChain), |
| 419 | std::make_tuple(StaticV, ExternV, ExpectUnlinkedDeclChain), |
| 420 | std::make_tuple(StaticV, StaticV, ExpectUnlinkedDeclChain), |
| 421 | std::make_tuple(StaticV, AnonV, ExpectUnlinkedDeclChain), |
| 422 | std::make_tuple(AnonV, ExternV, ExpectUnlinkedDeclChain), |
| 423 | std::make_tuple(AnonV, StaticV, ExpectUnlinkedDeclChain), |
| 424 | std::make_tuple(AnonV, AnonV, ExpectUnlinkedDeclChain))), ); |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 425 | INSTANTIATE_TEST_CASE_P( |
| 426 | ParameterizedTests, ImportClassesVisibility, |
| 427 | ::testing::Combine( |
| 428 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 429 | ::testing::Values( |
| 430 | std::make_tuple(ExternC, ExternC, ExpectLinkedDeclChain), |
| 431 | std::make_tuple(ExternC, AnonC, ExpectUnlinkedDeclChain), |
| 432 | std::make_tuple(AnonC, ExternC, ExpectUnlinkedDeclChain), |
| 433 | std::make_tuple(AnonC, AnonC, ExpectUnlinkedDeclChain))), ); |
Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 434 | INSTANTIATE_TEST_CASE_P( |
| 435 | ParameterizedTests, ImportEnumsVisibility, |
| 436 | ::testing::Combine( |
| 437 | DefaultTestValuesForRunOptions, |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 438 | ::testing::Values( |
| 439 | std::make_tuple(ExternE, ExternE, ExpectLinkedDeclChain), |
| 440 | std::make_tuple(ExternE, AnonE, ExpectUnlinkedDeclChain), |
| 441 | std::make_tuple(AnonE, ExternE, ExpectUnlinkedDeclChain), |
| 442 | std::make_tuple(AnonE, AnonE, ExpectUnlinkedDeclChain))), ); |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 443 | INSTANTIATE_TEST_CASE_P( |
Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 444 | ParameterizedTests, ImportScopedEnumsVisibility, |
| 445 | ::testing::Combine( |
| 446 | DefaultTestValuesForRunOptions, |
| 447 | ::testing::Values( |
| 448 | std::make_tuple(ExternEC, ExternEC, ExpectLinkedDeclChain), |
| 449 | std::make_tuple(ExternEC, AnonEC, ExpectUnlinkedDeclChain), |
| 450 | std::make_tuple(AnonEC, ExternEC, ExpectUnlinkedDeclChain), |
| 451 | std::make_tuple(AnonEC, AnonEC, ExpectUnlinkedDeclChain))), ); |
| 452 | INSTANTIATE_TEST_CASE_P( |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 453 | ParameterizedTests, ImportTypedefNameVisibility, |
| 454 | ::testing::Combine( |
| 455 | DefaultTestValuesForRunOptions, |
| 456 | ::testing::Values( |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 457 | std::make_tuple(ExternTypedef, ExternTypedef, |
| 458 | ExpectLinkedDeclChain), |
| 459 | std::make_tuple(ExternTypedef, AnonTypedef, |
| 460 | ExpectUnlinkedDeclChain), |
| 461 | std::make_tuple(AnonTypedef, ExternTypedef, |
| 462 | ExpectUnlinkedDeclChain), |
| 463 | std::make_tuple(AnonTypedef, AnonTypedef, ExpectUnlinkedDeclChain), |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 464 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 465 | std::make_tuple(ExternUsing, ExternUsing, ExpectLinkedDeclChain), |
| 466 | std::make_tuple(ExternUsing, AnonUsing, ExpectUnlinkedDeclChain), |
| 467 | std::make_tuple(AnonUsing, ExternUsing, ExpectUnlinkedDeclChain), |
| 468 | std::make_tuple(AnonUsing, AnonUsing, ExpectUnlinkedDeclChain), |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 469 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 470 | std::make_tuple(ExternUsing, ExternTypedef, ExpectLinkedDeclChain), |
| 471 | std::make_tuple(ExternUsing, AnonTypedef, ExpectUnlinkedDeclChain), |
| 472 | std::make_tuple(AnonUsing, ExternTypedef, ExpectUnlinkedDeclChain), |
| 473 | std::make_tuple(AnonUsing, AnonTypedef, ExpectUnlinkedDeclChain), |
Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 474 | |
Balazs Keri | caa4279 | 2019-09-05 07:59:45 +0000 | [diff] [blame] | 475 | std::make_tuple(ExternTypedef, ExternUsing, ExpectLinkedDeclChain), |
| 476 | std::make_tuple(ExternTypedef, AnonUsing, ExpectUnlinkedDeclChain), |
| 477 | std::make_tuple(AnonTypedef, ExternUsing, ExpectUnlinkedDeclChain), |
| 478 | std::make_tuple(AnonTypedef, AnonUsing, |
| 479 | ExpectUnlinkedDeclChain))), ); |
Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 480 | INSTANTIATE_TEST_CASE_P( |
| 481 | ParameterizedTests, ImportFunctionTemplatesVisibility, |
| 482 | ::testing::Combine( |
| 483 | DefaultTestValuesForRunOptions, |
| 484 | ::testing::Values( |
| 485 | std::make_tuple(ExternFT, ExternFT, ExpectLinkedDeclChain), |
| 486 | std::make_tuple(ExternFT, StaticFT, ExpectUnlinkedDeclChain), |
| 487 | std::make_tuple(ExternFT, AnonFT, ExpectUnlinkedDeclChain), |
| 488 | std::make_tuple(StaticFT, ExternFT, ExpectUnlinkedDeclChain), |
| 489 | std::make_tuple(StaticFT, StaticFT, ExpectUnlinkedDeclChain), |
| 490 | std::make_tuple(StaticFT, AnonFT, ExpectUnlinkedDeclChain), |
| 491 | std::make_tuple(AnonFT, ExternFT, ExpectUnlinkedDeclChain), |
| 492 | std::make_tuple(AnonFT, StaticFT, ExpectUnlinkedDeclChain), |
| 493 | std::make_tuple(AnonFT, AnonFT, ExpectUnlinkedDeclChain))), ); |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 494 | INSTANTIATE_TEST_CASE_P( |
Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 495 | ParameterizedTests, ImportVariableTemplatesVisibility, |
| 496 | ::testing::Combine( |
| 497 | DefaultTestValuesForRunOptions, |
| 498 | ::testing::Values( |
| 499 | std::make_tuple(ExternVT, ExternVT, ExpectLinkedDeclChain), |
| 500 | std::make_tuple(ExternVT, StaticVT, ExpectUnlinkedDeclChain), |
| 501 | std::make_tuple(ExternVT, AnonVT, ExpectUnlinkedDeclChain), |
| 502 | std::make_tuple(StaticVT, ExternVT, ExpectUnlinkedDeclChain), |
| 503 | std::make_tuple(StaticVT, StaticVT, ExpectUnlinkedDeclChain), |
| 504 | std::make_tuple(StaticVT, AnonVT, ExpectUnlinkedDeclChain), |
| 505 | std::make_tuple(AnonVT, ExternVT, ExpectUnlinkedDeclChain), |
| 506 | std::make_tuple(AnonVT, StaticVT, ExpectUnlinkedDeclChain), |
| 507 | std::make_tuple(AnonVT, AnonVT, ExpectUnlinkedDeclChain))), ); |
| 508 | INSTANTIATE_TEST_CASE_P( |
Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 509 | ParameterizedTests, ImportClassTemplatesVisibility, |
| 510 | ::testing::Combine( |
| 511 | DefaultTestValuesForRunOptions, |
| 512 | ::testing::Values(std::make_tuple(ExternCT, ExternCT, ExpectLinkedDeclChain), |
| 513 | std::make_tuple(ExternCT, AnonCT, ExpectUnlinkedDeclChain), |
| 514 | std::make_tuple(AnonCT, ExternCT, ExpectUnlinkedDeclChain), |
| 515 | std::make_tuple(AnonCT, AnonCT, ExpectUnlinkedDeclChain))), ); |
Gabor Marton | 3c72fe1 | 2019-05-13 10:06:25 +0000 | [diff] [blame] | 516 | } // end namespace ast_matchers |
| 517 | } // end namespace clang |