Author: Michael Buch Date: 2025-12-16T18:05:49Z New Revision: b2880eac7c09c1f3238d77c5a3356451178d7b8e
URL: https://github.com/llvm/llvm-project/commit/b2880eac7c09c1f3238d77c5a3356451178d7b8e DIFF: https://github.com/llvm/llvm-project/commit/b2880eac7c09c1f3238d77c5a3356451178d7b8e.diff LOG: [lldb][ClangASTSource][NFC] Clean up RegisterNamespaceMap (#172520) I've been trying to wrap my head around this code but there's a lot of action-at-a-distance going on which I'm having trouble following. This patch cleans up a small part of it. We were passing the `context`s namespace map as a separate mutable argument. But nothing in this function requires it to be mutable (and separate from the owning structure). This patch drops the redundant argument and passes the shared_ptr by value. Added: Modified: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h Removed: ################################################################################ diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp index e3b6ff8f17b4c..0a00335e5c9fb 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp @@ -969,10 +969,10 @@ void ClangASTImporter::SetDeclOrigin(const clang::Decl *decl, } void ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl, - NamespaceMapSP &namespace_map) { + NamespaceMapSP namespace_map) { ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); - context_md->m_namespace_maps[decl] = namespace_map; + context_md->m_namespace_maps[decl] = std::move(namespace_map); } ClangASTImporter::NamespaceMapSP diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h index 03d2556ca6f23..f13d8678f22b9 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h @@ -202,7 +202,7 @@ class ClangASTImporter { typedef std::shared_ptr<NamespaceMap> NamespaceMapSP; void RegisterNamespaceMap(const clang::NamespaceDecl *decl, - NamespaceMapSP &namespace_map); + NamespaceMapSP namespace_map); NamespaceMapSP GetNamespaceMap(const clang::NamespaceDecl *decl); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 0efeb2e68decb..65c8d3e1305aa 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -545,8 +545,7 @@ void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) { LLDB_LOG(log, " CAS::FEVD Registering namespace map {0:x} ({1} entries)", context.m_namespace_map.get(), context.m_namespace_map->size()); - NamespaceDecl *clang_namespace_decl = - AddNamespace(context, context.m_namespace_map); + NamespaceDecl *clang_namespace_decl = AddNamespace(context); if (clang_namespace_decl) clang_namespace_decl->setHasExternalVisibleStorage(); @@ -1432,13 +1431,12 @@ void ClangASTSource::CompleteNamespaceMap( } } -NamespaceDecl *ClangASTSource::AddNamespace( - NameSearchContext &context, - ClangASTImporter::NamespaceMapSP &namespace_decls) { - if (!namespace_decls) +NamespaceDecl *ClangASTSource::AddNamespace(NameSearchContext &context) { + if (!context.m_namespace_map) return nullptr; - const CompilerDeclContext &namespace_decl = namespace_decls->begin()->second; + const CompilerDeclContext &namespace_decl = + context.m_namespace_map->begin()->second; clang::ASTContext *src_ast = TypeSystemClang::DeclContextGetTypeSystemClang(namespace_decl); @@ -1463,7 +1461,7 @@ NamespaceDecl *ClangASTSource::AddNamespace( context.m_decls.push_back(copied_namespace_decl); m_ast_importer_sp->RegisterNamespaceMap(copied_namespace_decl, - namespace_decls); + context.m_namespace_map); return dyn_cast<NamespaceDecl>(copied_decl); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h index 2450635555eb6..33edc2d1eecc7 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h @@ -187,9 +187,7 @@ class ClangASTSource : public clang::ExternalASTSource, // Helper APIs // - clang::NamespaceDecl * - AddNamespace(NameSearchContext &context, - ClangASTImporter::NamespaceMapSP &namespace_decls); + clang::NamespaceDecl *AddNamespace(NameSearchContext &context); /// The worker function for FindExternalVisibleDeclsByName. /// _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
