[lldb] Remove ClangASTImporter from Target
Target is one of the classes responsible for vending ClangASTImporter.
Target doesn't need to know anything about ClangASTImporter, so if we
instead have ClangPersistentVariables vend it, we can preserve
existing behavior while improving layering and removing dependencies
from non-plugins to plugins.
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
index f7d4f17..7b2acb4 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp
@@ -459,7 +459,7 @@
StringRef name = decl->getName();
ConstString name_cs(name.str().c_str());
- Decl *D_scratch = m_target.GetClangASTImporter()->DeportDecl(
+ Decl *D_scratch = persistent_vars->GetClangASTImporter()->DeportDecl(
&scratch_ctx->getASTContext(), decl);
if (!D_scratch) {
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
index e3ada1c..f847dc9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
@@ -9,6 +9,7 @@
#include "ClangPersistentVariables.h"
#include "lldb/Core/Value.h"
+#include "lldb/Symbol/ClangASTImporter.h"
#include "lldb/Symbol/TypeSystemClang.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataExtractor.h"
@@ -99,3 +100,10 @@
ClangPersistentVariables::GetPersistentDecl(ConstString name) {
return m_persistent_decls.lookup(name.GetCString()).m_decl;
}
+
+lldb::ClangASTImporterSP ClangPersistentVariables::GetClangASTImporter() {
+ if (!m_ast_importer_sp) {
+ m_ast_importer_sp = std::make_shared<ClangASTImporter>();
+ }
+ return m_ast_importer_sp;
+}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
index 2ebe1c7..b72e43a 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
@@ -36,6 +36,8 @@
return pv->getKind() == PersistentExpressionState::eKindClang;
}
+ lldb::ClangASTImporterSP GetClangASTImporter();
+
lldb::ExpressionVariableSP
CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
@@ -96,6 +98,7 @@
m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
///these are the highest-
///< priority source for macros.
+ lldb::ClangASTImporterSP m_ast_importer_sp;
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
index 06c3ea9..2fca504 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -896,9 +896,16 @@
Materializer::PersistentVariableDelegate &delegate,
bool keep_result_in_memory,
ValueObject *ctx_obj) {
- m_expr_decl_map_up.reset(new ClangExpressionDeclMap(
- keep_result_in_memory, &delegate, exe_ctx.GetTargetSP(),
- exe_ctx.GetTargetRef().GetClangASTImporter(), ctx_obj));
+ lldb::ClangASTImporterSP ast_importer;
+ auto *state = exe_ctx.GetTargetSP()->GetPersistentExpressionStateForLanguage(
+ lldb::eLanguageTypeC);
+ if (state) {
+ auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
+ ast_importer = persistent_vars->GetClangASTImporter();
+ }
+ m_expr_decl_map_up.reset(
+ new ClangExpressionDeclMap(keep_result_in_memory, &delegate,
+ exe_ctx.GetTargetSP(), ast_importer, ctx_obj));
}
clang::ASTConsumer *
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
index 010c8d9..5e97e95 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
@@ -12,6 +12,7 @@
#include "ClangExpressionDeclMap.h"
#include "ClangExpressionParser.h"
#include "ClangExpressionSourceCode.h"
+#include "ClangPersistentVariables.h"
#include <stdio.h>
#if HAVE_SYS_TYPES_H
@@ -159,7 +160,14 @@
void ClangUtilityFunction::ClangUtilityFunctionHelper::ResetDeclMap(
ExecutionContext &exe_ctx, bool keep_result_in_memory) {
- m_expr_decl_map_up.reset(new ClangExpressionDeclMap(
- keep_result_in_memory, nullptr, exe_ctx.GetTargetSP(),
- exe_ctx.GetTargetRef().GetClangASTImporter(), nullptr));
+ lldb::ClangASTImporterSP ast_importer;
+ auto *state = exe_ctx.GetTargetSP()->GetPersistentExpressionStateForLanguage(
+ lldb::eLanguageTypeC);
+ if (state) {
+ auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
+ ast_importer = persistent_vars->GetClangASTImporter();
+ }
+ m_expr_decl_map_up.reset(
+ new ClangExpressionDeclMap(keep_result_in_memory, nullptr,
+ exe_ctx.GetTargetSP(), ast_importer, nullptr));
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
index 986e799..43b2cad 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -8,14 +8,14 @@
#include "BlockPointer.h"
+#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
-#include "lldb/Symbol/TypeSystemClang.h"
#include "lldb/Symbol/ClangASTImporter.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/TypeSystem.h"
+#include "lldb/Symbol/TypeSystemClang.h"
#include "lldb/Target/Target.h"
-
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Log.h"
@@ -56,7 +56,13 @@
return;
}
- ClangASTImporterSP clang_ast_importer = target_sp->GetClangASTImporter();
+ lldb::ClangASTImporterSP clang_ast_importer;
+ auto *state = target_sp->GetPersistentExpressionStateForLanguage(
+ lldb::eLanguageTypeC_plus_plus);
+ if (state) {
+ auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
+ clang_ast_importer = persistent_vars->GetClangASTImporter();
+ }
if (!clang_ast_importer) {
return;