Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/CxxModuleHandler.h
39648 views
//===-- CxxModuleHandler.h --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CXXMODULEHANDLER_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CXXMODULEHANDLER_H1011#include "clang/AST/ASTImporter.h"12#include "clang/Sema/Sema.h"13#include "llvm/ADT/StringSet.h"14#include <optional>1516namespace lldb_private {1718/// Handles importing decls into an ASTContext with an attached C++ module.19///20/// This class searches a C++ module (which must be attached to the target21/// ASTContext) for an equivalent decl to the one that should be imported.22/// If the decl that is found in the module is a suitable replacement23/// for the decl that should be imported, the module decl will be treated as24/// the result of the import process.25///26/// If the Decl that should be imported is a template specialization27/// that doesn't exist yet in the target ASTContext (e.g. `std::vector<int>`),28/// then this class tries to create the template specialization in the target29/// ASTContext. This is only possible if the CxxModuleHandler can determine30/// that instantiating this template is safe to do, e.g. because the target31/// decl is a container class from the STL.32class CxxModuleHandler {33/// The ASTImporter that should be used to import any Decls which aren't34/// directly handled by this class itself.35clang::ASTImporter *m_importer = nullptr;3637/// The Sema instance of the target ASTContext.38clang::Sema *m_sema = nullptr;3940/// List of template names this class currently supports. These are the41/// template names inside the 'std' namespace such as 'vector' or 'list'.42llvm::StringSet<> m_supported_templates;4344/// Tries to manually instantiate the given foreign template in the target45/// context (designated by m_sema).46std::optional<clang::Decl *> tryInstantiateStdTemplate(clang::Decl *d);4748public:49CxxModuleHandler() = default;50CxxModuleHandler(clang::ASTImporter &importer, clang::ASTContext *target);5152/// Attempts to import the given decl into the target ASTContext by53/// deserializing it from the 'std' module. This function returns a Decl if a54/// Decl has been deserialized from the 'std' module. Otherwise this function55/// returns nothing.56std::optional<clang::Decl *> Import(clang::Decl *d);5758/// Returns true iff this instance is capable of importing any declarations59/// in the target ASTContext.60bool isValid() const { return m_sema != nullptr; }61};6263} // namespace lldb_private6465#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CXXMODULEHANDLER_H666768