location.hh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // A Bison parser, made by GNU Bison 3.0.4.
  2. // Locations 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 location.hh
  27. ** Define the isc::dhcp::location class.
  28. */
  29. #ifndef YY_PARSER4_LOCATION_HH_INCLUDED
  30. # define YY_PARSER4_LOCATION_HH_INCLUDED
  31. # include "position.hh"
  32. #line 14 "dhcp4_parser.yy" // location.cc:296
  33. namespace isc { namespace dhcp {
  34. #line 46 "location.hh" // location.cc:296
  35. /// Abstract a location.
  36. class location
  37. {
  38. public:
  39. /// Construct a location from \a b to \a e.
  40. location (const position& b, const position& e)
  41. : begin (b)
  42. , end (e)
  43. {
  44. }
  45. /// Construct a 0-width location in \a p.
  46. explicit location (const position& p = position ())
  47. : begin (p)
  48. , end (p)
  49. {
  50. }
  51. /// Construct a 0-width location in \a f, \a l, \a c.
  52. explicit location (std::string* f,
  53. unsigned int l = 1u,
  54. unsigned int c = 1u)
  55. : begin (f, l, c)
  56. , end (f, l, c)
  57. {
  58. }
  59. /// Initialization.
  60. void initialize (std::string* f = YY_NULLPTR,
  61. unsigned int l = 1u,
  62. unsigned int c = 1u)
  63. {
  64. begin.initialize (f, l, c);
  65. end = begin;
  66. }
  67. /** \name Line and Column related manipulators
  68. ** \{ */
  69. public:
  70. /// Reset initial location to final location.
  71. void step ()
  72. {
  73. begin = end;
  74. }
  75. /// Extend the current location to the COUNT next columns.
  76. void columns (int count = 1)
  77. {
  78. end += count;
  79. }
  80. /// Extend the current location to the COUNT next lines.
  81. void lines (int count = 1)
  82. {
  83. end.lines (count);
  84. }
  85. /** \} */
  86. public:
  87. /// Beginning of the located region.
  88. position begin;
  89. /// End of the located region.
  90. position end;
  91. };
  92. /// Join two locations, in place.
  93. inline location& operator+= (location& res, const location& end)
  94. {
  95. res.end = end.end;
  96. return res;
  97. }
  98. /// Join two locations.
  99. inline location operator+ (location res, const location& end)
  100. {
  101. return res += end;
  102. }
  103. /// Add \a width columns to the end position, in place.
  104. inline location& operator+= (location& res, int width)
  105. {
  106. res.columns (width);
  107. return res;
  108. }
  109. /// Add \a width columns to the end position.
  110. inline location operator+ (location res, int width)
  111. {
  112. return res += width;
  113. }
  114. /// Subtract \a width columns to the end position, in place.
  115. inline location& operator-= (location& res, int width)
  116. {
  117. return res += -width;
  118. }
  119. /// Subtract \a width columns to the end position.
  120. inline location operator- (location res, int width)
  121. {
  122. return res -= width;
  123. }
  124. /// Compare two location objects.
  125. inline bool
  126. operator== (const location& loc1, const location& loc2)
  127. {
  128. return loc1.begin == loc2.begin && loc1.end == loc2.end;
  129. }
  130. /// Compare two location objects.
  131. inline bool
  132. operator!= (const location& loc1, const location& loc2)
  133. {
  134. return !(loc1 == loc2);
  135. }
  136. /** \brief Intercept output stream redirection.
  137. ** \param ostr the destination output stream
  138. ** \param loc a reference to the location to redirect
  139. **
  140. ** Avoid duplicate information.
  141. */
  142. template <typename YYChar>
  143. inline std::basic_ostream<YYChar>&
  144. operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
  145. {
  146. unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
  147. ostr << loc.begin;
  148. if (loc.end.filename
  149. && (!loc.begin.filename
  150. || *loc.begin.filename != *loc.end.filename))
  151. ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
  152. else if (loc.begin.line < loc.end.line)
  153. ostr << '-' << loc.end.line << '.' << end_col;
  154. else if (loc.begin.column < end_col)
  155. ostr << '-' << end_col;
  156. return ostr;
  157. }
  158. #line 14 "dhcp4_parser.yy" // location.cc:296
  159. } } // isc::dhcp
  160. #line 192 "location.hh" // location.cc:296
  161. #endif // !YY_PARSER4_LOCATION_HH_INCLUDED