QJson home page
position.hh
Go to the documentation of this file.
1/* A Bison parser, made by GNU Bison 2.7. */
2
3/* Positions 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
38#ifndef YY_YY_POSITION_HH_INCLUDED
39# define YY_YY_POSITION_HH_INCLUDED
40
41# include <algorithm> // std::max
42# include <iostream>
43# include <string>
44
45# ifndef YY_NULL
46# if defined __cplusplus && 201103L <= __cplusplus
47# define YY_NULL nullptr
48# else
49# define YY_NULL 0
50# endif
51# endif
52
53
54namespace yy {
55/* Line 36 of location.cc */
56#line 57 "position.hh"
59 {
60 public:
61
63 explicit position (std::string* f = YY_NULL,
64 unsigned int l = 1u,
65 unsigned int c = 1u)
66 : filename (f)
67 , line (l)
68 , column (c)
69 {
70 }
71
72
74 void initialize (std::string* fn = YY_NULL,
75 unsigned int l = 1u,
76 unsigned int c = 1u)
77 {
78 filename = fn;
79 line = l;
80 column = c;
81 }
82
86 void lines (int count = 1)
87 {
88 column = 1u;
89 line += count;
90 }
91
93 void columns (int count = 1)
94 {
95 column = std::max (1u, column + count);
96 }
100 std::string* filename;
102 unsigned int line;
104 unsigned int column;
105 };
106
108 inline position&
109 operator+= (position& res, const int width)
110 {
111 res.columns (width);
112 return res;
113 }
114
116 inline const position
117 operator+ (const position& begin, const int width)
118 {
119 position res = begin;
120 return res += width;
121 }
122
124 inline position&
125 operator-= (position& res, const int width)
126 {
127 return res += -width;
128 }
129
131 inline const position
132 operator- (const position& begin, const int width)
133 {
134 return begin + -width;
135 }
136
138 inline bool
139 operator== (const position& pos1, const position& pos2)
140 {
141 return (pos1.line == pos2.line
142 && pos1.column == pos2.column
143 && (pos1.filename == pos2.filename
144 || (pos1.filename && pos2.filename
145 && *pos1.filename == *pos2.filename)));
146 }
147
149 inline bool
150 operator!= (const position& pos1, const position& pos2)
151 {
152 return !(pos1 == pos2);
153 }
154
159 template <typename YYChar>
160 inline std::basic_ostream<YYChar>&
161 operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
162 {
163 if (pos.filename)
164 ostr << *pos.filename << ':';
165 return ostr << pos.line << '.' << pos.column;
166 }
167
168
169} // yy
170/* Line 148 of location.cc */
171#line 172 "position.hh"
172#endif /* !YY_YY_POSITION_HH_INCLUDED */
Abstract a position.
Definition: position.hh:59
void lines(int count=1)
(line related) Advance to the COUNT next lines.
Definition: position.hh:86
position(std::string *f=YY_NULL, unsigned int l=1u, unsigned int c=1u)
Construct a position.
Definition: position.hh:63
std::string * filename
File name to which this position refers.
Definition: position.hh:100
unsigned int line
Current line number.
Definition: position.hh:102
void columns(int count=1)
(column related) Advance to the COUNT next columns.
Definition: position.hh:93
unsigned int column
Current column number.
Definition: position.hh:104
void initialize(std::string *fn=YY_NULL, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: position.hh:74

SourceForge Logo hosts this site. Send comments to:
QJson Developers