forked from OSchip/llvm-project
[NFC] Cleanup RangeMap.h
The file contained very similar 4 implementation of the same data structure with a lot of duplicated code and some minor API differences. This CL refactor the class to eliminate the duplicated codes and to unify the APIs. RangeMap.h also contained a class called AddressDataArray what have very little added functionality over an std::vector and used only by ObjectFileMacO The CL moves the class to ObjectFileMachO.cpp as it isn't belongs into RangeMap.h and shouldn't be used in new places anyway because of the little added functionality. Differential revision: http://reviews.llvm.org/D16769 llvm-svn: 259538
This commit is contained in:
parent
bbac6d7c1b
commit
7a2a5ce058
File diff suppressed because it is too large
Load Diff
|
@ -107,6 +107,181 @@ struct lldb_copy_dyld_cache_local_symbols_entry
|
|||
uint32_t nlistCount;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// A simple range with data class where you get to define the type of
|
||||
// the range base "B", the type used for the range byte size "S", and
|
||||
// the type for the associated data "T".
|
||||
//----------------------------------------------------------------------
|
||||
template <typename B, typename T>
|
||||
struct AddressData
|
||||
{
|
||||
typedef B BaseType;
|
||||
typedef T DataType;
|
||||
|
||||
BaseType addr;
|
||||
DataType data;
|
||||
|
||||
AddressData () :
|
||||
addr (),
|
||||
data ()
|
||||
{
|
||||
}
|
||||
|
||||
AddressData (B a, DataType d) :
|
||||
addr (a),
|
||||
data (d)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
operator < (const AddressData &rhs) const
|
||||
{
|
||||
if (this->addr == rhs.addr)
|
||||
return this->data < rhs.data;
|
||||
return this->addr < rhs.addr;
|
||||
}
|
||||
|
||||
bool
|
||||
operator == (const AddressData &rhs) const
|
||||
{
|
||||
return this->addr == rhs.addr &&
|
||||
this->data == rhs.data;
|
||||
}
|
||||
|
||||
bool
|
||||
operator != (const AddressData &rhs) const
|
||||
{
|
||||
return this->addr != rhs.addr ||
|
||||
this->data == rhs.data;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename B, typename T, unsigned N>
|
||||
class AddressDataArray
|
||||
{
|
||||
public:
|
||||
typedef AddressData<B,T> Entry;
|
||||
typedef llvm::SmallVector<Entry, N> Collection;
|
||||
|
||||
AddressDataArray() = default;
|
||||
|
||||
~AddressDataArray() = default;
|
||||
|
||||
void
|
||||
Append (const Entry &entry)
|
||||
{
|
||||
m_entries.push_back (entry);
|
||||
}
|
||||
|
||||
void
|
||||
Sort ()
|
||||
{
|
||||
if (m_entries.size() > 1)
|
||||
std::stable_sort (m_entries.begin(), m_entries.end());
|
||||
}
|
||||
|
||||
#ifdef ASSERT_RANGEMAP_ARE_SORTED
|
||||
bool
|
||||
IsSorted () const
|
||||
{
|
||||
typename Collection::const_iterator pos, end, prev;
|
||||
// First we determine if we can combine any of the Entry objects so we
|
||||
// don't end up allocating and making a new collection for no reason
|
||||
for (pos = m_entries.begin(), end = m_entries.end(), prev = end; pos != end; prev = pos++)
|
||||
{
|
||||
if (prev != end && *pos < *prev)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
Clear ()
|
||||
{
|
||||
m_entries.clear();
|
||||
}
|
||||
|
||||
bool
|
||||
IsEmpty () const
|
||||
{
|
||||
return m_entries.empty();
|
||||
}
|
||||
|
||||
size_t
|
||||
GetSize () const
|
||||
{
|
||||
return m_entries.size();
|
||||
}
|
||||
|
||||
const Entry *
|
||||
GetEntryAtIndex (size_t i) const
|
||||
{
|
||||
return ((i < m_entries.size()) ? &m_entries[i] : nullptr);
|
||||
}
|
||||
|
||||
// Clients must ensure that "i" is a valid index prior to calling this function
|
||||
const Entry &
|
||||
GetEntryRef (size_t i) const
|
||||
{
|
||||
return m_entries[i];
|
||||
}
|
||||
|
||||
static bool
|
||||
BaseLessThan (const Entry& lhs, const Entry& rhs)
|
||||
{
|
||||
return lhs.addr < rhs.addr;
|
||||
}
|
||||
|
||||
Entry *
|
||||
FindEntry (B addr, bool exact_match_only)
|
||||
{
|
||||
#ifdef ASSERT_RANGEMAP_ARE_SORTED
|
||||
assert (IsSorted());
|
||||
#endif
|
||||
if ( !m_entries.empty() )
|
||||
{
|
||||
Entry entry;
|
||||
entry.addr = addr;
|
||||
typename Collection::iterator begin = m_entries.begin();
|
||||
typename Collection::iterator end = m_entries.end();
|
||||
typename Collection::iterator pos = std::lower_bound (begin, end, entry, BaseLessThan);
|
||||
|
||||
while(pos != begin && pos[-1].addr == addr)
|
||||
--pos;
|
||||
|
||||
if (pos != end)
|
||||
{
|
||||
if (pos->addr == addr || !exact_match_only)
|
||||
return &(*pos);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Entry *
|
||||
FindNextEntry (const Entry *entry)
|
||||
{
|
||||
if (entry >= &*m_entries.begin() && entry + 1 < &*m_entries.end())
|
||||
return entry + 1;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Entry *
|
||||
Back()
|
||||
{
|
||||
return (m_entries.empty() ? nullptr : &m_entries.back());
|
||||
}
|
||||
|
||||
const Entry *
|
||||
Back() const
|
||||
{
|
||||
return (m_entries.empty() ? nullptr : &m_entries.back());
|
||||
}
|
||||
|
||||
protected:
|
||||
Collection m_entries;
|
||||
};
|
||||
|
||||
class RegisterContextDarwin_x86_64_Mach : public RegisterContextDarwin_x86_64
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue