ClangExpressionVariable.h revision c61349681fa2923bd30ad16afce450a0da6108cf
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===-- ClangExpressionVariable.h -------------------------------*- C++ -*-===//
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//===----------------------------------------------------------------------===//
9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#ifndef liblldb_ClangExpressionVariable_h_
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define liblldb_ClangExpressionVariable_h_
12ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// C Includes
143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include <signal.h>
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <stdint.h>
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <string.h>
174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// C++ Includes
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <string>
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <vector>
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Other libraries and framework includes
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Project includes
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/lldb-public.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Core/ClangForward.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Core/ConstString.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Symbol/TaggedASTType.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace llvm {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    class Value;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace lldb_private {
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ClangExpressionVariableList;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ValueObjectConstResult;
37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)//----------------------------------------------------------------------
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// @class ClangExpressionVariable ClangExpressionVariable.h "lldb/Expression/ClangExpressionVariable.h"
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// @brief Encapsulates one variable for the expression parser.
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// The expression parser uses variables in three different contexts:
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// First, it stores persistent variables along with the process for use
45d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)/// in expressions.  These persistent variables contain their own data
46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)/// and are typed.
47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)///
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Second, in an interpreted expression, it stores the local variables
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// for the expression along with the expression.  These variables
504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/// contain their own data and are typed.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// Third, in a JIT-compiled expression, it stores the variables that
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// the expression needs to have materialized and dematerialized at each
54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/// execution.  These do not contain their own data but are named and
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// typed.
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// This class supports all of these use cases using simple type
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// polymorphism, and provides necessary support methods.  Its interface
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/// is RTTI-neutral.
60ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch//----------------------------------------------------------------------
6158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class ClangExpressionVariable
6258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles){
6358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)public:
647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    ClangExpressionVariable(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size);
657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    ClangExpressionVariable(const lldb::ValueObjectSP &valobj_sp);
673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    //----------------------------------------------------------------------
693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    /// If the variable contains its own data, make a Value point at it.
7058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /// If \a exe_ctx in not NULL, the value will be resolved in with
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    /// that execution context.
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ///
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /// @param[in] value
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ///     The value to point at the data.
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    ///
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    /// @param[in] exe_ctx
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    ///     The execution context to use to resolve \a value.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ///
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// @return
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ///     True on success; false otherwise (in particular, if this variable
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ///     does not contain its own data).
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    //----------------------------------------------------------------------
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PointValueAtData(Value &value, ExecutionContext *exe_ctx);
853240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch
863240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    lldb::ValueObjectSP
873240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    GetValueObject();
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //----------------------------------------------------------------------
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// The following values should not live beyond parsing
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //----------------------------------------------------------------------
92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    class ParserVars
93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    {
947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    public:
957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        ParserVars() :
977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch            m_parser_type(),
98ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch            m_named_decl (NULL),
997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch            m_llvm_value (NULL),
1007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch            m_lldb_value (NULL),
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            m_lldb_var   ()
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        {
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        }
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        TypeFromParser          m_parser_type;  ///< The type of the variable according to the parser
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        const clang::NamedDecl *m_named_decl;   ///< The Decl corresponding to this variable
107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        llvm::Value            *m_llvm_value;   ///< The IR value corresponding to this variable; usually a GlobalValue
108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        lldb_private::Value    *m_lldb_value;   ///< The value found in LLDB for this variable
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        lldb::VariableSP        m_lldb_var;     ///< The original variable for this variable
110424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        lldb_private::Symbol   *m_lldb_sym;     ///< The original symbol for this variable, if it was a symbol
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    private:
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        DISALLOW_COPY_AND_ASSIGN (ParserVars);
114a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    };
115a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    //----------------------------------------------------------------------
116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    /// Make this variable usable by the parser by allocating space for
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    /// parser-specific variables
11858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    //----------------------------------------------------------------------
11958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    void
12058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    EnableParserVars()
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        if (!m_parser_vars.get())
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            m_parser_vars.reset(new ParserVars);
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    //----------------------------------------------------------------------
12758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /// Deallocate parser-specific variables
12858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    //----------------------------------------------------------------------
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    void
130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    DisableParserVars()
131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    {
132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        m_parser_vars.reset();
133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    //----------------------------------------------------------------------
136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    /// The following values are valid if the variable is used by JIT code
13758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    //----------------------------------------------------------------------
13858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    struct JITVars {
139ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        JITVars () :
14058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            m_alignment (0),
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            m_size (0),
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            m_offset (0)
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        {
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        }
1457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        off_t   m_alignment;    ///< The required alignment of the variable, in bytes
14758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        size_t  m_size;         ///< The space required for the variable, in bytes
1483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)        off_t   m_offset;       ///< The offset of the variable in the struct, in bytes
14958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    };
15058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //----------------------------------------------------------------------
15258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /// Make this variable usable for materializing for the JIT by allocating
15358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /// space for JIT-specific variables
154a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    //----------------------------------------------------------------------
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EnableJITVars()
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    {
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        if (!m_jit_vars.get())
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            m_jit_vars.reset(new JITVars);
1603240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    }
1613240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch
1623240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    //----------------------------------------------------------------------
1633240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    /// Deallocate JIT-specific variables
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    //----------------------------------------------------------------------
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DisableJITVars()
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        m_jit_vars.reset();
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
170
171    //----------------------------------------------------------------------
172    /// Return the variable's size in bytes
173    //----------------------------------------------------------------------
174    size_t
175    GetByteSize ();
176
177    const ConstString &
178    GetName();
179
180    RegisterInfo *
181    GetRegisterInfo();
182
183    void
184    SetRegisterInfo (const RegisterInfo *reg_info);
185
186    lldb::clang_type_t
187    GetClangType ();
188
189    void
190    SetClangType (lldb::clang_type_t);
191
192    clang::ASTContext *
193    GetClangAST ();
194
195    void
196    SetClangAST (clang::ASTContext *ast);
197
198    TypeFromUser
199    GetTypeFromUser ();
200
201    uint8_t *
202    GetValueBytes ();
203
204    void
205    SetName (const ConstString &name);
206
207    void
208    ValueUpdated ();
209
210    // this function is used to copy the address-of m_live_sp into m_frozen_sp
211    // this is necessary because the results of certain cast and pointer-arithmetic
212    // operations (such as those described in bugzilla issues 11588 and 11618) generate
213    // frozen objcts that do not have a valid address-of, which can be troublesome when
214    // using synthetic children providers. transferring the address-of the live object
215    // solves these issues and provides the expected user-level behavior
216    void
217    TransferAddress (bool force = false);
218
219    typedef lldb::SharedPtr<ValueObjectConstResult>::Type ValueObjectConstResultSP;
220
221    //----------------------------------------------------------------------
222    /// Members
223    //----------------------------------------------------------------------
224    std::auto_ptr<ParserVars> m_parser_vars;
225    std::auto_ptr<JITVars> m_jit_vars;
226
227    enum Flags
228    {
229        EVNone                  = 0,
230        EVIsLLDBAllocated       = 1 << 0,   ///< This variable is resident in a location specifically allocated for it by LLDB in the target process
231        EVIsProgramReference    = 1 << 1,   ///< This variable is a reference to a (possibly invalid) area managed by the target program
232        EVNeedsAllocation       = 1 << 2,   ///< Space for this variable has yet to be allocated in the target process
233        EVIsFreezeDried         = 1 << 3,   ///< This variable's authoritative version is in m_frozen_sp (for example, for statically-computed results)
234        EVNeedsFreezeDry        = 1 << 4,   ///< Copy from m_live_sp to m_frozen_sp during dematerialization
235        EVKeepInTarget          = 1 << 5,   ///< Keep the allocation after the expression is complete rather than freeze drying its contents and freeing it
236        EVTypeIsReference       = 1 << 6,   ///< The original type of this variable is a reference, so materialize the value rather than the location
237        EVUnknownType           = 1 << 7    ///< This is a symbol of unknown type, and the type must be resolved after parsing is complete
238    };
239
240    uint16_t m_flags; // takes elements of Flags
241
242    lldb::ValueObjectSP m_frozen_sp;
243    lldb::ValueObjectSP m_live_sp;
244private:
245    DISALLOW_COPY_AND_ASSIGN (ClangExpressionVariable);
246};
247
248//----------------------------------------------------------------------
249/// @class ClangExpressionVariableListBase ClangExpressionVariable.h "lldb/Expression/ClangExpressionVariable.h"
250/// @brief A list of variable references.
251///
252/// This class stores variables internally, acting as the permanent store.
253//----------------------------------------------------------------------
254class ClangExpressionVariableList
255{
256public:
257    //----------------------------------------------------------------------
258    /// Implementation of methods in ClangExpressionVariableListBase
259    //----------------------------------------------------------------------
260    size_t
261    GetSize()
262    {
263        return m_variables.size();
264    }
265
266    lldb::ClangExpressionVariableSP
267    GetVariableAtIndex(size_t index)
268    {
269        lldb::ClangExpressionVariableSP var_sp;
270        if (index < m_variables.size())
271            var_sp = m_variables[index];
272        return var_sp;
273    }
274
275    size_t
276    AddVariable (const lldb::ClangExpressionVariableSP &var_sp)
277    {
278        m_variables.push_back(var_sp);
279        return m_variables.size() - 1;
280    }
281
282    bool
283    ContainsVariable (const lldb::ClangExpressionVariableSP &var_sp)
284    {
285        const size_t size = m_variables.size();
286        for (size_t index = 0; index < size; ++index)
287        {
288            if (m_variables[index].get() == var_sp.get())
289                return true;
290        }
291        return false;
292    }
293
294    //----------------------------------------------------------------------
295    /// Finds a variable by name in the list.
296    ///
297    /// @param[in] name
298    ///     The name of the requested variable.
299    ///
300    /// @return
301    ///     The variable requested, or NULL if that variable is not in the list.
302    //----------------------------------------------------------------------
303    lldb::ClangExpressionVariableSP
304    GetVariable (const ConstString &name)
305    {
306        lldb::ClangExpressionVariableSP var_sp;
307        for (size_t index = 0, size = GetSize(); index < size; ++index)
308        {
309            var_sp = GetVariableAtIndex(index);
310            if (var_sp->GetName() == name)
311                return var_sp;
312        }
313        var_sp.reset();
314        return var_sp;
315    }
316
317    lldb::ClangExpressionVariableSP
318    GetVariable (const char *name)
319    {
320        lldb::ClangExpressionVariableSP var_sp;
321        if (name && name[0])
322        {
323            for (size_t index = 0, size = GetSize(); index < size; ++index)
324            {
325                var_sp = GetVariableAtIndex(index);
326                const char *var_name_cstr = var_sp->GetName().GetCString();
327                if (!var_name_cstr || !name)
328                    continue;
329                if (::strcmp (var_name_cstr, name) == 0)
330                    return var_sp;
331            }
332            var_sp.reset();
333        }
334        return var_sp;
335    }
336
337    //----------------------------------------------------------------------
338    /// Finds a variable by NamedDecl in the list.
339    ///
340    /// @param[in] name
341    ///     The name of the requested variable.
342    ///
343    /// @return
344    ///     The variable requested, or NULL if that variable is not in the list.
345    //----------------------------------------------------------------------
346    lldb::ClangExpressionVariableSP
347    GetVariable (const clang::NamedDecl *decl)
348    {
349        lldb::ClangExpressionVariableSP var_sp;
350        for (size_t index = 0, size = GetSize(); index < size; ++index)
351        {
352            var_sp = GetVariableAtIndex(index);
353            if (var_sp->m_parser_vars.get() && var_sp->m_parser_vars->m_named_decl == decl)
354                return var_sp;
355        }
356        var_sp.reset();
357        return var_sp;
358    }
359
360    //----------------------------------------------------------------------
361    /// Create a new variable in the list and return its index
362    //----------------------------------------------------------------------
363    lldb::ClangExpressionVariableSP
364    CreateVariable (ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size)
365    {
366        lldb::ClangExpressionVariableSP var_sp(new ClangExpressionVariable(exe_scope, byte_order, addr_byte_size));
367        m_variables.push_back(var_sp);
368        return var_sp;
369    }
370
371    lldb::ClangExpressionVariableSP
372    CreateVariable(const lldb::ValueObjectSP &valobj_sp)
373    {
374        lldb::ClangExpressionVariableSP var_sp(new ClangExpressionVariable(valobj_sp));
375        m_variables.push_back(var_sp);
376        return var_sp;
377    }
378
379
380
381    lldb::ClangExpressionVariableSP
382    CreateVariable (ExecutionContextScope *exe_scope,
383                    const ConstString &name,
384                    const TypeFromUser& user_type,
385                    lldb::ByteOrder byte_order,
386                    uint32_t addr_byte_size)
387    {
388        lldb::ClangExpressionVariableSP var_sp(new ClangExpressionVariable(exe_scope, byte_order, addr_byte_size));
389        var_sp->SetName (name);
390        var_sp->SetClangType (user_type.GetOpaqueQualType());
391        var_sp->SetClangAST (user_type.GetASTContext());
392        m_variables.push_back(var_sp);
393        return var_sp;
394    }
395
396    void
397    Clear()
398    {
399        m_variables.clear();
400    }
401
402private:
403    std::vector <lldb::ClangExpressionVariableSP> m_variables;
404};
405
406
407} // namespace lldb_private
408
409#endif  // liblldb_ClangExpressionVariable_h_
410