Variable.h revision 3bc52d0a96c18be384028a90914f534ac252fbe4
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              Type *type,
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    const Declaration&
48    GetDeclaration() const
49    {
50        return m_declaration;
51    }
52
53    const ConstString&
54    GetName() const;
55
56    // Since a variable can have a basename "i" and also a mangled
57    // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
58    // "(anonymous namespace)::i", this function will allow a generic match
59    // function that can be called by commands and expression parsers to make
60    // sure we match anything we come across.
61    bool
62    NameMatches (const ConstString &name) const
63    {
64        if (m_name == name)
65            return true;
66        return m_mangled.NameMatches (name);
67    }
68
69    bool
70    NameMatches (const RegularExpression& regex) const;
71
72    Type *
73    GetType()
74    {
75        return m_type;
76    }
77
78    const Type *
79    GetType() const
80    {
81        return m_type;
82    }
83
84    lldb::ValueType
85    GetScope() const
86    {
87        return m_scope;
88    }
89
90    bool
91    IsExternal() const
92    {
93        return m_external;
94    }
95
96    bool
97    IsArtificial() const
98    {
99        return m_artificial;
100    }
101
102    DWARFExpression &
103    LocationExpression()
104    {
105        return m_location;
106    }
107
108    const DWARFExpression &
109    LocationExpression() const
110    {
111        return m_location;
112    }
113
114    size_t
115    MemorySize() const;
116
117    void
118    CalculateSymbolContext (SymbolContext *sc);
119
120    bool
121    IsInScope (StackFrame *frame);
122
123protected:
124    ConstString m_name;                 // The basename of the variable (no namespaces)
125    Mangled m_mangled;                  // The mangled name of hte variable
126    Type *m_type;                       // The type pointer of the variable (int, struct, class, etc)
127    lldb::ValueType m_scope;            // global, parameter, local
128    SymbolContextScope *m_owner_scope;  // The symbol file scope that this variable was defined in
129    Declaration m_declaration;          // Declaration location for this item.
130    DWARFExpression m_location;         // The location of this variable that can be fed to DWARFExpression::Evaluate()
131    uint8_t m_external:1,               // Visible outside the containing compile unit?
132            m_artificial:1;             // Non-zero if the variable is not explicitly declared in source
133private:
134    Variable(const Variable& rhs);
135    Variable& operator=(const Variable& rhs);
136};
137
138} // namespace lldb_private
139
140#endif  // liblldb_Variable_h_
141