9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H
10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H
17#include "clang/AST/ASTImporter.h"
18#include "clang/AST/CharUnits.h"
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclCXX.h"
21#include "clang/Basic/FileManager.h"
22#include "clang/Basic/FileSystemOptions.h"
31#include "llvm/ADT/DenseMap.h"
35class ClangASTMetadata;
68 typedef llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
80 FileSystem::Instance().GetVirtualFileSystem()) {}
97 clang::Decl *
CopyDecl(clang::ASTContext *dst_ctx, clang::Decl *decl);
110 clang::Decl *
DeportDecl(clang::ASTContext *dst_ctx, clang::Decl *decl);
119 void SetRecordLayout(clang::RecordDecl *decl,
const LayoutInfo &layout);
122 const clang::RecordDecl *record_decl, uint64_t &bit_size,
124 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
125 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
127 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
168 void SetDeclOrigin(
const clang::Decl *decl, clang::Decl *original_decl);
203 ContextMetadataMap::iterator context_md_iter =
m_metadata_map.find(dst_ctx);
209 context_md = context_md_iter->second;
212 context_md->m_map_completer = &completer;
216 void ForgetSource(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx);
224 assert(_decl ==
nullptr || &_decl->getASTContext() == _ctx);
239 clang::ASTContext *
ctx =
nullptr;
263 clang::ASTContext *source_ctx)
270 lldbassert(target_ctx != source_ctx &&
"Can't import into itself");
276 assert(target_ctx->getExternalSource() &&
"Missing ExternalSource");
277 setODRHandling(clang::ASTImporter::ODRHandlingType::Liberal);
313 void Imported(clang::Decl *from, clang::Decl *to)
override;
324 llvm::Expected<clang::Decl *>
ImportImpl(clang::Decl *From)
override;
340 typedef llvm::DenseMap<clang::ASTContext *, ImporterDelegateSP>
DelegateMap;
341 typedef llvm::DenseMap<const clang::NamespaceDecl *, NamespaceMapSP>
345 typedef llvm::DenseMap<const clang::Decl *, DeclOrigin>
OriginMap;
363 assert(&decl->getASTContext() != origin.
ctx &&
364 "Trying to set decl origin to its own ASTContext?");
365 assert(decl != origin.
decl &&
"Trying to set decl origin to itself?");
376 for (OriginMap::iterator iter =
m_origins.begin();
378 if (iter->second.ctx == ctx)
409 typedef llvm::DenseMap<const clang::ASTContext *, ASTContextMetadataSP>
415 ContextMetadataMap::iterator context_md_iter =
m_metadata_map.find(dst_ctx);
423 return context_md_iter->second;
427 ContextMetadataMap::iterator context_md_iter =
m_metadata_map.find(dst_ctx);
430 return context_md_iter->second;
435 clang::ASTContext *src_ctx) {
439 DelegateMap::iterator delegate_iter = delegates.find(src_ctx);
441 if (delegate_iter == delegates.end()) {
444 delegates[src_ctx] = delegate;
447 return delegate_iter->second;
453 typedef llvm::DenseMap<const clang::RecordDecl *, LayoutInfo>
void removeOrigin(const clang::Decl *decl)
Removes any tracked DeclOrigin for the given decl.
void removeOriginsWithContext(clang::ASTContext *ctx)
Remove all DeclOrigin entries that point to the given ASTContext.
void setOrigin(const clang::Decl *decl, DeclOrigin origin)
Sets the DeclOrigin for the given Decl and overwrites any existing DeclOrigin.
MapCompleter * m_map_completer
OriginMap m_origins
Maps declarations to the ASTContext/Decl from which they were imported from.
clang::ASTContext * m_dst_ctx
bool hasOrigin(const clang::Decl *decl) const
Returns true there is a known DeclOrigin for the given Decl.
llvm::DenseMap< const clang::Decl *, DeclOrigin > OriginMap
ASTContextMetadata(clang::ASTContext *dst_ctx)
NamespaceMetaMap m_namespace_maps
DeclOrigin getOrigin(const clang::Decl *decl) const
Returns the DeclOrigin for the given Decl or an invalid DeclOrigin instance if there no known DeclOri...
Scope guard that attaches a CxxModuleHandler to an ASTImporterDelegate and deattaches it at the end o...
bool m_valid
True iff we attached the handler to the ASTImporterDelegate.
CxxModuleScope(ASTImporterDelegate &delegate, clang::ASTContext *dst_ctx)
CxxModuleHandler m_handler
The handler we attach to the ASTImporterDelegate.
ASTImporterDelegate & m_delegate
The ASTImporterDelegate we are supposed to attach the handler to.
virtual void CompleteNamespaceMap(NamespaceMapSP &namespace_map, ConstString name, NamespaceMapSP &parent_map) const =0
Manages and observes all Clang AST node importing in LLDB.
bool CompleteTagDecl(clang::TagDecl *decl)
clang::Decl * DeportDecl(clang::ASTContext *dst_ctx, clang::Decl *decl)
Copies the given decl to the destination type system.
void BuildNamespaceMap(const clang::NamespaceDecl *decl)
void RegisterNamespaceMap(const clang::NamespaceDecl *decl, NamespaceMapSP &namespace_map)
void ForgetDestination(clang::ASTContext *dst_ctx)
CompilerType CopyType(TypeSystemClang &dst, const CompilerType &src_type)
Copies the given type and the respective declarations to the destination type system.
llvm::DenseMap< clang::ASTContext *, ImporterDelegateSP > DelegateMap
clang::Decl * CopyDecl(clang::ASTContext *dst_ctx, clang::Decl *decl)
DeclOrigin GetDeclOrigin(const clang::Decl *decl)
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
bool CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin)
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
ASTContextMetadataSP GetContextMetadata(clang::ASTContext *dst_ctx)
void ForgetSource(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx)
bool CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *interface_decl)
ASTContextMetadataSP MaybeGetContextMetadata(clang::ASTContext *dst_ctx)
void InstallMapCompleter(clang::ASTContext *dst_ctx, MapCompleter &completer)
std::shared_ptr< NamespaceMap > NamespaceMapSP
NamespaceMapSP GetNamespaceMap(const clang::NamespaceDecl *decl)
std::shared_ptr< ASTImporterDelegate > ImporterDelegateSP
llvm::DenseMap< const clang::NamespaceDecl *, NamespaceMapSP > NamespaceMetaMap
clang::FileManager m_file_manager
bool CompleteType(const CompilerType &compiler_type)
void SetRecordLayout(clang::RecordDecl *decl, const LayoutInfo &layout)
Sets the layout for the given RecordDecl.
ContextMetadataMap m_metadata_map
ClangASTMetadata * GetDeclMetadata(const clang::Decl *decl)
bool RequireCompleteType(clang::QualType type)
std::pair< lldb::ModuleSP, CompilerDeclContext > NamespaceMapItem
CompilerType DeportType(TypeSystemClang &dst, const CompilerType &src_type)
Copies the given type and the respective declarations to the destination type system.
llvm::DenseMap< const clang::RecordDecl *, LayoutInfo > RecordDeclToLayoutMap
RecordDeclToLayoutMap m_record_decl_to_layout_map
bool Import(const CompilerType &type)
If the given type was copied from another TypeSystemClang then copy over all missing information (e....
ImporterDelegateSP GetDelegate(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx)
void SetDeclOrigin(const clang::Decl *decl, clang::Decl *original_decl)
Updates the internal origin-tracking information so that the given 'original' decl is from now on use...
std::shared_ptr< ASTContextMetadata > ASTContextMetadataSP
bool CompleteAndFetchChildren(clang::QualType type)
llvm::DenseMap< const clang::ASTContext *, ASTContextMetadataSP > ContextMetadataMap
std::vector< NamespaceMapItem > NamespaceMap
Generic representation of a type in a programming language.
A uniqued constant string class.
Handles importing decls into an ASTContext with an attached C++ module.
A TypeSystem implementation based on Clang.
A class that represents a running process on the host machine.
ASTImporter that intercepts and records the import process of the underlying ASTImporter.
clang::Decl * GetOriginalDecl(clang::Decl *To) override
llvm::Expected< clang::Decl * > ImportImpl(clang::Decl *From) override
void RemoveImportListener()
llvm::SmallPtrSet< clang::Decl *, 16 > m_decls_to_ignore
Decls we should ignore when mapping decls back to their original ASTContext.
void SetImportListener(NewDeclListener *listener)
CxxModuleHandler * m_std_handler
void Imported(clang::Decl *from, clang::Decl *to) override
NewDeclListener * m_new_decl_listener
The currently attached listener.
ASTImporterDelegate(ClangASTImporter &main, clang::ASTContext *target_ctx, clang::ASTContext *source_ctx)
void ImportDefinitionTo(clang::Decl *to, clang::Decl *from)
clang::ASTContext * m_source_ctx
ClangASTImporter & m_main
DeclOrigin(clang::ASTContext *_ctx, clang::Decl *_decl)
DeclOrigin(const DeclOrigin &rhs)
void operator=(const DeclOrigin &rhs)
llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > OffsetMap
llvm::DenseMap< const clang::FieldDecl *, uint64_t > field_offsets
Listener interface used by the ASTImporterDelegate to inform other code about decls that have been im...
virtual ~NewDeclListener()=default
virtual void NewDeclImported(clang::Decl *from, clang::Decl *to)=0
A decl has been imported for the first time.