From 75e8a91cf84fce2432f70949ab9e353ff2322a5f Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 16 Dec 2019 11:52:36 +0100 Subject: [PATCH] [lldb][NFC] Remove all overloads of Copy/DeportType in ClangASTImporter The overloads that don't take a CompilerType serve no purpose as we always have a CompilerType in the scope where we call them. Instead just call the overload that takes a CompilerType and delete the now unused other overloaded methods. --- lldb/include/lldb/Symbol/ClangASTImporter.h | 11 +-- .../ExpressionParser/Clang/ClangASTSource.cpp | 5 +- .../Clang/ClangExpressionDeclMap.cpp | 5 +- lldb/source/Symbol/ClangASTImporter.cpp | 93 +++++++++------------- 4 files changed, 42 insertions(+), 72 deletions(-) diff --git a/lldb/include/lldb/Symbol/ClangASTImporter.h b/lldb/include/lldb/Symbol/ClangASTImporter.h index cd01bed..58e0686 100644 --- a/lldb/include/lldb/Symbol/ClangASTImporter.h +++ b/lldb/include/lldb/Symbol/ClangASTImporter.h @@ -48,21 +48,12 @@ public: : m_file_manager(clang::FileSystemOptions(), FileSystem::Instance().GetVirtualFileSystem()) {} - clang::QualType CopyType(clang::ASTContext *dst_ctx, - clang::ASTContext *src_ctx, clang::QualType type); - - lldb::opaque_compiler_type_t CopyType(clang::ASTContext *dst_ctx, - clang::ASTContext *src_ctx, - lldb::opaque_compiler_type_t type); - CompilerType CopyType(ClangASTContext &dst, const CompilerType &src_type); clang::Decl *CopyDecl(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, clang::Decl *decl); - lldb::opaque_compiler_type_t DeportType(clang::ASTContext *dst_ctx, - clang::ASTContext *src_ctx, - lldb::opaque_compiler_type_t type); + CompilerType DeportType(ClangASTContext &dst, const CompilerType &src_type); clang::Decl *DeportDecl(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, clang::Decl *decl); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 7a23606..58db9d4 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -2022,9 +2022,8 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) { QualType copied_qual_type; if (m_ast_importer_sp) { - copied_qual_type = - m_ast_importer_sp->CopyType(m_ast_context, src_ast->getASTContext(), - ClangUtil::GetQualType(src_type)); + copied_qual_type = ClangUtil::GetQualType( + m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type)); } else if (m_merger_up) { copied_qual_type = CopyTypeWithMerger(*src_ast->getASTContext(), *m_merger_up, diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp index b16c181..192e43a 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -206,10 +206,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target, assert(source.getASTContext() == m_ast_context); if (m_ast_importer_sp) { - return TypeFromUser(m_ast_importer_sp->DeportType( - target.getASTContext(), source.getASTContext(), - parser_type.GetOpaqueQualType()), - &target); + return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type)); } else if (m_merger_up) { clang::FileID source_file = source.getASTContext()->getSourceManager().getFileID( diff --git a/lldb/source/Symbol/ClangASTImporter.cpp b/lldb/source/Symbol/ClangASTImporter.cpp index a6125ce..1cfec25 100644 --- a/lldb/source/Symbol/ClangASTImporter.cpp +++ b/lldb/source/Symbol/ClangASTImporter.cpp @@ -25,52 +25,42 @@ using namespace lldb_private; using namespace clang; -clang::QualType ClangASTImporter::CopyType(clang::ASTContext *dst_ast, - clang::ASTContext *src_ast, - clang::QualType type) { - ImporterDelegateSP delegate_sp(GetDelegate(dst_ast, src_ast)); +CompilerType ClangASTImporter::CopyType(ClangASTContext &dst_ast, + const CompilerType &src_type) { + clang::ASTContext *dst_clang_ast = dst_ast.getASTContext(); + if (!dst_clang_ast) + return CompilerType(); - ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast); + ClangASTContext *src_ast = + llvm::dyn_cast_or_null(src_type.GetTypeSystem()); + if (!src_ast) + return CompilerType(); + clang::ASTContext *src_clang_ast = src_ast->getASTContext(); + if (!src_clang_ast) + return CompilerType(); + + clang::QualType src_qual_type = ClangUtil::GetQualType(src_type); + + ImporterDelegateSP delegate_sp(GetDelegate(dst_clang_ast, src_clang_ast)); if (!delegate_sp) - return QualType(); + return CompilerType(); + + ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_clang_ast); - llvm::Expected ret_or_error = delegate_sp->Import(type); + llvm::Expected ret_or_error = delegate_sp->Import(src_qual_type); if (!ret_or_error) { Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); LLDB_LOG_ERROR(log, ret_or_error.takeError(), "Couldn't import type: {0}"); - return QualType(); + return CompilerType(); } - return *ret_or_error; -} -lldb::opaque_compiler_type_t -ClangASTImporter::CopyType(clang::ASTContext *dst_ast, - clang::ASTContext *src_ast, - lldb::opaque_compiler_type_t type) { - return CopyType(dst_ast, src_ast, QualType::getFromOpaquePtr(type)) - .getAsOpaquePtr(); -} + lldb::opaque_compiler_type_t dst_clang_type = ret_or_error->getAsOpaquePtr(); -CompilerType ClangASTImporter::CopyType(ClangASTContext &dst_ast, - const CompilerType &src_type) { - clang::ASTContext *dst_clang_ast = dst_ast.getASTContext(); - if (dst_clang_ast) { - ClangASTContext *src_ast = - llvm::dyn_cast_or_null(src_type.GetTypeSystem()); - if (src_ast) { - clang::ASTContext *src_clang_ast = src_ast->getASTContext(); - if (src_clang_ast) { - lldb::opaque_compiler_type_t dst_clang_type = CopyType( - dst_clang_ast, src_clang_ast, src_type.GetOpaqueQualType()); - - if (dst_clang_type) - return CompilerType(&dst_ast, dst_clang_type); - } - } - } + if (dst_clang_type) + return CompilerType(&dst_ast, dst_clang_type); return CompilerType(); } @@ -306,34 +296,27 @@ public: }; } // namespace -lldb::opaque_compiler_type_t -ClangASTImporter::DeportType(clang::ASTContext *dst_ctx, - clang::ASTContext *src_ctx, - lldb::opaque_compiler_type_t type) { +CompilerType ClangASTImporter::DeportType(ClangASTContext &dst, + const CompilerType &src_type) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - LLDB_LOGF(log, - " [ClangASTImporter] DeportType called on (%sType*)0x%llx " - "from (ASTContext*)%p to (ASTContext*)%p", - QualType::getFromOpaquePtr(type)->getTypeClassName(), - (unsigned long long)type, static_cast(src_ctx), - static_cast(dst_ctx)); + ClangASTContext *src_ctxt = + llvm::cast(src_type.GetTypeSystem()); + + LLDB_LOG(log, + " [ClangASTImporter] DeportType called on ({0}Type*){1:x} " + "from (ASTContext*){2:x} to (ASTContext*){3:x}", + src_type.GetTypeName(), src_type.GetOpaqueQualType(), + src_ctxt->getASTContext(), dst.getASTContext()); DeclContextOverride decl_context_override; - if (auto *t = QualType::getFromOpaquePtr(type)->getAs()) + if (auto *t = ClangUtil::GetQualType(src_type)->getAs()) decl_context_override.OverrideAllDeclsFromContainingFunction(t->getDecl()); - lldb::opaque_compiler_type_t result; - { - CompleteTagDeclsScope complete_scope(*this, dst_ctx, src_ctx); - result = CopyType(dst_ctx, src_ctx, type); - } - - if (!result) - return nullptr; - - return result; + CompleteTagDeclsScope complete_scope(*this, dst.getASTContext(), + src_ctxt->getASTContext()); + return CopyType(dst, src_type); } clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx, -- 2.7.4