From 1a6ec936161eedc5c7b7cb36bfed5bec65bd1e06 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 8 Apr 2015 21:59:04 +0000 Subject: [PATCH] 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 --- lld/include/lld/Core/File.h | 70 ++++++++----------- lld/include/lld/Core/SharedLibraryFile.h | 8 +-- lld/include/lld/Core/Simple.h | 16 ++--- lld/lib/Core/File.cpp | 8 +-- .../ReaderWriter/MachO/ExecutableAtoms.hpp | 2 +- lld/lib/ReaderWriter/Native/ReaderNative.cpp | 10 +-- .../PECOFF/LinkerGeneratedSymbolFile.h | 2 +- lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp | 8 +-- .../PECOFF/ReaderImportHeader.cpp | 4 +- .../ReaderWriter/YAML/ReaderWriterYAML.cpp | 3 +- 10 files changed, 58 insertions(+), 73 deletions(-) diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h index e43141b9a5b2..48da03276ab8 100644 --- a/lld/include/lld/Core/File.h +++ b/lld/include/lld/Core/File.h @@ -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 - class atom_collection { + template class atom_collection { public: - virtual ~atom_collection() { } - virtual atom_iterator begin() const = 0; - virtual atom_iterator 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 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); + } + + uint64_t size() const { return _atoms.size(); } bool empty() const { return size() == 0; } + + std::vector _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 - class atom_collection_vector : public atom_collection { - public: - atom_iterator begin() const override { - const void *it = _atoms.data(); - return atom_iterator(*this, it); - } - - atom_iterator end() const override { - const void *it = _atoms.data() + _atoms.size(); - return atom_iterator(*this, it); - } - - const T *deref(const void *it) const override { - return *reinterpret_cast(it); - } - - void next(const void *&it) const override { - const T *const *p = reinterpret_cast(it); - ++p; - it = reinterpret_cast(p); - } - - uint64_t size() const override { return _atoms.size(); } - - std::vector _atoms; - }; - - static atom_collection_vector _noDefinedAtoms; - static atom_collection_vector _noUndefinedAtoms; - static atom_collection_vector _noSharedLibraryAtoms; - static atom_collection_vector _noAbsoluteAtoms; + static atom_collection _noDefinedAtoms; + static atom_collection _noUndefinedAtoms; + static atom_collection _noSharedLibraryAtoms; + static atom_collection _noAbsoluteAtoms; mutable llvm::BumpPtrAllocator _allocator; private: diff --git a/lld/include/lld/Core/SharedLibraryFile.h b/lld/include/lld/Core/SharedLibraryFile.h index 2f84624287d8..9c3f3ce35680 100644 --- a/lld/include/lld/Core/SharedLibraryFile.h +++ b/lld/include/lld/Core/SharedLibraryFile.h @@ -54,10 +54,10 @@ protected: /// only subclasses of SharedLibraryFile can be instantiated explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {} - atom_collection_vector _definedAtoms; - atom_collection_vector _undefinedAtoms; - atom_collection_vector _sharedLibraryAtoms; - atom_collection_vector _absoluteAtoms; + atom_collection _definedAtoms; + atom_collection _undefinedAtoms; + atom_collection _sharedLibraryAtoms; + atom_collection _absoluteAtoms; }; } // namespace lld diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h index 58fc5ea2c908..a4999e15f825 100644 --- a/lld/include/lld/Core/Simple.h +++ b/lld/include/lld/Core/Simple.h @@ -75,10 +75,10 @@ public: DefinedAtomRange definedAtoms() { return make_range(_defined._atoms); } private: - atom_collection_vector _defined; - atom_collection_vector _undefined; - atom_collection_vector _shared; - atom_collection_vector _absolute; + atom_collection _defined; + atom_collection _undefined; + atom_collection _shared; + atom_collection _absolute; }; /// \brief Archive library file that may be used as a virtual container @@ -117,10 +117,10 @@ public: } private: - atom_collection_vector _definedAtoms; - atom_collection_vector _undefinedAtoms; - atom_collection_vector _sharedLibraryAtoms; - atom_collection_vector _absoluteAtoms; + atom_collection _definedAtoms; + atom_collection _undefinedAtoms; + atom_collection _sharedLibraryAtoms; + atom_collection _absoluteAtoms; }; class SimpleReference : public Reference { diff --git a/lld/lib/Core/File.cpp b/lld/lib/Core/File.cpp index f07d2cc26743..6ada51601c8c 100644 --- a/lld/lib/Core/File.cpp +++ b/lld/lib/Core/File.cpp @@ -15,10 +15,10 @@ namespace lld { File::~File() {} -File::atom_collection_vector File::_noDefinedAtoms; -File::atom_collection_vector File::_noUndefinedAtoms; -File::atom_collection_vector File::_noSharedLibraryAtoms; -File::atom_collection_vector File::_noAbsoluteAtoms; +File::atom_collection File::_noDefinedAtoms; +File::atom_collection File::_noUndefinedAtoms; +File::atom_collection File::_noSharedLibraryAtoms; +File::atom_collection File::_noAbsoluteAtoms; std::error_code File::parse() { std::lock_guard lock(_parseMutex); diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp index 26f3b61e43c2..6caa10766bec 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp @@ -123,7 +123,7 @@ public: private: - mutable atom_collection_vector _definedAtoms; + mutable atom_collection _definedAtoms; StringRef _machHeaderSymbolName; }; diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index 8b3ee16e3b55..0ded101f8b02 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -398,7 +398,7 @@ private: // instantiate array of BASeT from IvarsT data in file template - std::error_code processAtoms(atom_collection_vector &result, + std::error_code processAtoms(atom_collection &result, const uint8_t *base, const NativeChunk *chunk) { std::vector vec(chunk->elementCount); const size_t ivarElementSize = chunk->fileSize / chunk->elementCount; @@ -690,10 +690,10 @@ private: std::unique_ptr _mb; const NativeFileHeader* _header; - atom_collection_vector _definedAtoms; - atom_collection_vector _undefinedAtoms; - atom_collection_vector _sharedLibraryAtoms; - atom_collection_vector _absoluteAtoms; + atom_collection _definedAtoms; + atom_collection _undefinedAtoms; + atom_collection _sharedLibraryAtoms; + atom_collection _absoluteAtoms; const uint8_t* _absAttributes; uint32_t _absAbsoluteMaxOffset; const uint8_t* _attributes; diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h index 9bf7a9c7111a..4bcae11ef8d3 100644 --- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h +++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h @@ -299,7 +299,7 @@ private: } PECOFFLinkingContext *_ctx; - atom_collection_vector _undefinedAtoms; + atom_collection _undefinedAtoms; std::mutex _mutex; llvm::BumpPtrAllocator _alloc; bool _firstTime; diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index 7d6a73f4440c..9a7a5809c908 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -159,10 +159,10 @@ private: std::unique_ptr _obj; std::unique_ptr _mb; - atom_collection_vector _definedAtoms; - atom_collection_vector _undefinedAtoms; - atom_collection_vector _sharedLibraryAtoms; - atom_collection_vector _absoluteAtoms; + atom_collection _definedAtoms; + atom_collection _undefinedAtoms; + atom_collection _sharedLibraryAtoms; + atom_collection _absoluteAtoms; // The target type of the object. Reference::KindArch _referenceArch; diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp index 0ddffb0f419c..26bdfaa14606 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp @@ -315,8 +315,8 @@ private: _definedAtoms._atoms.push_back(atom); } - atom_collection_vector _definedAtoms; - atom_collection_vector _sharedLibraryAtoms; + atom_collection _definedAtoms; + atom_collection _sharedLibraryAtoms; mutable llvm::BumpPtrAllocator _alloc; // Does the same thing as StringRef::ltrim() but removes at most one diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 00cf60f7fd36..3bf8a943637f 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -215,8 +215,7 @@ private: NameToAtom _groupMap; }; -template -using AtomList = lld::File::atom_collection_vector; +template using AtomList = lld::File::atom_collection; /// Mapping of kind: field in yaml files. enum FileKinds {