Variable.h revision 36da2aa6dc5ad9994b638ed09eb81c44cc05540b
1//===-- Variable.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_Variable_h_
11#define liblldb_Variable_h_
12
13#include <vector>
14
15#include "lldb/lldb-private.h"
16#include "lldb/lldb-enumerations.h"
17#include "lldb/Core/Mangled.h"
18#include "lldb/Core/UserID.h"
19#include "lldb/Expression/DWARFExpression.h"
20#include "lldb/Symbol/Declaration.h"
21
22namespace lldb_private {
23
24class Variable : public UserID
25{
26public:
27    //------------------------------------------------------------------
28    // Constructors and Destructors
29    //------------------------------------------------------------------
30    Variable (lldb::user_id_t uid,
31              const char *name,
32              const char *mangled,   // The mangled variable name for variables in namespaces
33              const lldb::SymbolFileTypeSP &symfile_type_sp,
34              lldb::ValueType scope,
35              SymbolContextScope *owner_scope,
36              Declaration* decl,
37              const DWARFExpression& location,
38              bool external,
39              bool artificial);
40
41    virtual
42    ~Variable();
43
44    void
45    Dump(Stream *s, bool show_context) const;
46
47    bool
48    DumpDeclaration (Stream *s,
49                     bool show_fullpaths,
50                     bool show_module);
51
52    const Declaration&
53    GetDeclaration() const
54    {
55        return m_declaration;
56    }
57
58    const ConstString&
59    GetName() const;
60
61    SymbolContextScope *
62    GetSymbolContextScope() const
63    {
64        return m_owner_scope;
65    }
66
67    // Since a variable can have a basename "i" and also a mangled
68    // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
69    // "(anonymous namespace)::i", this function will allow a generic match
70    // function that can be called by commands and expression parsers to make
71    // sure we match anything we come across.
72    bool
73    NameMatches (const ConstString &name) const
74    {
75        if (m_name == name)
76            return true;
77        return m_mangled.NameMatches (name);
78    }
79
80    bool
81    NameMatches (const RegularExpression& regex) const;
82
83    Type *
84    GetType();
85
86    lldb::ValueType
87    GetScope() const
88    {
89        return m_scope;
90    }
91
92    bool
93    IsExternal() const
94    {
95        return m_external;
96    }
97
98    bool
99    IsArtificial() const
100    {
101        return m_artificial;
102    }
103
104    DWARFExpression &
105    LocationExpression()
106    {
107        return m_location;
108    }
109
110    const DWARFExpression &
111    LocationExpression() const
112    {
113        return m_location;
114    }
115
116    bool
117    DumpLocationForAddress (Stream *s,
118                            const Address &address);
119
120    size_t
121    MemorySize() const;
122
123    void
124    CalculateSymbolContext (SymbolContext *sc);
125
126    bool
127    IsInScope (StackFrame *frame);
128
129    bool
130    LocationIsValidForFrame (StackFrame *frame);
131
132    bool
133    LocationIsValidForAddress (const Address &address);
134
135    bool
136    GetLocationIsConstantValueData () const
137    {
138        return m_loc_is_const_data;
139    }
140
141    void
142    SetLocationIsConstantValueData (bool b)
143    {
144        m_loc_is_const_data = b;
145    }
146
147    typedef size_t (*GetVariableCallback) (void *baton,
148                                           const char *name,
149                                           VariableList &var_list);
150
151
152    static Error
153    GetValuesForVariableExpressionPath (const char *variable_expr_path,
154                                        ExecutionContextScope *scope,
155                                        GetVariableCallback callback,
156                                        void *baton,
157                                        VariableList &variable_list,
158                                        ValueObjectList &valobj_list);
159
160protected:
161    ConstString m_name;                 // The basename of the variable (no namespaces)
162    Mangled m_mangled;                  // The mangled name of the variable
163    lldb::SymbolFileTypeSP m_symfile_type_sp;   // The type pointer of the variable (int, struct, class, etc)
164    lldb::ValueType m_scope;            // global, parameter, local
165    SymbolContextScope *m_owner_scope;  // The symbol file scope that this variable was defined in
166    Declaration m_declaration;          // Declaration location for this item.
167    DWARFExpression m_location;         // The location of this variable that can be fed to DWARFExpression::Evaluate()
168    uint8_t m_external:1,               // Visible outside the containing compile unit?
169            m_artificial:1,             // Non-zero if the variable is not explicitly declared in source
170            m_loc_is_const_data:1;      // The m_location expression contains the constant variable value data, not a DWARF location
171private:
172    Variable(const Variable& rhs);
173    Variable& operator=(const Variable& rhs);
174};
175
176} // namespace lldb_private
177
178#endif  // liblldb_Variable_h_
179