blob: 1c2bb0d19b91e0012acf6ed7067e0c7f1f0e3816 [file] [log] [blame]
Chris Lattner24943d22010-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 Clayton6bc0b5d2010-10-10 23:55:27 +000011
12#include "lldb/Core/RegularExpression.h"
Chris Lattner24943d22010-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 Lattner24943d22010-06-08 16:52:24 +000035void
Greg Clayton6bc0b5d2010-10-10 23:55:27 +000036VariableList::AddVariable(const VariableSP &var_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000037{
Greg Clayton6bc0b5d2010-10-10 23:55:27 +000038 m_variables.push_back(var_sp);
Chris Lattner24943d22010-06-08 16:52:24 +000039}
40
Greg Clayton6bc0b5d2010-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 Lattner24943d22010-06-08 16:52:24 +000051
52void
53VariableList::AddVariables(VariableList *variable_list)
54{
55 std::copy( variable_list->m_variables.begin(), // source begin
56 variable_list->m_variables.end(), // source end
57 back_inserter(m_variables)); // destination
58}
59
Chris Lattner24943d22010-06-08 16:52:24 +000060void
61VariableList::Clear()
62{
63 m_variables.clear();
64}
65
Chris Lattner24943d22010-06-08 16:52:24 +000066VariableSP
67VariableList::GetVariableAtIndex(uint32_t idx)
68{
Greg Clayton6bc0b5d2010-10-10 23:55:27 +000069 VariableSP var_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000070 if (idx < m_variables.size())
Greg Clayton6bc0b5d2010-10-10 23:55:27 +000071 var_sp = m_variables[idx];
72 return var_sp;
Chris Lattner24943d22010-06-08 16:52:24 +000073}
74
Greg Clayton5d81f492011-07-08 21:46:14 +000075VariableSP
76VariableList::RemoveVariableAtIndex(uint32_t idx)
77{
78 VariableSP var_sp;
79 if (idx < m_variables.size())
80 {
81 var_sp = m_variables[idx];
82 m_variables.erase (m_variables.begin() + idx);
83 }
84 return var_sp;
85}
86
Greg Clayton6bc0b5d2010-10-10 23:55:27 +000087uint32_t
88VariableList::FindVariableIndex (const VariableSP &var_sp)
89{
90 iterator pos, end = m_variables.end();
91 for (pos = m_variables.begin(); pos != end; ++pos)
92 {
93 if (pos->get() == var_sp.get())
94 return std::distance (m_variables.begin(), pos);
95 }
96 return UINT32_MAX;
97}
Chris Lattner24943d22010-06-08 16:52:24 +000098
99VariableSP
100VariableList::FindVariable(const ConstString& name)
101{
102 VariableSP var_sp;
103 iterator pos, end = m_variables.end();
104 for (pos = m_variables.begin(); pos != end; ++pos)
105 {
Greg Clayton3bc52d02010-11-14 22:13:40 +0000106 if ((*pos)->NameMatches(name))
Chris Lattner24943d22010-06-08 16:52:24 +0000107 {
108 var_sp = (*pos);
109 break;
110 }
111 }
112 return var_sp;
113}
114
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000115size_t
116VariableList::AppendVariablesIfUnique (const RegularExpression& regex, VariableList &var_list, size_t& total_matches)
117{
118 const size_t initial_size = var_list.GetSize();
119 iterator pos, end = m_variables.end();
120 for (pos = m_variables.begin(); pos != end; ++pos)
121 {
Greg Clayton3bc52d02010-11-14 22:13:40 +0000122 if ((*pos)->NameMatches (regex))
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000123 {
124 // Note the total matches found
125 total_matches++;
126 // Only add this variable if it isn't already in the "var_list"
127 var_list.AddVariableIfUnique (*pos);
128 }
129 }
130 // Return the number of new unique variables added to "var_list"
131 return var_list.GetSize() - initial_size;
132}
133
Greg Clayton17dae082010-09-02 02:59:18 +0000134uint32_t
135VariableList::FindIndexForVariable (Variable* variable)
136{
137 VariableSP var_sp;
138 iterator pos;
139 const iterator begin = m_variables.begin();
140 const iterator end = m_variables.end();
141 for (pos = m_variables.begin(); pos != end; ++pos)
142 {
143 if ((*pos).get() == variable)
144 return std::distance (begin, pos);
145 }
146 return UINT32_MAX;
147}
Chris Lattner24943d22010-06-08 16:52:24 +0000148
149size_t
150VariableList::MemorySize() const
151{
152 size_t mem_size = sizeof(VariableList);
153 const_iterator pos, end = m_variables.end();
154 for (pos = m_variables.begin(); pos != end; ++pos)
155 mem_size += (*pos)->MemorySize();
156 return mem_size;
157}
158
159size_t
160VariableList::GetSize() const
161{
162 return m_variables.size();
163}
164
Chris Lattner24943d22010-06-08 16:52:24 +0000165void
166VariableList::Dump(Stream *s, bool show_context) const
167{
168// s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
169// s.Indent();
170// s << "VariableList\n";
171
172 const_iterator pos, end = m_variables.end();
173 for (pos = m_variables.begin(); pos != end; ++pos)
174 {
175 (*pos)->Dump(s, show_context);
176 }
177}
178