diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h index 48da03276ab8..688b92d0f2aa 100644 --- a/lld/include/lld/Core/File.h +++ b/lld/include/lld/Core/File.h @@ -86,79 +86,28 @@ public: /// Sets the command line order of the file. void setOrdinal(uint64_t ordinal) const { _ordinal = ordinal; } - template class atom_iterator; // forward reference - /// For allocating any objects owned by this File. llvm::BumpPtrAllocator &allocator() const { return _allocator; } + template + using atom_iterator = typename std::vector::const_iterator; + /// \brief Different object file readers may instantiate and manage atoms with /// different data structures. This class is a collection abstraction. /// Each concrete File instance must implement these atom_collection /// methods to enable clients to interate the File's atoms. template class atom_collection { public: - atom_iterator begin() const { - const void *it = _atoms.data(); - return atom_iterator(*this, it); - } - - atom_iterator end() const { - const void *it = _atoms.data() + _atoms.size(); - return atom_iterator(*this, it); - } - - const T *deref(const void *it) const { - return *reinterpret_cast(it); - } - - void next(const void *&it) const { - const T *const *p = reinterpret_cast(it); - ++p; - it = reinterpret_cast(p); - } - + atom_iterator begin() const { return _atoms.begin(); } + atom_iterator end() const { return _atoms.end(); } uint64_t size() const { return _atoms.size(); } - bool empty() const { return size() == 0; } + bool empty() const { return _atoms.empty(); } std::vector _atoms; }; - /// \brief The class is the iterator type used to iterate through a File's - /// Atoms. This iterator delegates the work to the associated atom_collection - /// object. There are four kinds of Atoms, so this iterator is templated on - /// the four base Atom kinds. - template - class atom_iterator : public std::iterator { - public: - atom_iterator(const atom_collection &c, const void *it) - : _collection(&c), _it(it) { } - - const T *operator*() const { - return _collection->deref(_it); - } - const T *operator->() const { - return _collection->deref(_it); - } - - friend bool operator==(const atom_iterator &lhs, const atom_iterator &rhs) { - return lhs._it == rhs._it; - } - - friend bool operator!=(const atom_iterator &lhs, const atom_iterator &rhs) { - return !(lhs == rhs); - } - - atom_iterator &operator++() { - _collection->next(_it); - return *this; - } - private: - const atom_collection *_collection; - const void *_it; - }; - /// \brief Must be implemented to return the atom_collection object for /// all DefinedAtoms in this File. virtual const atom_collection &defined() const = 0;