1 //===-- VariableList.cpp ----------------------------------------*- 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 #include "lldb/Symbol/VariableList.h"
12 #include "lldb/Symbol/Block.h"
13 #include "lldb/Symbol/CompileUnit.h"
14 #include "lldb/Symbol/Function.h"
15 #include "lldb/Utility/RegularExpression.h"
18 using namespace lldb_private;
20 //----------------------------------------------------------------------
21 // VariableList constructor
22 //----------------------------------------------------------------------
23 VariableList::VariableList() : m_variables() {}
25 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 VariableList::~VariableList() {}
30 void VariableList::AddVariable(const VariableSP &var_sp) {
31 m_variables.push_back(var_sp);
34 bool VariableList::AddVariableIfUnique(const lldb::VariableSP &var_sp) {
35 if (FindVariableIndex(var_sp) == UINT32_MAX) {
36 m_variables.push_back(var_sp);
42 void VariableList::AddVariables(VariableList *variable_list) {
44 std::copy(variable_list->m_variables.begin(), // source begin
45 variable_list->m_variables.end(), // source end
46 back_inserter(m_variables)); // destination
50 void VariableList::Clear() { m_variables.clear(); }
52 VariableSP VariableList::GetVariableAtIndex(size_t idx) const {
54 if (idx < m_variables.size())
55 var_sp = m_variables[idx];
59 VariableSP VariableList::RemoveVariableAtIndex(size_t idx) {
61 if (idx < m_variables.size()) {
62 var_sp = m_variables[idx];
63 m_variables.erase(m_variables.begin() + idx);
68 uint32_t VariableList::FindVariableIndex(const VariableSP &var_sp) {
69 iterator pos, end = m_variables.end();
70 for (pos = m_variables.begin(); pos != end; ++pos) {
71 if (pos->get() == var_sp.get())
72 return std::distance(m_variables.begin(), pos);
77 VariableSP VariableList::FindVariable(const ConstString &name,
78 bool include_static_members) {
80 iterator pos, end = m_variables.end();
81 for (pos = m_variables.begin(); pos != end; ++pos) {
82 if ((*pos)->NameMatches(name)) {
83 if (include_static_members || !(*pos)->IsStaticMember()) {
92 VariableSP VariableList::FindVariable(const ConstString &name,
93 lldb::ValueType value_type,
94 bool include_static_members) {
96 iterator pos, end = m_variables.end();
97 for (pos = m_variables.begin(); pos != end; ++pos) {
98 if ((*pos)->NameMatches(name) && (*pos)->GetScope() == value_type) {
99 if (include_static_members || !(*pos)->IsStaticMember()) {
108 size_t VariableList::AppendVariablesIfUnique(VariableList &var_list) {
109 const size_t initial_size = var_list.GetSize();
110 iterator pos, end = m_variables.end();
111 for (pos = m_variables.begin(); pos != end; ++pos)
112 var_list.AddVariableIfUnique(*pos);
113 return var_list.GetSize() - initial_size;
116 size_t VariableList::AppendVariablesIfUnique(const RegularExpression ®ex,
117 VariableList &var_list,
118 size_t &total_matches) {
119 const size_t initial_size = var_list.GetSize();
120 iterator pos, end = m_variables.end();
121 for (pos = m_variables.begin(); pos != end; ++pos) {
122 if ((*pos)->NameMatches(regex)) {
123 // Note the total matches found
125 // Only add this variable if it isn't already in the "var_list"
126 var_list.AddVariableIfUnique(*pos);
129 // Return the number of new unique variables added to "var_list"
130 return var_list.GetSize() - initial_size;
133 size_t VariableList::AppendVariablesWithScope(lldb::ValueType type,
134 VariableList &var_list,
136 const size_t initial_size = var_list.GetSize();
137 iterator pos, end = m_variables.end();
138 for (pos = m_variables.begin(); pos != end; ++pos) {
139 if ((*pos)->GetScope() == type) {
141 var_list.AddVariableIfUnique(*pos);
143 var_list.AddVariable(*pos);
146 // Return the number of new unique variables added to "var_list"
147 return var_list.GetSize() - initial_size;
150 uint32_t VariableList::FindIndexForVariable(Variable *variable) {
153 const iterator begin = m_variables.begin();
154 const iterator end = m_variables.end();
155 for (pos = m_variables.begin(); pos != end; ++pos) {
156 if ((*pos).get() == variable)
157 return std::distance(begin, pos);
162 size_t VariableList::MemorySize() const {
163 size_t mem_size = sizeof(VariableList);
164 const_iterator pos, end = m_variables.end();
165 for (pos = m_variables.begin(); pos != end; ++pos)
166 mem_size += (*pos)->MemorySize();
170 size_t VariableList::GetSize() const { return m_variables.size(); }
172 void VariableList::Dump(Stream *s, bool show_context) const {
173 // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
175 // s << "VariableList\n";
177 const_iterator pos, end = m_variables.end();
178 for (pos = m_variables.begin(); pos != end; ++pos) {
179 (*pos)->Dump(s, show_context);