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 uint32_t 76 VariableList::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 } 86 87 VariableSP 88 VariableList::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)->NameMatches(name)) 95 { 96 var_sp = (*pos); 97 break; 98 } 99 } 100 return var_sp; 101 } 102 103 size_t 104 VariableList::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 ((*pos)->NameMatches (regex)) 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 122 uint32_t 123 VariableList::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 } 136 137 size_t 138 VariableList::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 147 size_t 148 VariableList::GetSize() const 149 { 150 return m_variables.size(); 151 } 152 153 void 154 VariableList::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 167