Home | History | Annotate | Download | only in MC
      1 //===- SymbolCategory.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_MC_SYMBOLCATEGORY_H
     10 #define MCLD_MC_SYMBOLCATEGORY_H
     11 #include <cstddef>
     12 #include <vector>
     13 
     14 namespace mcld
     15 {
     16 
     17 class LDSymbol;
     18 class ResolveInfo;
     19 /** \class SymbolCategory
     20  *  \brief SymbolCategory groups output LDSymbol into different categories.
     21  */
     22 class SymbolCategory
     23 {
     24 private:
     25   typedef std::vector<LDSymbol*> OutputSymbols;
     26 
     27 public:
     28   typedef OutputSymbols::iterator iterator;
     29   typedef OutputSymbols::const_iterator const_iterator;
     30 
     31 public:
     32   SymbolCategory();
     33 
     34   ~SymbolCategory();
     35 
     36   // -----  modifiers  ----- //
     37   SymbolCategory& add(LDSymbol& pSymbol);
     38 
     39   SymbolCategory& forceLocal(LDSymbol& pSymbol);
     40 
     41   SymbolCategory& arrange(LDSymbol& pSymbol, const ResolveInfo& pSourceInfo);
     42 
     43   SymbolCategory& changeCommonsToGlobal();
     44 
     45   SymbolCategory& changeToDynamic(LDSymbol& pSymbol);
     46 
     47   // -----  access  ----- //
     48   LDSymbol& at(size_t pPosition)
     49   { return *m_OutputSymbols.at(pPosition); }
     50 
     51   const LDSymbol& at(size_t pPosition) const
     52   { return *m_OutputSymbols.at(pPosition); }
     53 
     54   LDSymbol& operator[](size_t pPosition)
     55   { return *m_OutputSymbols[pPosition]; }
     56 
     57   const LDSymbol& operator[](size_t pPosition) const
     58   { return *m_OutputSymbols[pPosition]; }
     59 
     60   // -----  observers  ----- //
     61   size_t numOfSymbols() const;
     62 
     63   size_t numOfFiles() const;
     64 
     65   size_t numOfLocals() const;
     66 
     67   size_t numOfLocalDyns() const;
     68 
     69   size_t numOfCommons() const;
     70 
     71   size_t numOfDynamics() const;
     72 
     73   size_t numOfRegulars() const;
     74 
     75   bool empty() const;
     76 
     77   bool emptyFiles() const;
     78 
     79   bool emptyLocals() const;
     80 
     81   bool emptyLocalDyns() const;
     82 
     83   bool emptyCommons() const;
     84 
     85   bool emptyDynamics() const;
     86 
     87   bool emptyRegulars() const;
     88 
     89   // -----  iterators  ----- //
     90   iterator begin();
     91   iterator end();
     92   const_iterator begin() const;
     93   const_iterator end() const;
     94 
     95   iterator fileBegin();
     96   iterator fileEnd();
     97   const_iterator fileBegin() const;
     98   const_iterator fileEnd() const;
     99 
    100   iterator localBegin();
    101   iterator localEnd();
    102   const_iterator localBegin() const;
    103   const_iterator localEnd() const;
    104 
    105   iterator localDynBegin();
    106   iterator localDynEnd();
    107   const_iterator localDynBegin() const;
    108   const_iterator localDynEnd() const;
    109 
    110   iterator commonBegin();
    111   iterator commonEnd();
    112   const_iterator commonBegin() const;
    113   const_iterator commonEnd() const;
    114 
    115   iterator dynamicBegin();
    116   iterator dynamicEnd();
    117   const_iterator dynamicBegin() const;
    118   const_iterator dynamicEnd() const;
    119 
    120   iterator regularBegin();
    121   iterator regularEnd();
    122   const_iterator regularBegin() const;
    123   const_iterator regularEnd() const;
    124 
    125 private:
    126   class Category
    127   {
    128   public:
    129     enum Type {
    130       File,
    131       Local,
    132       LocalDyn,
    133       Common,
    134       Dynamic,
    135       Regular
    136     };
    137 
    138   public:
    139     Type type;
    140 
    141     size_t begin;
    142     size_t end;
    143 
    144     Category* prev;
    145     Category* next;
    146 
    147   public:
    148     Category(Type pType)
    149       : type(pType),
    150         begin(0),
    151         end(0),
    152         prev(NULL),
    153         next(NULL) {
    154     }
    155 
    156     size_t size() const
    157     { return (end - begin); }
    158 
    159     bool empty() const
    160     { return (begin == end); }
    161 
    162     bool isFirst() const
    163     { return (NULL == prev); }
    164 
    165     bool isLast() const
    166     { return (NULL == next); }
    167 
    168     static Type categorize(const ResolveInfo& pInfo);
    169   };
    170 
    171 private:
    172   SymbolCategory& add(LDSymbol& pSymbol, Category::Type pTarget);
    173 
    174   SymbolCategory& arrange(LDSymbol& pSymbol,
    175                           Category::Type pSource,
    176                           Category::Type pTarget);
    177 
    178 private:
    179   OutputSymbols m_OutputSymbols;
    180 
    181   Category* m_pFile;
    182   Category* m_pLocal;
    183   Category* m_pLocalDyn;
    184   Category* m_pCommon;
    185   Category* m_pDynamic;
    186   Category* m_pRegular;
    187 };
    188 
    189 } // namespace of mcld
    190 
    191 #endif
    192 
    193