]> gcc.gnu.org Git - gcc.git/blob - gcc/m2/mc-boot/GmcError.c
Remove unused parameter warning via introducing attribute unused.
[gcc.git] / gcc / m2 / mc-boot / GmcError.c
1 /* do not edit automatically generated by mc from mcError. */
2 /* mcError.mod provides an interface between the string handling modules.
3
4 Copyright (C) 2015-2022 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6
7 This file is part of GNU Modula-2.
8
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU Modula-2; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 #include "config.h"
24 #include "system.h"
25 # if !defined (PROC_D)
26 # define PROC_D
27 typedef void (*PROC_t) (void);
28 typedef struct { PROC_t proc; } PROC;
29 # endif
30
31 # if !defined (TRUE)
32 # define TRUE (1==1)
33 # endif
34
35 # if !defined (FALSE)
36 # define FALSE (1==0)
37 # endif
38
39 # include "GStorage.h"
40 #if defined(__cplusplus)
41 # undef NULL
42 # define NULL 0
43 #endif
44 #define _mcError_H
45 #define _mcError_C
46
47 # include "GASCII.h"
48 # include "GDynamicStrings.h"
49 # include "GFIO.h"
50 # include "GStrLib.h"
51 # include "GFormatStrings.h"
52 # include "GStorage.h"
53 # include "GM2RTS.h"
54 # include "GSYSTEM.h"
55 # include "GStdIO.h"
56 # include "GnameKey.h"
57 # include "GmcLexBuf.h"
58 # include "GmcPrintf.h"
59
60 # define Debugging TRUE
61 # define DebugTrace FALSE
62 # define Xcode TRUE
63 typedef struct _T2_r _T2;
64
65 typedef _T2 *mcError_error;
66
67 struct _T2_r {
68 mcError_error parent;
69 mcError_error child;
70 mcError_error next;
71 unsigned int fatal;
72 DynamicStrings_String s;
73 unsigned int token;
74 };
75
76 static mcError_error head;
77 static unsigned int inInternal;
78
79 /*
80 internalError - displays an internal error message together with the compiler source
81 file and line number.
82 This function is not buffered and is used when the compiler is about
83 to give up.
84 */
85
86 extern "C" void mcError_internalError (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line);
87
88 /*
89 writeFormat0 - displays the source module and line together
90 with the encapsulated format string.
91 Used for simple error messages tied to the current token.
92 */
93
94 extern "C" void mcError_writeFormat0 (const char *a_, unsigned int _a_high);
95
96 /*
97 writeFormat1 - displays the source module and line together
98 with the encapsulated format string.
99 Used for simple error messages tied to the current token.
100 */
101
102 extern "C" void mcError_writeFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
103
104 /*
105 writeFormat2 - 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 extern "C" void mcError_writeFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
111
112 /*
113 writeFormat3 - displays the module and line together with the encapsulated
114 format strings.
115 Used for simple error messages tied to the current token.
116 */
117
118 extern "C" void mcError_writeFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high);
119
120 /*
121 newError - creates and returns a new error handle.
122 */
123
124 extern "C" mcError_error mcError_newError (unsigned int atTokenNo);
125
126 /*
127 newWarning - creates and returns a new error handle suitable for a warning.
128 A warning will not stop compilation.
129 */
130
131 extern "C" mcError_error mcError_newWarning (unsigned int atTokenNo);
132
133 /*
134 chainError - creates and returns a new error handle, this new error
135 is associated with, e, and is chained onto the end of, e.
136 If, e, is NIL then the result to NewError is returned.
137 */
138
139 extern "C" mcError_error mcError_chainError (unsigned int atTokenNo, mcError_error e);
140 extern "C" void mcError_errorFormat0 (mcError_error e, const char *a_, unsigned int _a_high);
141 extern "C" void mcError_errorFormat1 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
142 extern "C" void mcError_errorFormat2 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
143 extern "C" void mcError_errorFormat3 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high);
144 extern "C" void mcError_errorString (mcError_error e, DynamicStrings_String str);
145
146 /*
147 errorStringAt - given an error string, s, it places this
148 string at token position, tok.
149 The string is consumed.
150 */
151
152 extern "C" void mcError_errorStringAt (DynamicStrings_String s, unsigned int tok);
153
154 /*
155 errorStringAt2 - given an error string, s, it places this
156 string at token positions, tok1 and tok2, respectively.
157 The string is consumed.
158 */
159
160 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2);
161
162 /*
163 errorStringsAt2 - given error strings, s1, and, s2, it places these
164 strings at token positions, tok1 and tok2, respectively.
165 Both strings are consumed.
166 */
167
168 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2);
169
170 /*
171 warnStringAt - given an error string, s, it places this
172 string at token position, tok.
173 The string is consumed.
174 */
175
176 extern "C" void mcError_warnStringAt (DynamicStrings_String s, unsigned int tok);
177
178 /*
179 warnStringAt2 - given an warning string, s, it places this
180 string at token positions, tok1 and tok2, respectively.
181 The string is consumed.
182 */
183
184 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2);
185
186 /*
187 warnStringsAt2 - given warning strings, s1, and, s2, it places these
188 strings at token positions, tok1 and tok2, respectively.
189 Both strings are consumed.
190 */
191
192 extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2);
193 extern "C" void mcError_warnFormat0 (const char *a_, unsigned int _a_high);
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 extern "C" void mcError_warnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
202
203 /*
204 flushErrors - switches the output channel to the error channel
205 and then writes out all errors.
206 */
207
208 extern "C" void mcError_flushErrors (void);
209
210 /*
211 flushWarnings - switches the output channel to the error channel
212 and then writes out all warnings.
213 If an error is present the compilation is terminated,
214 if warnings only were emitted then compilation will
215 continue.
216 */
217
218 extern "C" void mcError_flushWarnings (void);
219
220 /*
221 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
222 */
223
224 extern "C" void mcError_errorAbort0 (const char *a_, unsigned int _a_high);
225
226 /*
227 cast - casts a := b
228 */
229
230 static void cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high);
231 static unsigned int translateNameToCharStar (char *a, unsigned int _a_high, unsigned int n);
232
233 /*
234 outString - writes the contents of String to stdout.
235 The string, s, is destroyed.
236 */
237
238 static void outString (DynamicStrings_String file, unsigned int line, unsigned int col, DynamicStrings_String s);
239 static DynamicStrings_String doFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
240
241 /*
242 doFormat2 -
243 */
244
245 static DynamicStrings_String doFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
246
247 /*
248 writeFormat2 - displays the module and line together with the encapsulated
249 format strings.
250 Used for simple error messages tied to the current token.
251 */
252
253 static DynamicStrings_String doFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high);
254
255 /*
256 init - initializes the error list.
257 */
258
259 static void init (void);
260
261 /*
262 checkIncludes - generates a sequence of error messages which determine the relevant
263 included file and line number.
264 For example:
265
266 gcc a.c
267 In file included from b.h:1,
268 from a.c:1:
269 c.h:1: parse error before `and'
270
271 where a.c is: #include "b.h"
272 b.h is: #include "c.h"
273 c.h is: and this and that
274
275 we attempt to follow the error messages that gcc issues.
276 */
277
278 static void checkIncludes (unsigned int token, unsigned int depth);
279
280 /*
281 flushAll - flushes all errors in list, e.
282 */
283
284 static unsigned int flushAll (mcError_error e, unsigned int FatalStatus);
285
286
287 /*
288 cast - casts a := b
289 */
290
291 static void cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high)
292 {
293 unsigned int i;
294 unsigned char b[_b_high+1];
295
296 /* make a local copy of each unbounded array. */
297 memcpy (b, b_, _b_high+1);
298
299 if (_a_high == _b_high)
300 {
301 for (i=0; i<=_a_high; i++)
302 {
303 a[i] = b[i];
304 }
305 }
306 }
307
308 static unsigned int translateNameToCharStar (char *a, unsigned int _a_high, unsigned int n)
309 {
310 unsigned int argno;
311 unsigned int i;
312 unsigned int h;
313
314 /*
315 translateNameToString - takes a format specification string, a, and
316 if they consist of of %a then this is translated
317 into a String and %a is replaced by %s.
318 */
319 argno = 1;
320 i = 0;
321 h = StrLib_StrLen ((const char *) a, _a_high);
322 while (i < h)
323 {
324 if ((a[i] == '%') && ((i+1) < h))
325 {
326 if ((a[i+1] == 'a') && (argno == n))
327 {
328 a[i+1] = 's';
329 return TRUE;
330 }
331 argno += 1;
332 if (argno > n)
333 {
334 /* all done */
335 return FALSE;
336 }
337 }
338 i += 1;
339 }
340 return FALSE;
341 /* static analysis guarentees a RETURN statement will be used before here. */
342 __builtin_unreachable ();
343 }
344
345
346 /*
347 outString - writes the contents of String to stdout.
348 The string, s, is destroyed.
349 */
350
351 static void outString (DynamicStrings_String file, unsigned int line, unsigned int col, DynamicStrings_String s)
352 {
353 typedef char *_T1;
354
355 DynamicStrings_String leader;
356 _T1 p;
357 _T1 q;
358 unsigned int space;
359 unsigned int newline;
360
361 col += 1;
362 if (Xcode)
363 {
364 leader = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%s:%d:", 6)), (const unsigned char *) &file, (sizeof (file)-1), (const unsigned char *) &line, (sizeof (line)-1));
365 }
366 else
367 {
368 leader = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%s:%d:%d:", 9)), (const unsigned char *) &file, (sizeof (file)-1), (const unsigned char *) &line, (sizeof (line)-1), (const unsigned char *) &col, (sizeof (col)-1));
369 }
370 p = static_cast<_T1> (DynamicStrings_string (s));
371 newline = TRUE;
372 space = FALSE;
373 while ((p != NULL) && ((*p) != ASCII_nul))
374 {
375 if (newline)
376 {
377 q = static_cast<_T1> (DynamicStrings_string (leader));
378 while ((q != NULL) && ((*q) != ASCII_nul))
379 {
380 StdIO_Write ((*q));
381 q += 1;
382 }
383 }
384 newline = (*p) == ASCII_nl;
385 space = (*p) == ' ';
386 if (newline && Xcode)
387 {
388 mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col, (sizeof (col)-1));
389 }
390 StdIO_Write ((*p));
391 p += 1;
392 }
393 if (! newline)
394 {
395 if (Xcode)
396 {
397 if (! space)
398 {
399 StdIO_Write (' ');
400 }
401 mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col, (sizeof (col)-1));
402 }
403 StdIO_Write (ASCII_nl);
404 }
405 FIO_FlushBuffer (FIO_StdOut);
406 if (! Debugging)
407 {
408 s = DynamicStrings_KillString (s);
409 leader = DynamicStrings_KillString (leader);
410 }
411 }
412
413 static DynamicStrings_String doFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
414 {
415 DynamicStrings_String s;
416 nameKey_Name n;
417 char a[_a_high+1];
418 unsigned char w[_w_high+1];
419
420 /* make a local copy of each unbounded array. */
421 memcpy (a, a_, _a_high+1);
422 memcpy (w, w_, _w_high+1);
423
424 /*
425 DoFormat1 -
426 */
427 if (translateNameToCharStar ((char *) a, _a_high, 1))
428 {
429 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w, _w_high);
430 s = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
431 s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s, (sizeof (s)-1));
432 }
433 else
434 {
435 s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w, _w_high);
436 }
437 return s;
438 /* static analysis guarentees a RETURN statement will be used before here. */
439 __builtin_unreachable ();
440 }
441
442
443 /*
444 doFormat2 -
445 */
446
447 static DynamicStrings_String doFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high)
448 {
449 nameKey_Name n;
450 DynamicStrings_String s;
451 DynamicStrings_String s1;
452 DynamicStrings_String s2;
453 unsigned int b;
454 char a[_a_high+1];
455 unsigned char w1[_w1_high+1];
456 unsigned char w2[_w2_high+1];
457
458 /* make a local copy of each unbounded array. */
459 memcpy (a, a_, _a_high+1);
460 memcpy (w1, w1_, _w1_high+1);
461 memcpy (w2, w2_, _w2_high+1);
462
463 b = (unsigned int) 0;
464 if (translateNameToCharStar ((char *) a, _a_high, 1))
465 {
466 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high);
467 s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
468 b |= (1 << (1 ));
469 }
470 if (translateNameToCharStar ((char *) a, _a_high, 2))
471 {
472 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high);
473 s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
474 b |= (1 << (2 ));
475 }
476 switch (b)
477 {
478 case (unsigned int) 0:
479 s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
480 break;
481
482 case (unsigned int) ((1 << (1))):
483 s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) w2, _w2_high);
484 break;
485
486 case (unsigned int) ((1 << (2))):
487 s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) &s2, (sizeof (s2)-1));
488 break;
489
490 case (unsigned int) ((1 << (1)) | (1 << (2))):
491 s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1));
492 break;
493
494
495 default:
496 M2RTS_HALT (-1);
497 __builtin_unreachable ();
498 break;
499 }
500 return s;
501 /* static analysis guarentees a RETURN statement will be used before here. */
502 __builtin_unreachable ();
503 }
504
505
506 /*
507 writeFormat2 - displays the module and line together with the encapsulated
508 format strings.
509 Used for simple error messages tied to the current token.
510 */
511
512 static DynamicStrings_String doFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high)
513 {
514 nameKey_Name n;
515 DynamicStrings_String s;
516 DynamicStrings_String s1;
517 DynamicStrings_String s2;
518 DynamicStrings_String s3;
519 unsigned int b;
520 char a[_a_high+1];
521 unsigned char w1[_w1_high+1];
522 unsigned char w2[_w2_high+1];
523 unsigned char w3[_w3_high+1];
524
525 /* make a local copy of each unbounded array. */
526 memcpy (a, a_, _a_high+1);
527 memcpy (w1, w1_, _w1_high+1);
528 memcpy (w2, w2_, _w2_high+1);
529 memcpy (w3, w3_, _w3_high+1);
530
531 b = (unsigned int) 0;
532 if (translateNameToCharStar ((char *) a, _a_high, 1))
533 {
534 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high);
535 s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
536 b |= (1 << (1 ));
537 }
538 if (translateNameToCharStar ((char *) a, _a_high, 2))
539 {
540 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high);
541 s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
542 b |= (1 << (2 ));
543 }
544 if (translateNameToCharStar ((char *) a, _a_high, 3))
545 {
546 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w3, _w3_high);
547 s3 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
548 b |= (1 << (3 ));
549 }
550 switch (b)
551 {
552 case (unsigned int) 0:
553 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high);
554 break;
555
556 case (unsigned int) ((1 << (1))):
557 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high);
558 break;
559
560 case (unsigned int) ((1 << (2))):
561 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) w3, _w3_high);
562 break;
563
564 case (unsigned int) ((1 << (1)) | (1 << (2))):
565 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) w3, _w3_high);
566 break;
567
568 case (unsigned int) ((1 << (3))):
569 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) &s3, (sizeof (s3)-1));
570 break;
571
572 case (unsigned int) ((1 << (1)) | (1 << (3))):
573 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) w2, _w2_high, (const unsigned char *) &s3, (sizeof (s3)-1));
574 break;
575
576 case (unsigned int) ((1 << (2)) | (1 << (3))):
577 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) &s3, (sizeof (s3)-1));
578 break;
579
580 case (unsigned int) ((1 << (1)) | (1 << (2)) | (1 << (3))):
581 s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) &s3, (sizeof (s3)-1));
582 break;
583
584
585 default:
586 M2RTS_HALT (-1);
587 __builtin_unreachable ();
588 break;
589 }
590 return s;
591 /* static analysis guarentees a RETURN statement will be used before here. */
592 __builtin_unreachable ();
593 }
594
595
596 /*
597 init - initializes the error list.
598 */
599
600 static void init (void)
601 {
602 head = NULL;
603 inInternal = FALSE;
604 }
605
606
607 /*
608 checkIncludes - generates a sequence of error messages which determine the relevant
609 included file and line number.
610 For example:
611
612 gcc a.c
613 In file included from b.h:1,
614 from a.c:1:
615 c.h:1: parse error before `and'
616
617 where a.c is: #include "b.h"
618 b.h is: #include "c.h"
619 c.h is: and this and that
620
621 we attempt to follow the error messages that gcc issues.
622 */
623
624 static void checkIncludes (unsigned int token, unsigned int depth)
625 {
626 DynamicStrings_String included;
627 unsigned int lineno;
628
629 included = mcLexBuf_findFileNameFromToken (token, depth+1);
630 if (included != NULL)
631 {
632 lineno = mcLexBuf_tokenToLineNo (token, depth+1);
633 if (depth == 0)
634 {
635 mcPrintf_printf2 ((const char *) "In file included from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1));
636 }
637 else
638 {
639 mcPrintf_printf2 ((const char *) " from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1));
640 }
641 if ((mcLexBuf_findFileNameFromToken (token, depth+2)) == NULL)
642 {
643 mcPrintf_printf0 ((const char *) ":\\n", 3);
644 }
645 else
646 {
647 mcPrintf_printf0 ((const char *) ",\\n", 3);
648 }
649 checkIncludes (token, depth+1);
650 }
651 }
652
653
654 /*
655 flushAll - flushes all errors in list, e.
656 */
657
658 static unsigned int flushAll (mcError_error e, unsigned int FatalStatus)
659 {
660 mcError_error f;
661 unsigned int written;
662
663 written = FALSE;
664 if (e != NULL)
665 {
666 do {
667 if ((FatalStatus == e->fatal) && (e->s != NULL))
668 {
669 checkIncludes (e->token, 0);
670 if (e->fatal)
671 {
672 e->s = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " error: ", 8), DynamicStrings_Mark (e->s));
673 }
674 else
675 {
676 e->s = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " warning: ", 10), DynamicStrings_Mark (e->s));
677 }
678 outString (mcLexBuf_findFileNameFromToken (e->token, 0), mcLexBuf_tokenToLineNo (e->token, 0), mcLexBuf_tokenToColumnNo (e->token, 0), e->s);
679 if ((e->child != NULL) && (flushAll (e->child, FatalStatus)))
680 {} /* empty. */
681 e->s = static_cast<DynamicStrings_String> (NULL);
682 written = TRUE;
683 }
684 f = e;
685 e = e->next;
686 if (! Debugging)
687 {
688 f->s = DynamicStrings_KillString (f->s);
689 Storage_DEALLOCATE ((void **) &f, sizeof (_T2));
690 }
691 } while (! (e == NULL));
692 }
693 return written;
694 /* static analysis guarentees a RETURN statement will be used before here. */
695 __builtin_unreachable ();
696 }
697
698
699 /*
700 internalError - displays an internal error message together with the compiler source
701 file and line number.
702 This function is not buffered and is used when the compiler is about
703 to give up.
704 */
705
706 extern "C" void mcError_internalError (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line)
707 {
708 char a[_a_high+1];
709 char file[_file_high+1];
710
711 /* make a local copy of each unbounded array. */
712 memcpy (a, a_, _a_high+1);
713 memcpy (file, file_, _file_high+1);
714
715 M2RTS_ExitOnHalt (1);
716 if (! inInternal)
717 {
718 inInternal = TRUE;
719 mcError_flushErrors ();
720 outString (mcLexBuf_findFileNameFromToken (mcLexBuf_getTokenNo (), 0), mcLexBuf_tokenToLineNo (mcLexBuf_getTokenNo (), 0), mcLexBuf_tokenToColumnNo (mcLexBuf_getTokenNo (), 0), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "*** fatal error ***", 19)));
721 }
722 outString (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) file, _file_high)), line, 0, DynamicStrings_ConCat (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "*** internal error *** ", 23)), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high))));
723 M2RTS_HALT (-1);
724 __builtin_unreachable ();
725 }
726
727
728 /*
729 writeFormat0 - displays the source module and line together
730 with the encapsulated format string.
731 Used for simple error messages tied to the current token.
732 */
733
734 extern "C" void mcError_writeFormat0 (const char *a_, unsigned int _a_high)
735 {
736 mcError_error e;
737 char a[_a_high+1];
738
739 /* make a local copy of each unbounded array. */
740 memcpy (a, a_, _a_high+1);
741
742 e = mcError_newError (mcLexBuf_getTokenNo ());
743 e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
744 }
745
746
747 /*
748 writeFormat1 - displays the source module and line together
749 with the encapsulated format string.
750 Used for simple error messages tied to the current token.
751 */
752
753 extern "C" void mcError_writeFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
754 {
755 mcError_error e;
756 char a[_a_high+1];
757 unsigned char w[_w_high+1];
758
759 /* make a local copy of each unbounded array. */
760 memcpy (a, a_, _a_high+1);
761 memcpy (w, w_, _w_high+1);
762
763 e = mcError_newError (mcLexBuf_getTokenNo ());
764 e->s = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
765 }
766
767
768 /*
769 writeFormat2 - displays the module and line together with the encapsulated
770 format strings.
771 Used for simple error messages tied to the current token.
772 */
773
774 extern "C" void mcError_writeFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high)
775 {
776 mcError_error e;
777 char a[_a_high+1];
778 unsigned char w1[_w1_high+1];
779 unsigned char w2[_w2_high+1];
780
781 /* make a local copy of each unbounded array. */
782 memcpy (a, a_, _a_high+1);
783 memcpy (w1, w1_, _w1_high+1);
784 memcpy (w2, w2_, _w2_high+1);
785
786 e = mcError_newError (mcLexBuf_getTokenNo ());
787 e->s = doFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
788 }
789
790
791 /*
792 writeFormat3 - displays the module and line together with the encapsulated
793 format strings.
794 Used for simple error messages tied to the current token.
795 */
796
797 extern "C" void mcError_writeFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high)
798 {
799 mcError_error e;
800 char a[_a_high+1];
801 unsigned char w1[_w1_high+1];
802 unsigned char w2[_w2_high+1];
803 unsigned char w3[_w3_high+1];
804
805 /* make a local copy of each unbounded array. */
806 memcpy (a, a_, _a_high+1);
807 memcpy (w1, w1_, _w1_high+1);
808 memcpy (w2, w2_, _w2_high+1);
809 memcpy (w3, w3_, _w3_high+1);
810
811 e = mcError_newError (mcLexBuf_getTokenNo ());
812 e->s = doFormat3 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high);
813 }
814
815
816 /*
817 newError - creates and returns a new error handle.
818 */
819
820 extern "C" mcError_error mcError_newError (unsigned int atTokenNo)
821 {
822 mcError_error e;
823 mcError_error f;
824
825 Storage_ALLOCATE ((void **) &e, sizeof (_T2));
826 e->s = static_cast<DynamicStrings_String> (NULL);
827 e->token = atTokenNo;
828 e->next = NULL;
829 e->parent = NULL;
830 e->child = NULL;
831 e->fatal = TRUE;
832 if ((head == NULL) || (head->token > atTokenNo))
833 {
834 e->next = head;
835 head = e;
836 }
837 else
838 {
839 f = head;
840 while ((f->next != NULL) && (f->next->token < atTokenNo))
841 {
842 f = f->next;
843 }
844 e->next = f->next;
845 f->next = e;
846 }
847 return e;
848 /* static analysis guarentees a RETURN statement will be used before here. */
849 __builtin_unreachable ();
850 }
851
852
853 /*
854 newWarning - creates and returns a new error handle suitable for a warning.
855 A warning will not stop compilation.
856 */
857
858 extern "C" mcError_error mcError_newWarning (unsigned int atTokenNo)
859 {
860 mcError_error e;
861
862 e = mcError_newError (atTokenNo);
863 e->fatal = FALSE;
864 return e;
865 /* static analysis guarentees a RETURN statement will be used before here. */
866 __builtin_unreachable ();
867 }
868
869
870 /*
871 chainError - creates and returns a new error handle, this new error
872 is associated with, e, and is chained onto the end of, e.
873 If, e, is NIL then the result to NewError is returned.
874 */
875
876 extern "C" mcError_error mcError_chainError (unsigned int atTokenNo, mcError_error e)
877 {
878 mcError_error f;
879
880 if (e == NULL)
881 {
882 return mcError_newError (atTokenNo);
883 }
884 else
885 {
886 Storage_ALLOCATE ((void **) &f, sizeof (_T2));
887 f->s = static_cast<DynamicStrings_String> (NULL);
888 f->token = atTokenNo;
889 f->next = e->child;
890 f->parent = e;
891 f->child = NULL;
892 f->fatal = e->fatal;
893 e->child = f;
894 }
895 return f;
896 /* static analysis guarentees a RETURN statement will be used before here. */
897 __builtin_unreachable ();
898 }
899
900 extern "C" void mcError_errorFormat0 (mcError_error e, const char *a_, unsigned int _a_high)
901 {
902 char a[_a_high+1];
903
904 /* make a local copy of each unbounded array. */
905 memcpy (a, a_, _a_high+1);
906
907 /*
908 errorFormat routines provide a printf capability for the error handle.
909 */
910 if (e->s == NULL)
911 {
912 e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
913 }
914 else
915 {
916 e->s = DynamicStrings_ConCat (e->s, DynamicStrings_Mark (FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)))));
917 }
918 }
919
920 extern "C" void mcError_errorFormat1 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
921 {
922 DynamicStrings_String s1;
923 char a[_a_high+1];
924 unsigned char w[_w_high+1];
925
926 /* make a local copy of each unbounded array. */
927 memcpy (a, a_, _a_high+1);
928 memcpy (w, w_, _w_high+1);
929
930 s1 = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
931 if (e->s == NULL)
932 {
933 e->s = s1;
934 }
935 else
936 {
937 e->s = DynamicStrings_ConCat (e->s, DynamicStrings_Mark (s1));
938 }
939 }
940
941 extern "C" void mcError_errorFormat2 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high)
942 {
943 DynamicStrings_String s1;
944 char a[_a_high+1];
945 unsigned char w1[_w1_high+1];
946 unsigned char w2[_w2_high+1];
947
948 /* make a local copy of each unbounded array. */
949 memcpy (a, a_, _a_high+1);
950 memcpy (w1, w1_, _w1_high+1);
951 memcpy (w2, w2_, _w2_high+1);
952
953 s1 = doFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
954 if (e->s == NULL)
955 {
956 e->s = s1;
957 }
958 else
959 {
960 e->s = DynamicStrings_ConCat (e->s, DynamicStrings_Mark (s1));
961 }
962 }
963
964 extern "C" void mcError_errorFormat3 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high)
965 {
966 DynamicStrings_String s1;
967 char a[_a_high+1];
968 unsigned char w1[_w1_high+1];
969 unsigned char w2[_w2_high+1];
970 unsigned char w3[_w3_high+1];
971
972 /* make a local copy of each unbounded array. */
973 memcpy (a, a_, _a_high+1);
974 memcpy (w1, w1_, _w1_high+1);
975 memcpy (w2, w2_, _w2_high+1);
976 memcpy (w3, w3_, _w3_high+1);
977
978 s1 = doFormat3 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high);
979 if (e->s == NULL)
980 {
981 e->s = s1;
982 }
983 else
984 {
985 e->s = DynamicStrings_ConCat (e->s, DynamicStrings_Mark (s1));
986 }
987 }
988
989 extern "C" void mcError_errorString (mcError_error e, DynamicStrings_String str)
990 {
991 e->s = str;
992 }
993
994
995 /*
996 errorStringAt - given an error string, s, it places this
997 string at token position, tok.
998 The string is consumed.
999 */
1000
1001 extern "C" void mcError_errorStringAt (DynamicStrings_String s, unsigned int tok)
1002 {
1003 mcError_error e;
1004
1005 e = mcError_newError (tok);
1006 mcError_errorString (e, s);
1007 }
1008
1009
1010 /*
1011 errorStringAt2 - given an error string, s, it places this
1012 string at token positions, tok1 and tok2, respectively.
1013 The string is consumed.
1014 */
1015
1016 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2)
1017 {
1018 mcError_errorStringsAt2 (s, s, tok1, tok2);
1019 }
1020
1021
1022 /*
1023 errorStringsAt2 - given error strings, s1, and, s2, it places these
1024 strings at token positions, tok1 and tok2, respectively.
1025 Both strings are consumed.
1026 */
1027
1028 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2)
1029 {
1030 mcError_error e;
1031
1032 if (s1 == s2)
1033 {
1034 s2 = DynamicStrings_Dup (s1);
1035 }
1036 e = mcError_newError (tok1);
1037 mcError_errorString (e, s1);
1038 mcError_errorString (mcError_chainError (tok2, e), s2);
1039 }
1040
1041
1042 /*
1043 warnStringAt - given an error string, s, it places this
1044 string at token position, tok.
1045 The string is consumed.
1046 */
1047
1048 extern "C" void mcError_warnStringAt (DynamicStrings_String s, unsigned int tok)
1049 {
1050 mcError_error e;
1051
1052 e = mcError_newWarning (tok);
1053 mcError_errorString (e, s);
1054 }
1055
1056
1057 /*
1058 warnStringAt2 - given an warning string, s, it places this
1059 string at token positions, tok1 and tok2, respectively.
1060 The string is consumed.
1061 */
1062
1063 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2)
1064 {
1065 mcError_warnStringsAt2 (s, s, tok1, tok2);
1066 }
1067
1068
1069 /*
1070 warnStringsAt2 - given warning strings, s1, and, s2, it places these
1071 strings at token positions, tok1 and tok2, respectively.
1072 Both strings are consumed.
1073 */
1074
1075 extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2)
1076 {
1077 mcError_error e;
1078
1079 if (s1 == s2)
1080 {
1081 s2 = DynamicStrings_Dup (s1);
1082 }
1083 e = mcError_newWarning (tok1);
1084 mcError_errorString (e, s1);
1085 mcError_errorString (mcError_chainError (tok2, e), s2);
1086 }
1087
1088 extern "C" void mcError_warnFormat0 (const char *a_, unsigned int _a_high)
1089 {
1090 mcError_error e;
1091 char a[_a_high+1];
1092
1093 /* make a local copy of each unbounded array. */
1094 memcpy (a, a_, _a_high+1);
1095
1096 /*
1097 WarnFormat0 - displays the source module and line together
1098 with the encapsulated format string.
1099 Used for simple warning messages tied to the current token.
1100 */
1101 e = mcError_newWarning (mcLexBuf_getTokenNo ());
1102 e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
1103 }
1104
1105
1106 /*
1107 warnFormat1 - displays the source module and line together
1108 with the encapsulated format string.
1109 Used for simple warning messages tied to the current token.
1110 */
1111
1112 extern "C" void mcError_warnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
1113 {
1114 mcError_error e;
1115 char a[_a_high+1];
1116 unsigned char w[_w_high+1];
1117
1118 /* make a local copy of each unbounded array. */
1119 memcpy (a, a_, _a_high+1);
1120 memcpy (w, w_, _w_high+1);
1121
1122 e = mcError_newWarning (mcLexBuf_getTokenNo ());
1123 e->s = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
1124 }
1125
1126
1127 /*
1128 flushErrors - switches the output channel to the error channel
1129 and then writes out all errors.
1130 */
1131
1132 extern "C" void mcError_flushErrors (void)
1133 {
1134 if (DebugTrace)
1135 {
1136 mcPrintf_printf0 ((const char *) "\\nFlushing all errors\\n", 23);
1137 mcPrintf_printf0 ((const char *) "===================\\n", 21);
1138 }
1139 if (flushAll (head, TRUE))
1140 {
1141 M2RTS_ExitOnHalt (1);
1142 M2RTS_HALT (-1);
1143 __builtin_unreachable ();
1144 }
1145 }
1146
1147
1148 /*
1149 flushWarnings - switches the output channel to the error channel
1150 and then writes out all warnings.
1151 If an error is present the compilation is terminated,
1152 if warnings only were emitted then compilation will
1153 continue.
1154 */
1155
1156 extern "C" void mcError_flushWarnings (void)
1157 {
1158 if (flushAll (head, FALSE))
1159 {} /* empty. */
1160 }
1161
1162
1163 /*
1164 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
1165 */
1166
1167 extern "C" void mcError_errorAbort0 (const char *a_, unsigned int _a_high)
1168 {
1169 char a[_a_high+1];
1170
1171 /* make a local copy of each unbounded array. */
1172 memcpy (a, a_, _a_high+1);
1173
1174 mcError_flushWarnings ();
1175 if (! (StrLib_StrEqual ((const char *) a, _a_high, (const char *) "", 0)))
1176 {
1177 mcError_writeFormat0 ((const char *) a, _a_high);
1178 }
1179 if (! (flushAll (head, TRUE)))
1180 {
1181 mcError_writeFormat0 ((const char *) "unidentified error", 18);
1182 if (flushAll (head, TRUE))
1183 {} /* empty. */
1184 }
1185 M2RTS_ExitOnHalt (1);
1186 M2RTS_HALT (-1);
1187 __builtin_unreachable ();
1188 }
1189
1190 extern "C" void _M2_mcError_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
1191 {
1192 init ();
1193 }
1194
1195 extern "C" void _M2_mcError_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
1196 {
1197 }
This page took 0.091034 seconds and 5 git commands to generate.