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 //----------------------------------------------------------------------
28 /// @class ClangPersistentVariables ClangPersistentVariables.h "lldb/Expression/ClangPersistentVariables.h"
29 /// @brief Manages persistent values that need to be preserved between expression invocations.
30 ///
31 /// A list of variables that can be accessed and updated by any expression.  See
32 /// ClangPersistentVariable for more discussion.  Also provides an increasing,
33 /// 0-based counter for naming result variables.
34 //----------------------------------------------------------------------
35 class ClangPersistentVariables : public PersistentExpressionState
36 {
37 public:
38     ClangPersistentVariables();
39 
40     ~ClangPersistentVariables() override = default;
41 
42     //------------------------------------------------------------------
43     // llvm casting support
44     //------------------------------------------------------------------
45     static bool classof(const PersistentExpressionState *pv)
46     {
47         return pv->getKind() == PersistentExpressionState::eKindClang;
48     }
49 
50     lldb::ExpressionVariableSP
51     CreatePersistentVariable (const lldb::ValueObjectSP &valobj_sp) override;
52 
53     lldb::ExpressionVariableSP
54     CreatePersistentVariable (ExecutionContextScope *exe_scope,
55                               const ConstString &name,
56                               const CompilerType& compiler_type,
57                               lldb::ByteOrder byte_order,
58                               uint32_t addr_byte_size) override;
59 
60     //----------------------------------------------------------------------
61     /// Return the next entry in the sequence of strings "$0", "$1", ... for
62     /// use naming persistent expression convenience variables.
63     ///
64     /// @return
65     ///     A string that contains the next persistent variable name.
66     //----------------------------------------------------------------------
67     ConstString
68     GetNextPersistentVariableName () override;
69 
70     void
71     RemovePersistentVariable (lldb::ExpressionVariableSP variable) override;
72 
73     void
74     RegisterPersistentDecl (const ConstString &name,
75                             clang::NamedDecl *decl);
76 
77     clang::NamedDecl *
78     GetPersistentDecl (const ConstString &name);
79 
80     void
81     AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module)
82     {
83         m_hand_loaded_clang_modules.push_back(module);
84     }
85 
86     const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules()
87     {
88         return m_hand_loaded_clang_modules;
89     }
90 
91 private:
92     uint32_t                                                m_next_persistent_variable_id;  ///< The counter used by GetNextResultName().
93 
94     typedef llvm::DenseMap<const char *, clang::NamedDecl *>    PersistentDeclMap;
95     PersistentDeclMap                                           m_persistent_decls;         ///< Persistent entities declared by the user.
96 
97     ClangModulesDeclVendor::ModuleVector                    m_hand_loaded_clang_modules;    ///< These are Clang modules we hand-loaded; these are the highest-
98                                                                                             ///< priority source for macros.
99 };
100 
101 } // namespace lldb_private
102 
103 #endif // liblldb_ClangPersistentVariables_h_
104