[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.
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 @@
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 @@
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 @@
}
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 @@
}
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 @@
}
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 *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<ClangASTContext> createAST() {
- return std::make_unique<ClangASTContext>(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<ClangASTContext> 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 @@
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 @@
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 @@
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 @@
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<ClangASTContext> 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 @@
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