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_
21 #include "llvm/Support/Casting.h"
23 #include "lldb/Core/ClangForward.h"
24 #include "lldb/Core/Value.h"
25 #include "lldb/Expression/ExpressionVariable.h"
26 #include "lldb/Symbol/TaggedASTType.h"
27 #include "lldb/Utility/ConstString.h"
28 #include "lldb/lldb-public.h"
34 namespace lldb_private {
36 class ValueObjectConstResult;
38 //----------------------------------------------------------------------
39 /// @class ClangExpressionVariable ClangExpressionVariable.h
40 /// "lldb/Expression/ClangExpressionVariable.h" Encapsulates one variable for
41 /// the expression parser.
43 /// The expression parser uses variables in three different contexts:
45 /// First, it stores persistent variables along with the process for use in
46 /// expressions. These persistent variables contain their own data and are
49 /// Second, in an interpreted expression, it stores the local variables for
50 /// the expression along with the expression. These variables contain their
51 /// own data and are typed.
53 /// Third, in a JIT-compiled expression, it stores the variables that the
54 /// expression needs to have materialized and dematerialized at each
55 /// execution. These do not contain their own data but are named and typed.
57 /// This class supports all of these use cases using simple type polymorphism,
58 /// and provides necessary support methods. Its interface is RTTI-neutral.
59 //----------------------------------------------------------------------
60 class ClangExpressionVariable : public ExpressionVariable {
62 ClangExpressionVariable(ExecutionContextScope *exe_scope,
63 lldb::ByteOrder byte_order, uint32_t addr_byte_size);
65 ClangExpressionVariable(ExecutionContextScope *exe_scope, Value &value,
66 const ConstString &name, uint16_t flags = EVNone);
68 ClangExpressionVariable(const lldb::ValueObjectSP &valobj_sp);
70 ClangExpressionVariable(ExecutionContextScope *exe_scope,
71 const ConstString &name,
72 const TypeFromUser &user_type,
73 lldb::ByteOrder byte_order, uint32_t addr_byte_size);
75 //----------------------------------------------------------------------
76 /// Utility functions for dealing with ExpressionVariableLists in Clang-
78 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
81 /// Finds a variable by NamedDecl in the list.
84 /// The name of the requested variable.
87 /// The variable requested, or NULL if that variable is not in the list.
88 //----------------------------------------------------------------------
89 static ClangExpressionVariable *
90 FindVariableInList(ExpressionVariableList &list, const clang::NamedDecl *decl,
92 lldb::ExpressionVariableSP var_sp;
93 for (size_t index = 0, size = list.GetSize(); index < size; ++index) {
94 var_sp = list.GetVariableAtIndex(index);
96 if (ClangExpressionVariable *clang_var =
97 llvm::dyn_cast<ClangExpressionVariable>(var_sp.get())) {
98 ClangExpressionVariable::ParserVars *parser_vars =
99 clang_var->GetParserVars(parser_id);
101 if (parser_vars && parser_vars->m_named_decl == decl)
108 //----------------------------------------------------------------------
109 /// If the variable contains its own data, make a Value point at it. If \a
110 /// exe_ctx in not NULL, the value will be resolved in with that execution
114 /// The value to point at the data.
116 /// @param[in] exe_ctx
117 /// The execution context to use to resolve \a value.
120 /// True on success; false otherwise (in particular, if this variable
121 /// does not contain its own data).
122 //----------------------------------------------------------------------
123 bool PointValueAtData(Value &value, ExecutionContext *exe_ctx);
125 //----------------------------------------------------------------------
126 /// The following values should not live beyond parsing
127 //----------------------------------------------------------------------
131 : m_parser_type(), m_named_decl(NULL), m_llvm_value(NULL),
132 m_lldb_value(), m_lldb_var(), m_lldb_sym(NULL) {}
135 m_parser_type; ///< The type of the variable according to the parser
136 const clang::NamedDecl
137 *m_named_decl; ///< The Decl corresponding to this variable
138 llvm::Value *m_llvm_value; ///< The IR value corresponding to this variable;
139 ///usually a GlobalValue
141 m_lldb_value; ///< The value found in LLDB for this variable
142 lldb::VariableSP m_lldb_var; ///< The original variable for this variable
143 const lldb_private::Symbol *m_lldb_sym; ///< The original symbol for this
144 ///variable, if it was a symbol
148 typedef std::map<uint64_t, ParserVars> ParserVarMap;
149 ParserVarMap m_parser_vars;
152 //----------------------------------------------------------------------
153 /// Make this variable usable by the parser by allocating space for parser-
154 /// specific variables
155 //----------------------------------------------------------------------
156 void EnableParserVars(uint64_t parser_id) {
157 m_parser_vars.insert(std::make_pair(parser_id, ParserVars()));
160 //----------------------------------------------------------------------
161 /// Deallocate parser-specific variables
162 //----------------------------------------------------------------------
163 void DisableParserVars(uint64_t parser_id) { m_parser_vars.erase(parser_id); }
165 //----------------------------------------------------------------------
166 /// Access parser-specific variables
167 //----------------------------------------------------------------------
168 ParserVars *GetParserVars(uint64_t parser_id) {
169 ParserVarMap::iterator i = m_parser_vars.find(parser_id);
171 if (i == m_parser_vars.end())
177 //----------------------------------------------------------------------
178 /// The following values are valid if the variable is used by JIT code
179 //----------------------------------------------------------------------
181 JITVars() : m_alignment(0), m_size(0), m_offset(0) {}
184 m_alignment; ///< The required alignment of the variable, in bytes
185 size_t m_size; ///< The space required for the variable, in bytes
187 m_offset; ///< The offset of the variable in the struct, in bytes
191 typedef std::map<uint64_t, JITVars> JITVarMap;
192 JITVarMap m_jit_vars;
195 //----------------------------------------------------------------------
196 /// Make this variable usable for materializing for the JIT by allocating
197 /// space for JIT-specific variables
198 //----------------------------------------------------------------------
199 void EnableJITVars(uint64_t parser_id) {
200 m_jit_vars.insert(std::make_pair(parser_id, JITVars()));
203 //----------------------------------------------------------------------
204 /// Deallocate JIT-specific variables
205 //----------------------------------------------------------------------
206 void DisableJITVars(uint64_t parser_id) { m_jit_vars.erase(parser_id); }
208 JITVars *GetJITVars(uint64_t parser_id) {
209 JITVarMap::iterator i = m_jit_vars.find(parser_id);
211 if (i == m_jit_vars.end())
217 TypeFromUser GetTypeFromUser();
219 //------------------------------------------------------------------
220 // llvm casting support
221 //------------------------------------------------------------------
222 static bool classof(const ExpressionVariable *ev) {
223 return ev->getKind() == ExpressionVariable::eKindClang;
226 //----------------------------------------------------------------------
228 //----------------------------------------------------------------------
229 DISALLOW_COPY_AND_ASSIGN(ClangExpressionVariable);
232 } // namespace lldb_private
234 #endif // liblldb_ClangExpressionVariable_h_