RpnExpr.h revision 87f34658dec9097d987d254a990ea7f311bfc95f
1//===- RPNExpr.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_SCRIPT_RPNEXPR_H
10#define MCLD_SCRIPT_RPNEXPR_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14
15#include <mcld/Support/Allocators.h>
16#include <mcld/Config/Config.h>
17#include <mcld/Object/SectionMap.h>
18#include <vector>
19
20namespace mcld
21{
22
23class ExprToken;
24class Fragment;
25
26/** \class RpnExpr
27 *  \brief This class defines the interfaces to a rpn expression.
28 */
29
30class RpnExpr
31{
32public:
33  typedef std::vector<ExprToken*> TokenQueue;
34  typedef TokenQueue::const_iterator const_iterator;
35  typedef TokenQueue::iterator iterator;
36
37private:
38  friend class Chunk<RpnExpr, MCLD_SYMBOLS_PER_INPUT>;
39  RpnExpr();
40
41public:
42  ~RpnExpr();
43
44  const_iterator begin() const { return m_TokenQueue.begin(); }
45  iterator       begin()       { return m_TokenQueue.begin(); }
46  const_iterator end()   const { return m_TokenQueue.end(); }
47  iterator       end()         { return m_TokenQueue.end(); }
48
49  size_t size() const { return m_TokenQueue.size(); }
50
51  bool empty() const { return m_TokenQueue.empty(); }
52
53  bool hasDot() const;
54
55  void dump() const;
56
57  void push_back(ExprToken* pToken);
58
59  iterator insert(iterator pPosition, ExprToken* pToken);
60
61  void erase(iterator pPosition);
62
63  /* factory methods */
64  static RpnExpr* create();
65  static void destroy(RpnExpr*& pRpnExpr);
66  static void clear();
67
68  // buildHelperExpr - build the helper expr:
69  //                   ADDR ( `output_sect' ) + SIZEOF ( `output_sect' )
70  static RpnExpr* buildHelperExpr(SectionMap::iterator pIter);
71  // buildHelperExpr - build the helper expr: `fragment'
72  static RpnExpr* buildHelperExpr(Fragment& pFrag);
73
74private:
75  TokenQueue m_TokenQueue;
76};
77
78} // namespace of mcld
79
80#endif
81
82