Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
39648 views
//===-- ClangPersistentVariables.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_CLANGPERSISTENTVARIABLES_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H1011#include "llvm/ADT/DenseMap.h"1213#include "ClangExpressionVariable.h"14#include "ClangModulesDeclVendor.h"1516#include "lldb/Expression/ExpressionVariable.h"17#include <optional>1819namespace lldb_private {2021class ClangASTImporter;22class ClangModulesDeclVendor;23class Target;24class TypeSystemClang;2526/// \class ClangPersistentVariables ClangPersistentVariables.h27/// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values28/// that need to be preserved between expression invocations.29///30/// A list of variables that can be accessed and updated by any expression. See31/// ClangPersistentVariable for more discussion. Also provides an increasing,32/// 0-based counter for naming result variables.33class ClangPersistentVariables34: public llvm::RTTIExtends<ClangPersistentVariables,35PersistentExpressionState> {36public:37// LLVM RTTI support38static char ID;3940ClangPersistentVariables(std::shared_ptr<Target> target_sp);4142~ClangPersistentVariables() override = default;4344std::shared_ptr<ClangASTImporter> GetClangASTImporter();45std::shared_ptr<ClangModulesDeclVendor> GetClangModulesDeclVendor();4647lldb::ExpressionVariableSP48CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;4950lldb::ExpressionVariableSP CreatePersistentVariable(51ExecutionContextScope *exe_scope, ConstString name,52const CompilerType &compiler_type, lldb::ByteOrder byte_order,53uint32_t addr_byte_size) override;5455void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;5657ConstString GetNextPersistentVariableName(bool is_error = false) override;5859/// Returns the next file name that should be used for user expressions.60std::string GetNextExprFileName() {61std::string name;62name.append("<user expression ");63name.append(std::to_string(m_next_user_file_id++));64name.append(">");65return name;66}6768std::optional<CompilerType>69GetCompilerTypeFromPersistentDecl(ConstString type_name) override;7071void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,72std::shared_ptr<TypeSystemClang> ctx);7374clang::NamedDecl *GetPersistentDecl(ConstString name);7576void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {77m_hand_loaded_clang_modules.push_back(module);78}7980const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {81return m_hand_loaded_clang_modules;82}8384protected:85llvm::StringRef86GetPersistentVariablePrefix(bool is_error = false) const override {87return "$";88}8990private:91/// The counter used by GetNextExprFileName.92uint32_t m_next_user_file_id = 0;93// The counter used by GetNextPersistentVariableName94uint32_t m_next_persistent_variable_id = 0;9596struct PersistentDecl {97/// The persistent decl.98clang::NamedDecl *m_decl = nullptr;99/// The TypeSystemClang for the ASTContext of m_decl.100lldb::TypeSystemWP m_context;101};102103typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;104PersistentDeclMap105m_persistent_decls; ///< Persistent entities declared by the user.106107ClangModulesDeclVendor::ModuleVector108m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;109///these are the highest-110///< priority source for macros.111std::shared_ptr<ClangASTImporter> m_ast_importer_sp;112std::shared_ptr<ClangModulesDeclVendor> m_modules_decl_vendor_sp;113std::shared_ptr<Target> m_target_sp;114};115116} // namespace lldb_private117118#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H119120121