You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

162 regels
4.1 KiB

  1. /* A Bison parser, made by GNU Bison 2.4.2. */
  2. /* Positions for Bison parsers in C++
  3. Copyright (C) 2002-2007, 2009-2010 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 lol::position class.
  28. */
  29. #ifndef BISON_POSITION_HH
  30. # define BISON_POSITION_HH
  31. # include <iostream>
  32. # include <string>
  33. # include <algorithm>
  34. namespace lol {
  35. /* Line 37 of location.cc */
  36. #line 50 "generated/position.hh"
  37. /// Abstract a position.
  38. class position
  39. {
  40. public:
  41. /// Construct a position.
  42. position ()
  43. : filename (0), line (1), column (1)
  44. {
  45. }
  46. /// Initialization.
  47. inline void initialize (std::string* fn)
  48. {
  49. filename = fn;
  50. line = 1;
  51. column = 1;
  52. }
  53. /** \name Line and Column related manipulators
  54. ** \{ */
  55. public:
  56. /// (line related) Advance to the COUNT next lines.
  57. inline void lines (int count = 1)
  58. {
  59. column = 1;
  60. line += count;
  61. }
  62. /// (column related) Advance to the COUNT next columns.
  63. inline void columns (int count = 1)
  64. {
  65. column = std::max (1u, column + count);
  66. }
  67. /** \} */
  68. public:
  69. /// File name to which this position refers.
  70. std::string* filename;
  71. /// Current line number.
  72. unsigned int line;
  73. /// Current column number.
  74. unsigned int column;
  75. };
  76. /// Add and assign a position.
  77. inline const position&
  78. operator+= (position& res, const int width)
  79. {
  80. res.columns (width);
  81. return res;
  82. }
  83. /// Add two position objects.
  84. inline const position
  85. operator+ (const position& begin, const int width)
  86. {
  87. position res = begin;
  88. return res += width;
  89. }
  90. /// Add and assign a position.
  91. inline const position&
  92. operator-= (position& res, const int width)
  93. {
  94. return res += -width;
  95. }
  96. /// Add two position objects.
  97. inline const position
  98. operator- (const position& begin, const int width)
  99. {
  100. return begin + -width;
  101. }
  102. /// Compare two position objects.
  103. inline bool
  104. operator== (const position& pos1, const position& pos2)
  105. {
  106. return (pos1.line == pos2.line
  107. && pos1.column == pos2.column
  108. && (pos1.filename == pos2.filename
  109. || (pos1.filename && pos2.filename
  110. && *pos1.filename == *pos2.filename)));
  111. }
  112. /// Compare two position objects.
  113. inline bool
  114. operator!= (const position& pos1, const position& pos2)
  115. {
  116. return !(pos1 == pos2);
  117. }
  118. /** \brief Intercept output stream redirection.
  119. ** \param ostr the destination output stream
  120. ** \param pos a reference to the position to redirect
  121. */
  122. inline std::ostream&
  123. operator<< (std::ostream& ostr, const position& pos)
  124. {
  125. if (pos.filename)
  126. ostr << *pos.filename << ':';
  127. return ostr << pos.line << '.' << pos.column;
  128. }
  129. } // lol
  130. /* Line 144 of location.cc */
  131. #line 161 "generated/position.hh"
  132. #endif // not BISON_POSITION_HH