spot  1.0.1
position.hh
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 2.5. */
2 
3 /* Positions for Bison parsers in C++
4 
5  Copyright (C) 2002-2007, 2009-2011 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 
38 #ifndef BISON_POSITION_HH
39 # define BISON_POSITION_HH
40 
41 # include <iostream>
42 # include <string>
43 # include <algorithm>
44 
45 
46 namespace ltlyy {
47 
48 /* Line 37 of location.cc */
49 #line 50 "position.hh"
50 
51  class position
52  {
53  public:
54 
57  : filename (0), line (1), column (1)
58  {
59  }
60 
61 
63  inline void initialize (std::string* fn)
64  {
65  filename = fn;
66  line = 1;
67  column = 1;
68  }
69 
72  public:
74  inline void lines (int count = 1)
75  {
76  column = 1;
77  line += count;
78  }
79 
81  inline void columns (int count = 1)
82  {
83  column = std::max (1u, column + count);
84  }
87  public:
89  std::string* filename;
91  unsigned int line;
93  unsigned int column;
94  };
95 
97  inline const position&
98  operator+= (position& res, const int width)
99  {
100  res.columns (width);
101  return res;
102  }
103 
105  inline const position
106  operator+ (const position& begin, const int width)
107  {
108  position res = begin;
109  return res += width;
110  }
111 
113  inline const position&
114  operator-= (position& res, const int width)
115  {
116  return res += -width;
117  }
118 
120  inline const position
121  operator- (const position& begin, const int width)
122  {
123  return begin + -width;
124  }
125 
127  inline bool
128  operator== (const position& pos1, const position& pos2)
129  {
130  return (pos1.line == pos2.line
131  && pos1.column == pos2.column
132  && (pos1.filename == pos2.filename
133  || (pos1.filename && pos2.filename
134  && *pos1.filename == *pos2.filename)));
135  }
136 
138  inline bool
139  operator!= (const position& pos1, const position& pos2)
140  {
141  return !(pos1 == pos2);
142  }
143 
148  inline std::ostream&
149  operator<< (std::ostream& ostr, const position& pos)
150  {
151  if (pos.filename)
152  ostr << *pos.filename << ':';
153  return ostr << pos.line << '.' << pos.column;
154  }
155 
156 
157 } // ltlyy
158 
159 /* Line 144 of location.cc */
160 #line 161 "position.hh"
161 #endif // not BISON_POSITION_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Jan 23 2013 15:00:00 for spot by doxygen 1.8.1.2