Merge atom_collection_vector with atom_collection.

atom_collection_vector is the only derived class of atom_collection.
This patch merges the two.

llvm-svn: 234443
This commit is contained in:
Rui Ueyama 2015-04-08 21:59:04 +00:00
parent 2f05640409
commit 1a6ec93616
10 changed files with 58 additions and 73 deletions

View File

@ -97,16 +97,32 @@ public:
/// 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 <typename T>
class atom_collection {
template <typename T> class atom_collection {
public:
virtual ~atom_collection() { }
virtual atom_iterator<T> begin() const = 0;
virtual atom_iterator<T> end() const = 0;
virtual const T *deref(const void *it) const = 0;
virtual void next(const void *&it) const = 0;
virtual uint64_t size() const = 0;
atom_iterator<T> begin() const {
const void *it = _atoms.data();
return atom_iterator<T>(*this, it);
}
atom_iterator<T> end() const {
const void *it = _atoms.data() + _atoms.size();
return atom_iterator<T>(*this, it);
}
const T *deref(const void *it) const {
return *reinterpret_cast<const T *const *>(it);
}
void next(const void *&it) const {
const T *const *p = reinterpret_cast<const T *const *>(it);
++p;
it = reinterpret_cast<const void *>(p);
}
uint64_t size() const { return _atoms.size(); }
bool empty() const { return size() == 0; }
std::vector<const T *> _atoms;
};
/// \brief The class is the iterator type used to iterate through a File's
@ -193,40 +209,10 @@ protected:
/// memory buffer passed to this file's constructor.
virtual std::error_code doParse() { return std::error_code(); }
/// \brief This is a convenience class for File subclasses which manage their
/// atoms as a simple std::vector<>.
template <typename T>
class atom_collection_vector : public atom_collection<T> {
public:
atom_iterator<T> begin() const override {
const void *it = _atoms.data();
return atom_iterator<T>(*this, it);
}
atom_iterator<T> end() const override {
const void *it = _atoms.data() + _atoms.size();
return atom_iterator<T>(*this, it);
}
const T *deref(const void *it) const override {
return *reinterpret_cast<const T *const *>(it);
}
void next(const void *&it) const override {
const T *const *p = reinterpret_cast<const T *const *>(it);
++p;
it = reinterpret_cast<const void*>(p);
}
uint64_t size() const override { return _atoms.size(); }
std::vector<const T *> _atoms;
};
static atom_collection_vector<DefinedAtom> _noDefinedAtoms;
static atom_collection_vector<UndefinedAtom> _noUndefinedAtoms;
static atom_collection_vector<SharedLibraryAtom> _noSharedLibraryAtoms;
static atom_collection_vector<AbsoluteAtom> _noAbsoluteAtoms;
static atom_collection<DefinedAtom> _noDefinedAtoms;
static atom_collection<UndefinedAtom> _noUndefinedAtoms;
static atom_collection<SharedLibraryAtom> _noSharedLibraryAtoms;
static atom_collection<AbsoluteAtom> _noAbsoluteAtoms;
mutable llvm::BumpPtrAllocator _allocator;
private:

View File

@ -54,10 +54,10 @@ protected:
/// only subclasses of SharedLibraryFile can be instantiated
explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
atom_collection<DefinedAtom> _definedAtoms;
atom_collection<UndefinedAtom> _undefinedAtoms;
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection<AbsoluteAtom> _absoluteAtoms;
};
} // namespace lld

View File

@ -75,10 +75,10 @@ public:
DefinedAtomRange definedAtoms() { return make_range(_defined._atoms); }
private:
atom_collection_vector<DefinedAtom> _defined;
atom_collection_vector<UndefinedAtom> _undefined;
atom_collection_vector<SharedLibraryAtom> _shared;
atom_collection_vector<AbsoluteAtom> _absolute;
atom_collection<DefinedAtom> _defined;
atom_collection<UndefinedAtom> _undefined;
atom_collection<SharedLibraryAtom> _shared;
atom_collection<AbsoluteAtom> _absolute;
};
/// \brief Archive library file that may be used as a virtual container
@ -117,10 +117,10 @@ public:
}
private:
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
atom_collection<DefinedAtom> _definedAtoms;
atom_collection<UndefinedAtom> _undefinedAtoms;
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection<AbsoluteAtom> _absoluteAtoms;
};
class SimpleReference : public Reference {

View File

@ -15,10 +15,10 @@ namespace lld {
File::~File() {}
File::atom_collection_vector<DefinedAtom> File::_noDefinedAtoms;
File::atom_collection_vector<UndefinedAtom> File::_noUndefinedAtoms;
File::atom_collection_vector<SharedLibraryAtom> File::_noSharedLibraryAtoms;
File::atom_collection_vector<AbsoluteAtom> File::_noAbsoluteAtoms;
File::atom_collection<DefinedAtom> File::_noDefinedAtoms;
File::atom_collection<UndefinedAtom> File::_noUndefinedAtoms;
File::atom_collection<SharedLibraryAtom> File::_noSharedLibraryAtoms;
File::atom_collection<AbsoluteAtom> File::_noAbsoluteAtoms;
std::error_code File::parse() {
std::lock_guard<std::mutex> lock(_parseMutex);

View File

@ -123,7 +123,7 @@ public:
private:
mutable atom_collection_vector<DefinedAtom> _definedAtoms;
mutable atom_collection<DefinedAtom> _definedAtoms;
StringRef _machHeaderSymbolName;
};

View File

@ -398,7 +398,7 @@ private:
// instantiate array of BASeT from IvarsT data in file
template <typename BaseT, typename AtomT, typename IvarsT>
std::error_code processAtoms(atom_collection_vector<BaseT> &result,
std::error_code processAtoms(atom_collection<BaseT> &result,
const uint8_t *base, const NativeChunk *chunk) {
std::vector<const BaseT *> vec(chunk->elementCount);
const size_t ivarElementSize = chunk->fileSize / chunk->elementCount;
@ -690,10 +690,10 @@ private:
std::unique_ptr<MemoryBuffer> _mb;
const NativeFileHeader* _header;
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
atom_collection<DefinedAtom> _definedAtoms;
atom_collection<UndefinedAtom> _undefinedAtoms;
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection<AbsoluteAtom> _absoluteAtoms;
const uint8_t* _absAttributes;
uint32_t _absAbsoluteMaxOffset;
const uint8_t* _attributes;

View File

@ -299,7 +299,7 @@ private:
}
PECOFFLinkingContext *_ctx;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection<UndefinedAtom> _undefinedAtoms;
std::mutex _mutex;
llvm::BumpPtrAllocator _alloc;
bool _firstTime;

View File

@ -159,10 +159,10 @@ private:
std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
std::unique_ptr<MemoryBuffer> _mb;
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
atom_collection<DefinedAtom> _definedAtoms;
atom_collection<UndefinedAtom> _undefinedAtoms;
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection<AbsoluteAtom> _absoluteAtoms;
// The target type of the object.
Reference::KindArch _referenceArch;

View File

@ -315,8 +315,8 @@ private:
_definedAtoms._atoms.push_back(atom);
}
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection<DefinedAtom> _definedAtoms;
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
mutable llvm::BumpPtrAllocator _alloc;
// Does the same thing as StringRef::ltrim() but removes at most one

View File

@ -215,8 +215,7 @@ private:
NameToAtom _groupMap;
};
template <typename T>
using AtomList = lld::File::atom_collection_vector<T>;
template <typename T> using AtomList = lld::File::atom_collection<T>;
/// Mapping of kind: field in yaml files.
enum FileKinds {