position.hh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // A Bison parser, made by GNU Bison 3.0.4.
  2. // Positions for Bison parsers in C++
  3. // Copyright (C) 2002-2015 Free Software Foundation, Inc.
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License
  13. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. // As a special exception, you may create a larger work that contains
  15. // part or all of the Bison parser skeleton and distribute that work
  16. // under terms of your choice, so long as that work isn't itself a
  17. // parser generator using the skeleton or a modified version thereof
  18. // as a parser skeleton. Alternatively, if you modify or redistribute
  19. // the parser skeleton itself, you may (at your option) remove this
  20. // special exception, which will cause the skeleton and the resulting
  21. // Bison output files to be licensed under the GNU General Public
  22. // License without this special exception.
  23. // This special exception was added by the Free Software Foundation in
  24. // version 2.2 of Bison.
  25. /**
  26. ** \file position.hh
  27. ** Define the isc::eval::position class.
  28. */
  29. #ifndef YY_YY_POSITION_HH_INCLUDED
  30. # define YY_YY_POSITION_HH_INCLUDED
  31. # include <algorithm> // std::max
  32. # include <iostream>
  33. # include <string>
  34. # ifndef YY_NULLPTR
  35. # if defined __cplusplus && 201103L <= __cplusplus
  36. # define YY_NULLPTR nullptr
  37. # else
  38. # define YY_NULLPTR 0
  39. # endif
  40. # endif
  41. #line 21 "parser.yy" // location.cc:337
  42. namespace isc { namespace eval {
  43. #line 56 "position.hh" // location.cc:337
  44. /// Abstract a position.
  45. class position
  46. {
  47. public:
  48. /// Construct a position.
  49. explicit position (std::string* f = YY_NULLPTR,
  50. unsigned int l = 1u,
  51. unsigned int c = 1u)
  52. : filename (f)
  53. , line (l)
  54. , column (c)
  55. {
  56. }
  57. /// Initialization.
  58. void initialize (std::string* fn = YY_NULLPTR,
  59. unsigned int l = 1u,
  60. unsigned int c = 1u)
  61. {
  62. filename = fn;
  63. line = l;
  64. column = c;
  65. }
  66. /** \name Line and Column related manipulators
  67. ** \{ */
  68. /// (line related) Advance to the COUNT next lines.
  69. void lines (int count = 1)
  70. {
  71. if (count)
  72. {
  73. column = 1u;
  74. line = add_ (line, count, 1);
  75. }
  76. }
  77. /// (column related) Advance to the COUNT next columns.
  78. void columns (int count = 1)
  79. {
  80. column = add_ (column, count, 1);
  81. }
  82. /** \} */
  83. /// File name to which this position refers.
  84. std::string* filename;
  85. /// Current line number.
  86. unsigned int line;
  87. /// Current column number.
  88. unsigned int column;
  89. private:
  90. /// Compute max(min, lhs+rhs) (provided min <= lhs).
  91. static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
  92. {
  93. return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
  94. ? rhs + lhs
  95. : min);
  96. }
  97. };
  98. /// Add \a width columns, in place.
  99. inline position&
  100. operator+= (position& res, int width)
  101. {
  102. res.columns (width);
  103. return res;
  104. }
  105. /// Add \a width columns.
  106. inline position
  107. operator+ (position res, int width)
  108. {
  109. return res += width;
  110. }
  111. /// Subtract \a width columns, in place.
  112. inline position&
  113. operator-= (position& res, int width)
  114. {
  115. return res += -width;
  116. }
  117. /// Subtract \a width columns.
  118. inline position
  119. operator- (position res, int width)
  120. {
  121. return res -= width;
  122. }
  123. /// Compare two position objects.
  124. inline bool
  125. operator== (const position& pos1, const position& pos2)
  126. {
  127. return (pos1.line == pos2.line
  128. && pos1.column == pos2.column
  129. && (pos1.filename == pos2.filename
  130. || (pos1.filename && pos2.filename
  131. && *pos1.filename == *pos2.filename)));
  132. }
  133. /// Compare two position objects.
  134. inline bool
  135. operator!= (const position& pos1, const position& pos2)
  136. {
  137. return !(pos1 == pos2);
  138. }
  139. /** \brief Intercept output stream redirection.
  140. ** \param ostr the destination output stream
  141. ** \param pos a reference to the position to redirect
  142. */
  143. template <typename YYChar>
  144. inline std::basic_ostream<YYChar>&
  145. operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
  146. {
  147. if (pos.filename)
  148. ostr << *pos.filename << ':';
  149. return ostr << pos.line << '.' << pos.column;
  150. }
  151. #line 21 "parser.yy" // location.cc:337
  152. } } // isc::eval
  153. #line 180 "position.hh" // location.cc:337
  154. #endif // !YY_YY_POSITION_HH_INCLUDED