Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

location.hh 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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