1/* A Bison parser, made by GNU Bison 2.6.90.8-d4fe.  */
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
33/**
34 ** \file ../../../../examples/calc++/position.hh
35 ** Define the yy::position class.
36 */
37
38#ifndef YY_YY_EXAMPLES_CALC_POSITION_HH_INCLUDED
39# define YY_YY_EXAMPLES_CALC_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 "../../../../examples/calc++/position.hh"
57  /// Abstract a position.
58  class position
59  {
60  public:
61
62    /// Construct a position.
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
73    /// Initialization.
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
83    /** \name Line and Column related manipulators
84     ** \{ */
85    /// (line related) Advance to the COUNT next lines.
86    void lines (int count = 1)
87    {
88      column = 1u;
89      line += count;
90    }
91
92    /// (column related) Advance to the COUNT next columns.
93    void columns (int count = 1)
94    {
95      column = std::max (1u, column + count);
96    }
97    /** \} */
98
99    /// File name to which this position refers.
100    std::string* filename;
101    /// Current line number.
102    unsigned int line;
103    /// Current column number.
104    unsigned int column;
105  };
106
107  /// Add and assign a position.
108  inline position&
109  operator+= (position& res, const int width)
110  {
111    res.columns (width);
112    return res;
113  }
114
115  /// Add two position objects.
116  inline const position
117  operator+ (const position& begin, const int width)
118  {
119    position res = begin;
120    return res += width;
121  }
122
123  /// Add and assign a position.
124  inline position&
125  operator-= (position& res, const int width)
126  {
127    return res += -width;
128  }
129
130  /// Add two position objects.
131  inline const position
132  operator- (const position& begin, const int width)
133  {
134    return begin + -width;
135  }
136
137  /// Compare two position objects.
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
148  /// Compare two position objects.
149  inline bool
150  operator!= (const position& pos1, const position& pos2)
151  {
152    return !(pos1 == pos2);
153  }
154
155  /** \brief Intercept output stream redirection.
156   ** \param ostr the destination output stream
157   ** \param pos a reference to the position to redirect
158   */
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 "../../../../examples/calc++/position.hh"
172#endif /* !YY_YY_EXAMPLES_CALC_POSITION_HH_INCLUDED  */
173