blob: 15f2b2907969fbf105d84e27e8face03e2b5a469 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- VariableList.cpp ----------------------------------------*- 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#include "lldb/Symbol/VariableList.h"
Greg Clayton46747022010-10-10 23:55:27 +000011
12#include "lldb/Core/RegularExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Symbol/Block.h"
14#include "lldb/Symbol/Function.h"
15#include "lldb/Symbol/CompileUnit.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20//----------------------------------------------------------------------
21// VariableList constructor
22//----------------------------------------------------------------------
23VariableList::VariableList() :
24 m_variables()
25{
26}
27
28//----------------------------------------------------------------------
29// Destructor
30//----------------------------------------------------------------------
31VariableList::~VariableList()
32{
33}
34
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035void
Greg Clayton46747022010-10-10 23:55:27 +000036VariableList::AddVariable(const VariableSP &var_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037{
Greg Clayton46747022010-10-10 23:55:27 +000038 m_variables.push_back(var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039}
40
Greg Clayton46747022010-10-10 23:55:27 +000041bool
42VariableList::AddVariableIfUnique (const lldb::VariableSP &var_sp)
43{
44 if (FindVariableIndex (var_sp) == UINT32_MAX)
45 {
46 m_variables.push_back(var_sp);
47 return true;
48 }
49 return false;
50}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
52void
53VariableList::AddVariables(VariableList *variable_list)
54{
Greg Clayton1f746072012-08-29 21:13:06 +000055 if (variable_list)
56 {
57 std::copy(variable_list->m_variables.begin(), // source begin
58 variable_list->m_variables.end(), // source end
59 back_inserter(m_variables)); // destination
60 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061}
62
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063void
64VariableList::Clear()
65{
66 m_variables.clear();
67}
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069VariableSP
Greg Claytonc7bece562013-01-25 18:06:21 +000070VariableList::GetVariableAtIndex(size_t idx) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071{
Greg Clayton46747022010-10-10 23:55:27 +000072 VariableSP var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073 if (idx < m_variables.size())
Greg Clayton46747022010-10-10 23:55:27 +000074 var_sp = m_variables[idx];
75 return var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076}
77
Greg Clayton884fb692011-07-08 21:46:14 +000078VariableSP
Greg Claytonc7bece562013-01-25 18:06:21 +000079VariableList::RemoveVariableAtIndex(size_t idx)
Greg Clayton884fb692011-07-08 21:46:14 +000080{
81 VariableSP var_sp;
82 if (idx < m_variables.size())
83 {
84 var_sp = m_variables[idx];
85 m_variables.erase (m_variables.begin() + idx);
86 }
87 return var_sp;
88}
89
Greg Clayton46747022010-10-10 23:55:27 +000090uint32_t
91VariableList::FindVariableIndex (const VariableSP &var_sp)
92{
93 iterator pos, end = m_variables.end();
94 for (pos = m_variables.begin(); pos != end; ++pos)
95 {
96 if (pos->get() == var_sp.get())
97 return std::distance (m_variables.begin(), pos);
98 }
99 return UINT32_MAX;
100}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101
102VariableSP
103VariableList::FindVariable(const ConstString& name)
104{
105 VariableSP var_sp;
106 iterator pos, end = m_variables.end();
107 for (pos = m_variables.begin(); pos != end; ++pos)
108 {
Greg Clayton83c5cd92010-11-14 22:13:40 +0000109 if ((*pos)->NameMatches(name))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 {
111 var_sp = (*pos);
112 break;
113 }
114 }
115 return var_sp;
116}
117
Enrico Granata08a04322014-02-18 23:48:11 +0000118VariableSP
119VariableList::FindVariable (const ConstString& name, lldb::ValueType value_type)
120{
121 VariableSP var_sp;
122 iterator pos, end = m_variables.end();
123 for (pos = m_variables.begin(); pos != end; ++pos)
124 {
125 if ((*pos)->NameMatches(name) && (*pos)->GetScope() == value_type)
126 {
127 var_sp = (*pos);
128 break;
129 }
130 }
131 return var_sp;
132}
133
Greg Clayton46747022010-10-10 23:55:27 +0000134size_t
135VariableList::AppendVariablesIfUnique (const RegularExpression& regex, VariableList &var_list, size_t& total_matches)
136{
137 const size_t initial_size = var_list.GetSize();
138 iterator pos, end = m_variables.end();
139 for (pos = m_variables.begin(); pos != end; ++pos)
140 {
Greg Clayton83c5cd92010-11-14 22:13:40 +0000141 if ((*pos)->NameMatches (regex))
Greg Clayton46747022010-10-10 23:55:27 +0000142 {
143 // Note the total matches found
144 total_matches++;
145 // Only add this variable if it isn't already in the "var_list"
146 var_list.AddVariableIfUnique (*pos);
147 }
148 }
149 // Return the number of new unique variables added to "var_list"
150 return var_list.GetSize() - initial_size;
151}
152
Enrico Granatacc7f9bf2013-05-08 20:27:37 +0000153size_t
154VariableList::AppendVariablesWithScope (lldb::ValueType type,
155 VariableList &var_list,
156 bool if_unique)
157{
158 const size_t initial_size = var_list.GetSize();
159 iterator pos, end = m_variables.end();
160 for (pos = m_variables.begin(); pos != end; ++pos)
161 {
162 if ((*pos)->GetScope() == type)
163 {
164 if (if_unique)
165 var_list.AddVariableIfUnique (*pos);
166 else
167 var_list.AddVariable(*pos);
168 }
169 }
170 // Return the number of new unique variables added to "var_list"
171 return var_list.GetSize() - initial_size;
172}
173
Greg Clayton288bdf92010-09-02 02:59:18 +0000174uint32_t
175VariableList::FindIndexForVariable (Variable* variable)
176{
177 VariableSP var_sp;
178 iterator pos;
179 const iterator begin = m_variables.begin();
180 const iterator end = m_variables.end();
181 for (pos = m_variables.begin(); pos != end; ++pos)
182 {
183 if ((*pos).get() == variable)
184 return std::distance (begin, pos);
185 }
186 return UINT32_MAX;
187}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188
189size_t
190VariableList::MemorySize() const
191{
192 size_t mem_size = sizeof(VariableList);
193 const_iterator pos, end = m_variables.end();
194 for (pos = m_variables.begin(); pos != end; ++pos)
195 mem_size += (*pos)->MemorySize();
196 return mem_size;
197}
198
199size_t
200VariableList::GetSize() const
201{
202 return m_variables.size();
203}
204
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205void
206VariableList::Dump(Stream *s, bool show_context) const
207{
208// s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
209// s.Indent();
210// s << "VariableList\n";
211
212 const_iterator pos, end = m_variables.end();
213 for (pos = m_variables.begin(); pos != end; ++pos)
214 {
215 (*pos)->Dump(s, show_context);
216 }
217}