diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2018-01-27 16:11:45 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2018-01-27 16:11:45 +0000 |
commit | c78d99a84bbf1d485e0893b17a087ad1672d7c29 (patch) | |
tree | 8508bca1becfb6de1e99c25cd8abd86d440ec0d3 /clang/unittests/AST/ASTImporterTest.cpp | |
parent | 1ae296da366920a5fdfd1c5583aa8523905716f0 (diff) | |
download | bcm5719-llvm-c78d99a84bbf1d485e0893b17a087ad1672d7c29.tar.gz bcm5719-llvm-c78d99a84bbf1d485e0893b17a087ad1672d7c29.zip |
[ASTImporter] Add support to import some AST nodes:
* CXXOperatorCallExpr
* SizeOfPackExpr
* DependentTemplateSpecializationType
* DependentSizedArray
* CXXTypeidExpr
* Fix importing CXXTemporaryObjectExpr
Some of the changes are based on
https://github.com/haoNoQ/clang/blob/summary-ipa-draft/lib/AST/ASTImporter.cpp
Differential Revision: https://reviews.llvm.org/D42335
llvm-svn: 323589
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 277d16fa3b3..44f95828415 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -484,6 +484,16 @@ TEST(ImportExpr, ImportVAArgExpr) { vaArgExpr()))))))); } +TEST(ImportExpr, CXXTemporaryObjectExpr) { + MatchVerifier<Decl> Verifier; + testImport("struct C {};" + "void declToImport() { C c = C(); }", + Lang_CXX, "", Lang_CXX, Verifier, + functionDecl(hasBody(compoundStmt(has( + declStmt(has(varDecl(has(exprWithCleanups(has(cxxConstructExpr( + has(materializeTemporaryExpr(has(implicitCastExpr( + has(cxxTemporaryObjectExpr()))))))))))))))))); +} TEST(ImportType, ImportAtomicType) { MatchVerifier<Decl> Verifier; @@ -568,6 +578,50 @@ TEST(ImportType, ImportPackExpansion) { declRefExpr()))))))))); } +const internal::VariadicDynCastAllOfMatcher<Type, + DependentTemplateSpecializationType> + dependentTemplateSpecializationType; + +TEST(ImportType, ImportDependentTemplateSpecialization) { + MatchVerifier<Decl> Verifier; + testImport("template<typename T>" + "struct A;" + "template<typename T>" + "struct declToImport {" + " typename A<T>::template B<T> a;" + "};", + Lang_CXX, "", Lang_CXX, Verifier, + classTemplateDecl(has(cxxRecordDecl(has( + fieldDecl(hasType(dependentTemplateSpecializationType()))))))); +} + +const internal::VariadicDynCastAllOfMatcher<Stmt, SizeOfPackExpr> + sizeOfPackExpr; + +TEST(ImportExpr, ImportSizeOfPackExpr) { + MatchVerifier<Decl> Verifier; + testImport("template <typename... Ts>" + "void declToImport() {" + " const int i = sizeof...(Ts);" + "};" + "void g() { declToImport<int>(); }", + Lang_CXX11, "", Lang_CXX11, Verifier, + functionTemplateDecl(has(functionDecl( + hasBody(compoundStmt(has(declStmt(has(varDecl(hasInitializer( + implicitCastExpr(has(sizeOfPackExpr()))))))))))))); + testImport( + "template <typename... Ts>" + "using X = int[sizeof...(Ts)];" + "template <typename... Us>" + "struct Y {" + " X<Us..., int, double, int, Us...> f;" + "};" + "Y<float, int> declToImport;", + Lang_CXX11, "", Lang_CXX11, Verifier, + varDecl(hasType(classTemplateSpecializationDecl(has(fieldDecl(hasType( + hasUnqualifiedDesugaredType(constantArrayType(hasSize(7)))))))))); +} + /// \brief Matches __builtin_types_compatible_p: /// GNU extension to check equivalent types /// Given @@ -590,6 +644,24 @@ TEST(ImportExpr, ImportTypeTraitExpr) { typeTraitExpr(hasType(asString("int")))))))); } +const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTypeidExpr> cxxTypeidExpr; + +TEST(ImportExpr, ImportCXXTypeidExpr) { + MatchVerifier<Decl> Verifier; + testImport( + "namespace std { class type_info {}; }" + "void declToImport() {" + " int x;" + " auto a = typeid(int); auto b = typeid(x);" + "}", + Lang_CXX11, "", Lang_CXX11, Verifier, + functionDecl( + hasDescendant(varDecl( + hasName("a"), hasInitializer(hasDescendant(cxxTypeidExpr())))), + hasDescendant(varDecl( + hasName("b"), hasInitializer(hasDescendant(cxxTypeidExpr())))))); +} + TEST(ImportExpr, ImportTypeTraitExprValDep) { MatchVerifier<Decl> Verifier; testImport("template<typename T> struct declToImport {" @@ -712,5 +784,25 @@ TEST(ImportDecl, ImportTemplatedDeclForTemplate) { unless(has(cxxRecordDecl(hasName("declToImport")))))))); } +TEST(ImportExpr, CXXOperatorCallExpr) { + MatchVerifier<Decl> Verifier; + testImport("class declToImport {" + " void f() { *this = declToImport(); }" + "};", + Lang_CXX, "", Lang_CXX, Verifier, + cxxRecordDecl(has(cxxMethodDecl(hasBody(compoundStmt( + has(exprWithCleanups(has(cxxOperatorCallExpr()))))))))); +} + +TEST(ImportExpr, DependentSizedArrayType) { + MatchVerifier<Decl> Verifier; + testImport("template<typename T, int Size> class declToImport {" + " T data[Size];" + "};", + Lang_CXX, "", Lang_CXX, Verifier, + classTemplateDecl(has(cxxRecordDecl( + has(fieldDecl(hasType(dependentSizedArrayType()))))))); +} + } // end namespace ast_matchers } // end namespace clang |