1 //===- SectionData.h ------------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef MCLD_LD_SECTIONDATA_H_
10 #define MCLD_LD_SECTIONDATA_H_
11 
12 #include "mcld/Config/Config.h"
13 #include "mcld/Fragment/Fragment.h"
14 #include "mcld/Support/Allocators.h"
15 #include "mcld/Support/Compiler.h"
16 
17 #include <llvm/ADT/ilist.h>
18 #include <llvm/ADT/ilist_node.h>
19 #include <llvm/Support/DataTypes.h>
20 
21 namespace mcld {
22 
23 class LDSection;
24 
25 /** \class SectionData
26  *  \brief SectionData provides a container for all Fragments.
27  */
28 class SectionData {
29  private:
30   friend class Chunk<SectionData, MCLD_SECTIONS_PER_INPUT>;
31 
32   SectionData();
33   explicit SectionData(LDSection& pSection);
34 
35  public:
36   typedef llvm::iplist<Fragment> FragmentListType;
37 
38   typedef FragmentListType::reference reference;
39   typedef FragmentListType::const_reference const_reference;
40 
41   typedef FragmentListType::iterator iterator;
42   typedef FragmentListType::const_iterator const_iterator;
43 
44   typedef FragmentListType::reverse_iterator reverse_iterator;
45   typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
46 
47  public:
48   static SectionData* Create(LDSection& pSection);
49 
50   static void Destroy(SectionData*& pSection);
51 
52   static void Clear();
53 
getSection()54   const LDSection& getSection() const { return *m_pSection; }
getSection()55   LDSection& getSection() { return *m_pSection; }
56 
getFragmentList()57   const FragmentListType& getFragmentList() const { return m_Fragments; }
getFragmentList()58   FragmentListType& getFragmentList() { return m_Fragments; }
59 
size()60   size_t size() const { return m_Fragments.size(); }
61 
empty()62   bool empty() const { return m_Fragments.empty(); }
63 
getSublistAccess(Fragment *)64   static FragmentListType SectionData::*getSublistAccess(Fragment *) {
65     return &SectionData::m_Fragments;
66   }
67 
front()68   reference front() { return m_Fragments.front(); }
front()69   const_reference front() const { return m_Fragments.front(); }
back()70   reference back() { return m_Fragments.back(); }
back()71   const_reference back() const { return m_Fragments.back(); }
72 
begin()73   const_iterator begin() const { return m_Fragments.begin(); }
begin()74   iterator begin() { return m_Fragments.begin(); }
end()75   const_iterator end() const { return m_Fragments.end(); }
end()76   iterator end() { return m_Fragments.end(); }
rbegin()77   const_reverse_iterator rbegin() const { return m_Fragments.rbegin(); }
rbegin()78   reverse_iterator rbegin() { return m_Fragments.rbegin(); }
rend()79   const_reverse_iterator rend() const { return m_Fragments.rend(); }
rend()80   reverse_iterator rend() { return m_Fragments.rend(); }
81 
82  private:
83   FragmentListType m_Fragments;
84   LDSection* m_pSection;
85 
86  private:
87   DISALLOW_COPY_AND_ASSIGN(SectionData);
88 };
89 
90 }  // namespace mcld
91 
92 #endif  // MCLD_LD_SECTIONDATA_H_
93