location.hh 5.2 KB

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