1*5ffd83dbSDimitry Andric //===-- CxxModuleHandler.h --------------------------------------*- C++ -*-===// 2*5ffd83dbSDimitry Andric // 3*5ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*5ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*5ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*5ffd83dbSDimitry Andric // 7*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 8*5ffd83dbSDimitry Andric 9*5ffd83dbSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CXXMODULEHANDLER_H 10*5ffd83dbSDimitry Andric #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CXXMODULEHANDLER_H 11*5ffd83dbSDimitry Andric 12*5ffd83dbSDimitry Andric #include "clang/AST/ASTImporter.h" 13*5ffd83dbSDimitry Andric #include "clang/Sema/Sema.h" 14*5ffd83dbSDimitry Andric #include "llvm/ADT/StringSet.h" 15*5ffd83dbSDimitry Andric 16*5ffd83dbSDimitry Andric namespace lldb_private { 17*5ffd83dbSDimitry Andric 18*5ffd83dbSDimitry Andric /// Handles importing decls into an ASTContext with an attached C++ module. 19*5ffd83dbSDimitry Andric /// 20*5ffd83dbSDimitry Andric /// This class searches a C++ module (which must be attached to the target 21*5ffd83dbSDimitry Andric /// ASTContext) for an equivalent decl to the one that should be imported. 22*5ffd83dbSDimitry Andric /// If the decl that is found in the module is a suitable replacement 23*5ffd83dbSDimitry Andric /// for the decl that should be imported, the module decl will be treated as 24*5ffd83dbSDimitry Andric /// the result of the import process. 25*5ffd83dbSDimitry Andric /// 26*5ffd83dbSDimitry Andric /// If the Decl that should be imported is a template specialization 27*5ffd83dbSDimitry Andric /// that doesn't exist yet in the target ASTContext (e.g. `std::vector<int>`), 28*5ffd83dbSDimitry Andric /// then this class tries to create the template specialization in the target 29*5ffd83dbSDimitry Andric /// ASTContext. This is only possible if the CxxModuleHandler can determine 30*5ffd83dbSDimitry Andric /// that instantiating this template is safe to do, e.g. because the target 31*5ffd83dbSDimitry Andric /// decl is a container class from the STL. 32*5ffd83dbSDimitry Andric class CxxModuleHandler { 33*5ffd83dbSDimitry Andric /// The ASTImporter that should be used to import any Decls which aren't 34*5ffd83dbSDimitry Andric /// directly handled by this class itself. 35*5ffd83dbSDimitry Andric clang::ASTImporter *m_importer = nullptr; 36*5ffd83dbSDimitry Andric 37*5ffd83dbSDimitry Andric /// The Sema instance of the target ASTContext. 38*5ffd83dbSDimitry Andric clang::Sema *m_sema = nullptr; 39*5ffd83dbSDimitry Andric 40*5ffd83dbSDimitry Andric /// List of template names this class currently supports. These are the 41*5ffd83dbSDimitry Andric /// template names inside the 'std' namespace such as 'vector' or 'list'. 42*5ffd83dbSDimitry Andric llvm::StringSet<> m_supported_templates; 43*5ffd83dbSDimitry Andric 44*5ffd83dbSDimitry Andric /// Tries to manually instantiate the given foreign template in the target 45*5ffd83dbSDimitry Andric /// context (designated by m_sema). 46*5ffd83dbSDimitry Andric llvm::Optional<clang::Decl *> tryInstantiateStdTemplate(clang::Decl *d); 47*5ffd83dbSDimitry Andric 48*5ffd83dbSDimitry Andric public: 49*5ffd83dbSDimitry Andric CxxModuleHandler() = default; 50*5ffd83dbSDimitry Andric CxxModuleHandler(clang::ASTImporter &importer, clang::ASTContext *target); 51*5ffd83dbSDimitry Andric 52*5ffd83dbSDimitry Andric /// Attempts to import the given decl into the target ASTContext by 53*5ffd83dbSDimitry Andric /// deserializing it from the 'std' module. This function returns a Decl if a 54*5ffd83dbSDimitry Andric /// Decl has been deserialized from the 'std' module. Otherwise this function 55*5ffd83dbSDimitry Andric /// returns nothing. 56*5ffd83dbSDimitry Andric llvm::Optional<clang::Decl *> Import(clang::Decl *d); 57*5ffd83dbSDimitry Andric 58*5ffd83dbSDimitry Andric /// Returns true iff this instance is capable of importing any declarations 59*5ffd83dbSDimitry Andric /// in the target ASTContext. 60*5ffd83dbSDimitry Andric bool isValid() const { return m_sema != nullptr; } 61*5ffd83dbSDimitry Andric }; 62*5ffd83dbSDimitry Andric 63*5ffd83dbSDimitry Andric } // namespace lldb_private 64*5ffd83dbSDimitry Andric 65*5ffd83dbSDimitry Andric #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CXXMODULEHANDLER_H 66