]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/server/src/location.hh
update
[l4.git] / l4 / pkg / io / server / src / location.hh
1 /* A Bison parser, made by GNU Bison 2.6.2.  */
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 location.hh
35  ** Define the cfg::location class.
36  */
37
38 #ifndef CFG_LOCATION_HH
39 # define CFG_LOCATION_HH
40
41 # include <iostream>
42 # include <string>
43 # include "position.hh"
44
45
46 namespace cfg {
47 /* Line 166 of location.cc  */
48 #line 49 "location.hh"
49
50   /// Abstract a location.
51   class location
52   {
53   public:
54
55     /// Construct a location from \a b to \a e.
56     location (const position& b, const position& e)
57       : begin (b)
58       , end (e)
59     {
60     }
61
62     /// Construct a 0-width location in \a p.
63     explicit location (const position& p = position ())
64       : begin (p)
65       , end (p)
66     {
67     }
68
69     /// Construct a 0-width location in \a f, \a l, \a c.
70     explicit location (std::string* f,
71                        unsigned int l = 1u,
72                        unsigned int c = 1u)
73       : begin (f, l, c)
74       , end (f, l, c)
75     {
76     }
77
78
79     /// Initialization.
80     void initialize (std::string* f = YY_NULL,
81                      unsigned int l = 1u,
82                      unsigned int c = 1u)
83     {
84       begin.initialize (f, l, c);
85       end = begin;
86     }
87
88     /** \name Line and Column related manipulators
89      ** \{ */
90   public:
91     /// Reset initial location to final location.
92     void step ()
93     {
94       begin = end;
95     }
96
97     /// Extend the current location to the COUNT next columns.
98     void columns (unsigned int count = 1)
99     {
100       end += count;
101     }
102
103     /// Extend the current location to the COUNT next lines.
104     void lines (unsigned int count = 1)
105     {
106       end.lines (count);
107     }
108     /** \} */
109
110
111   public:
112     /// Beginning of the located region.
113     position begin;
114     /// End of the located region.
115     position end;
116   };
117
118   /// Join two location objects to create a location.
119   inline const location operator+ (const location& begin, const location& end)
120   {
121     location res = begin;
122     res.end = end.end;
123     return res;
124   }
125
126   /// Add two location objects.
127   inline const location operator+ (const location& begin, unsigned int width)
128   {
129     location res = begin;
130     res.columns (width);
131     return res;
132   }
133
134   /// Add and assign a location.
135   inline location& operator+= (location& res, unsigned int width)
136   {
137     res.columns (width);
138     return res;
139   }
140
141   /// Compare two location objects.
142   inline bool
143   operator== (const location& loc1, const location& loc2)
144   {
145     return loc1.begin == loc2.begin && loc1.end == loc2.end;
146   }
147
148   /// Compare two location objects.
149   inline bool
150   operator!= (const location& loc1, const location& loc2)
151   {
152     return !(loc1 == loc2);
153   }
154
155   /** \brief Intercept output stream redirection.
156    ** \param ostr the destination output stream
157    ** \param loc a reference to the location to redirect
158    **
159    ** Avoid duplicate information.
160    */
161   inline std::ostream& operator<< (std::ostream& 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 } // cfg
178 /* Line 294 of location.cc  */
179 #line 180 "location.hh"
180
181 #endif /* !CFG_LOCATION_HH  */