[Lldb-commits] [lldb] 6be76f4 - [lldb][NFC] Remove redundant ASTContext args to CopyDecl/DeportDecl
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 20 09:45:35 PST 2019
Author: Raphael Isemann
Date: 2019-12-20T18:45:14+01:00
New Revision: 6be76f491fcbb2a8476e58cb8d3310155c71e74a
URL: https://github.com/llvm/llvm-project/commit/6be76f491fcbb2a8476e58cb8d3310155c71e74a
DIFF: https://github.com/llvm/llvm-project/commit/6be76f491fcbb2a8476e58cb8d3310155c71e74a.diff
LOG: [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.
Added:
Modified:
lldb/include/lldb/Symbol/ClangASTImporter.h
lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Symbol/ClangASTImporter.cpp
lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
lldb/unittests/Symbol/TestClangASTImporter.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Symbol/ClangASTImporter.h b/lldb/include/lldb/Symbol/ClangASTImporter.h
index 9c0a95beb1e8..faec3a77b56f 100644
--- a/lldb/include/lldb/Symbol/ClangASTImporter.h
+++ b/lldb/include/lldb/Symbol/ClangASTImporter.h
@@ -50,13 +50,11 @@ class ClangASTImporter {
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 24dc7268976d..6d6830c740d1 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 f37fe21b5545..e326d239cb55 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 d856443b268a..7bdbe2bcc1dc 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 36d45fe5a58f..d94b1d4052fb 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 126484e8d047..ce4bdab6cfb8 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<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 @@ 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
More information about the lldb-commits
mailing list