/src/tools/liberty_errors.e

http://github.com/tybor/Liberty · Specman e · 186 lines · 149 code · 22 blank · 15 comment · 2 complexity · 382c9bcc2af3018f0ba92b1b652a9088 MD5 · raw file

  1. -- This file is part of Liberty Eiffel.
  2. --
  3. -- Liberty Eiffel is free software: you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation, version 3 of the License.
  6. --
  7. -- Liberty Eiffel is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. -- GNU General Public License for more details.
  11. --
  12. -- You should have received a copy of the GNU General Public License
  13. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  14. --
  15. expanded class LIBERTY_ERRORS
  16. insert
  17. LIBERTY_ERROR_LEVELS
  18. feature {ANY} -- Threshold
  19. set_error_threshold (a_threshold: like threshold) is
  20. require
  21. valid_level(a_threshold)
  22. do
  23. threshold_memory.set_item(a_threshold)
  24. ensure
  25. threshold = a_threshold
  26. end
  27. threshold: INTEGER_8 is
  28. do
  29. Result := threshold_memory.item
  30. end
  31. feature {ANY} -- Emit stream
  32. set_stream (a_stream: like stream) is
  33. require
  34. a_stream.is_connected
  35. do
  36. stream_memory.set_item(a_stream)
  37. ensure
  38. stream = a_stream
  39. end
  40. stream: OUTPUT_STREAM is
  41. do
  42. Result := stream_memory.item
  43. end
  44. feature {ANY} -- Errors
  45. last_error: LIBERTY_ERROR is
  46. do
  47. Result := last_error_memory.item
  48. end
  49. has_error: BOOLEAN is
  50. do
  51. if last_error /= Void then
  52. Result := last_error.is_error
  53. end
  54. end
  55. has_warning_or_error: BOOLEAN is
  56. do
  57. Result := last_error /= Void
  58. end
  59. set (level: INTEGER_8; message: STRING) is
  60. require
  61. valid_level(level)
  62. local
  63. err: LIBERTY_ERROR
  64. do
  65. err := last_error
  66. create err.make(level, positions.twin, message, err)
  67. last_error_memory.set_item(err)
  68. if level < level_error then
  69. emit
  70. elseif level = level_error then
  71. breakpoint
  72. end
  73. cancel_positions
  74. ensure
  75. dead_if_fatal: level >= level_error
  76. end
  77. emit is
  78. require
  79. has_warning_or_error
  80. stream.is_connected
  81. do
  82. last_error.emit(stream, threshold)
  83. last_error_memory.set_item(Void)
  84. ensure
  85. not has_warning_or_error
  86. dead_if_fatal: not old (last_error.is_fatal)
  87. end
  88. emit_syntax_error (error: PARSE_ERROR; code: STRING; file: FIXED_STRING) is
  89. -- utility method that adds all the syntax errors and emit as a fatal error
  90. require
  91. stream.is_connected
  92. local
  93. e: PARSE_ERROR
  94. do
  95. from
  96. e := error
  97. until
  98. e = Void
  99. loop
  100. add_position(syntax_position(e.index, code, file))
  101. set(level_error, e.message)
  102. e := e.next
  103. end
  104. emit
  105. end
  106. feature {ANY} -- Positions
  107. has_positions: BOOLEAN is
  108. do
  109. Result := not positions.is_empty
  110. end
  111. syntax_position (a_index: INTEGER; a_source: STRING; a_file: FIXED_STRING): LIBERTY_SYNTAX_POSITION is
  112. require
  113. a_index.in_range(a_source.lower, a_source.upper)
  114. do
  115. create Result.make(a_index, a_source, a_file)
  116. ensure
  117. Result /= Void
  118. end
  119. semantics_position (a_index: INTEGER; a_ast: LIBERTY_AST_NON_TERMINAL_NODE; a_file: FIXED_STRING): LIBERTY_SEMANTICS_POSITION is
  120. require
  121. a_index > 0
  122. a_ast /= Void
  123. a_file /= Void
  124. do
  125. create Result.make(a_index, a_ast, a_file)
  126. ensure
  127. Result /= Void
  128. end
  129. unknown_position: LIBERTY_UNKNOWN_POSITION is
  130. once
  131. create Result.make
  132. end
  133. add_position (a_position: LIBERTY_POSITION) is
  134. require
  135. a_position /= Void
  136. do
  137. positions.add_last(a_position)
  138. ensure
  139. has_positions
  140. end
  141. cancel_positions is
  142. do
  143. positions.clear_count
  144. ensure
  145. not has_positions
  146. end
  147. feature {}
  148. last_error_memory: REFERENCE[LIBERTY_ERROR] is
  149. once
  150. create Result
  151. end
  152. positions: COLLECTION[LIBERTY_POSITION] is
  153. once
  154. create {FAST_ARRAY[LIBERTY_POSITION]} Result.with_capacity(4)
  155. end
  156. threshold_memory: REFERENCE[INTEGER_8] is
  157. once
  158. create Result.set_item(level_error)
  159. end
  160. stream_memory: REFERENCE[OUTPUT_STREAM] is
  161. once
  162. create Result.set_item(std_output)
  163. end
  164. end