1 /* A Bison parser, made by GNU Bison 2.6.90.8-d4fe.  */
2 
3 /* Locations for Bison parsers in C++
4 
5       Copyright (C) 2002-2007, 2009-2012 Free Software Foundation, Inc.
6 
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29 
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32 
33 /**
34  ** \file ../../../../examples/calc++/location.hh
35  ** Define the yy::location class.
36  */
37 
38 #ifndef YY_YY_EXAMPLES_CALC_LOCATION_HH_INCLUDED
39 # define YY_YY_EXAMPLES_CALC_LOCATION_HH_INCLUDED
40 
41 # include "position.hh"
42 
43 
44 namespace yy {
45 /* Line 166 of location.cc  */
46 #line 47 "../../../../examples/calc++/location.hh"
47 
48   /// Abstract a location.
49   class location
50   {
51   public:
52 
53     /// Construct a location from \a b to \a e.
location(const position & b,const position & e)54     location (const position& b, const position& e)
55       : begin (b)
56       , end (e)
57     {
58     }
59 
60     /// Construct a 0-width location in \a p.
location(const position & p=position ())61     explicit location (const position& p = position ())
62       : begin (p)
63       , end (p)
64     {
65     }
66 
67     /// Construct a 0-width location in \a f, \a l, \a c.
location(std::string * f,unsigned int l=1u,unsigned int c=1u)68     explicit location (std::string* f,
69                        unsigned int l = 1u,
70                        unsigned int c = 1u)
71       : begin (f, l, c)
72       , end (f, l, c)
73     {
74     }
75 
76 
77     /// Initialization.
initialize(std::string * f=YY_NULL,unsigned int l=1u,unsigned int c=1u)78     void initialize (std::string* f = YY_NULL,
79                      unsigned int l = 1u,
80                      unsigned int c = 1u)
81     {
82       begin.initialize (f, l, c);
83       end = begin;
84     }
85 
86     /** \name Line and Column related manipulators
87      ** \{ */
88   public:
89     /// Reset initial location to final location.
step()90     void step ()
91     {
92       begin = end;
93     }
94 
95     /// Extend the current location to the COUNT next columns.
columns(unsigned int count=1)96     void columns (unsigned int count = 1)
97     {
98       end += count;
99     }
100 
101     /// Extend the current location to the COUNT next lines.
lines(unsigned int count=1)102     void lines (unsigned int count = 1)
103     {
104       end.lines (count);
105     }
106     /** \} */
107 
108 
109   public:
110     /// Beginning of the located region.
111     position begin;
112     /// End of the located region.
113     position end;
114   };
115 
116   /// Join two location objects to create a location.
operator +(const location & begin,const location & end)117   inline const location operator+ (const location& begin, const location& end)
118   {
119     location res = begin;
120     res.end = end.end;
121     return res;
122   }
123 
124   /// Add two location objects.
operator +(const location & begin,unsigned int width)125   inline const location operator+ (const location& begin, unsigned int width)
126   {
127     location res = begin;
128     res.columns (width);
129     return res;
130   }
131 
132   /// Add and assign a location.
operator +=(location & res,unsigned int width)133   inline location& operator+= (location& res, unsigned int width)
134   {
135     res.columns (width);
136     return res;
137   }
138 
139   /// Compare two location objects.
140   inline bool
operator ==(const location & loc1,const location & loc2)141   operator== (const location& loc1, const location& loc2)
142   {
143     return loc1.begin == loc2.begin && loc1.end == loc2.end;
144   }
145 
146   /// Compare two location objects.
147   inline bool
operator !=(const location & loc1,const location & loc2)148   operator!= (const location& loc1, const location& loc2)
149   {
150     return !(loc1 == loc2);
151   }
152 
153   /** \brief Intercept output stream redirection.
154    ** \param ostr the destination output stream
155    ** \param loc a reference to the location to redirect
156    **
157    ** Avoid duplicate information.
158    */
159   template <typename YYChar>
160   inline std::basic_ostream<YYChar>&
operator <<(std::basic_ostream<YYChar> & ostr,const location & loc)161   operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
162   {
163     position last = loc.end - 1;
164     ostr << loc.begin;
165     if (last.filename
166 	&& (!loc.begin.filename
167 	    || *loc.begin.filename != *last.filename))
168       ostr << '-' << last;
169     else if (loc.begin.line != last.line)
170       ostr << '-' << last.line  << '.' << last.column;
171     else if (loc.begin.column != last.column)
172       ostr << '-' << last.column;
173     return ostr;
174   }
175 
176 
177 } // yy
178 /* Line 296 of location.cc  */
179 #line 180 "../../../../examples/calc++/location.hh"
180 
181 #endif /* !YY_YY_EXAMPLES_CALC_LOCATION_HH_INCLUDED  */
182