PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

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