[Object][ELF] Refactor ELFRelocationIterator into ELFEntityIterator. No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171647 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer
2013-01-06 03:56:14 +00:00
parent e36291a1ef
commit fe23da7949

View File

@ -527,54 +527,54 @@ private:
mutable const char *dt_soname; mutable const char *dt_soname;
public: public:
/// \brief Iterate over relocations in a .rel or .rela section. /// \brief Iterate over constant sized entities.
template<class RelocT> template<class EntT>
class ELFRelocationIterator { class ELFEntityIterator {
public: public:
typedef void difference_type; typedef void difference_type;
typedef const RelocT value_type; typedef EntT value_type;
typedef std::forward_iterator_tag iterator_category; typedef std::forward_iterator_tag iterator_category;
typedef value_type &reference; typedef value_type &reference;
typedef value_type *pointer; typedef value_type *pointer;
/// \brief Default construct iterator. /// \brief Default construct iterator.
ELFRelocationIterator() : Section(0), Current(0) {} ELFEntityIterator() : EntitySize(0), Current(0) {}
ELFRelocationIterator(const Elf_Shdr *Sec, const char *Start) ELFEntityIterator(uint64_t EntSize, const char *Start)
: Section(Sec) : EntitySize(EntSize)
, Current(Start) {} , Current(Start) {}
reference operator *() { reference operator *() {
assert(Current && "Attempted to dereference an invalid iterator!"); assert(Current && "Attempted to dereference an invalid iterator!");
return *reinterpret_cast<const RelocT*>(Current); return *reinterpret_cast<pointer>(Current);
} }
pointer operator ->() { pointer operator ->() {
assert(Current && "Attempted to dereference an invalid iterator!"); assert(Current && "Attempted to dereference an invalid iterator!");
return reinterpret_cast<const RelocT*>(Current); return reinterpret_cast<pointer>(Current);
} }
bool operator ==(const ELFRelocationIterator &Other) { bool operator ==(const ELFEntityIterator &Other) {
return Section == Other.Section && Current == Other.Current; return Current == Other.Current;
} }
bool operator !=(const ELFRelocationIterator &Other) { bool operator !=(const ELFEntityIterator &Other) {
return !(*this == Other); return !(*this == Other);
} }
ELFRelocationIterator &operator ++(int) { ELFEntityIterator &operator ++() {
assert(Current && "Attempted to increment an invalid iterator!"); assert(Current && "Attempted to increment an invalid iterator!");
Current += Section->sh_entsize; Current += EntitySize;
return *this; return *this;
} }
ELFRelocationIterator operator ++() { ELFEntityIterator operator ++(int) {
ELFRelocationIterator Tmp = *this; ELFEntityIterator Tmp = *this;
++*this; ++*this;
return Tmp; return Tmp;
} }
private: private:
const Elf_Shdr *Section; const uint64_t EntitySize;
const char *Current; const char *Current;
}; };
@ -717,24 +717,26 @@ public:
virtual dyn_iterator begin_dynamic_table() const; virtual dyn_iterator begin_dynamic_table() const;
virtual dyn_iterator end_dynamic_table() const; virtual dyn_iterator end_dynamic_table() const;
typedef ELFRelocationIterator<Elf_Rela> Elf_Rela_Iter; typedef ELFEntityIterator<const Elf_Rela> Elf_Rela_Iter;
typedef ELFRelocationIterator<Elf_Rel> Elf_Rel_Iter; typedef ELFEntityIterator<const Elf_Rel> Elf_Rel_Iter;
virtual Elf_Rela_Iter beginELFRela(const Elf_Shdr *sec) const { Elf_Rela_Iter beginELFRela(const Elf_Shdr *sec) const {
return Elf_Rela_Iter(sec, (const char *)(base() + sec->sh_offset)); return Elf_Rela_Iter(sec->sh_entsize,
(const char *)(base() + sec->sh_offset));
} }
virtual Elf_Rela_Iter endELFRela(const Elf_Shdr *sec) const { Elf_Rela_Iter endELFRela(const Elf_Shdr *sec) const {
return Elf_Rela_Iter(sec, (const char *) return Elf_Rela_Iter(sec->sh_entsize, (const char *)
(base() + sec->sh_offset + sec->sh_size)); (base() + sec->sh_offset + sec->sh_size));
} }
virtual Elf_Rel_Iter beginELFRel(const Elf_Shdr *sec) const { Elf_Rel_Iter beginELFRel(const Elf_Shdr *sec) const {
return Elf_Rel_Iter(sec, (const char *)(base() + sec->sh_offset)); return Elf_Rel_Iter(sec->sh_entsize,
(const char *)(base() + sec->sh_offset));
} }
virtual Elf_Rel_Iter endELFRel(const Elf_Shdr *sec) const { Elf_Rel_Iter endELFRel(const Elf_Shdr *sec) const {
return Elf_Rel_Iter(sec, (const char *) return Elf_Rel_Iter(sec->sh_entsize, (const char *)
(base() + sec->sh_offset + sec->sh_size)); (base() + sec->sh_offset + sec->sh_size));
} }