PageRenderTime 36ms CodeModel.GetById 31ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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--
 15expanded class LIBERTY_ERRORS
 16
 17insert
 18   LIBERTY_ERROR_LEVELS
 19
 20feature {ANY} -- Threshold
 21   set_error_threshold (a_threshold: like threshold) is
 22      require
 23         valid_level(a_threshold)
 24      do
 25         threshold_memory.set_item(a_threshold)
 26      ensure
 27         threshold = a_threshold
 28      end
 29
 30   threshold: INTEGER_8 is
 31      do
 32         Result := threshold_memory.item
 33      end
 34
 35feature {ANY} -- Emit stream
 36   set_stream (a_stream: like stream) is
 37      require
 38         a_stream.is_connected
 39      do
 40         stream_memory.set_item(a_stream)
 41      ensure
 42         stream = a_stream
 43      end
 44
 45   stream: OUTPUT_STREAM is
 46      do
 47         Result := stream_memory.item
 48      end
 49
 50feature {ANY} -- Errors
 51   last_error: LIBERTY_ERROR is
 52      do
 53         Result := last_error_memory.item
 54      end
 55
 56   has_error: BOOLEAN is
 57      do
 58         if last_error /= Void then
 59            Result := last_error.is_error
 60         end
 61      end
 62
 63   has_warning_or_error: BOOLEAN is
 64      do
 65         Result := last_error /= Void
 66      end
 67
 68   set (level: INTEGER_8; message: STRING) is
 69      require
 70         valid_level(level)
 71      local
 72         err: LIBERTY_ERROR
 73      do
 74         err := last_error
 75         create err.make(level, positions.twin, message, err)
 76         last_error_memory.set_item(err)
 77         if level < level_error then
 78            emit
 79         elseif level = level_error then
 80            breakpoint
 81         end
 82         cancel_positions
 83      ensure
 84         dead_if_fatal: level >= level_error
 85      end
 86
 87   emit is
 88      require
 89         has_warning_or_error
 90         stream.is_connected
 91      do
 92         last_error.emit(stream, threshold)
 93         last_error_memory.set_item(Void)
 94      ensure
 95         not has_warning_or_error
 96         dead_if_fatal: not old (last_error.is_fatal)
 97      end
 98
 99   emit_syntax_error (error: PARSE_ERROR; code: STRING; file: FIXED_STRING) is
100         -- utility method that adds all the syntax errors and emit as a fatal error
101      require
102         stream.is_connected
103      local
104         e: PARSE_ERROR
105      do
106         from
107            e := error
108         until
109            e = Void
110         loop
111            add_position(syntax_position(e.index, code, file))
112            set(level_error, e.message)
113            e := e.next
114         end
115         emit
116      end
117
118feature {ANY} -- Positions
119   has_positions: BOOLEAN is
120      do
121         Result := not positions.is_empty
122      end
123
124   syntax_position (a_index: INTEGER; a_source: STRING; a_file: FIXED_STRING): LIBERTY_SYNTAX_POSITION is
125      require
126         a_index.in_range(a_source.lower, a_source.upper)
127      do
128         create Result.make(a_index, a_source, a_file)
129      ensure
130         Result /= Void
131      end
132
133   semantics_position (a_index: INTEGER; a_ast: LIBERTY_AST_NON_TERMINAL_NODE; a_file: FIXED_STRING): LIBERTY_SEMANTICS_POSITION is
134      require
135         a_index > 0
136         a_ast /= Void
137         a_file /= Void
138      do
139         create Result.make(a_index, a_ast, a_file)
140      ensure
141         Result /= Void
142      end
143
144   unknown_position: LIBERTY_UNKNOWN_POSITION is
145      once
146         create Result.make
147      end
148
149   add_position (a_position: LIBERTY_POSITION) is
150      require
151         a_position /= Void
152      do
153         positions.add_last(a_position)
154      ensure
155         has_positions
156      end
157
158   cancel_positions is
159      do
160         positions.clear_count
161      ensure
162         not has_positions
163      end
164
165feature {}
166   last_error_memory: REFERENCE[LIBERTY_ERROR] is
167      once
168         create Result
169      end
170
171   positions: COLLECTION[LIBERTY_POSITION] is
172      once
173         create {FAST_ARRAY[LIBERTY_POSITION]} Result.with_capacity(4)
174      end
175
176   threshold_memory: REFERENCE[INTEGER_8] is
177      once
178         create Result.set_item(level_error)
179      end
180
181   stream_memory: REFERENCE[OUTPUT_STREAM] is
182      once
183         create Result.set_item(std_output)
184      end
185
186end