File indexing completed on 2024-03-24 03:57:06

0001 
0002 /* A Bison parser, made by GNU Bison 2.4.1.  */
0003 
0004 /* Positions for Bison parsers in C++
0005 
0006     SPDX-FileCopyrightText: 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
0007 
0008     SPDX-License-Identifier: GPL-3.0-or-later WITH Bison-exception-2.2
0009 */
0010 
0011 /**
0012  ** \file position.hh
0013  ** Define the KHolidays::position class.
0014  */
0015 
0016 #ifndef BISON_POSITION_HH
0017 # define BISON_POSITION_HH
0018 
0019 # include <iostream>
0020 # include <string>
0021 # include <algorithm>
0022 
0023 
0024 /* Line 38 of location.cc  */
0025 #line 1 "[Bison:b4_percent_define_default]"
0026 
0027 namespace KHolidays {
0028 
0029 /* Line 38 of location.cc  */
0030 #line 54 "position.hh"
0031   /// Abstract a position.
0032   class position
0033   {
0034   public:
0035 
0036     /// Construct a position.
0037     position ()
0038       : filename (nullptr), line (1), column (1)
0039     {
0040     }
0041 
0042 
0043     /// Initialization.
0044     inline void initialize (std::string* fn)
0045     {
0046       filename = fn;
0047       line = 1;
0048       column = 1;
0049     }
0050 
0051     /** \name Line and Column related manipulators
0052      ** \{ */
0053   public:
0054     /// (line related) Advance to the COUNT next lines.
0055     inline void lines (int count = 1)
0056     {
0057       column = 1;
0058       line += count;
0059     }
0060 
0061     /// (column related) Advance to the COUNT next columns.
0062     inline void columns (int count = 1)
0063     {
0064       column = std::max (1u, column + count);
0065     }
0066     /** \} */
0067 
0068   public:
0069     /// File name to which this position refers.
0070     std::string* filename;
0071     /// Current line number.
0072     unsigned int line;
0073     /// Current column number.
0074     unsigned int column;
0075   };
0076 
0077   /// Add and assign a position.
0078   inline const position&
0079   operator+= (position& res, const int width)
0080   {
0081     res.columns (width);
0082     return res;
0083   }
0084 
0085   /// Add two position objects.
0086   inline const position
0087   operator+ (const position& begin, const int width)
0088   {
0089     position res = begin;
0090     return res += width;
0091   }
0092 
0093   /// Add and assign a position.
0094   inline const position&
0095   operator-= (position& res, const int width)
0096   {
0097     return res += -width;
0098   }
0099 
0100   /// Add two position objects.
0101   inline const position
0102   operator- (const position& begin, const int width)
0103   {
0104     return begin + -width;
0105   }
0106 
0107   /// Compare two position objects.
0108   inline bool
0109   operator== (const position& pos1, const position& pos2)
0110   {
0111     return
0112       (pos1.filename == pos2.filename
0113        || (pos1.filename && pos2.filename && *pos1.filename == *pos2.filename))
0114       && pos1.line == pos2.line && pos1.column == pos2.column;
0115   }
0116 
0117   /// Compare two position objects.
0118   inline bool
0119   operator!= (const position& pos1, const position& pos2)
0120   {
0121     return !(pos1 == pos2);
0122   }
0123 
0124   /** \brief Intercept output stream redirection.
0125    ** \param ostr the destination output stream
0126    ** \param pos a reference to the position to redirect
0127    */
0128   inline std::ostream&
0129   operator<< (std::ostream& ostr, const position& pos)
0130   {
0131     if (pos.filename)
0132       ostr << *pos.filename << ':';
0133     return ostr << pos.line << '.' << pos.column;
0134   }
0135 
0136 
0137 /* Line 144 of location.cc  */
0138 #line 1 "[Bison:b4_percent_define_default]"
0139 
0140 } // KHolidays
0141 
0142 /* Line 144 of location.cc  */
0143 #line 167 "position.hh"
0144 #endif // not BISON_POSITION_HH