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 #include "llvm/ADT/DenseMap.h" 14 15 #include "ClangExpressionVariable.h" 16 #include "ClangModulesDeclVendor.h" 17 18 #include "lldb/Expression/ExpressionVariable.h" 19 20 namespace lldb_private { 21 22 //---------------------------------------------------------------------- 23 /// @class ClangPersistentVariables ClangPersistentVariables.h 24 /// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values 25 /// that need to be preserved between expression invocations. 26 /// 27 /// A list of variables that can be accessed and updated by any expression. See 28 /// ClangPersistentVariable for more discussion. Also provides an increasing, 29 /// 0-based counter for naming result variables. 30 //---------------------------------------------------------------------- 31 class ClangPersistentVariables : public PersistentExpressionState { 32 public: 33 ClangPersistentVariables(); 34 35 ~ClangPersistentVariables() override = default; 36 37 //------------------------------------------------------------------ 38 // llvm casting support 39 //------------------------------------------------------------------ classof(const PersistentExpressionState * pv)40 static bool classof(const PersistentExpressionState *pv) { 41 return pv->getKind() == PersistentExpressionState::eKindClang; 42 } 43 44 lldb::ExpressionVariableSP 45 CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override; 46 47 lldb::ExpressionVariableSP CreatePersistentVariable( 48 ExecutionContextScope *exe_scope, const ConstString &name, 49 const CompilerType &compiler_type, lldb::ByteOrder byte_order, 50 uint32_t addr_byte_size) override; 51 52 void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override; 53 llvm::StringRef GetPersistentVariablePrefix(bool is_error)54 GetPersistentVariablePrefix(bool is_error) const override { 55 return "$"; 56 } 57 58 void RegisterPersistentDecl(const ConstString &name, clang::NamedDecl *decl); 59 60 clang::NamedDecl *GetPersistentDecl(const ConstString &name); 61 AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module)62 void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) { 63 m_hand_loaded_clang_modules.push_back(module); 64 } 65 GetHandLoadedClangModules()66 const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() { 67 return m_hand_loaded_clang_modules; 68 } 69 70 private: 71 uint32_t m_next_persistent_variable_id; ///< The counter used by 72 ///GetNextResultName(). 73 74 typedef llvm::DenseMap<const char *, clang::NamedDecl *> PersistentDeclMap; 75 PersistentDeclMap 76 m_persistent_decls; ///< Persistent entities declared by the user. 77 78 ClangModulesDeclVendor::ModuleVector 79 m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded; 80 ///these are the highest- 81 ///< priority source for macros. 82 }; 83 84 } // namespace lldb_private 85 86 #endif // liblldb_ClangPersistentVariables_h_ 87