//===-- ClangASTImporter.h --------------------------------------*- C++ -*-===// // // 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 // //===----------------------------------------------------------------------===// #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H #include <map> #include <memory> #include <set> #include <vector> #include "clang/AST/ASTContext.h" #include "clang/AST/ASTImporter.h" #include "clang/AST/CharUnits.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" #include "lldb/Host/FileSystem.h" #include "lldb/Symbol/CompilerDeclContext.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/lldb-types.h" #include "Plugins/ExpressionParser/Clang/CxxModuleHandler.h" #include "llvm/ADT/DenseMap.h" namespace lldb_private { class ClangASTMetadata; class TypeSystemClang; /// Manages and observes all Clang AST node importing in LLDB. /// /// The ClangASTImporter takes care of two things: /// /// 1. Keeps track of all ASTImporter instances in LLDB. /// /// Clang's ASTImporter takes care of importing types from one ASTContext to /// another. This class expands this concept by allowing copying from several /// ASTContext instances to several other ASTContext instances. Instead of /// constructing a new ASTImporter manually to copy over a type/decl, this class /// can be asked to do this. It will construct a ASTImporter for the caller (and /// will cache the ASTImporter instance for later use) and then perform the /// import. /// /// This mainly prevents that a caller might construct several ASTImporter /// instances for the same source/target ASTContext combination. As the /// ASTImporter has an internal state that keeps track of already imported /// declarations and so on, using only one ASTImporter instance is more /// efficient and less error-prone than using multiple. /// /// 2. Keeps track of from where declarations were imported (origin-tracking). /// The ASTImporter instances in this class usually only performa a minimal /// import, i.e., only a shallow copy is made that is filled out on demand /// when more information is requested later on. This requires record-keeping /// of where any shallow clone originally came from so that the right original /// declaration can be found and used as the source of any missing information. class ClangASTImporter { … }; template <class D> class TaggedASTDecl { … }; template <class D2, template <class D> class TD, class D1> TD<D2> DynCast(TD<D1> source) { … } template <class D = clang::Decl> class DeclFromParser; template <class D = clang::Decl> class DeclFromUser; template <class D> class DeclFromParser : public TaggedASTDecl<D> { … }; template <class D> class DeclFromUser : public TaggedASTDecl<D> { … }; template <class D> DeclFromUser<D> DeclFromParser<D>::GetOrigin(ClangASTImporter &importer) { … } template <class D> DeclFromParser<D> DeclFromUser<D>::Import(clang::ASTContext *dest_ctx, ClangASTImporter &importer) { … } } // namespace lldb_private #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H