diff options
Diffstat (limited to 'include/lldb/Symbol/ClangASTImporter.h')
-rw-r--r-- | include/lldb/Symbol/ClangASTImporter.h | 106 |
1 files changed, 81 insertions, 25 deletions
diff --git a/include/lldb/Symbol/ClangASTImporter.h b/include/lldb/Symbol/ClangASTImporter.h index 465d7e24a1e71..353b1232d9404 100644 --- a/include/lldb/Symbol/ClangASTImporter.h +++ b/include/lldb/Symbol/ClangASTImporter.h @@ -1,9 +1,8 @@ //===-- ClangASTImporter.h --------------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -22,7 +21,9 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Symbol/CompilerDeclContext.h" +#include "lldb/Symbol/CxxModuleHandler.h" #include "lldb/lldb-types.h" #include "llvm/ADT/DenseMap.h" @@ -94,7 +95,9 @@ public: vbase_offsets; }; - ClangASTImporter() : m_file_manager(clang::FileSystemOptions()) {} + ClangASTImporter() + : m_file_manager(clang::FileSystemOptions(), + FileSystem::Instance().GetVirtualFileSystem()) {} clang::QualType CopyType(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, clang::QualType type); @@ -185,7 +188,7 @@ public: virtual ~MapCompleter(); virtual void CompleteNamespaceMap(NamespaceMapSP &namespace_map, - const ConstString &name, + ConstString name, NamespaceMapSP &parent_map) const = 0; }; @@ -232,16 +235,61 @@ private: typedef std::map<const clang::Decl *, DeclOrigin> OriginMap; - class Minion : public clang::ASTImporter { + /// ASTImporter that intercepts and records the import process of the + /// underlying ASTImporter. + /// + /// This class updates the map from declarations to their original + /// declarations and can record and complete declarations that have been + /// imported in a certain interval. + /// + /// When intercepting a declaration import, the ASTImporterDelegate uses the + /// CxxModuleHandler to replace any missing or malformed declarations with + /// their counterpart from a C++ module. + class ASTImporterDelegate : public clang::ASTImporter { public: - Minion(ClangASTImporter &master, clang::ASTContext *target_ctx, - clang::ASTContext *source_ctx) + ASTImporterDelegate(ClangASTImporter &master, clang::ASTContext *target_ctx, + clang::ASTContext *source_ctx) : clang::ASTImporter(*target_ctx, master.m_file_manager, *source_ctx, master.m_file_manager, true /*minimal*/), m_decls_to_deport(nullptr), m_decls_already_deported(nullptr), m_master(master), m_source_ctx(source_ctx) {} - // A call to "InitDeportWorkQueues" puts the minion into deport mode. + /// Scope guard that attaches a CxxModuleHandler to an ASTImporterDelegate + /// and deattaches it at the end of the scope. Supports being used multiple + /// times on the same ASTImporterDelegate instance in nested scopes. + class CxxModuleScope { + /// The handler we attach to the ASTImporterDelegate. + CxxModuleHandler m_handler; + /// The ASTImporterDelegate we are supposed to attach the handler to. + ASTImporterDelegate &m_delegate; + /// True iff we attached the handler to the ASTImporterDelegate. + bool m_valid = false; + + public: + CxxModuleScope(ASTImporterDelegate &delegate, clang::ASTContext *dst_ctx) + : m_delegate(delegate) { + // If the delegate doesn't have a CxxModuleHandler yet, create one + // and attach it. + if (!delegate.m_std_handler) { + m_handler = CxxModuleHandler(delegate, dst_ctx); + m_valid = true; + delegate.m_std_handler = &m_handler; + } + } + ~CxxModuleScope() { + if (m_valid) { + // Make sure no one messed with the handler we placed. + assert(m_delegate.m_std_handler == &m_handler); + m_delegate.m_std_handler = nullptr; + } + } + }; + + protected: + llvm::Expected<clang::Decl *> ImportImpl(clang::Decl *From) override; + + public: + // A call to "InitDeportWorkQueues" puts the delegate into deport mode. // In deport mode, every copied Decl that could require completion is // recorded and placed into the decls_to_deport set. // @@ -249,8 +297,8 @@ private: // are in decls_to_deport, adding any Decls it sees along the way that it // hasn't already deported. It proceeds until decls_to_deport is empty. // - // These calls must be paired. Leaving a minion in deport mode or trying - // to start deport minion with a new pair of queues will result in an + // These calls must be paired. Leaving a delegate in deport mode or trying + // to start deport delegate with a new pair of queues will result in an // assertion failure. void @@ -260,28 +308,34 @@ private: void ImportDefinitionTo(clang::Decl *to, clang::Decl *from); - clang::Decl *Imported(clang::Decl *from, clang::Decl *to) override; + void Imported(clang::Decl *from, clang::Decl *to) override; clang::Decl *GetOriginalDecl(clang::Decl *To) override; + /// 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 + /// tries to sync them with the broken equivalent in the debug info AST. + std::set<clang::Decl *> m_decls_to_ignore; std::set<clang::NamedDecl *> *m_decls_to_deport; std::set<clang::NamedDecl *> *m_decls_already_deported; ClangASTImporter &m_master; clang::ASTContext *m_source_ctx; + CxxModuleHandler *m_std_handler = nullptr; }; - typedef std::shared_ptr<Minion> MinionSP; - typedef std::map<clang::ASTContext *, MinionSP> MinionMap; + typedef std::shared_ptr<ASTImporterDelegate> ImporterDelegateSP; + typedef std::map<clang::ASTContext *, ImporterDelegateSP> DelegateMap; typedef std::map<const clang::NamespaceDecl *, NamespaceMapSP> NamespaceMetaMap; struct ASTContextMetadata { ASTContextMetadata(clang::ASTContext *dst_ctx) - : m_dst_ctx(dst_ctx), m_minions(), m_origins(), m_namespace_maps(), + : m_dst_ctx(dst_ctx), m_delegates(), m_origins(), m_namespace_maps(), m_map_completer(nullptr) {} clang::ASTContext *m_dst_ctx; - MinionMap m_minions; + DelegateMap m_delegates; OriginMap m_origins; NamespaceMetaMap m_namespace_maps; @@ -316,18 +370,20 @@ private: return ASTContextMetadataSP(); } - MinionSP GetMinion(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx) { + ImporterDelegateSP GetDelegate(clang::ASTContext *dst_ctx, + clang::ASTContext *src_ctx) { ASTContextMetadataSP context_md = GetContextMetadata(dst_ctx); - MinionMap &minions = context_md->m_minions; - MinionMap::iterator minion_iter = minions.find(src_ctx); + DelegateMap &delegates = context_md->m_delegates; + DelegateMap::iterator delegate_iter = delegates.find(src_ctx); - if (minion_iter == minions.end()) { - MinionSP minion = MinionSP(new Minion(*this, dst_ctx, src_ctx)); - minions[src_ctx] = minion; - return minion; + if (delegate_iter == delegates.end()) { + ImporterDelegateSP delegate = + ImporterDelegateSP(new ASTImporterDelegate(*this, dst_ctx, src_ctx)); + delegates[src_ctx] = delegate; + return delegate; } else { - return minion_iter->second; + return delegate_iter->second; } } |