1 //===-- Variable.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_Variable_h_
11 #define liblldb_Variable_h_
16 #include "lldb/Core/Mangled.h"
17 #include "lldb/Core/RangeMap.h"
18 #include "lldb/Expression/DWARFExpression.h"
19 #include "lldb/Symbol/Declaration.h"
20 #include "lldb/Utility/UserID.h"
21 #include "lldb/lldb-enumerations.h"
22 #include "lldb/lldb-private.h"
24 namespace lldb_private {
26 class Variable : public UserID, public std::enable_shared_from_this<Variable> {
28 typedef RangeVector<lldb::addr_t, lldb::addr_t> RangeList;
30 //------------------------------------------------------------------
31 // Constructors and Destructors
32 //------------------------------------------------------------------
33 Variable(lldb::user_id_t uid, const char *name,
35 *mangled, // The mangled or fully qualified name of the variable.
36 const lldb::SymbolFileTypeSP &symfile_type_sp,
37 lldb::ValueType scope, SymbolContextScope *owner_scope,
38 const RangeList &scope_range, Declaration *decl,
39 const DWARFExpression &location, bool external, bool artificial,
40 bool static_member = false);
44 void Dump(Stream *s, bool show_context) const;
46 bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module);
48 const Declaration &GetDeclaration() const { return m_declaration; }
50 ConstString GetName() const;
52 ConstString GetUnqualifiedName() const;
54 SymbolContextScope *GetSymbolContextScope() const { return m_owner_scope; }
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 NameMatches(const ConstString &name) const;
63 bool NameMatches(const RegularExpression ®ex) const;
67 lldb::LanguageType GetLanguage() const;
69 lldb::ValueType GetScope() const { return m_scope; }
71 bool IsExternal() const { return m_external; }
73 bool IsArtificial() const { return m_artificial; }
75 bool IsStaticMember() const { return m_static_member; }
77 DWARFExpression &LocationExpression() { return m_location; }
79 const DWARFExpression &LocationExpression() const { return m_location; }
81 bool DumpLocationForAddress(Stream *s, const Address &address);
83 size_t MemorySize() const;
85 void CalculateSymbolContext(SymbolContext *sc);
87 bool IsInScope(StackFrame *frame);
89 bool LocationIsValidForFrame(StackFrame *frame);
91 bool LocationIsValidForAddress(const Address &address);
93 bool GetLocationIsConstantValueData() const { return m_loc_is_const_data; }
95 void SetLocationIsConstantValueData(bool b) { m_loc_is_const_data = b; }
97 typedef size_t (*GetVariableCallback)(void *baton, const char *name,
98 VariableList &var_list);
100 static Status GetValuesForVariableExpressionPath(
101 llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
102 GetVariableCallback callback, void *baton, VariableList &variable_list,
103 ValueObjectList &valobj_list);
105 static size_t AutoComplete(const ExecutionContext &exe_ctx,
106 llvm::StringRef name, StringList &matches,
107 bool &word_complete);
109 CompilerDeclContext GetDeclContext();
111 CompilerDecl GetDecl();
114 ConstString m_name; // The basename of the variable (no namespaces)
115 Mangled m_mangled; // The mangled name of the variable
116 lldb::SymbolFileTypeSP m_symfile_type_sp; // The type pointer of the variable
117 // (int, struct, class, etc)
118 lldb::ValueType m_scope; // global, parameter, local
120 *m_owner_scope; // The symbol file scope that this variable was defined in
121 RangeList m_scope_range; // The list of ranges inside the owner's scope where
122 // this variable is valid
123 Declaration m_declaration; // Declaration location for this item.
124 DWARFExpression m_location; // The location of this variable that can be fed
125 // to DWARFExpression::Evaluate()
126 uint8_t m_external : 1, // Visible outside the containing compile unit?
127 m_artificial : 1, // Non-zero if the variable is not explicitly declared
129 m_loc_is_const_data : 1, // The m_location expression contains the
130 // constant variable value data, not a DWARF
132 m_static_member : 1; // Non-zero if variable is static member of a class
135 Variable(const Variable &rhs);
136 Variable &operator=(const Variable &rhs);
139 } // namespace lldb_private
141 #endif // liblldb_Variable_h_