blob: 75106ffc6fb0ae81c1801b2be189e6161aa2f52a [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 Clayton6bc0b5d2010-10-10 23:55:27 +000075uint32_t
76VariableList::FindVariableIndex (const VariableSP &var_sp)
77{
78 iterator pos, end = m_variables.end();
79 for (pos = m_variables.begin(); pos != end; ++pos)
80 {
81 if (pos->get() == var_sp.get())
82 return std::distance (m_variables.begin(), pos);
83 }
84 return UINT32_MAX;
85}
Chris Lattner24943d22010-06-08 16:52:24 +000086
87VariableSP
88VariableList::FindVariable(const ConstString& name)
89{
90 VariableSP var_sp;
91 iterator pos, end = m_variables.end();
92 for (pos = m_variables.begin(); pos != end; ++pos)
93 {
94 if ((*pos)->GetName() == name)
95 {
96 var_sp = (*pos);
97 break;
98 }
99 }
100 return var_sp;
101}
102
Greg Clayton6bc0b5d2010-10-10 23:55:27 +0000103size_t
104VariableList::AppendVariablesIfUnique (const RegularExpression& regex, VariableList &var_list, size_t& total_matches)
105{
106 const size_t initial_size = var_list.GetSize();
107 iterator pos, end = m_variables.end();
108 for (pos = m_variables.begin(); pos != end; ++pos)
109 {
110 if (regex.Execute ((*pos)->GetName().AsCString()))
111 {
112 // Note the total matches found
113 total_matches++;
114 // Only add this variable if it isn't already in the "var_list"
115 var_list.AddVariableIfUnique (*pos);
116 }
117 }
118 // Return the number of new unique variables added to "var_list"
119 return var_list.GetSize() - initial_size;
120}
121
Greg Clayton17dae082010-09-02 02:59:18 +0000122uint32_t
123VariableList::FindIndexForVariable (Variable* variable)
124{
125 VariableSP var_sp;
126 iterator pos;
127 const iterator begin = m_variables.begin();
128 const iterator end = m_variables.end();
129 for (pos = m_variables.begin(); pos != end; ++pos)
130 {
131 if ((*pos).get() == variable)
132 return std::distance (begin, pos);
133 }
134 return UINT32_MAX;
135}
Chris Lattner24943d22010-06-08 16:52:24 +0000136
137size_t
138VariableList::MemorySize() const
139{
140 size_t mem_size = sizeof(VariableList);
141 const_iterator pos, end = m_variables.end();
142 for (pos = m_variables.begin(); pos != end; ++pos)
143 mem_size += (*pos)->MemorySize();
144 return mem_size;
145}
146
147size_t
148VariableList::GetSize() const
149{
150 return m_variables.size();
151}
152
Chris Lattner24943d22010-06-08 16:52:24 +0000153void
154VariableList::Dump(Stream *s, bool show_context) const
155{
156// s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
157// s.Indent();
158// s << "VariableList\n";
159
160 const_iterator pos, end = m_variables.end();
161 for (pos = m_variables.begin(); pos != end; ++pos)
162 {
163 (*pos)->Dump(s, show_context);
164 }
165}
166