選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

165 行
4.2 KiB

  1. /* A Bison parser, made by GNU Bison 2.4.2. */
  2. /* Locations 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 location.hh
  27. ** Define the lol::location class.
  28. */
  29. #ifndef BISON_LOCATION_HH
  30. # define BISON_LOCATION_HH
  31. # include <iostream>
  32. # include <string>
  33. # include "position.hh"
  34. namespace lol {
  35. /* Line 162 of location.cc */
  36. #line 50 "generated/location.hh"
  37. /// Abstract a location.
  38. class location
  39. {
  40. public:
  41. /// Construct a location.
  42. location ()
  43. : begin (), end ()
  44. {
  45. }
  46. /// Initialization.
  47. inline void initialize (std::string* fn)
  48. {
  49. begin.initialize (fn);
  50. end = begin;
  51. }
  52. /** \name Line and Column related manipulators
  53. ** \{ */
  54. public:
  55. /// Reset initial location to final location.
  56. inline void step ()
  57. {
  58. begin = end;
  59. }
  60. /// Extend the current location to the COUNT next columns.
  61. inline void columns (unsigned int count = 1)
  62. {
  63. end += count;
  64. }
  65. /// Extend the current location to the COUNT next lines.
  66. inline void lines (unsigned int count = 1)
  67. {
  68. end.lines (count);
  69. }
  70. /** \} */
  71. public:
  72. /// Beginning of the located region.
  73. position begin;
  74. /// End of the located region.
  75. position end;
  76. };
  77. /// Join two location objects to create a location.
  78. inline const location operator+ (const location& begin, const location& end)
  79. {
  80. location res = begin;
  81. res.end = end.end;
  82. return res;
  83. }
  84. /// Add two location objects.
  85. inline const location operator+ (const location& begin, unsigned int width)
  86. {
  87. location res = begin;
  88. res.columns (width);
  89. return res;
  90. }
  91. /// Add and assign a location.
  92. inline location& operator+= (location& res, unsigned int width)
  93. {
  94. res.columns (width);
  95. return res;
  96. }
  97. /// Compare two location objects.
  98. inline bool
  99. operator== (const location& loc1, const location& loc2)
  100. {
  101. return loc1.begin == loc2.begin && loc1.end == loc2.end;
  102. }
  103. /// Compare two location objects.
  104. inline bool
  105. operator!= (const location& loc1, const location& loc2)
  106. {
  107. return !(loc1 == loc2);
  108. }
  109. /** \brief Intercept output stream redirection.
  110. ** \param ostr the destination output stream
  111. ** \param loc a reference to the location to redirect
  112. **
  113. ** Avoid duplicate information.
  114. */
  115. inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
  116. {
  117. position last = loc.end - 1;
  118. ostr << loc.begin;
  119. if (last.filename
  120. && (!loc.begin.filename
  121. || *loc.begin.filename != *last.filename))
  122. ostr << '-' << last;
  123. else if (loc.begin.line != last.line)
  124. ostr << '-' << last.line << '.' << last.column;
  125. else if (loc.begin.column != last.column)
  126. ostr << '-' << last.column;
  127. return ostr;
  128. }
  129. } // lol
  130. /* Line 271 of location.cc */
  131. #line 163 "generated/location.hh"
  132. #endif // not BISON_LOCATION_HH