Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:42

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     Definition of the position_iterator and file_position templates
0005 
0006     http://www.boost.org/
0007 
0008     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0009     Software License, Version 1.0. (See accompanying file
0010     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0011 =============================================================================*/
0012 
0013 #if !defined(BOOST_FILE_POSITION_H_52BDEDF7_DAD3_4F24_802F_E66BB8098F68_INCLUDED)
0014 #define BOOST_FILE_POSITION_H_52BDEDF7_DAD3_4F24_802F_E66BB8098F68_INCLUDED
0015 
0016 #include <string>
0017 #include <ostream>
0018 
0019 #include <boost/assert.hpp>
0020 #include <boost/spirit/include/classic_version.hpp>
0021 #include <boost/spirit/include/classic_position_iterator.hpp>
0022 #include <boost/wave/wave_config.hpp>
0023 #if BOOST_WAVE_SERIALIZATION != 0
0024 #include <boost/serialization/serialization.hpp>
0025 #endif
0026 
0027 // this must occur after all of the includes and before any code appears
0028 #ifdef BOOST_HAS_ABI_HEADERS
0029 #include BOOST_ABI_PREFIX
0030 #endif
0031 
0032 ///////////////////////////////////////////////////////////////////////////////
0033 namespace boost {
0034 namespace wave {
0035 namespace util {
0036 
0037 ///////////////////////////////////////////////////////////////////////////////
0038 //
0039 //  file_position
0040 //
0041 //  A structure to hold positional information. This includes the filename,
0042 //  line number and column number of a current token position.
0043 //
0044 ///////////////////////////////////////////////////////////////////////////////
0045 
0046 template <typename StringT>
0047 struct file_position {
0048 
0049 public:
0050     typedef StringT string_type;
0051 
0052     file_position()
0053     :   file(), line(1), column(1)
0054     {}
0055     explicit file_position(string_type const& file_, std::size_t line_ = 1,
0056             std::size_t column_ = 1)
0057     :   file(file_), line(line_), column(column_)
0058     {}
0059 
0060     // accessors
0061     string_type const &get_file() const { return file; }
0062     std::size_t get_line() const { return line; }
0063     std::size_t get_column() const { return column; }
0064 
0065     void set_file(string_type const &file_)
0066     {
0067         file = file_;
0068     }
0069     void set_line(std::size_t line_) { line = line_; }
0070     void set_column(std::size_t column_) { column = column_; }
0071 
0072 private:
0073 #if BOOST_WAVE_SERIALIZATION != 0
0074     friend class boost::serialization::access;
0075     template<typename Archive>
0076     void serialize(Archive &ar, const unsigned int version)
0077     {
0078         using namespace boost::serialization;
0079         ar & make_nvp("filename", file);
0080         ar & make_nvp("line", line);
0081         ar & make_nvp("column", column);
0082     }
0083 #endif
0084 
0085     string_type file;
0086     std::size_t line;
0087     std::size_t column;
0088 };
0089 
0090 template <typename StringT>
0091 bool operator== (file_position<StringT> const &lhs,
0092     file_position<StringT> const &rhs)
0093 {
0094     return lhs.get_column() == rhs.get_column() &&
0095         lhs.get_line() == rhs.get_line() && lhs.get_file() == rhs.get_file();
0096 }
0097 
0098 template <typename StringT>
0099 inline std::ostream &
0100 operator<< (std::ostream &o, file_position<StringT> const &pos)
0101 {
0102     o << pos.get_file() << ":" << pos.get_line() << ":"  << pos.get_column();
0103     return o;
0104 }
0105 
0106 typedef file_position<BOOST_WAVE_STRINGTYPE> file_position_type;
0107 
0108 ///////////////////////////////////////////////////////////////////////////////
0109 //
0110 //  position_iterator
0111 //
0112 //  The position_iterator used by Wave is now based on the corresponding Spirit
0113 //  type. This type is used with our own file_position though. The needed
0114 //  specialization of the boost::spirit::classic::position_policy class is
0115 //  provided below.
0116 //
0117 ///////////////////////////////////////////////////////////////////////////////
0118 
0119 template <typename IteratorT, typename PositionT>
0120 struct position_iterator
0121 :   boost::spirit::classic::position_iterator<IteratorT, PositionT>
0122 {
0123     typedef boost::spirit::classic::position_iterator<IteratorT, PositionT> base_type;
0124 
0125     position_iterator()
0126     {
0127     }
0128 
0129     position_iterator(IteratorT const &begin, IteratorT const &end,
0130             PositionT const &pos)
0131     :   base_type(begin, end, pos)
0132     {
0133     }
0134 };
0135 
0136 ///////////////////////////////////////////////////////////////////////////////
0137 }   // namespace util
0138 }   // namespace wave
0139 
0140 ///////////////////////////////////////////////////////////////////////////////
0141 
0142 namespace spirit { namespace classic {
0143 
0144 ///////////////////////////////////////////////////////////////////////////////
0145 //
0146 //  The boost::spirit::classic::position_policy has to be specialized for our
0147 //  file_position class
0148 //
0149 ///////////////////////////////////////////////////////////////////////////////
0150 
0151     template <>
0152     class position_policy<boost::wave::util::file_position_type> {
0153 
0154     public:
0155         position_policy()
0156             : m_CharsPerTab(4)
0157         {}
0158 
0159         void next_line(boost::wave::util::file_position_type &pos)
0160         {
0161             pos.set_line(pos.get_line() + 1);
0162             pos.set_column(1);
0163         }
0164 
0165         void set_tab_chars(unsigned int chars)
0166         {
0167             m_CharsPerTab = chars;
0168         }
0169 
0170         void next_char(boost::wave::util::file_position_type &pos)
0171         {
0172             pos.set_column(pos.get_column() + 1);
0173         }
0174 
0175         void tabulation(boost::wave::util::file_position_type &pos)
0176         {
0177             pos.set_column(pos.get_column() + m_CharsPerTab -
0178                 (pos.get_column() - 1) % m_CharsPerTab);
0179         }
0180 
0181     private:
0182         unsigned int m_CharsPerTab;
0183     };
0184 
0185 ///////////////////////////////////////////////////////////////////////////////
0186 }}   // namespace spirit::classic
0187 
0188 }   // namespace boost
0189 
0190 // the suffix header occurs after all of the code
0191 #ifdef BOOST_HAS_ABI_HEADERS
0192 #include BOOST_ABI_SUFFIX
0193 #endif
0194 
0195 #endif // !defined(BOOST_FILE_POSITION_H_52BDEDF7_DAD3_4F24_802F_E66BB8098F68_INCLUDED)