1 //===-- ClangPersistentVariables.h ------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_ClangPersistentVariables_h_ 11 #define liblldb_ClangPersistentVariables_h_ 12 13 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 #include "llvm/ADT/DenseMap.h" 17 18 // Project includes 19 #include "ClangExpressionVariable.h" 20 #include "ClangModulesDeclVendor.h" 21 22 #include "lldb/Expression/ExpressionVariable.h" 23 24 namespace lldb_private { 25 26 //---------------------------------------------------------------------- 27 /// @class ClangPersistentVariables ClangPersistentVariables.h 28 /// "lldb/Expression/ClangPersistentVariables.h" 29 /// @brief Manages persistent values that need to be preserved between 30 /// expression invocations. 31 /// 32 /// A list of variables that can be accessed and updated by any expression. See 33 /// ClangPersistentVariable for more discussion. Also provides an increasing, 34 /// 0-based counter for naming result variables. 35 //---------------------------------------------------------------------- 36 class ClangPersistentVariables : public PersistentExpressionState { 37 public: 38 ClangPersistentVariables(); 39 40 ~ClangPersistentVariables() override = default; 41 42 //------------------------------------------------------------------ 43 // llvm casting support 44 //------------------------------------------------------------------ 45 static bool classof(const PersistentExpressionState *pv) { 46 return pv->getKind() == PersistentExpressionState::eKindClang; 47 } 48 49 lldb::ExpressionVariableSP 50 CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override; 51 52 lldb::ExpressionVariableSP CreatePersistentVariable( 53 ExecutionContextScope *exe_scope, const ConstString &name, 54 const CompilerType &compiler_type, lldb::ByteOrder byte_order, 55 uint32_t addr_byte_size) override; 56 57 //---------------------------------------------------------------------- 58 /// Return the next entry in the sequence of strings "$0", "$1", ... for 59 /// use naming persistent expression convenience variables. 60 /// 61 /// @return 62 /// A string that contains the next persistent variable name. 63 //---------------------------------------------------------------------- 64 ConstString GetNextPersistentVariableName() override; 65 66 void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override; 67 68 void RegisterPersistentDecl(const ConstString &name, clang::NamedDecl *decl); 69 70 clang::NamedDecl *GetPersistentDecl(const ConstString &name); 71 72 void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) { 73 m_hand_loaded_clang_modules.push_back(module); 74 } 75 76 const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() { 77 return m_hand_loaded_clang_modules; 78 } 79 80 private: 81 uint32_t m_next_persistent_variable_id; ///< The counter used by 82 ///GetNextResultName(). 83 84 typedef llvm::DenseMap<const char *, clang::NamedDecl *> PersistentDeclMap; 85 PersistentDeclMap 86 m_persistent_decls; ///< Persistent entities declared by the user. 87 88 ClangModulesDeclVendor::ModuleVector 89 m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded; 90 ///these are the highest- 91 ///< priority source for macros. 92 }; 93 94 } // namespace lldb_private 95 96 #endif // liblldb_ClangPersistentVariables_h_ 97