1 //===-- ClangExpressionVariable.h -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ClangExpressionVariable_h_
11 #define liblldb_ClangExpressionVariable_h_
23 // Other libraries and framework includes
24 #include "llvm/Support/Casting.h"
27 #include "lldb/Core/ClangForward.h"
28 #include "lldb/Core/Value.h"
29 #include "lldb/Expression/ExpressionVariable.h"
30 #include "lldb/Symbol/TaggedASTType.h"
31 #include "lldb/Utility/ConstString.h"
32 #include "lldb/lldb-public.h"
38 namespace lldb_private {
40 class ValueObjectConstResult;
42 //----------------------------------------------------------------------
43 /// @class ClangExpressionVariable ClangExpressionVariable.h
44 /// "lldb/Expression/ClangExpressionVariable.h" Encapsulates one variable for
45 /// the expression parser.
47 /// The expression parser uses variables in three different contexts:
49 /// First, it stores persistent variables along with the process for use in
50 /// expressions. These persistent variables contain their own data and are
53 /// Second, in an interpreted expression, it stores the local variables for
54 /// the expression along with the expression. These variables contain their
55 /// own data and are typed.
57 /// Third, in a JIT-compiled expression, it stores the variables that the
58 /// expression needs to have materialized and dematerialized at each
59 /// execution. These do not contain their own data but are named and typed.
61 /// This class supports all of these use cases using simple type polymorphism,
62 /// and provides necessary support methods. Its interface is RTTI-neutral.
63 //----------------------------------------------------------------------
64 class ClangExpressionVariable : public ExpressionVariable {
66 ClangExpressionVariable(ExecutionContextScope *exe_scope,
67 lldb::ByteOrder byte_order, uint32_t addr_byte_size);
69 ClangExpressionVariable(ExecutionContextScope *exe_scope, Value &value,
70 const ConstString &name, uint16_t flags = EVNone);
72 ClangExpressionVariable(const lldb::ValueObjectSP &valobj_sp);
74 ClangExpressionVariable(ExecutionContextScope *exe_scope,
75 const ConstString &name,
76 const TypeFromUser &user_type,
77 lldb::ByteOrder byte_order, uint32_t addr_byte_size);
79 //----------------------------------------------------------------------
80 /// Utility functions for dealing with ExpressionVariableLists in Clang-
82 //----------------------------------------------------------------------
84 //----------------------------------------------------------------------
85 /// Finds a variable by NamedDecl in the list.
88 /// The name of the requested variable.
91 /// The variable requested, or NULL if that variable is not in the list.
92 //----------------------------------------------------------------------
93 static ClangExpressionVariable *
94 FindVariableInList(ExpressionVariableList &list, const clang::NamedDecl *decl,
96 lldb::ExpressionVariableSP var_sp;
97 for (size_t index = 0, size = list.GetSize(); index < size; ++index) {
98 var_sp = list.GetVariableAtIndex(index);
100 if (ClangExpressionVariable *clang_var =
101 llvm::dyn_cast<ClangExpressionVariable>(var_sp.get())) {
102 ClangExpressionVariable::ParserVars *parser_vars =
103 clang_var->GetParserVars(parser_id);
105 if (parser_vars && parser_vars->m_named_decl == decl)
112 //----------------------------------------------------------------------
113 /// If the variable contains its own data, make a Value point at it. If \a
114 /// exe_ctx in not NULL, the value will be resolved in with that execution
118 /// The value to point at the data.
120 /// @param[in] exe_ctx
121 /// The execution context to use to resolve \a value.
124 /// True on success; false otherwise (in particular, if this variable
125 /// does not contain its own data).
126 //----------------------------------------------------------------------
127 bool PointValueAtData(Value &value, ExecutionContext *exe_ctx);
129 //----------------------------------------------------------------------
130 /// The following values should not live beyond parsing
131 //----------------------------------------------------------------------
135 : m_parser_type(), m_named_decl(NULL), m_llvm_value(NULL),
136 m_lldb_value(), m_lldb_var(), m_lldb_sym(NULL) {}
139 m_parser_type; ///< The type of the variable according to the parser
140 const clang::NamedDecl
141 *m_named_decl; ///< The Decl corresponding to this variable
142 llvm::Value *m_llvm_value; ///< The IR value corresponding to this variable;
143 ///usually a GlobalValue
145 m_lldb_value; ///< The value found in LLDB for this variable
146 lldb::VariableSP m_lldb_var; ///< The original variable for this variable
147 const lldb_private::Symbol *m_lldb_sym; ///< The original symbol for this
148 ///variable, if it was a symbol
152 typedef std::map<uint64_t, ParserVars> ParserVarMap;
153 ParserVarMap m_parser_vars;
156 //----------------------------------------------------------------------
157 /// Make this variable usable by the parser by allocating space for parser-
158 /// specific variables
159 //----------------------------------------------------------------------
160 void EnableParserVars(uint64_t parser_id) {
161 m_parser_vars.insert(std::make_pair(parser_id, ParserVars()));
164 //----------------------------------------------------------------------
165 /// Deallocate parser-specific variables
166 //----------------------------------------------------------------------
167 void DisableParserVars(uint64_t parser_id) { m_parser_vars.erase(parser_id); }
169 //----------------------------------------------------------------------
170 /// Access parser-specific variables
171 //----------------------------------------------------------------------
172 ParserVars *GetParserVars(uint64_t parser_id) {
173 ParserVarMap::iterator i = m_parser_vars.find(parser_id);
175 if (i == m_parser_vars.end())
181 //----------------------------------------------------------------------
182 /// The following values are valid if the variable is used by JIT code
183 //----------------------------------------------------------------------
185 JITVars() : m_alignment(0), m_size(0), m_offset(0) {}
188 m_alignment; ///< The required alignment of the variable, in bytes
189 size_t m_size; ///< The space required for the variable, in bytes
191 m_offset; ///< The offset of the variable in the struct, in bytes
195 typedef std::map<uint64_t, JITVars> JITVarMap;
196 JITVarMap m_jit_vars;
199 //----------------------------------------------------------------------
200 /// Make this variable usable for materializing for the JIT by allocating
201 /// space for JIT-specific variables
202 //----------------------------------------------------------------------
203 void EnableJITVars(uint64_t parser_id) {
204 m_jit_vars.insert(std::make_pair(parser_id, JITVars()));
207 //----------------------------------------------------------------------
208 /// Deallocate JIT-specific variables
209 //----------------------------------------------------------------------
210 void DisableJITVars(uint64_t parser_id) { m_jit_vars.erase(parser_id); }
212 JITVars *GetJITVars(uint64_t parser_id) {
213 JITVarMap::iterator i = m_jit_vars.find(parser_id);
215 if (i == m_jit_vars.end())
221 TypeFromUser GetTypeFromUser();
223 //------------------------------------------------------------------
224 // llvm casting support
225 //------------------------------------------------------------------
226 static bool classof(const ExpressionVariable *ev) {
227 return ev->getKind() == ExpressionVariable::eKindClang;
230 //----------------------------------------------------------------------
232 //----------------------------------------------------------------------
233 DISALLOW_COPY_AND_ASSIGN(ClangExpressionVariable);
236 } // namespace lldb_private
238 #endif // liblldb_ClangExpressionVariable_h_