Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 11 | |
| 12 | #include "lldb/Core/RegularExpression.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | void |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 36 | VariableList::AddVariable(const VariableSP &var_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | { |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 38 | m_variables.push_back(var_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | void |
| 61 | VariableList::Clear() |
| 62 | { |
| 63 | m_variables.clear(); |
| 64 | } |
| 65 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | VariableSP |
| 67 | VariableList::GetVariableAtIndex(uint32_t idx) |
| 68 | { |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 69 | VariableSP var_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | if (idx < m_variables.size()) |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 71 | var_sp = m_variables[idx]; |
| 72 | return var_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Greg Clayton | 5d81f49 | 2011-07-08 21:46:14 +0000 | [diff] [blame^] | 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 | |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | { |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 106 | if ((*pos)->NameMatches(name)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | { |
| 108 | var_sp = (*pos); |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | return var_sp; |
| 113 | } |
| 114 | |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 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 | { |
Greg Clayton | 3bc52d0 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 122 | if ((*pos)->NameMatches (regex)) |
Greg Clayton | 6bc0b5d | 2010-10-10 23:55:27 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |