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