1292932Sdim//===-- ClangPersistentVariables.h ------------------------------*- C++ -*-===// 2292932Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6292932Sdim// 7292932Sdim//===----------------------------------------------------------------------===// 8292932Sdim 9292932Sdim#ifndef liblldb_ClangPersistentVariables_h_ 10292932Sdim#define liblldb_ClangPersistentVariables_h_ 11292932Sdim 12292932Sdim#include "llvm/ADT/DenseMap.h" 13292932Sdim 14292932Sdim#include "ClangExpressionVariable.h" 15292932Sdim#include "ClangModulesDeclVendor.h" 16292932Sdim 17292932Sdim#include "lldb/Expression/ExpressionVariable.h" 18292932Sdim 19314564Sdimnamespace lldb_private { 20314564Sdim 21353358Sdim/// \class ClangPersistentVariables ClangPersistentVariables.h 22341825Sdim/// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values 23341825Sdim/// that need to be preserved between expression invocations. 24292932Sdim/// 25292932Sdim/// A list of variables that can be accessed and updated by any expression. See 26292932Sdim/// ClangPersistentVariable for more discussion. Also provides an increasing, 27292932Sdim/// 0-based counter for naming result variables. 28314564Sdimclass ClangPersistentVariables : public PersistentExpressionState { 29292932Sdimpublic: 30314564Sdim ClangPersistentVariables(); 31292932Sdim 32314564Sdim ~ClangPersistentVariables() override = default; 33292932Sdim 34314564Sdim // llvm casting support 35314564Sdim static bool classof(const PersistentExpressionState *pv) { 36314564Sdim return pv->getKind() == PersistentExpressionState::eKindClang; 37314564Sdim } 38292932Sdim 39314564Sdim lldb::ExpressionVariableSP 40314564Sdim CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override; 41292932Sdim 42314564Sdim lldb::ExpressionVariableSP CreatePersistentVariable( 43353358Sdim ExecutionContextScope *exe_scope, ConstString name, 44314564Sdim const CompilerType &compiler_type, lldb::ByteOrder byte_order, 45314564Sdim uint32_t addr_byte_size) override; 46292932Sdim 47314564Sdim void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override; 48360784Sdim 49360784Sdim llvm::StringRef GetPersistentVariablePrefix(bool is_error) const override { 50341825Sdim return "$"; 51341825Sdim } 52314564Sdim 53360784Sdim /// Returns the next file name that should be used for user expressions. 54360784Sdim std::string GetNextExprFileName() { 55360784Sdim std::string name; 56360784Sdim name.append("<user expression "); 57360784Sdim name.append(std::to_string(m_next_user_file_id++)); 58360784Sdim name.append(">"); 59360784Sdim return name; 60360784Sdim } 61360784Sdim 62353358Sdim llvm::Optional<CompilerType> 63353358Sdim GetCompilerTypeFromPersistentDecl(ConstString type_name) override; 64314564Sdim 65360784Sdim void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl, 66360784Sdim ClangASTContext *ctx); 67314564Sdim 68353358Sdim clang::NamedDecl *GetPersistentDecl(ConstString name); 69353358Sdim 70314564Sdim void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) { 71314564Sdim m_hand_loaded_clang_modules.push_back(module); 72314564Sdim } 73314564Sdim 74314564Sdim const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() { 75314564Sdim return m_hand_loaded_clang_modules; 76314564Sdim } 77314564Sdim 78292932Sdimprivate: 79360784Sdim /// The counter used by GetNextExprFileName. 80360784Sdim uint32_t m_next_user_file_id = 0; 81360784Sdim // The counter used by GetNextPersistentVariableName 82360784Sdim uint32_t m_next_persistent_variable_id = 0; 83314564Sdim 84360784Sdim struct PersistentDecl { 85360784Sdim /// The persistent decl. 86360784Sdim clang::NamedDecl *m_decl = nullptr; 87360784Sdim /// The ClangASTContext for the ASTContext of m_decl. 88360784Sdim ClangASTContext *m_context = nullptr; 89360784Sdim }; 90360784Sdim 91360784Sdim typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap; 92314564Sdim PersistentDeclMap 93314564Sdim m_persistent_decls; ///< Persistent entities declared by the user. 94314564Sdim 95314564Sdim ClangModulesDeclVendor::ModuleVector 96314564Sdim m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded; 97314564Sdim ///these are the highest- 98314564Sdim ///< priority source for macros. 99292932Sdim}; 100292932Sdim 101292932Sdim} // namespace lldb_private 102292932Sdim 103292932Sdim#endif // liblldb_ClangPersistentVariables_h_ 104