]>
Commit | Line | Data |
---|---|---|
1eee94d3 GM |
1 | (* M2Error.def error reporting interface. |
2 | ||
a945c346 | 3 | Copyright (C) 2001-2024 Free Software Foundation, Inc. |
1eee94d3 GM |
4 | Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
5 | ||
6 | This file is part of GNU Modula-2. | |
7 | ||
8 | GNU Modula-2 is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU Modula-2 is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU Modula-2; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. *) | |
21 | ||
22 | DEFINITION MODULE M2Error ; | |
23 | ||
24 | (* | |
25 | Title : M2Error | |
26 | Author : Gaius Mulley | |
27 | System : UNIX (gm2) | |
28 | Description: provides an interface between the string handling modules | |
29 | and the compiler. | |
30 | *) | |
31 | ||
32 | FROM SYSTEM IMPORT BYTE ; | |
33 | FROM DynamicStrings IMPORT String ; | |
34 | FROM NameKey IMPORT Name ; | |
35 | ||
36 | EXPORT QUALIFIED Error, ErrorScope, | |
37 | InternalError, | |
38 | WriteFormat0, WriteFormat1, WriteFormat2, WriteFormat3, | |
39 | NewError, ErrorFormat0, ErrorFormat1, ErrorFormat2, ErrorFormat3, | |
40 | ErrorString, | |
41 | NewWarning, NewNote, SetColor, | |
42 | FlushErrors, FlushWarnings, ChainError, | |
43 | ErrorStringAt, ErrorStringAt2, ErrorStringsAt2, | |
44 | WarnStringAt, WarnStringAt2, WarnStringsAt2, | |
45 | ErrorAbort0, | |
46 | WarnFormat0, WarnFormat1, MoveError, | |
47 | AnnounceScope, EnterImplementationScope, | |
48 | EnterModuleScope, EnterDefinitionScope, EnterProgramScope, | |
49 | EnterProcedureScope, DepthScope, GetAnnounceScope, | |
50 | DefaultProgramModule, DefaultImplementationModule, | |
51 | DefaultDefinitionModule, DefaultInnerModule, DefaultProcedure, | |
52 | EnterErrorScope, GetCurrentErrorScope, ResetErrorScope, | |
53 | LeaveErrorScope ; | |
54 | ||
55 | ||
56 | TYPE | |
57 | Error ; | |
58 | ErrorScope ; | |
59 | ||
60 | ||
61 | (* | |
62 | InternalError - displays an internal error message together with the compiler source | |
63 | file and line number. | |
64 | This function is not buffered and is used when the compiler is about | |
65 | to give up. | |
66 | *) | |
67 | ||
68 | PROCEDURE InternalError (message: ARRAY OF CHAR) <* noreturn *> ; | |
69 | ||
70 | ||
71 | ||
72 | (* *************************************************************************** | |
73 | The following routines are used for normal syntax and semantic error reporting | |
74 | *************************************************************************** *) | |
75 | ||
76 | ||
77 | (* | |
78 | WriteFormat0 - displays the source module and line together | |
79 | with the encapsulated format string. | |
80 | Used for simple error messages tied to the current token. | |
81 | *) | |
82 | ||
83 | PROCEDURE WriteFormat0 (a: ARRAY OF CHAR) ; | |
84 | ||
85 | ||
86 | (* | |
87 | WriteFormat1 - displays the source module and line together | |
88 | with the encapsulated format string. | |
89 | Used for simple error messages tied to the current token. | |
90 | *) | |
91 | ||
92 | PROCEDURE WriteFormat1 (a: ARRAY OF CHAR; w: ARRAY OF BYTE) ; | |
93 | ||
94 | ||
95 | (* | |
96 | WriteFormat2 - displays the module and line together with the encapsulated | |
97 | format strings. | |
98 | Used for simple error messages tied to the current token. | |
99 | *) | |
100 | ||
101 | PROCEDURE WriteFormat2 (a: ARRAY OF CHAR; w1, w2: ARRAY OF BYTE) ; | |
102 | ||
103 | ||
104 | (* | |
105 | WriteFormat3 - displays the module and line together with the encapsulated | |
106 | format strings. | |
107 | Used for simple error messages tied to the current token. | |
108 | *) | |
109 | ||
110 | PROCEDURE WriteFormat3 (a: ARRAY OF CHAR; w1, w2, w3: ARRAY OF BYTE) ; | |
111 | ||
112 | ||
113 | (* | |
114 | NewError - creates and returns a new error handle. | |
115 | *) | |
116 | ||
117 | PROCEDURE NewError (AtTokenNo: CARDINAL) : Error ; | |
118 | ||
119 | ||
120 | (* | |
121 | NewWarning - creates and returns a new error handle suitable for a warning. | |
122 | A warning will not stop compilation. | |
123 | *) | |
124 | ||
125 | PROCEDURE NewWarning (AtTokenNo: CARDINAL) : Error ; | |
126 | ||
127 | ||
128 | (* | |
129 | NewNote - creates and returns a new error handle suitable for a note. | |
130 | A note will not stop compilation. | |
131 | *) | |
132 | ||
133 | PROCEDURE NewNote (AtTokenNo: CARDINAL) : Error ; | |
134 | ||
135 | ||
136 | (* | |
137 | ChainError - creates and returns a new error handle, this new error | |
138 | is associated with, e, and is chained onto the end of, e. | |
139 | *) | |
140 | ||
141 | PROCEDURE ChainError (AtTokenNo: CARDINAL; e: Error) : Error ; | |
142 | ||
143 | ||
144 | (* | |
145 | MoveError - repositions an error, e, to token, AtTokenNo, and returns, e. | |
146 | *) | |
147 | ||
148 | PROCEDURE MoveError (e: Error; AtTokenNo: CARDINAL) : Error ; | |
149 | ||
150 | ||
151 | (* | |
152 | SetColor - informs the error module that this error will have had colors | |
153 | assigned to it. If an error is issued without colors assigned | |
154 | then the default colors will be assigned to the legacy error | |
155 | messages. | |
156 | *) | |
157 | ||
158 | PROCEDURE SetColor (e: Error) : Error ; | |
159 | ||
160 | ||
161 | (* | |
162 | ErrorFormat routines provide a printf capability for the error handle. | |
163 | *) | |
164 | ||
165 | PROCEDURE ErrorFormat0 (e: Error; a: ARRAY OF CHAR) ; | |
166 | PROCEDURE ErrorFormat1 (e: Error; a: ARRAY OF CHAR; w: ARRAY OF BYTE) ; | |
167 | PROCEDURE ErrorFormat2 (e: Error; a: ARRAY OF CHAR; w1, w2: ARRAY OF BYTE) ; | |
168 | PROCEDURE ErrorFormat3 (e: Error; a: ARRAY OF CHAR; w1, w2, w3: ARRAY OF BYTE) ; | |
169 | PROCEDURE ErrorString (e: Error; str: String) ; | |
170 | ||
171 | ||
172 | (* *************************************************************************** | |
173 | The following routines are useful for positioning and warnings and errors | |
174 | at tokens. The strings are emitted later, so the caller must not destroy | |
175 | the strings. | |
176 | *************************************************************************** *) | |
177 | ||
178 | PROCEDURE ErrorStringAt (s: String; tok: CARDINAL) ; | |
179 | PROCEDURE ErrorStringAt2 (s: String; tok1, tok2: CARDINAL) ; | |
180 | PROCEDURE ErrorStringsAt2 (s1, s2: String; tok1, tok2: CARDINAL) ; | |
181 | PROCEDURE WarnStringAt (s: String; tok: CARDINAL) ; | |
182 | PROCEDURE WarnStringAt2 (s: String; tok1, tok2: CARDINAL) ; | |
183 | PROCEDURE WarnStringsAt2 (s1, s2: String; tok1, tok2: CARDINAL) ; | |
184 | ||
185 | ||
186 | (* | |
187 | WarnFormat0 - displays the source module and line together | |
188 | with the encapsulated format string. | |
189 | Used for simple warning messages tied to the current token. | |
190 | *) | |
191 | ||
192 | PROCEDURE WarnFormat0 (a: ARRAY OF CHAR) ; | |
193 | ||
194 | ||
195 | (* | |
196 | WarnFormat1 - displays the source module and line together | |
197 | with the encapsulated format string. | |
198 | Used for simple warning messages tied to the current token. | |
199 | *) | |
200 | ||
201 | PROCEDURE WarnFormat1 (a: ARRAY OF CHAR; w: ARRAY OF BYTE) ; | |
202 | ||
203 | ||
204 | (* | |
205 | FlushErrors - switches the output channel to the error channel | |
206 | and then writes out all errors. | |
207 | If an error is present the compilation is terminated. | |
208 | All warnings are ignored. | |
209 | *) | |
210 | ||
211 | PROCEDURE FlushErrors ; | |
212 | ||
213 | ||
214 | (* | |
215 | FlushWarnings - switches the output channel to the error channel | |
216 | and then writes out all warnings. | |
217 | If an error is present the compilation is terminated, | |
218 | if warnings only were emitted then compilation will | |
219 | continue. | |
220 | *) | |
221 | ||
222 | PROCEDURE FlushWarnings ; | |
223 | ||
224 | ||
225 | (* | |
226 | ErrorAbort0 - aborts compiling, it flushes all warnings and errors before aborting. | |
227 | *) | |
228 | ||
1bd13193 | 229 | PROCEDURE ErrorAbort0 (a: ARRAY OF CHAR) <* noreturn *> ; |
1eee94d3 GM |
230 | |
231 | ||
232 | (* | |
233 | AnnounceScope - return the error string message with a scope description prepended | |
234 | assuming that scope has changed. | |
235 | *) | |
236 | ||
237 | PROCEDURE AnnounceScope (e: Error; message: String) : String ; | |
238 | ||
239 | ||
240 | (* | |
241 | EnterImplementationScope - signifies to the error routines that the front end | |
242 | has started to compile implementation module scopeName. | |
243 | *) | |
244 | ||
245 | PROCEDURE EnterImplementationScope (scopename: Name) ; | |
246 | ||
247 | ||
248 | (* | |
249 | EnterProgramScope - signifies to the error routines that the front end | |
250 | has started to compile program module scopeName. | |
251 | *) | |
252 | ||
253 | PROCEDURE EnterProgramScope (scopename: Name) ; | |
254 | ||
255 | ||
256 | (* | |
257 | EnterModuleScope - signifies to the error routines that the front end | |
258 | has started to compile an inner module scopeName. | |
259 | *) | |
260 | ||
261 | PROCEDURE EnterModuleScope (scopename: Name) ; | |
262 | ||
263 | ||
264 | (* | |
265 | EnterDefinitionScope - signifies to the error routines that the front end | |
266 | has started to compile definition module scopeName. | |
267 | *) | |
268 | ||
269 | PROCEDURE EnterDefinitionScope (scopename: Name) ; | |
270 | ||
271 | ||
272 | (* | |
273 | EnterProcedureScope - signifies to the error routines that the front end | |
274 | has started to compile definition module scopeName. | |
275 | *) | |
276 | ||
277 | PROCEDURE EnterProcedureScope (scopename: Name) ; | |
278 | ||
279 | ||
280 | (* | |
281 | DepthScope - returns the depth of the scope stack. | |
282 | *) | |
283 | ||
284 | PROCEDURE DepthScope () : CARDINAL ; | |
285 | ||
286 | ||
287 | (* | |
288 | GetAnnounceScope - return message with the error scope attached to message. | |
289 | filename and message are treated as read only by this | |
290 | procedure function. | |
291 | *) | |
292 | ||
293 | PROCEDURE GetAnnounceScope (filename, message: String) : String ; | |
294 | ||
295 | ||
296 | (* | |
297 | DefaultProgramModule - sets up an unnamed program scope before the Ident is seen. | |
298 | *) | |
299 | ||
300 | PROCEDURE DefaultProgramModule ; | |
301 | ||
302 | ||
303 | (* | |
304 | DefaultImplementationModule - sets up an unnamed implementation | |
305 | scope before the Ident is seen. | |
306 | *) | |
307 | ||
308 | PROCEDURE DefaultImplementationModule ; | |
309 | ||
310 | ||
311 | (* | |
312 | DefaultDefinitionModule - sets up an unnamed definition | |
313 | scope before the Ident is seen. | |
314 | *) | |
315 | ||
316 | PROCEDURE DefaultDefinitionModule ; | |
317 | ||
318 | ||
319 | (* | |
320 | DefaultInnerModule - sets up an unnamed inner | |
321 | scope before the Ident is seen. | |
322 | *) | |
323 | ||
324 | PROCEDURE DefaultInnerModule ; | |
325 | ||
326 | ||
327 | (* | |
328 | DefaultProcedure - sets up an unnamed procedure | |
329 | scope before the Ident is seen. | |
330 | *) | |
331 | ||
332 | PROCEDURE DefaultProcedure ; | |
333 | ||
334 | ||
335 | (* | |
336 | EnterErrorScope - pushes the currentScope and sets currentScope to scope. | |
337 | *) | |
338 | ||
339 | PROCEDURE EnterErrorScope (scope: ErrorScope) ; | |
340 | ||
341 | ||
342 | (* | |
343 | LeaveErrorScope - leave the current scope and pop into the previous one. | |
344 | *) | |
345 | ||
346 | PROCEDURE LeaveErrorScope ; | |
347 | ||
348 | ||
349 | (* | |
350 | GetCurrentErrorScope - returns currentScope. | |
351 | *) | |
352 | ||
353 | PROCEDURE GetCurrentErrorScope () : ErrorScope ; | |
354 | ||
355 | ||
356 | (* | |
357 | ResetErrorScope - should be called at the start of each pass to | |
358 | reset the error scope index. | |
359 | *) | |
360 | ||
361 | PROCEDURE ResetErrorScope ; | |
362 | ||
363 | ||
364 | END M2Error. |