File indexing completed on 2024-12-08 03:39:30

0001 
0002 /* A Bison parser, made by GNU Bison 2.4.1.  */
0003 
0004 /*  Locations 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 location.hh
0013  ** Define the KHolidays::location class.
0014  */
0015 
0016 #ifndef BISON_LOCATION_HH
0017 # define BISON_LOCATION_HH
0018 
0019 # include <iostream>
0020 # include <string>
0021 # include "position.hh"
0022 
0023 
0024 /* Line 162 of location.cc  */
0025 #line 1 "[Bison:b4_percent_define_default]"
0026 
0027 namespace KHolidays {
0028 
0029 /* Line 162 of location.cc  */
0030 #line 54 "location.hh"
0031 
0032   /// Abstract a location.
0033   class location
0034   {
0035   public:
0036 
0037     /// Construct a location.
0038     location ()
0039       : begin (), end ()
0040     {
0041     }
0042 
0043 
0044     /// Initialization.
0045     inline void initialize (std::string* fn)
0046     {
0047       begin.initialize (fn);
0048       end = begin;
0049     }
0050 
0051     /** \name Line and Column related manipulators
0052      ** \{ */
0053   public:
0054     /// Reset initial location to final location.
0055     inline void step ()
0056     {
0057       begin = end;
0058     }
0059 
0060     /// Extend the current location to the COUNT next columns.
0061     inline void columns (unsigned int count = 1)
0062     {
0063       end += count;
0064     }
0065 
0066     /// Extend the current location to the COUNT next lines.
0067     inline void lines (unsigned int count = 1)
0068     {
0069       end.lines (count);
0070     }
0071     /** \} */
0072 
0073 
0074   public:
0075     /// Beginning of the located region.
0076     position begin;
0077     /// End of the located region.
0078     position end;
0079   };
0080 
0081   /// Join two location objects to create a location.
0082   inline const location operator+ (const location& begin, const location& end)
0083   {
0084     location res = begin;
0085     res.end = end.end;
0086     return res;
0087   }
0088 
0089   /// Add two location objects.
0090   inline const location operator+ (const location& begin, unsigned int width)
0091   {
0092     location res = begin;
0093     res.columns (width);
0094     return res;
0095   }
0096 
0097   /// Add and assign a location.
0098   inline location& operator+= (location& res, unsigned int width)
0099   {
0100     res.columns (width);
0101     return res;
0102   }
0103 
0104   /// Compare two location objects.
0105   inline bool
0106   operator== (const location& loc1, const location& loc2)
0107   {
0108     return loc1.begin == loc2.begin && loc1.end == loc2.end;
0109   }
0110 
0111   /// Compare two location objects.
0112   inline bool
0113   operator!= (const location& loc1, const location& loc2)
0114   {
0115     return !(loc1 == loc2);
0116   }
0117 
0118   /** \brief Intercept output stream redirection.
0119    ** \param ostr the destination output stream
0120    ** \param loc a reference to the location to redirect
0121    **
0122    ** Avoid duplicate information.
0123    */
0124   inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
0125   {
0126     position last = loc.end - 1;
0127     ostr << loc.begin;
0128     if (last.filename
0129     && (!loc.begin.filename
0130         || *loc.begin.filename != *last.filename))
0131       ostr << '-' << last;
0132     else if (loc.begin.line != last.line)
0133       ostr << '-' << last.line  << '.' << last.column;
0134     else if (loc.begin.column != last.column)
0135       ostr << '-' << last.column;
0136     return ostr;
0137   }
0138 
0139 
0140 /* Line 271 of location.cc  */
0141 #line 1 "[Bison:b4_percent_define_default]"
0142 
0143 } // KHolidays
0144 
0145 /* Line 271 of location.cc  */
0146 #line 170 "location.hh"
0147 
0148 #endif // not BISON_LOCATION_HH