From 6be76f491fcbb2a8476e58cb8d3310155c71e74a Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Fri, 20 Dec 2019 18:44:39 +0100 Subject: [PATCH] [lldb][NFC] Remove redundant ASTContext args to CopyDecl/DeportDecl We already pass a Decl here and the additional ASTContext needs to match the Decl. We might as well just pass the Decl and then extract the ASTContext from that. --- lldb/include/lldb/Symbol/ClangASTImporter.h | 6 ++---- .../ExpressionParser/Clang/ASTResultSynthesizer.cpp | 3 +-- .../Plugins/ExpressionParser/Clang/ClangASTSource.cpp | 3 +-- lldb/source/Symbol/ClangASTImporter.cpp | 6 +++--- .../Expression/ClangExpressionDeclMapTest.cpp | 6 +----- lldb/unittests/Symbol/TestClangASTImporter.cpp | 18 ++++++------------ 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/lldb/include/lldb/Symbol/ClangASTImporter.h b/lldb/include/lldb/Symbol/ClangASTImporter.h index 9c0a95b..faec3a7 100644 --- a/lldb/include/lldb/Symbol/ClangASTImporter.h +++ b/lldb/include/lldb/Symbol/ClangASTImporter.h @@ -50,13 +50,11 @@ public: CompilerType CopyType(ClangASTContext &dst, const CompilerType &src_type); - clang::Decl *CopyDecl(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, - clang::Decl *decl); + clang::Decl *CopyDecl(clang::ASTContext *dst_ctx, clang::Decl *decl); CompilerType DeportType(ClangASTContext &dst, const CompilerType &src_type); - clang::Decl *DeportDecl(clang::ASTContext *dst_ctx, - clang::ASTContext *src_ctx, clang::Decl *decl); + clang::Decl *DeportDecl(clang::ASTContext *dst_ctx, clang::Decl *decl); /// Sets the layout for the given RecordDecl. The layout will later be /// used by Clang's during code generation. Not calling this function for diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp index 24dc726..6d6830c 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp @@ -453,8 +453,7 @@ void ASTResultSynthesizer::CommitPersistentDecls() { ConstString name_cs(name.str().c_str()); Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl( - ClangASTContext::GetScratch(m_target)->getASTContext(), m_ast_context, - decl); + ClangASTContext::GetScratch(m_target)->getASTContext(), decl); if (!D_scratch) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index f37fe21..e326d23 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -1823,9 +1823,8 @@ NamespaceDecl *ClangASTSource::AddNamespace( } clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) { - clang::ASTContext &from_context = src_decl->getASTContext(); if (m_ast_importer_sp) { - return m_ast_importer_sp->CopyDecl(m_ast_context, &from_context, src_decl); + return m_ast_importer_sp->CopyDecl(m_ast_context, src_decl); } else { lldbassert(0 && "No mechanism for copying a decl!"); return nullptr; diff --git a/lldb/source/Symbol/ClangASTImporter.cpp b/lldb/source/Symbol/ClangASTImporter.cpp index d856443..7bdbe2b 100644 --- a/lldb/source/Symbol/ClangASTImporter.cpp +++ b/lldb/source/Symbol/ClangASTImporter.cpp @@ -65,10 +65,10 @@ CompilerType ClangASTImporter::CopyType(ClangASTContext &dst_ast, } clang::Decl *ClangASTImporter::CopyDecl(clang::ASTContext *dst_ast, - clang::ASTContext *src_ast, clang::Decl *decl) { ImporterDelegateSP delegate_sp; + clang::ASTContext *src_ast = &decl->getASTContext(); delegate_sp = GetDelegate(dst_ast, src_ast); ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast); @@ -320,10 +320,10 @@ CompilerType ClangASTImporter::DeportType(ClangASTContext &dst, } clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx, - clang::ASTContext *src_ctx, clang::Decl *decl) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + clang::ASTContext *src_ctx = &decl->getASTContext(); LLDB_LOGF(log, " [ClangASTImporter] DeportDecl called on (%sDecl*)%p from " "(ASTContext*)%p to (ASTContext*)%p", @@ -337,7 +337,7 @@ clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx, clang::Decl *result; { CompleteTagDeclsScope complete_scope(*this, dst_ctx, src_ctx); - result = CopyDecl(dst_ctx, src_ctx, decl); + result = CopyDecl(dst_ctx, decl); } if (!result) diff --git a/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp b/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp index 36d45fe..d94b1d4 100644 --- a/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp +++ b/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp @@ -18,16 +18,12 @@ using namespace lldb_private; using namespace lldb; -static std::unique_ptr createAST() { - return std::make_unique(HostInfo::GetTargetTriple()); -} - namespace { struct FakeClangExpressionDeclMap : public ClangExpressionDeclMap { FakeClangExpressionDeclMap(const ClangASTImporterSP &importer) : ClangExpressionDeclMap(false, nullptr, lldb::TargetSP(), importer, nullptr) { - m_scratch_context = createAST(); + m_scratch_context = clang_utils::createAST(); } std::unique_ptr m_scratch_context; /// Adds a persistent decl that can be found by the ClangExpressionDeclMap diff --git a/lldb/unittests/Symbol/TestClangASTImporter.cpp b/lldb/unittests/Symbol/TestClangASTImporter.cpp index 126484e..ce4bdab 100644 --- a/lldb/unittests/Symbol/TestClangASTImporter.cpp +++ b/lldb/unittests/Symbol/TestClangASTImporter.cpp @@ -80,8 +80,7 @@ TEST_F(TestClangASTImporter, CopyDeclTagDecl) { ClangASTImporter importer; clang::Decl *imported = - importer.CopyDecl(target_ast->getASTContext(), - source.ast->getASTContext(), source.record_decl); + importer.CopyDecl(target_ast->getASTContext(), source.record_decl); ASSERT_NE(nullptr, imported); // Check that we got the correct decl by just comparing their qualified name. @@ -131,8 +130,7 @@ TEST_F(TestClangASTImporter, DeportDeclTagDecl) { ClangASTImporter importer; clang::Decl *imported = - importer.DeportDecl(target_ast->getASTContext(), - source.ast->getASTContext(), source.record_decl); + importer.DeportDecl(target_ast->getASTContext(), source.record_decl); ASSERT_NE(nullptr, imported); // Check that we got the correct decl by just comparing their qualified name. @@ -179,8 +177,7 @@ TEST_F(TestClangASTImporter, MetadataPropagation) { ClangASTImporter importer; clang::Decl *imported = - importer.CopyDecl(target_ast->getASTContext(), - source.ast->getASTContext(), source.record_decl); + importer.CopyDecl(target_ast->getASTContext(), source.record_decl); ASSERT_NE(nullptr, imported); // Check that we got the same Metadata. @@ -202,14 +199,12 @@ TEST_F(TestClangASTImporter, MetadataPropagationIndirectImport) { ClangASTImporter importer; clang::Decl *temporary_imported = - importer.CopyDecl(temporary_ast->getASTContext(), - source.ast->getASTContext(), source.record_decl); + importer.CopyDecl(temporary_ast->getASTContext(), source.record_decl); ASSERT_NE(nullptr, temporary_imported); std::unique_ptr target_ast = createAST(); clang::Decl *imported = - importer.CopyDecl(target_ast->getASTContext(), - temporary_ast->getASTContext(), temporary_imported); + importer.CopyDecl(target_ast->getASTContext(), temporary_imported); ASSERT_NE(nullptr, imported); // Check that we got the same Metadata. @@ -228,8 +223,7 @@ TEST_F(TestClangASTImporter, MetadataPropagationAfterCopying) { ClangASTImporter importer; clang::Decl *imported = - importer.CopyDecl(target_ast->getASTContext(), - source.ast->getASTContext(), source.record_decl); + importer.CopyDecl(target_ast->getASTContext(), source.record_decl); ASSERT_NE(nullptr, imported); // The TagDecl has been imported. Now set the metadata of the source and -- 2.7.4