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