/src/tools/errors/liberty_error.e

http://github.com/tybor/Liberty · Specman e · 117 lines · 90 code · 11 blank · 16 comment · 5 complexity · b4f5ba0068b2925c72ec652dc16354c3 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. class LIBERTY_ERROR
  16. insert
  17. EIFFEL_NODE_HANDLER
  18. LIBERTY_ERROR_LEVELS
  19. create {LIBERTY_ERRORS}
  20. make
  21. feature {LIBERTY_ERROR, LIBERTY_ERRORS}
  22. positions: TRAVERSABLE[LIBERTY_POSITION]
  23. message: STRING
  24. previous: LIBERTY_ERROR
  25. level: INTEGER_8
  26. is_fatal: BOOLEAN is
  27. do
  28. if level < level_error then
  29. Result := True
  30. elseif previous /= Void then
  31. Result := previous.is_fatal
  32. end
  33. end
  34. is_error: BOOLEAN is
  35. do
  36. if level <= level_error then
  37. Result := True
  38. elseif previous /= Void then
  39. Result := previous.is_error
  40. end
  41. end
  42. feature {LIBERTY_ERRORS}
  43. emit (stream: OUTPUT_STREAM; threshold: like level) is
  44. -- May not return.
  45. require
  46. stream.is_connected
  47. filter_only_warnings: threshold >= errors.level_error
  48. do
  49. do_emit(stream, threshold)
  50. if is_fatal then
  51. breakpoint
  52. die_with_code(1)
  53. end
  54. ensure
  55. is_fatal = old is_fatal
  56. warn_or_die: not is_fatal
  57. end
  58. feature {LIBERTY_ERROR}
  59. do_emit (stream: OUTPUT_STREAM; threshold: like level) is
  60. -- May not return.
  61. require
  62. stream.is_connected
  63. filter_only_warnings: threshold >= errors.level_error
  64. local
  65. i: INTEGER
  66. do
  67. if previous /= Void then
  68. previous.do_emit(stream, threshold)
  69. stream.put_new_line
  70. end
  71. if level <= threshold then
  72. stream.put_string(once "*** ")
  73. stream.put_string(errors.level_tag(level))
  74. stream.put_string(once ": ")
  75. stream.put_line(message)
  76. from
  77. i := positions.lower
  78. until
  79. i > positions.upper
  80. loop
  81. positions.item(i).emit(stream)
  82. i := i + 1
  83. end
  84. end
  85. end
  86. feature {}
  87. make (a_level: like level; a_positions: like positions; a_message: like message; a_previous: like Current) is
  88. require
  89. a_positions /= Void
  90. a_message /= Void
  91. valid_level(a_level)
  92. do
  93. positions := a_positions
  94. message := a_message
  95. previous := a_previous
  96. level := a_level
  97. ensure
  98. positions = a_positions
  99. message = a_message
  100. previous = a_previous
  101. end
  102. errors: LIBERTY_ERRORS
  103. invariant
  104. positions /= Void
  105. message /= Void
  106. end