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