187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//===- RPNExpr.h ----------------------------------------------------------===//
287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//                     The MCLinker Project
487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// This file is distributed under the University of Illinois Open Source
687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// License. See LICENSE.TXT for details.
787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//===----------------------------------------------------------------------===//
937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef MCLD_SCRIPT_RPNEXPR_H_
1037b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define MCLD_SCRIPT_RPNEXPR_H_
1137b74a387bb3993387029859c2d9d051c41c724eStephen Hines
1237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Config/Config.h"
1337b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Object/SectionMap.h"
1437b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/Support/Allocators.h"
1587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
1687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#include <vector>
1787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
1837b74a387bb3993387029859c2d9d051c41c724eStephen Hinesnamespace mcld {
1987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
2087f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesclass ExprToken;
2187f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesclass Fragment;
2287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
2387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines/** \class RpnExpr
2487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines *  \brief This class defines the interfaces to a rpn expression.
2587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines */
2687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
2737b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass RpnExpr {
2837b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
2987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  typedef std::vector<ExprToken*> TokenQueue;
3087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  typedef TokenQueue::const_iterator const_iterator;
3187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  typedef TokenQueue::iterator iterator;
3287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3337b74a387bb3993387029859c2d9d051c41c724eStephen Hines private:
3487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  friend class Chunk<RpnExpr, MCLD_SYMBOLS_PER_INPUT>;
3587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  RpnExpr();
3687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3737b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
3887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  ~RpnExpr();
3987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  const_iterator begin() const { return m_TokenQueue.begin(); }
4137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator begin() { return m_TokenQueue.begin(); }
4237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const_iterator end() const { return m_TokenQueue.end(); }
4337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  iterator end() { return m_TokenQueue.end(); }
4487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  size_t size() const { return m_TokenQueue.size(); }
4687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  bool empty() const { return m_TokenQueue.empty(); }
4887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
4987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  bool hasDot() const;
5087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  void dump() const;
5287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  void push_back(ExprToken* pToken);
5487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  iterator insert(iterator pPosition, ExprToken* pToken);
5687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  void erase(iterator pPosition);
5887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  /* factory methods */
6087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  static RpnExpr* create();
6187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  static void destroy(RpnExpr*& pRpnExpr);
6287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  static void clear();
6387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
6487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  // buildHelperExpr - build the helper expr:
6587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  //                   ADDR ( `output_sect' ) + SIZEOF ( `output_sect' )
6687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  static RpnExpr* buildHelperExpr(SectionMap::iterator pIter);
6787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  // buildHelperExpr - build the helper expr: `fragment'
6887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  static RpnExpr* buildHelperExpr(Fragment& pFrag);
6987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
7037b74a387bb3993387029859c2d9d051c41c724eStephen Hines private:
7187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  TokenQueue m_TokenQueue;
7287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines};
7387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
7437b74a387bb3993387029859c2d9d051c41c724eStephen Hines}  // namespace mcld
7587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
7637b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif  // MCLD_SCRIPT_RPNEXPR_H_
77