Subversion Repositories Kolibri OS

Rev

Rev 7693 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7693 Rev 7696
1
(*
1
(*
2
    BSD 2-Clause License
2
    BSD 2-Clause License
3
 
3
 
4
    Copyright (c) 2018, 2019, Anton Krotov
4
    Copyright (c) 2018-2019, Anton Krotov
5
    All rights reserved.
5
    All rights reserved.
6
*)
6
*)
7
 
7
 
8
MODULE ERRORS;
8
MODULE ERRORS;
9
 
9
 
10
IMPORT C := CONSOLE, UTILS, mConst := CONSTANTS;
10
IMPORT C := CONSOLE, UTILS, mConst := CONSTANTS;
11
 
11
 
12
 
12
 
13
PROCEDURE HintMsg* (name: ARRAY OF CHAR; line, col, hint: INTEGER);
13
PROCEDURE HintMsg* (name: ARRAY OF CHAR; line, col, hint: INTEGER);
14
BEGIN
14
BEGIN
15
    IF hint = 0 THEN
15
    IF hint = 0 THEN
16
        C.String("  hint ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
16
        C.String("  hint ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
17
        C.String("variable '"); C.String(name); C.StringLn("' never used")
17
        C.String("variable '"); C.String(name); C.StringLn("' never used")
18
    END
18
    END
19
END HintMsg;
19
END HintMsg;
20
 
20
 
21
 
21
 
22
PROCEDURE WarningMsg* (line, col, warning: INTEGER);
22
PROCEDURE WarningMsg* (line, col, warning: INTEGER);
23
BEGIN
23
BEGIN
24
    C.String("  warning ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
24
    C.String("  warning ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
25
    CASE warning OF
25
    CASE warning OF
26
    |0: C.StringLn("passing a string value as a fixed array")
26
    |0: C.StringLn("passing a string value as a fixed array")
27
    |1: C.StringLn("endless FOR loop")
27
    |1: C.StringLn("endless FOR loop")
28
    END
28
    END
29
END WarningMsg;
29
END WarningMsg;
30
 
30
 
31
 
31
 
32
PROCEDURE ErrorMsg* (fname: ARRAY OF CHAR; line, col, errno: INTEGER);
32
PROCEDURE ErrorMsg* (fname: ARRAY OF CHAR; line, col, errno: INTEGER);
33
VAR
33
VAR
34
    str: ARRAY 80 OF CHAR;
34
    str: ARRAY 80 OF CHAR;
35
 
35
 
36
BEGIN
36
BEGIN
37
    C.Ln;
37
    C.Ln;
38
    C.String("  error  ("); C.Int(errno); C.String(") ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
38
    C.String("  error  ("); C.Int(errno); C.String(") ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
39
 
39
 
40
    CASE errno OF
40
    CASE errno OF
41
    |  1: str := "missing 'H' or 'X'"
41
    |  1: str := "missing 'H' or 'X'"
42
    |  2: str := "missing scale"
42
    |  2: str := "missing scale"
43
    |  3: str := "unclosed string"
43
    |  3: str := "unclosed string"
44
    |  4: str := "illegal character"
44
    |  4: str := "illegal character"
45
    |  5: str := "string too long"
45
    |  5: str := "string too long"
46
    |  6: str := "identifier too long"
46
    |  6: str := "identifier too long"
47
    |  7: str := "number too long"
47
    |  7: str := "number too long"
48
    |  8..12: str := "number too large"
48
    |  8..12: str := "number too large"
49
    | 13: str := "real numbers not supported"
49
    | 13: str := "real numbers not supported"
50
 
50
 
51
    | 21: str := "'MODULE' expected"
51
    | 21: str := "'MODULE' expected"
52
    | 22: str := "identifier expected"
52
    | 22: str := "identifier expected"
53
    | 23: str := "module name does not match file name"
53
    | 23: str := "module name does not match file name"
54
    | 24: str := "';' expected"
54
    | 24: str := "';' expected"
55
    | 25: str := "identifier does not match module name"
55
    | 25: str := "identifier does not match module name"
56
    | 26: str := "'.' expected"
56
    | 26: str := "'.' expected"
57
    | 27: str := "'END' expected"
57
    | 27: str := "'END' expected"
58
    | 28: str := "',', ';' or ':=' expected"
58
    | 28: str := "',', ';' or ':=' expected"
59
    | 29: str := "module not found"
59
    | 29: str := "module not found"
60
    | 30: str := "multiply defined identifier"
60
    | 30: str := "multiply defined identifier"
61
    | 31: str := "recursive import"
61
    | 31: str := "recursive import"
62
    | 32: str := "'=' expected"
62
    | 32: str := "'=' expected"
63
    | 33: str := "')' expected"
63
    | 33: str := "')' expected"
64
    | 34: str := "syntax error in expression"
64
    | 34: str := "syntax error in expression"
65
    | 35: str := "'}' expected"
65
    | 35: str := "'}' expected"
66
    | 36: str := "incompatible operand"
66
    | 36: str := "incompatible operand"
67
    | 37: str := "incompatible operands"
67
    | 37: str := "incompatible operands"
68
    | 38: str := "'RETURN' expected"
68
    | 38: str := "'RETURN' expected"
69
    | 39: str := "integer overflow"
69
    | 39: str := "integer overflow"
70
    | 40: str := "floating point overflow"
70
    | 40: str := "floating point overflow"
71
    | 41: str := "not enough floating point registers; simplify expression"
71
    | 41: str := "not enough floating point registers; simplify expression"
72
    | 42: str := "out of range 0..255"
72
    | 42: str := "out of range 0..255"
73
    | 43: str := "expression is not an integer"
73
    | 43: str := "expression is not an integer"
74
    | 44: str := "out of range 0..MAXSET"
74
    | 44: str := "out of range 0..MAXSET"
75
    | 45: str := "division by zero"
75
    | 45: str := "division by zero"
76
    | 46: str := "integer division by zero"
76
    | 46: str := "integer division by zero"
77
    | 47: str := "'OF' or ',' expected"
77
    | 47: str := "'OF' or ',' expected"
78
    | 48: str := "undeclared identifier"
78
    | 48: str := "undeclared identifier"
79
    | 49: str := "type expected"
79
    | 49: str := "type expected"
80
    | 50: str := "recursive type definition"
80
    | 50: str := "recursive type definition"
81
    | 51: str := "illegal value of constant"
81
    | 51: str := "illegal value of constant"
82
    | 52: str := "not a record type"
82
    | 52: str := "not a record type"
83
    | 53: str := "':' expected"
83
    | 53: str := "':' expected"
84
    | 54: str := "need to import SYSTEM"
84
    | 54: str := "need to import SYSTEM"
85
    | 55: str := "pointer type not defined"
85
    | 55: str := "pointer type not defined"
86
    | 56: str := "out of range 0..MAXSET"
86
    | 56: str := "out of range 0..MAXSET"
87
    | 57: str := "'TO' expected"
87
    | 57: str := "'TO' expected"
88
    | 58: str := "not a record type"
88
    | 58: str := "not a record type"
89
    | 59: str := "this expression cannot be a procedure"
89
    | 59: str := "this expression cannot be a procedure"
90
    | 60: str := "identifier does not match procedure name"
90
    | 60: str := "identifier does not match procedure name"
91
    | 61: str := "illegally marked identifier"
91
    | 61: str := "illegally marked identifier"
92
    | 62: str := "expression should be constant"
92
    | 62: str := "expression should be constant"
93
    | 63: str := "not enough RAM"
93
    | 63: str := "not enough RAM"
94
    | 64: str := "'(' expected"
94
    | 64: str := "'(' expected"
95
    | 65: str := "',' expected"
95
    | 65: str := "',' expected"
96
    | 66: str := "incompatible parameter"
96
    | 66: str := "incompatible parameter"
97
    | 67: str := "'OF' expected"
97
    | 67: str := "'OF' expected"
98
    | 68: str := "type expected"
98
    | 68: str := "type expected"
99
    | 69: str := "result type of procedure is not a basic type"
99
    | 69: str := "result type of procedure is not a basic type"
100
    | 70: str := "import not supported"
100
    | 70: str := "import not supported"
101
    | 71: str := "']' expected"
101
    | 71: str := "']' expected"
102
    | 72: str := "expression is not BOOLEAN"
102
    | 72: str := "expression is not BOOLEAN"
103
    | 73: str := "not a record"
103
    | 73: str := "not a record"
104
    | 74: str := "undefined record field"
104
    | 74: str := "undefined record field"
105
    | 75: str := "not an array"
105
    | 75: str := "not an array"
106
    | 76: str := "expression is not an integer"
106
    | 76: str := "expression is not an integer"
107
    | 77: str := "not a pointer"
107
    | 77: str := "not a pointer"
108
    | 78: str := "type guard not allowed"
108
    | 78: str := "type guard not allowed"
109
    | 79: str := "not a type"
109
    | 79: str := "not a type"
110
    | 80: str := "not a record type"
110
    | 80: str := "not a record type"
111
    | 81: str := "not a pointer type"
111
    | 81: str := "not a pointer type"
112
    | 82: str := "type guard not allowed"
112
    | 82: str := "type guard not allowed"
113
    | 83: str := "index out of range"
113
    | 83: str := "index out of range"
114
    | 84: str := "dimension too large"
114
    | 84: str := "dimension too large"
115
    | 85: str := "procedure must have level 0"
115
    | 85: str := "procedure must have level 0"
116
    | 86: str := "not a procedure"
116
    | 86: str := "not a procedure"
117
    | 87: str := "incompatible expression (RETURN)"
117
    | 87: str := "incompatible expression (RETURN)"
118
    | 88: str := "'THEN' expected"
118
    | 88: str := "'THEN' expected"
119
    | 89: str := "'DO' expected"
119
    | 89: str := "'DO' expected"
120
    | 90: str := "'UNTIL' expected"
120
    | 90: str := "'UNTIL' expected"
121
    | 91: str := "incompatible assignment"
121
    | 91: str := "incompatible assignment"
122
    | 92: str := "procedure call of a function"
122
    | 92: str := "procedure call of a function"
123
    | 93: str := "not a variable"
123
    | 93: str := "not a variable"
124
    | 94: str := "read only variable"
124
    | 94: str := "read only variable"
125
    | 95: str := "invalid type of expression (CASE)"
125
    | 95: str := "invalid type of expression (CASE)"
126
    | 96: str := "':=' expected"
126
    | 96: str := "':=' expected"
127
    | 97: str := "not INTEGER variable"
127
    | 97: str := "not INTEGER variable"
128
    | 98: str := "illegal value of constant (0)"
128
    | 98: str := "illegal value of constant (0)"
129
    | 99: str := "incompatible label"
129
    | 99: str := "incompatible label"
130
    |100: str := "multiply defined label"
130
    |100: str := "multiply defined label"
131
    |101: str := "too large parameter of WCHR"
131
    |101: str := "too large parameter of WCHR"
132
    |102: str := "label expected"
132
    |102: str := "label expected"
133
    |103: str := "illegal value of constant"
133
    |103: str := "illegal value of constant"
134
    |104: str := "type too large"
134
    |104: str := "type too large"
135
    |105: str := "access to intermediate variables not allowed"
135
    |105: str := "access to intermediate variables not allowed"
136
    |106: str := "qualified identifier expected"
136
    |106: str := "qualified identifier expected"
137
    |107: str := "too large parameter of CHR"
137
    |107: str := "too large parameter of CHR"
138
    |108: str := "a variable or a procedure expected"
138
    |108: str := "a variable or a procedure expected"
139
    |109: str := "expression should be constant"
139
    |109: str := "expression should be constant"
140
 
140
 
141
    |111: str := "record [noalign] cannot have a base type"
141
    |111: str := "record [noalign] cannot have a base type"
142
    |112: str := "record [noalign] cannot be a base type"
142
    |112: str := "record [noalign] cannot be a base type"
143
    |113: str := "result type of procedure should not be REAL"
143
    |113: str := "result type of procedure should not be REAL"
144
    |114: str := "identifiers 'lib_init' and 'version' are reserved"
144
    |114: str := "identifiers 'lib_init' and 'version' are reserved"
145
    |115: str := "recursive constant definition"
145
    |115: str := "recursive constant definition"
146
    |116: str := "procedure too deep nested"
146
    |116: str := "procedure too deep nested"
147
 
147
 
148
    |120: str := "too many formal parameters"
148
    |120: str := "too many formal parameters"
149
 
149
 
150
    |122: str := "negative divisor"
150
    |122: str := "negative divisor"
151
    |123: str := "illegal flag"
151
    |123: str := "illegal flag"
152
    |124: str := "unknown flag"
152
    |124: str := "unknown flag"
153
    |125: str := "flag not supported"
153
    |125: str := "flag not supported"
154
    END;
154
    END;
155
    C.StringLn(str);
155
    C.StringLn(str);
156
    C.String("  file:  ");  C.StringLn(fname);
156
    C.String("  file:  ");  C.StringLn(fname);
157
    UTILS.Exit(1)
157
    UTILS.Exit(1)
158
END ErrorMsg;
158
END ErrorMsg;
159
 
159
 
160
 
160
 
161
PROCEDURE Error1 (s1: ARRAY OF CHAR);
161
PROCEDURE Error1 (s1: ARRAY OF CHAR);
162
BEGIN
162
BEGIN
163
    C.Ln;
163
    C.Ln;
164
    C.StringLn(s1);
164
    C.StringLn(s1);
165
    UTILS.Exit(1)
165
    UTILS.Exit(1)
166
END Error1;
166
END Error1;
167
 
167
 
168
 
168
 
169
PROCEDURE Error3 (s1, s2, s3: ARRAY OF CHAR);
169
PROCEDURE Error3 (s1, s2, s3: ARRAY OF CHAR);
170
BEGIN
170
BEGIN
171
    C.Ln;
171
    C.Ln;
172
    C.String(s1); C.String(s2); C.StringLn(s3);
172
    C.String(s1); C.String(s2); C.StringLn(s3);
173
    UTILS.Exit(1)
173
    UTILS.Exit(1)
174
END Error3;
174
END Error3;
175
 
175
 
176
 
176
 
177
PROCEDURE Error5 (s1, s2, s3, s4, s5: ARRAY OF CHAR);
177
PROCEDURE Error5 (s1, s2, s3, s4, s5: ARRAY OF CHAR);
178
BEGIN
178
BEGIN
179
    C.Ln;
179
    C.Ln;
180
    C.String(s1); C.String(s2); C.String(s3); C.String(s4); C.StringLn(s5);
180
    C.String(s1); C.String(s2); C.String(s3); C.String(s4); C.StringLn(s5);
181
    UTILS.Exit(1)
181
    UTILS.Exit(1)
182
END Error5;
182
END Error5;
183
 
183
 
184
 
184
 
185
PROCEDURE WrongRTL* (ProcName: ARRAY OF CHAR);
185
PROCEDURE WrongRTL* (ProcName: ARRAY OF CHAR);
186
BEGIN
186
BEGIN
187
    Error5("procedure ", mConst.RTL_NAME, ".", ProcName, " not found")
187
    Error5("procedure ", mConst.RTL_NAME, ".", ProcName, " not found")
188
END WrongRTL;
188
END WrongRTL;
189
 
189
 
190
 
190
 
191
PROCEDURE BadParam* (param: ARRAY OF CHAR);
191
PROCEDURE BadParam* (param: ARRAY OF CHAR);
192
BEGIN
192
BEGIN
193
    Error3("bad parameter: ", param, "")
193
    Error3("bad parameter: ", param, "")
194
END BadParam;
194
END BadParam;
195
 
195
 
196
 
196
 
197
PROCEDURE FileNotFound* (Path, Name, Ext: ARRAY OF CHAR);
197
PROCEDURE FileNotFound* (Path, Name, Ext: ARRAY OF CHAR);
198
BEGIN
198
BEGIN
199
    Error5("file ", Path, Name, Ext, " not found")
199
    Error5("file ", Path, Name, Ext, " not found")
200
END FileNotFound;
200
END FileNotFound;
201
 
201
 
202
 
202
 
203
PROCEDURE Error* (n: INTEGER);
203
PROCEDURE Error* (n: INTEGER);
204
BEGIN
204
BEGIN
205
    CASE n OF
205
    CASE n OF
206
    |201: Error1("writing file error")
206
    |201: Error1("writing file error")
207
    |202: Error1("too many relocations")
207
    |202: Error1("too many relocations")
208
    |203: Error1("size of program is too large")
208
    |203: Error1("size of program is too large")
209
    |204: Error1("size of global variables is too large")
209
    |204: Error1("size of variables is too large")
210
    |205: Error1("not enough parameters")
210
    |205: Error1("not enough parameters")
211
    |206: Error1("bad parameter ")
211
    |206: Error1("bad parameter ")
212
    |207: Error3('inputfile name extension must be "', mConst.FILE_EXT, '"')
212
    |207: Error3('inputfile name extension must be "', mConst.FILE_EXT, '"')
213
    END
213
    END
214
END Error;
214
END Error;
215
 
215
 
216
 
216
 
217
END ERRORS.
217
END ERRORS.