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