Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 /* Line 36 of location.cc */
54 #line 4 "evalexpr_parser.yy"
55 namespace yy {
56 /* Line 36 of location.cc */
57 #line 58 "position.hh"
58  class position
60  {
61  public:
62 
64  explicit position (std::string* f = YY_NULL,
65  unsigned int l = 1u,
66  unsigned int c = 1u)
67  : filename (f)
68  , line (l)
69  , column (c)
70  {
71  }
72 
73 
75  void initialize (std::string* fn = YY_NULL,
76  unsigned int l = 1u,
77  unsigned int c = 1u)
78  {
79  filename = fn;
80  line = l;
81  column = c;
82  }
83 
86  void lines (int count = 1)
88  {
89  column = 1u;
90  line += count;
91  }
92 
94  void columns (int count = 1)
95  {
96  column = std::max (1u, column + count);
97  }
100  std::string* filename;
103  unsigned int line;
105  unsigned int column;
106  };
107 
109  inline position&
110  operator+= (position& res, const int width)
111  {
112  res.columns (width);
113  return res;
114  }
115 
117  inline const position
118  operator+ (const position& begin, const int width)
119  {
120  position res = begin;
121  return res += width;
122  }
123 
125  inline position&
126  operator-= (position& res, const int width)
127  {
128  return res += -width;
129  }
130 
132  inline const position
133  operator- (const position& begin, const int width)
134  {
135  return begin + -width;
136  }
137 
139  inline bool
140  operator== (const position& pos1, const position& pos2)
141  {
142  return (pos1.line == pos2.line
143  && pos1.column == pos2.column
144  && (pos1.filename == pos2.filename
145  || (pos1.filename && pos2.filename
146  && *pos1.filename == *pos2.filename)));
147  }
148 
150  inline bool
151  operator!= (const position& pos1, const position& pos2)
152  {
153  return !(pos1 == pos2);
154  }
155 
160  template <typename YYChar>
161  inline std::basic_ostream<YYChar>&
162  operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
163  {
164  if (pos.filename)
165  ostr << *pos.filename << ':';
166  return ostr << pos.line << '.' << pos.column;
167  }
168 
169 /* Line 148 of location.cc */
170 #line 4 "evalexpr_parser.yy"
171 } // yy
172 /* Line 148 of location.cc */
173 #line 174 "position.hh"
174 #endif /* !YY_YY_POSITION_HH_INCLUDED */
Abstract a position.
Definition: position.hh:59
bool operator!=(const location &loc1, const location &loc2)
Compare two location objects.
Definition: location.hh:149
position & operator-=(position &res, const int width)
Add and assign a position.
Definition: position.hh:126
void initialize(std::string *fn=YY_NULL, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: position.hh:75
position(std::string *f=YY_NULL, unsigned int l=1u, unsigned int c=1u)
Construct a position.
Definition: position.hh:64
const location operator+(const location &begin, const location &end)
Join two location objects to create a location.
Definition: location.hh:118
const position operator-(const position &begin, const int width)
Add two position objects.
Definition: position.hh:133
unsigned int column
Current column number.
Definition: position.hh:105
#define YY_NULL
Definition: position.hh:49
void columns(int count=1)
(column related) Advance to the COUNT next columns.
Definition: position.hh:94
location & operator+=(location &res, unsigned int width)
Add and assign a location.
Definition: location.hh:134
void lines(int count=1)
(line related) Advance to the COUNT next lines.
Definition: position.hh:87
bool operator==(const location &loc1, const location &loc2)
Compare two location objects.
Definition: location.hh:142
unsigned int line
Current line number.
Definition: position.hh:103
std::string * filename
File name to which this position refers.
Definition: position.hh:101