[lld] r234443 - Merge atom_collection_vector with atom_collection.

Rui Ueyama ruiu at google.com
Wed Apr 8 14:59:04 PDT 2015


Author: ruiu
Date: Wed Apr  8 16:59:04 2015
New Revision: 234443

URL: http://llvm.org/viewvc/llvm-project?rev=234443&view=rev
Log:
Merge atom_collection_vector with atom_collection.

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

Modified:
    lld/trunk/include/lld/Core/File.h
    lld/trunk/include/lld/Core/SharedLibraryFile.h
    lld/trunk/include/lld/Core/Simple.h
    lld/trunk/lib/Core/File.cpp
    lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
    lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
    lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp

Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Wed Apr  8 16:59:04 2015
@@ -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:

Modified: lld/trunk/include/lld/Core/SharedLibraryFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SharedLibraryFile.h?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SharedLibraryFile.h (original)
+++ lld/trunk/include/lld/Core/SharedLibraryFile.h Wed Apr  8 16:59:04 2015
@@ -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

Modified: lld/trunk/include/lld/Core/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Simple.h?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Simple.h (original)
+++ lld/trunk/include/lld/Core/Simple.h Wed Apr  8 16:59:04 2015
@@ -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 {

Modified: lld/trunk/lib/Core/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/File.cpp?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/Core/File.cpp (original)
+++ lld/trunk/lib/Core/File.cpp Wed Apr  8 16:59:04 2015
@@ -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);

Modified: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp Wed Apr  8 16:59:04 2015
@@ -123,7 +123,7 @@ public:
 
 
 private:
-  mutable atom_collection_vector<DefinedAtom> _definedAtoms;
+  mutable atom_collection<DefinedAtom> _definedAtoms;
   StringRef _machHeaderSymbolName;
 };
 

Modified: lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp (original)
+++ lld/trunk/lib/ReaderWriter/Native/ReaderNative.cpp Wed Apr  8 16:59:04 2015
@@ -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;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Wed Apr  8 16:59:04 2015
@@ -299,7 +299,7 @@ private:
   }
 
   PECOFFLinkingContext *_ctx;
-  atom_collection_vector<UndefinedAtom> _undefinedAtoms;
+  atom_collection<UndefinedAtom> _undefinedAtoms;
   std::mutex _mutex;
   llvm::BumpPtrAllocator _alloc;
   bool _firstTime;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Wed Apr  8 16:59:04 2015
@@ -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;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp Wed Apr  8 16:59:04 2015
@@ -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

Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Wed Apr  8 16:59:04 2015
@@ -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 {





More information about the llvm-commits mailing list