Resolver.h revision d8a752331fe7a30ce41835f139aa8a4c675ad07a
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
17namespace mcld
18{
19
20class ResolveInfo;
21class StrSymPool;
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 */
31class Resolver
32{
33public:
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
53public:
54  Resolver();
55
56  Resolver(const Resolver& pCopy);
57
58  virtual ~Resolver();
59
60  /// shouldOverride - Can resolver override the symbol pOld by the symbol pNew?
61  /// @return the action should be taken.
62  /// @param pOld the symbol which may be overridden.
63  /// @param pNew the symbol which is used to replace pOld
64  virtual unsigned int resolve(ResolveInfo & __restrict__ pOld,
65                               const ResolveInfo & __restrict__ pNew,
66                               bool &pOverride) = 0;
67
68  /// resolveAgain - Can override by derived classes.
69  /// @return the pointer to resolved ResolveInfo
70  /// @return is the symbol existent?
71  virtual void resolveAgain(StrSymPool& pStrSymPool,
72                              unsigned int pAction,
73                              ResolveInfo& __restrict__ pOld,
74                              const ResolveInfo& __restrict__ pNew,
75                              Result& pResult) {
76    pResult.info = NULL;
77    pResult.existent = false;
78    pResult.overriden = false;
79  }
80
81  const std::string& mesg() const
82  { return m_Mesg; }
83
84  void clearMesg();
85
86  Resolver* clone() const {
87    return doClone();
88  }
89
90protected:
91  std::string m_Mesg;
92
93private:
94  virtual Resolver* doClone() const = 0;
95};
96
97} // namespace of mcld
98
99#endif
100