[Lldb-commits] [lldb] 8968183 - [lldb][ClangASTImporter][NFC] Factor out completion logic out of ClangASTImporterDelegate
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 13 02:22:41 PDT 2025
Author: Michael Buch
Date: 2025-08-13T10:22:23+01:00
New Revision: 89681839e367476e0ff66bec3a3931e1c41c7cb4
URL: https://github.com/llvm/llvm-project/commit/89681839e367476e0ff66bec3a3931e1c41c7cb4
DIFF: https://github.com/llvm/llvm-project/commit/89681839e367476e0ff66bec3a3931e1c41c7cb4.diff
LOG: [lldb][ClangASTImporter][NFC] Factor out completion logic out of ClangASTImporterDelegate
Upstreams two helpers that make this more readable.
Added:
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 624eea91b48f2..8a39fae9498c0 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -235,6 +235,35 @@ class CompleteTagDeclsScope : public ClangASTImporter::NewDeclListener {
clang::ASTContext *m_src_ctx;
ClangASTImporter &importer;
+ void CompleteDecl(
+ Decl *decl,
+ lldb_private::ClangASTImporter::ASTContextMetadata const &to_context_md) {
+ // The decl that should be completed has to be imported into the target
+ // context from some other context.
+ assert(to_context_md.hasOrigin(decl));
+ // We should only complete decls coming from the source context.
+ assert(to_context_md.getOrigin(decl).ctx == m_src_ctx);
+
+ Decl *original_decl = to_context_md.getOrigin(decl).decl;
+
+ // Complete the decl now.
+ TypeSystemClang::GetCompleteDecl(m_src_ctx, original_decl);
+ if (auto *tag_decl = dyn_cast<TagDecl>(decl)) {
+ if (auto *original_tag_decl = dyn_cast<TagDecl>(original_decl)) {
+ if (original_tag_decl->isCompleteDefinition()) {
+ m_delegate->ImportDefinitionTo(tag_decl, original_tag_decl);
+ tag_decl->setCompleteDefinition(true);
+ }
+ }
+
+ tag_decl->setHasExternalLexicalStorage(false);
+ tag_decl->setHasExternalVisibleStorage(false);
+ } else if (auto *container_decl = dyn_cast<ObjCContainerDecl>(decl)) {
+ container_decl->setHasExternalLexicalStorage(false);
+ container_decl->setHasExternalVisibleStorage(false);
+ }
+ }
+
public:
/// Constructs a CompleteTagDeclsScope.
/// \param importer The ClangASTImporter that we should observe.
@@ -257,30 +286,7 @@ class CompleteTagDeclsScope : public ClangASTImporter::NewDeclListener {
NamedDecl *decl = m_decls_to_complete.pop_back_val();
m_decls_already_completed.insert(decl);
- // The decl that should be completed has to be imported into the target
- // context from some other context.
- assert(to_context_md->hasOrigin(decl));
- // We should only complete decls coming from the source context.
- assert(to_context_md->getOrigin(decl).ctx == m_src_ctx);
-
- Decl *original_decl = to_context_md->getOrigin(decl).decl;
-
- // Complete the decl now.
- TypeSystemClang::GetCompleteDecl(m_src_ctx, original_decl);
- if (auto *tag_decl = dyn_cast<TagDecl>(decl)) {
- if (auto *original_tag_decl = dyn_cast<TagDecl>(original_decl)) {
- if (original_tag_decl->isCompleteDefinition()) {
- m_delegate->ImportDefinitionTo(tag_decl, original_tag_decl);
- tag_decl->setCompleteDefinition(true);
- }
- }
-
- tag_decl->setHasExternalLexicalStorage(false);
- tag_decl->setHasExternalVisibleStorage(false);
- } else if (auto *container_decl = dyn_cast<ObjCContainerDecl>(decl)) {
- container_decl->setHasExternalLexicalStorage(false);
- container_decl->setHasExternalVisibleStorage(false);
- }
+ CompleteDecl(decl, *to_context_md);
to_context_md->removeOrigin(decl);
}
@@ -1370,6 +1376,18 @@ void ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
from, m_source_ctx, &to->getASTContext());
}
+ if (auto *to_namespace_decl = dyn_cast<NamespaceDecl>(to)) {
+ m_main.BuildNamespaceMap(to_namespace_decl);
+ to_namespace_decl->setHasExternalVisibleStorage();
+ }
+
+ MarkDeclImported(from, to);
+}
+
+void ClangASTImporter::ASTImporterDelegate::MarkDeclImported(Decl *from,
+ Decl *to) {
+ Log *log = GetLog(LLDBLog::Expressions);
+
if (auto *to_tag_decl = dyn_cast<TagDecl>(to)) {
to_tag_decl->setHasExternalLexicalStorage();
to_tag_decl->getPrimaryContext()->setMustBuildLookupTable();
@@ -1384,11 +1402,6 @@ void ClangASTImporter::ASTImporterDelegate::Imported(clang::Decl *from,
(to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
}
- if (auto *to_namespace_decl = dyn_cast<NamespaceDecl>(to)) {
- m_main.BuildNamespaceMap(to_namespace_decl);
- to_namespace_decl->setHasExternalVisibleStorage();
- }
-
if (auto *to_container_decl = dyn_cast<ObjCContainerDecl>(to)) {
to_container_decl->setHasExternalLexicalStorage();
to_container_decl->setHasExternalVisibleStorage();
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
index 47b137a1314f8..1c77c5bb4a47b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h
@@ -346,6 +346,8 @@ class ClangASTImporter {
llvm::Expected<clang::Decl *> ImportImpl(clang::Decl *From) override;
private:
+ void MarkDeclImported(clang::Decl *from, clang::Decl *to);
+
/// Decls we should ignore when mapping decls back to their original
/// ASTContext. Used by the CxxModuleHandler to mark declarations that
/// were created from the 'std' C++ module to prevent that the Importer
More information about the lldb-commits
mailing list