[Lldb-commits] [lldb] 49b206f - [lldb][NFC] Remove all ASTContext getter wrappers from ClangASTContext
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Sat Dec 21 06:47:52 PST 2019
Author: Raphael Isemann
Date: 2019-12-21T15:41:18+01:00
New Revision: 49b206f95806f35ff8f9a715185355fc2a159760
URL: https://github.com/llvm/llvm-project/commit/49b206f95806f35ff8f9a715185355fc2a159760
DIFF: https://github.com/llvm/llvm-project/commit/49b206f95806f35ff8f9a715185355fc2a159760.diff
LOG: [lldb][NFC] Remove all ASTContext getter wrappers from ClangASTContext
Their naming is misleading as they only return the
ClangASTContext-owned variables. For ClangASTContext instances constructed
for a given clang::ASTContext they silently generated duplicated instances
(e.g., a second IdentifierTable) that were essentially unusable.
This removes all these getters as they are anyway not very useful in comparison
to just calling the clang::ASTContext getters. The initialization
code has been moved to the CreateASTContext initialization method so that all
code for making our own clang::ASTContext is in one place.
Added:
Modified:
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/source/Symbol/ClangASTContext.cpp
lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
Removed:
################################################################################
diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h
index 6cebd6f3b62a..e5dc77504afb 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -102,22 +102,6 @@ class ClangASTContext : public TypeSystem {
clang::ASTContext *getASTContext();
- clang::Builtin::Context *getBuiltinContext();
-
- clang::IdentifierTable *getIdentifierTable();
-
- clang::LangOptions *getLanguageOptions();
-
- clang::SelectorTable *getSelectorTable();
-
- clang::FileManager *getFileManager();
-
- clang::SourceManager *getSourceManager();
-
- clang::DiagnosticsEngine *getDiagnosticsEngine();
-
- clang::DiagnosticConsumer *getDiagnosticConsumer();
-
clang::MangleContext *getMangleContext();
std::shared_ptr<clang::TargetOptions> &getTargetOptions();
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index e326d239cb55..e044a4d33b42 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -56,12 +56,10 @@ ClangASTSource::ClangASTSource(const lldb::TargetSP &target,
m_ast_importer_sp = importer;
}
-void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context,
- clang::FileManager &file_manager,
- bool is_shared_context) {
+void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context) {
m_ast_context = clang_ast_context.getASTContext();
m_clang_ast_context = &clang_ast_context;
- m_file_manager = &file_manager;
+ m_file_manager = &m_ast_context->getSourceManager().getFileManager();
m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this);
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
index e0442aeca326..609b182ed61a 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
@@ -60,9 +60,7 @@ class ClangASTSource : public ClangExternalASTSourceCommon,
}
void MaterializeVisibleDecls(const clang::DeclContext *DC) { return; }
- void InstallASTContext(ClangASTContext &ast_context,
- clang::FileManager &file_manager,
- bool is_shared_context = false);
+ void InstallASTContext(ClangASTContext &ast_context);
//
// APIs for ExternalASTSource
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 15b242a8b87e..ebd2d5c1644b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -997,7 +997,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
} else {
ast_context.setExternalSource(ast_source);
}
- decl_map->InstallASTContext(*m_ast_context, m_compiler->getFileManager());
+ decl_map->InstallASTContext(*m_ast_context);
}
// Check that the ASTReader is properly attached to ASTContext and Sema.
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 2e66b9a06c64..65b95089b931 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -571,9 +571,7 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
new ClangASTContextForExpressions(*target, fixed_arch));
ast_sp->m_scratch_ast_source_up.reset(new ClangASTSource(
target->shared_from_this(), target->GetClangASTImporter()));
- lldbassert(ast_sp->getFileManager());
- ast_sp->m_scratch_ast_source_up->InstallASTContext(
- *ast_sp, *ast_sp->getFileManager(), true);
+ ast_sp->m_scratch_ast_source_up->InstallASTContext(*ast_sp);
llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(
ast_sp->m_scratch_ast_source_up->CreateProxy());
ast_sp->SetExternalSource(proxy_ast_source);
@@ -663,14 +661,60 @@ ASTContext *ClangASTContext::getASTContext() {
return m_ast_up.get();
}
+class NullDiagnosticConsumer : public DiagnosticConsumer {
+public:
+ NullDiagnosticConsumer() {
+ m_log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
+ }
+
+ void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+ const clang::Diagnostic &info) override {
+ if (m_log) {
+ llvm::SmallVector<char, 32> diag_str(10);
+ info.FormatDiagnostic(diag_str);
+ diag_str.push_back('\0');
+ LLDB_LOGF(m_log, "Compiler diagnostic: %s\n", diag_str.data());
+ }
+ }
+
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
+ return new NullDiagnosticConsumer();
+ }
+
+private:
+ Log *m_log;
+};
+
void ClangASTContext::CreateASTContext() {
assert(!m_ast_up);
m_ast_owned = true;
- m_ast_up.reset(new ASTContext(*getLanguageOptions(), *getSourceManager(),
- *getIdentifierTable(), *getSelectorTable(),
- *getBuiltinContext()));
- m_ast_up->getDiagnostics().setClient(getDiagnosticConsumer(), false);
+ m_language_options_up.reset(new LangOptions());
+ ParseLangArgs(*m_language_options_up, clang::Language::ObjCXX,
+ GetTargetTriple());
+
+ m_identifier_table_up.reset(
+ new IdentifierTable(*m_language_options_up, nullptr));
+ m_builtins_up.reset(new Builtin::Context());
+
+ m_selector_table_up.reset(new SelectorTable());
+
+ clang::FileSystemOptions file_system_options;
+ m_file_manager_up.reset(new clang::FileManager(
+ file_system_options, FileSystem::Instance().GetVirtualFileSystem()));
+
+ llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs());
+ m_diagnostics_engine_up.reset(
+ new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions()));
+
+ m_source_manager_up.reset(
+ new clang::SourceManager(*m_diagnostics_engine_up, *m_file_manager_up));
+ m_ast_up.reset(new ASTContext(*m_language_options_up, *m_source_manager_up,
+ *m_identifier_table_up, *m_selector_table_up,
+ *m_builtins_up));
+
+ m_diagnostic_consumer_up.reset(new NullDiagnosticConsumer);
+ m_ast_up->getDiagnostics().setClient(m_diagnostic_consumer_up.get(), false);
// This can be NULL if we don't know anything about the architecture or if
// the target for an architecture isn't enabled in the llvm/clang that we
@@ -699,97 +743,12 @@ ClangASTContext *ClangASTContext::GetASTContext(clang::ASTContext *ast) {
return clang_ast;
}
-Builtin::Context *ClangASTContext::getBuiltinContext() {
- if (m_builtins_up == nullptr)
- m_builtins_up.reset(new Builtin::Context());
- return m_builtins_up.get();
-}
-
-IdentifierTable *ClangASTContext::getIdentifierTable() {
- if (m_identifier_table_up == nullptr)
- m_identifier_table_up.reset(
- new IdentifierTable(*ClangASTContext::getLanguageOptions(), nullptr));
- return m_identifier_table_up.get();
-}
-
-LangOptions *ClangASTContext::getLanguageOptions() {
- if (m_language_options_up == nullptr) {
- m_language_options_up.reset(new LangOptions());
- ParseLangArgs(*m_language_options_up, clang::Language::ObjCXX,
- GetTargetTriple());
- // InitializeLangOptions(*m_language_options_up, Language::ObjCXX);
- }
- return m_language_options_up.get();
-}
-
-SelectorTable *ClangASTContext::getSelectorTable() {
- if (m_selector_table_up == nullptr)
- m_selector_table_up.reset(new SelectorTable());
- return m_selector_table_up.get();
-}
-
-clang::FileManager *ClangASTContext::getFileManager() {
- if (m_file_manager_up == nullptr) {
- clang::FileSystemOptions file_system_options;
- m_file_manager_up.reset(new clang::FileManager(
- file_system_options, FileSystem::Instance().GetVirtualFileSystem()));
- }
- return m_file_manager_up.get();
-}
-
-clang::SourceManager *ClangASTContext::getSourceManager() {
- if (m_source_manager_up == nullptr)
- m_source_manager_up.reset(
- new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager()));
- return m_source_manager_up.get();
-}
-
-clang::DiagnosticsEngine *ClangASTContext::getDiagnosticsEngine() {
- if (m_diagnostics_engine_up == nullptr) {
- llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs());
- m_diagnostics_engine_up.reset(
- new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions()));
- }
- return m_diagnostics_engine_up.get();
-}
-
clang::MangleContext *ClangASTContext::getMangleContext() {
if (m_mangle_ctx_up == nullptr)
m_mangle_ctx_up.reset(getASTContext()->createMangleContext());
return m_mangle_ctx_up.get();
}
-class NullDiagnosticConsumer : public DiagnosticConsumer {
-public:
- NullDiagnosticConsumer() {
- m_log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
- }
-
- void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
- const clang::Diagnostic &info) override {
- if (m_log) {
- llvm::SmallVector<char, 32> diag_str(10);
- info.FormatDiagnostic(diag_str);
- diag_str.push_back('\0');
- LLDB_LOGF(m_log, "Compiler diagnostic: %s\n", diag_str.data());
- }
- }
-
- DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
- return new NullDiagnosticConsumer();
- }
-
-private:
- Log *m_log;
-};
-
-DiagnosticConsumer *ClangASTContext::getDiagnosticConsumer() {
- if (m_diagnostic_consumer_up == nullptr)
- m_diagnostic_consumer_up.reset(new NullDiagnosticConsumer);
-
- return m_diagnostic_consumer_up.get();
-}
-
std::shared_ptr<clang::TargetOptions> &ClangASTContext::getTargetOptions() {
if (m_target_options_rp == nullptr && !m_target_triple.empty()) {
m_target_options_rp = std::make_shared<clang::TargetOptions>();
@@ -802,8 +761,8 @@ std::shared_ptr<clang::TargetOptions> &ClangASTContext::getTargetOptions() {
TargetInfo *ClangASTContext::getTargetInfo() {
// target_triple should be something like "x86_64-apple-macosx"
if (m_target_info_up == nullptr && !m_target_triple.empty())
- m_target_info_up.reset(TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(),
- getTargetOptions()));
+ m_target_info_up.reset(TargetInfo::CreateTargetInfo(
+ getASTContext()->getDiagnostics(), getTargetOptions()));
return m_target_info_up.get();
}
diff --git a/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp b/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
index d94b1d4052fb..12ba5fc1592f 100644
--- a/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
+++ b/lldb/unittests/Expression/ClangExpressionDeclMapTest.cpp
@@ -75,7 +75,7 @@ struct ClangExpressionDeclMapTest : public testing::Test {
importer = std::make_shared<ClangASTImporter>();
decl_map = std::make_unique<FakeClangExpressionDeclMap>(importer);
target_ast = clang_utils::createAST();
- decl_map->InstallASTContext(*target_ast, *target_ast->getFileManager());
+ decl_map->InstallASTContext(*target_ast);
}
void TearDown() override {
diff --git a/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h b/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
index b1b1f30e2f6d..f9590825e075 100644
--- a/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
+++ b/lldb/unittests/TestingSupport/Symbol/ClangTestUtils.h
@@ -17,7 +17,7 @@ namespace lldb_private {
namespace clang_utils {
inline clang::DeclarationName getDeclarationName(ClangASTContext &ast,
llvm::StringRef name) {
- clang::IdentifierInfo &II = ast.getIdentifierTable()->get(name);
+ clang::IdentifierInfo &II = ast.getASTContext()->Idents.get(name);
return ast.getASTContext()->DeclarationNames.getIdentifier(&II);
}
More information about the lldb-commits
mailing list