Home | History | Annotate | Download | only in LD
      1 //===- Resolver.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_RESOLVER_H
     10 #define MCLD_LD_RESOLVER_H
     11 #include <string>
     12 #include <utility>
     13 #include <mcld/LD/LDSymbol.h>
     14 
     15 namespace mcld
     16 {
     17 
     18 class ResolveInfo;
     19 class NamePool;
     20 
     21 /** \class Resolver
     22  *  \brief Resolver binds a symbol reference from one file to a symbol
     23  *   definition of another file.
     24  *
     25  *  Resolver seals up the algorithm of symbol resolution. The resolution of
     26  *  two symbols depends on their type, binding and whether it is belonging to
     27  *  a shared object.
     28  */
     29 class Resolver
     30 {
     31 public:
     32   enum Action {
     33     Success,
     34     Warning,
     35     Abort,
     36     LastAction
     37   };
     38 
     39   /** \class Resolver::Result
     40    *  \brief the result of symbol resolution
     41    *   - info, the pointer to overrided info
     42    *   - existent, if true, the info is existent
     43    *   - overriden, if true, the info is being overriden.
     44    */
     45   struct Result {
     46     ResolveInfo* info;
     47     bool existent;
     48     bool overriden;
     49   };
     50 
     51 public:
     52   virtual ~Resolver();
     53 
     54   /// shouldOverride - Can resolver override the symbol pOld by the symbol pNew?
     55   /// @return the action should be taken.
     56   /// @param pOld the symbol which may be overridden.
     57   /// @param pNew the symbol which is used to replace pOld
     58   virtual bool resolve(ResolveInfo & __restrict__ pOld,
     59                        const ResolveInfo & __restrict__ pNew,
     60                        bool &pOverride, LDSymbol::ValueType pValue) const = 0;
     61 
     62   /// resolveAgain - Can override by derived classes.
     63   /// @return the pointer to resolved ResolveInfo
     64   /// @return is the symbol existent?
     65   virtual void resolveAgain(NamePool& pNamePool,
     66                               unsigned int pAction,
     67                               ResolveInfo& __restrict__ pOld,
     68                               const ResolveInfo& __restrict__ pNew,
     69                               Result& pResult) const {
     70     pResult.info = NULL;
     71     pResult.existent = false;
     72     pResult.overriden = false;
     73   }
     74 
     75 };
     76 
     77 } // namespace of mcld
     78 
     79 #endif
     80 
     81