Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

173 rader
4.6 KiB

  1. /* A Bison parser, made by GNU Bison 2.7.12-4996. */
  2. /* Positions for Bison parsers in C++
  3. Copyright (C) 2002-2007, 2009-2013 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 generated/position.hh
  27. ** Define the lol::position class.
  28. */
  29. #ifndef YY_LOL_GENERATED_POSITION_HH_INCLUDED
  30. # define YY_LOL_GENERATED_POSITION_HH_INCLUDED
  31. # include <algorithm> // std::max
  32. # include <iostream>
  33. # include <string>
  34. # ifndef YY_NULL
  35. # if defined __cplusplus && 201103L <= __cplusplus
  36. # define YY_NULL nullptr
  37. # else
  38. # define YY_NULL 0
  39. # endif
  40. # endif
  41. namespace lol {
  42. /* Line 36 of location.cc */
  43. #line 57 "generated/position.hh"
  44. /// Abstract a position.
  45. class position
  46. {
  47. public:
  48. /// Construct a position.
  49. explicit position (std::string* f = YY_NULL,
  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_NULL,
  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. column = 1u;
  72. line += count;
  73. }
  74. /// (column related) Advance to the COUNT next columns.
  75. void columns (int count = 1)
  76. {
  77. column = std::max (1u, column + count);
  78. }
  79. /** \} */
  80. /// File name to which this position refers.
  81. std::string* filename;
  82. /// Current line number.
  83. unsigned int line;
  84. /// Current column number.
  85. unsigned int column;
  86. };
  87. /// Add and assign a position.
  88. inline position&
  89. operator+= (position& res, const int width)
  90. {
  91. res.columns (width);
  92. return res;
  93. }
  94. /// Add two position objects.
  95. inline const position
  96. operator+ (const position& begin, const int width)
  97. {
  98. position res = begin;
  99. return res += width;
  100. }
  101. /// Add and assign a position.
  102. inline position&
  103. operator-= (position& res, const int width)
  104. {
  105. return res += -width;
  106. }
  107. /// Add two position objects.
  108. inline const position
  109. operator- (const position& begin, const int width)
  110. {
  111. return begin + -width;
  112. }
  113. /// Compare two position objects.
  114. inline bool
  115. operator== (const position& pos1, const position& pos2)
  116. {
  117. return (pos1.line == pos2.line
  118. && pos1.column == pos2.column
  119. && (pos1.filename == pos2.filename
  120. || (pos1.filename && pos2.filename
  121. && *pos1.filename == *pos2.filename)));
  122. }
  123. /// Compare two position objects.
  124. inline bool
  125. operator!= (const position& pos1, const position& pos2)
  126. {
  127. return !(pos1 == pos2);
  128. }
  129. /** \brief Intercept output stream redirection.
  130. ** \param ostr the destination output stream
  131. ** \param pos a reference to the position to redirect
  132. */
  133. template <typename YYChar>
  134. inline std::basic_ostream<YYChar>&
  135. operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
  136. {
  137. if (pos.filename)
  138. ostr << *pos.filename << ':';
  139. return ostr << pos.line << '.' << pos.column;
  140. }
  141. } // lol
  142. /* Line 148 of location.cc */
  143. #line 172 "generated/position.hh"
  144. #endif /* !YY_LOL_GENERATED_POSITION_HH_INCLUDED */