| 1 |
(* mcMetaError.def provides a set of high level error routines. |
| 2 |
|
| 3 |
Copyright (C) 2015-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 mcMetaError ; |
| 23 |
|
| 24 |
(* Provides a set of high level error routines. These |
| 25 |
routines utilise M2Error and provides the programmer |
| 26 |
with an easier method to obtain useful symbol table |
| 27 |
information. *) |
| 28 |
|
| 29 |
FROM SYSTEM IMPORT BYTE ; |
| 30 |
FROM DynamicStrings IMPORT String ; |
| 31 |
|
| 32 |
|
| 33 |
(* |
| 34 |
All the procedures below expect the n, n1, n2, n3, n4 to be nodes |
| 35 |
or Name or Cardinal. |
| 36 |
and m, m1, m2, m3 are error messages and format specifiers. |
| 37 |
The format specifiers are: |
| 38 |
|
| 39 |
{%1a} symbol name for the first symbol. |
| 40 |
{%1q} qualified name for the first symbol. |
| 41 |
{%1t} type name for the first symbol. |
| 42 |
{%1ts} skips type pseudonyms. |
| 43 |
{%1d} symbol description |
| 44 |
{%1td} type symbol description. |
| 45 |
{%1k} operand is a Name not a symbol. |
| 46 |
{%1N} operand is a CARDINAL, generate english description of |
| 47 |
the number (count), ie 1st, 2nd, 3rd, 4th, 19th. |
| 48 |
{%1n} operand is a CARDINAL, convert to a number. |
| 49 |
|
| 50 |
{%1D} sets the error message to where symbol 1 was declared. |
| 51 |
The declaration will choose the definition module, then |
| 52 |
implementation (or program) module. |
| 53 |
{%1M} sets the error message to where symbol 1 was declared. |
| 54 |
The declaration will choose the implementation or program |
| 55 |
module and if these do not exist then it falls back to |
| 56 |
the definition module. |
| 57 |
{%1U} sets the error message to where symbol 1 was first used. |
| 58 |
{%E} error (default) |
| 59 |
{%W} message is a warning, not an error. |
| 60 |
%% % |
| 61 |
%{ { |
| 62 |
%} } |
| 63 |
|
| 64 |
the error messages may also embed optional strings such as: |
| 65 |
|
| 66 |
{%1a:this string is emitted if the symbol name is non null} |
| 67 |
{!%1a:this string is emitted if the symbol name is null} |
| 68 |
{!%1a:{%1d}} |
| 69 |
if the symbol name does not exist then print a description |
| 70 |
of the symbol. |
| 71 |
{%1atd} was incompatible with the return type of the procedure |
| 72 |
means print the symbol name (if null then print the type name |
| 73 |
if null then print out the description) followed by the |
| 74 |
string "was incompatible with the return type of the procedure" |
| 75 |
|
| 76 |
Note all replaced names or descriptions are enclosed in quotes, like: |
| 77 |
'foo', which matches the behaviour of gcc. Also note temporary names |
| 78 |
are treated as null. Finally the order of format specifiers does |
| 79 |
matter, {%1td} means get type name and use it if non null, otherwise |
| 80 |
describe the symbol. |
| 81 |
*) |
| 82 |
|
| 83 |
(* |
| 84 |
ebnf := { percent | lbra | any } =: |
| 85 |
|
| 86 |
percent := '%' anych =: |
| 87 |
|
| 88 |
lbra := '{' [ '!' ] percenttoken '}' =: |
| 89 |
|
| 90 |
percenttoken := '%' ( '1' op | '2' op | '3' op | '4' op ) =: |
| 91 |
|
| 92 |
op := {'a'|'q'|'t'|'d'|'k'|'n'|'s'|'D'|'U'|'E'|'W'} then =: |
| 93 |
|
| 94 |
then := [ ':' ebnf ] =: |
| 95 |
*) |
| 96 |
|
| 97 |
PROCEDURE metaError1 (m: ARRAY OF CHAR; s: ARRAY OF BYTE) ; |
| 98 |
PROCEDURE metaError2 (m: ARRAY OF CHAR; s1, s2: ARRAY OF BYTE) ; |
| 99 |
PROCEDURE metaError3 (m: ARRAY OF CHAR; s1, s2, s3: ARRAY OF BYTE) ; |
| 100 |
PROCEDURE metaError4 (m: ARRAY OF CHAR; s1, s2, s3, s4: ARRAY OF BYTE) ; |
| 101 |
|
| 102 |
PROCEDURE metaErrors1 (m1, m2: ARRAY OF CHAR; s: ARRAY OF BYTE) ; |
| 103 |
PROCEDURE metaErrors2 (m1, m2: ARRAY OF CHAR; s1, s2: ARRAY OF BYTE) ; |
| 104 |
PROCEDURE metaErrors3 (m1, m2: ARRAY OF CHAR; s1, s2, s3: ARRAY OF BYTE) ; |
| 105 |
PROCEDURE metaErrors4 (m1, m2: ARRAY OF CHAR; s1, s2, s3, s4: ARRAY OF BYTE) ; |
| 106 |
|
| 107 |
PROCEDURE metaErrorT1 (tok: CARDINAL; m: ARRAY OF CHAR; s: ARRAY OF BYTE) ; |
| 108 |
PROCEDURE metaErrorT2 (tok: CARDINAL; m: ARRAY OF CHAR; s1, s2: ARRAY OF BYTE) ; |
| 109 |
PROCEDURE metaErrorT3 (tok: CARDINAL; m: ARRAY OF CHAR; s1, s2, s3: ARRAY OF BYTE) ; |
| 110 |
PROCEDURE metaErrorT4 (tok: CARDINAL; m: ARRAY OF CHAR; s1, s2, s3, s4: ARRAY OF BYTE) ; |
| 111 |
|
| 112 |
PROCEDURE metaErrorsT1 (tok: CARDINAL; m1, m2: ARRAY OF CHAR; s: ARRAY OF BYTE) ; |
| 113 |
PROCEDURE metaErrorsT2 (tok: CARDINAL; m1, m2: ARRAY OF CHAR; s1, s2: ARRAY OF BYTE) ; |
| 114 |
PROCEDURE metaErrorsT3 (tok: CARDINAL; m1, m2: ARRAY OF CHAR; s1, s2, s3: ARRAY OF BYTE) ; |
| 115 |
PROCEDURE metaErrorsT4 (tok: CARDINAL; m1, m2: ARRAY OF CHAR; s1, s2, s3, s4: ARRAY OF BYTE) ; |
| 116 |
|
| 117 |
PROCEDURE metaErrorString1 (m: String; s: ARRAY OF BYTE) ; |
| 118 |
PROCEDURE metaErrorString2 (m: String; s1, s2: ARRAY OF BYTE) ; |
| 119 |
PROCEDURE metaErrorString3 (m: String; s1, s2, s3: ARRAY OF BYTE) ; |
| 120 |
PROCEDURE metaErrorString4 (m: String; s1, s2, s3, s4: ARRAY OF BYTE) ; |
| 121 |
|
| 122 |
PROCEDURE metaErrorStringT1 (tok: CARDINAL; m: String; s: ARRAY OF BYTE) ; |
| 123 |
PROCEDURE metaErrorStringT2 (tok: CARDINAL; m: String; s1, s2: ARRAY OF BYTE) ; |
| 124 |
PROCEDURE metaErrorStringT3 (tok: CARDINAL; m: String; s1, s2, s3: ARRAY OF BYTE) ; |
| 125 |
PROCEDURE metaErrorStringT4 (tok: CARDINAL; m: String; s1, s2, s3, s4: ARRAY OF BYTE) ; |
| 126 |
|
| 127 |
|
| 128 |
END mcMetaError. |