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 12 #include "lldb/Core/RegularExpression.h" 13 #include "lldb/Symbol/Block.h" 14 #include "lldb/Symbol/Function.h" 15 #include "lldb/Symbol/CompileUnit.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 //---------------------------------------------------------------------- 21 // VariableList constructor 22 //---------------------------------------------------------------------- 23 VariableList::VariableList() : 24 m_variables() 25 { 26 } 27 28 //---------------------------------------------------------------------- 29 // Destructor 30 //---------------------------------------------------------------------- 31 VariableList::~VariableList() 32 { 33 } 34 35 void 36 VariableList::AddVariable(const VariableSP &var_sp) 37 { 38 m_variables.push_back(var_sp); 39 } 40 41 bool 42 VariableList::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 } 51 52 void 53 VariableList::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 60 void 61 VariableList::Clear() 62 { 63 m_variables.clear(); 64 } 65 66 VariableSP 67 VariableList::GetVariableAtIndex(uint32_t idx) 68 { 69 VariableSP var_sp; 70 if (idx < m_variables.size()) 71 var_sp = m_variables[idx]; 72 return var_sp; 73 } 74 75 VariableSP 76 VariableList::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 87 uint32_t 88 VariableList::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 } 98 99 VariableSP 100 VariableList::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 { 106 if ((*pos)->NameMatches(name)) 107 { 108 var_sp = (*pos); 109 break; 110 } 111 } 112 return var_sp; 113 } 114 115 size_t 116 VariableList::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 { 122 if ((*pos)->NameMatches (regex)) 123 { 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 134 uint32_t 135 VariableList::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 } 148 149 size_t 150 VariableList::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 159 size_t 160 VariableList::GetSize() const 161 { 162 return m_variables.size(); 163 } 164 165 void 166 VariableList::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 179