1 //===-- 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"
11 #include "lldb/Symbol/Block.h"
12 #include "lldb/Symbol/Function.h"
13 #include "lldb/Symbol/CompileUnit.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 //----------------------------------------------------------------------
19 // VariableList constructor
20 //----------------------------------------------------------------------
21 VariableList::VariableList() :
22     m_variables()
23 {
24 }
25 
26 //----------------------------------------------------------------------
27 // Destructor
28 //----------------------------------------------------------------------
29 VariableList::~VariableList()
30 {
31 }
32 
33 
34 void
35 VariableList::AddVariable(const VariableSP &variable_sp)
36 {
37     m_variables.push_back(variable_sp);
38 }
39 
40 
41 void
42 VariableList::AddVariables(VariableList *variable_list)
43 {
44     std::copy(  variable_list->m_variables.begin(), // source begin
45                 variable_list->m_variables.end(),   // source end
46                 back_inserter(m_variables));        // destination
47 }
48 
49 
50 void
51 VariableList::Clear()
52 {
53     m_variables.clear();
54 }
55 
56 
57 
58 VariableSP
59 VariableList::GetVariableAtIndex(uint32_t idx)
60 {
61     VariableSP variable_sp;
62     if (idx < m_variables.size())
63         variable_sp = m_variables[idx];
64     return variable_sp;
65 }
66 
67 
68 
69 VariableSP
70 VariableList::FindVariable(const ConstString& name)
71 {
72     VariableSP var_sp;
73     iterator pos, end = m_variables.end();
74     for (pos = m_variables.begin(); pos != end; ++pos)
75     {
76         if ((*pos)->GetName() == name)
77         {
78             var_sp = (*pos);
79             break;
80         }
81     }
82     return var_sp;
83 }
84 
85 uint32_t
86 VariableList::FindIndexForVariable (Variable* variable)
87 {
88     VariableSP var_sp;
89     iterator pos;
90     const iterator begin = m_variables.begin();
91     const iterator end = m_variables.end();
92     for (pos = m_variables.begin(); pos != end; ++pos)
93     {
94         if ((*pos).get() == variable)
95             return std::distance (begin, pos);
96     }
97     return UINT32_MAX;
98 }
99 
100 size_t
101 VariableList::MemorySize() const
102 {
103     size_t mem_size = sizeof(VariableList);
104     const_iterator pos, end = m_variables.end();
105     for (pos = m_variables.begin(); pos != end; ++pos)
106         mem_size += (*pos)->MemorySize();
107     return mem_size;
108 }
109 
110 size_t
111 VariableList::GetSize() const
112 {
113     return m_variables.size();
114 }
115 
116 
117 void
118 VariableList::Dump(Stream *s, bool show_context) const
119 {
120 //  s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
121 //  s.Indent();
122 //  s << "VariableList\n";
123 
124     const_iterator pos, end = m_variables.end();
125     for (pos = m_variables.begin(); pos != end; ++pos)
126     {
127         (*pos)->Dump(s, show_context);
128     }
129 }
130 
131