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