Variable.h revision 309124
1//===-- Variable.h ----------------------------------------------*- C++
2//-*-===//
3//
4//                     The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef liblldb_Variable_h_
12#define liblldb_Variable_h_
13
14#include <memory>
15#include <vector>
16
17#include "lldb/lldb-private.h"
18#include "lldb/lldb-enumerations.h"
19#include "lldb/Core/Mangled.h"
20#include "lldb/Core/RangeMap.h"
21#include "lldb/Core/UserID.h"
22#include "lldb/Expression/DWARFExpression.h"
23#include "lldb/Symbol/Declaration.h"
24
25namespace lldb_private {
26
27class Variable : public UserID,
28    public std::enable_shared_from_this<Variable>
29{
30public:
31    typedef RangeVector<lldb::addr_t, lldb::addr_t> RangeList;
32
33    //------------------------------------------------------------------
34    // Constructors and Destructors
35    //------------------------------------------------------------------
36    Variable (lldb::user_id_t uid,
37              const char *name,
38              const char *mangled,  // The mangled or fully qualified name of the variable.
39              const lldb::SymbolFileTypeSP &symfile_type_sp,
40              lldb::ValueType scope,
41              SymbolContextScope *owner_scope,
42              const RangeList& scope_range,
43              Declaration* decl,
44              const DWARFExpression& location,
45              bool external,
46              bool artificial,
47              bool static_member = false);
48
49    virtual
50    ~Variable();
51
52    void
53    Dump(Stream *s, bool show_context) const;
54
55    bool
56    DumpDeclaration (Stream *s,
57                     bool show_fullpaths,
58                     bool show_module);
59
60    const Declaration&
61    GetDeclaration() const
62    {
63        return m_declaration;
64    }
65
66    ConstString
67    GetName() const;
68
69    ConstString
70    GetUnqualifiedName() const;
71
72    SymbolContextScope *
73    GetSymbolContextScope() const
74    {
75        return m_owner_scope;
76    }
77
78    // Since a variable can have a basename "i" and also a mangled
79    // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
80    // "(anonymous namespace)::i", this function will allow a generic match
81    // function that can be called by commands and expression parsers to make
82    // sure we match anything we come across.
83    bool
84    NameMatches (const ConstString &name) const;
85
86    bool
87    NameMatches (const RegularExpression& regex) const;
88
89    Type *
90    GetType();
91
92    lldb::LanguageType
93    GetLanguage () const;
94
95    lldb::ValueType
96    GetScope() const
97    {
98        return m_scope;
99    }
100
101    bool
102    IsExternal() const
103    {
104        return m_external;
105    }
106
107    bool
108    IsArtificial() const
109    {
110        return m_artificial;
111    }
112
113    bool IsStaticMember() const
114    {
115        return m_static_member;
116    }
117
118    DWARFExpression &
119    LocationExpression()
120    {
121        return m_location;
122    }
123
124    const DWARFExpression &
125    LocationExpression() const
126    {
127        return m_location;
128    }
129
130    bool
131    DumpLocationForAddress (Stream *s,
132                            const Address &address);
133
134    size_t
135    MemorySize() const;
136
137    void
138    CalculateSymbolContext (SymbolContext *sc);
139
140    bool
141    IsInScope (StackFrame *frame);
142
143    bool
144    LocationIsValidForFrame (StackFrame *frame);
145
146    bool
147    LocationIsValidForAddress (const Address &address);
148
149    bool
150    GetLocationIsConstantValueData () const
151    {
152        return m_loc_is_const_data;
153    }
154
155    void
156    SetLocationIsConstantValueData (bool b)
157    {
158        m_loc_is_const_data = b;
159    }
160
161    typedef size_t (*GetVariableCallback) (void *baton,
162                                           const char *name,
163                                           VariableList &var_list);
164
165
166    static Error
167    GetValuesForVariableExpressionPath (const char *variable_expr_path,
168                                        ExecutionContextScope *scope,
169                                        GetVariableCallback callback,
170                                        void *baton,
171                                        VariableList &variable_list,
172                                        ValueObjectList &valobj_list);
173
174    static size_t
175    AutoComplete (const ExecutionContext &exe_ctx,
176                  const char *name,
177                  StringList &matches,
178                  bool &word_complete);
179
180    CompilerDeclContext
181    GetDeclContext ();
182
183    CompilerDecl
184    GetDecl ();
185
186protected:
187    ConstString m_name;                 // The basename of the variable (no namespaces)
188    Mangled m_mangled;                  // The mangled name of the variable
189    lldb::SymbolFileTypeSP m_symfile_type_sp;   // The type pointer of the variable (int, struct, class, etc)
190    lldb::ValueType m_scope;            // global, parameter, local
191    SymbolContextScope *m_owner_scope;  // The symbol file scope that this variable was defined in
192    RangeList m_scope_range;            // The list of ranges inside the owner's scope where this variable is valid
193    Declaration m_declaration;          // Declaration location for this item.
194    DWARFExpression m_location;         // The location of this variable that can be fed to DWARFExpression::Evaluate()
195    uint8_t m_external:1,               // Visible outside the containing compile unit?
196            m_artificial:1,             // Non-zero if the variable is not explicitly declared in source
197            m_loc_is_const_data:1,      // The m_location expression contains the constant variable value data, not a DWARF location
198            m_static_member:1;          // Non-zero if variable is static member of a class or struct.
199private:
200    Variable(const Variable& rhs);
201    Variable& operator=(const Variable& rhs);
202};
203
204} // namespace lldb_private
205
206#endif  // liblldb_Variable_h_
207