Daily bump.
[official-gcc.git] / gcc / m2 / mc-boot / GmcError.cc
bloba3df34e77996825f219c6b121017f3ca2cad0505
1 /* do not edit automatically generated by mc from mcError. */
2 /* mcError.mod provides an interface between the string handling modules.
4 Copyright (C) 2015-2025 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
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.
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.
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/>. */
23 #include "config.h"
24 #include "system.h"
25 #include <stdbool.h>
26 # if !defined (PROC_D)
27 # define PROC_D
28 typedef void (*PROC_t) (void);
29 typedef struct { PROC_t proc; } PROC;
30 # endif
32 # if !defined (TRUE)
33 # define TRUE (1==1)
34 # endif
36 # if !defined (FALSE)
37 # define FALSE (1==0)
38 # endif
40 # include "GStorage.h"
41 #if defined(__cplusplus)
42 # undef NULL
43 # define NULL 0
44 #endif
45 #define _mcError_C
47 #include "GmcError.h"
48 # include "GASCII.h"
49 # include "GDynamicStrings.h"
50 # include "GFIO.h"
51 # include "GStrLib.h"
52 # include "GFormatStrings.h"
53 # include "GStorage.h"
54 # include "GM2RTS.h"
55 # include "GSYSTEM.h"
56 # include "GStdIO.h"
57 # include "GnameKey.h"
58 # include "GmcLexBuf.h"
59 # include "GmcPrintf.h"
61 # define Debugging true
62 # define DebugTrace false
63 # define Xcode true
64 typedef struct mcError__T2_r mcError__T2;
66 typedef mcError__T2 *mcError_error__opaque;
68 struct mcError__T2_r {
69 mcError_error__opaque parent;
70 mcError_error__opaque child;
71 mcError_error__opaque next;
72 bool fatal;
73 DynamicStrings_String s;
74 unsigned int token;
77 static mcError_error__opaque head;
78 static bool inInternal;
81 internalError - displays an internal error message together with the compiler source
82 file and line number.
83 This function is not buffered and is used when the compiler is about
84 to give up.
87 extern "C" void mcError_internalError (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line);
90 writeFormat0 - displays the source module and line together
91 with the encapsulated format string.
92 Used for simple error messages tied to the current token.
95 extern "C" void mcError_writeFormat0 (const char *a_, unsigned int _a_high);
98 writeFormat1 - displays the source module and line together
99 with the encapsulated format string.
100 Used for simple error messages tied to the current token.
103 extern "C" void mcError_writeFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
106 writeFormat2 - displays the module and line together with the encapsulated
107 format strings.
108 Used for simple error messages tied to the current token.
111 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);
114 writeFormat3 - displays the module and line together with the encapsulated
115 format strings.
116 Used for simple error messages tied to the current token.
119 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);
122 newError - creates and returns a new error handle.
125 extern "C" mcError_error mcError_newError (unsigned int atTokenNo);
128 newWarning - creates and returns a new error handle suitable for a warning.
129 A warning will not stop compilation.
132 extern "C" mcError_error mcError_newWarning (unsigned int atTokenNo);
135 chainError - creates and returns a new error handle, this new error
136 is associated with, e, and is chained onto the end of, e.
137 If, e, is NIL then the result to NewError is returned.
140 extern "C" mcError_error mcError_chainError (unsigned int atTokenNo, mcError_error e);
141 extern "C" void mcError_errorFormat0 (mcError_error e, const char *a_, unsigned int _a_high);
142 extern "C" void mcError_errorFormat1 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
143 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);
144 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);
145 extern "C" void mcError_errorString (mcError_error e, DynamicStrings_String str);
148 errorStringAt - given an error string, s, it places this
149 string at token position, tok.
150 The string is consumed.
153 extern "C" void mcError_errorStringAt (DynamicStrings_String s, unsigned int tok);
156 errorStringAt2 - given an error string, s, it places this
157 string at token positions, tok1 and tok2, respectively.
158 The string is consumed.
161 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2);
164 errorStringsAt2 - given error strings, s1, and, s2, it places these
165 strings at token positions, tok1 and tok2, respectively.
166 Both strings are consumed.
169 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2);
172 warnStringAt - given an error string, s, it places this
173 string at token position, tok.
174 The string is consumed.
177 extern "C" void mcError_warnStringAt (DynamicStrings_String s, unsigned int tok);
180 warnStringAt2 - given an warning string, s, it places this
181 string at token positions, tok1 and tok2, respectively.
182 The string is consumed.
185 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2);
188 warnStringsAt2 - given warning strings, s1, and, s2, it places these
189 strings at token positions, tok1 and tok2, respectively.
190 Both strings are consumed.
193 extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2);
194 extern "C" void mcError_warnFormat0 (const char *a_, unsigned int _a_high);
197 warnFormat1 - displays the source module and line together
198 with the encapsulated format string.
199 Used for simple warning messages tied to the current token.
202 extern "C" void mcError_warnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
205 flushErrors - switches the output channel to the error channel
206 and then writes out all errors.
209 extern "C" void mcError_flushErrors (void);
212 flushWarnings - switches the output channel to the error channel
213 and then writes out all warnings.
214 If an error is present the compilation is terminated,
215 if warnings only were emitted then compilation will
216 continue.
219 extern "C" void mcError_flushWarnings (void);
222 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
225 extern "C" void mcError_errorAbort0 (const char *a_, unsigned int _a_high);
228 cast - casts a := b
231 static void cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high);
232 static bool translateNameToCharStar (char *a, unsigned int _a_high, unsigned int n);
235 outString - writes the contents of String to stdout.
236 The string, s, is destroyed.
239 static void outString (DynamicStrings_String file, unsigned int line, unsigned int col, DynamicStrings_String s);
240 static DynamicStrings_String doFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
243 doFormat2 -
246 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);
249 writeFormat2 - displays the module and line together with the encapsulated
250 format strings.
251 Used for simple error messages tied to the current token.
254 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);
257 init - initializes the error list.
260 static void init (void);
263 checkIncludes - generates a sequence of error messages which determine the relevant
264 included file and line number.
265 For example:
267 gcc a.c
268 In file included from b.h:1,
269 from a.c:1:
270 c.h:1: parse error before `and'
272 where a.c is: #include "b.h"
273 b.h is: #include "c.h"
274 c.h is: and this and that
276 we attempt to follow the error messages that gcc issues.
279 static void checkIncludes (unsigned int token, unsigned int depth);
282 flushAll - flushes all errors in list, e.
285 static bool flushAll (mcError_error__opaque e, bool FatalStatus);
289 cast - casts a := b
292 static void cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high)
294 unsigned int i;
295 unsigned char b[_b_high+1];
297 /* make a local copy of each unbounded array. */
298 memcpy (b, b_, _b_high+1);
300 if (_a_high == _b_high)
302 for (i=0; i<=_a_high; i++)
304 const_cast<unsigned char *>(a)[i] = b[i];
309 static bool translateNameToCharStar (char *a, unsigned int _a_high, unsigned int n)
311 unsigned int argno;
312 unsigned int i;
313 unsigned int h;
316 translateNameToString - takes a format specification string, a, and
317 if they consist of of %a then this is translated
318 into a String and %a is replaced by %s.
320 argno = 1;
321 i = 0;
322 h = StrLib_StrLen ((const char *) a, _a_high);
323 while (i < h)
325 if ((a[i] == '%') && ((i+1) < h))
327 if ((a[i+1] == 'a') && (argno == n))
329 const_cast<char *>(a)[i+1] = 's';
330 return true;
332 argno += 1;
333 if (argno > n)
335 /* all done */
336 return false;
339 i += 1;
341 return false;
342 /* static analysis guarentees a RETURN statement will be used before here. */
343 __builtin_unreachable ();
348 outString - writes the contents of String to stdout.
349 The string, s, is destroyed.
352 static void outString (DynamicStrings_String file, unsigned int line, unsigned int col, DynamicStrings_String s)
354 typedef char *outString__T1;
356 DynamicStrings_String leader;
357 outString__T1 p;
358 outString__T1 q;
359 bool space;
360 bool newline;
362 col += 1;
363 if (Xcode)
365 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));
367 else
369 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));
371 p = static_cast<outString__T1> (DynamicStrings_string (s));
372 newline = true;
373 space = false;
374 while ((p != NULL) && ((*p) != ASCII_nul))
376 if (newline)
378 q = static_cast<outString__T1> (DynamicStrings_string (leader));
379 while ((q != NULL) && ((*q) != ASCII_nul))
381 StdIO_Write ((*q));
382 q += 1;
385 newline = (*p) == ASCII_nl;
386 space = (*p) == ' ';
387 if (newline && Xcode)
389 mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col, (sizeof (col)-1));
391 StdIO_Write ((*p));
392 p += 1;
394 if (! newline)
396 if (Xcode)
398 if (! space)
400 StdIO_Write (' ');
402 mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col, (sizeof (col)-1));
404 StdIO_Write (ASCII_nl);
406 FIO_FlushBuffer (FIO_StdOut);
407 if (! Debugging)
409 s = DynamicStrings_KillString (s);
410 leader = DynamicStrings_KillString (leader);
414 static DynamicStrings_String doFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
416 DynamicStrings_String s;
417 nameKey_Name n;
418 char a[_a_high+1];
419 unsigned char w[_w_high+1];
421 /* make a local copy of each unbounded array. */
422 memcpy (a, a_, _a_high+1);
423 memcpy (w, w_, _w_high+1);
426 DoFormat1 -
428 if (translateNameToCharStar ((char *) a, _a_high, 1))
430 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w, _w_high);
431 s = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
432 s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s, (sizeof (s)-1));
434 else
436 s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w, _w_high);
438 return s;
439 /* static analysis guarentees a RETURN statement will be used before here. */
440 __builtin_unreachable ();
445 doFormat2 -
448 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)
450 nameKey_Name n;
451 DynamicStrings_String s;
452 DynamicStrings_String s1;
453 DynamicStrings_String s2;
454 unsigned int b;
455 char a[_a_high+1];
456 unsigned char w1[_w1_high+1];
457 unsigned char w2[_w2_high+1];
459 /* make a local copy of each unbounded array. */
460 memcpy (a, a_, _a_high+1);
461 memcpy (w1, w1_, _w1_high+1);
462 memcpy (w2, w2_, _w2_high+1);
464 b = (unsigned int) 0;
465 if (translateNameToCharStar ((char *) a, _a_high, 1))
467 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high);
468 s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
469 b |= (1 << (1 ));
471 if (translateNameToCharStar ((char *) a, _a_high, 2))
473 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high);
474 s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
475 b |= (1 << (2 ));
477 switch (b)
479 case (unsigned int) 0:
480 s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
481 break;
483 case (unsigned int) ((1 << (1))):
484 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);
485 break;
487 case (unsigned int) ((1 << (2))):
488 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));
489 break;
491 case (unsigned int) ((1 << (1)) | (1 << (2))):
492 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));
493 break;
496 default:
497 M2RTS_HALT (-1);
498 __builtin_unreachable ();
499 break;
501 return s;
502 /* static analysis guarentees a RETURN statement will be used before here. */
503 __builtin_unreachable ();
508 writeFormat2 - displays the module and line together with the encapsulated
509 format strings.
510 Used for simple error messages tied to the current token.
513 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)
515 nameKey_Name n;
516 DynamicStrings_String s;
517 DynamicStrings_String s1;
518 DynamicStrings_String s2;
519 DynamicStrings_String s3;
520 unsigned int b;
521 char a[_a_high+1];
522 unsigned char w1[_w1_high+1];
523 unsigned char w2[_w2_high+1];
524 unsigned char w3[_w3_high+1];
526 /* make a local copy of each unbounded array. */
527 memcpy (a, a_, _a_high+1);
528 memcpy (w1, w1_, _w1_high+1);
529 memcpy (w2, w2_, _w2_high+1);
530 memcpy (w3, w3_, _w3_high+1);
532 b = (unsigned int) 0;
533 if (translateNameToCharStar ((char *) a, _a_high, 1))
535 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high);
536 s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
537 b |= (1 << (1 ));
539 if (translateNameToCharStar ((char *) a, _a_high, 2))
541 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high);
542 s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
543 b |= (1 << (2 ));
545 if (translateNameToCharStar ((char *) a, _a_high, 3))
547 cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w3, _w3_high);
548 s3 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n)));
549 b |= (1 << (3 ));
551 switch (b)
553 case (unsigned int) 0:
554 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);
555 break;
557 case (unsigned int) ((1 << (1))):
558 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);
559 break;
561 case (unsigned int) ((1 << (2))):
562 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);
563 break;
565 case (unsigned int) ((1 << (1)) | (1 << (2))):
566 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);
567 break;
569 case (unsigned int) ((1 << (3))):
570 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));
571 break;
573 case (unsigned int) ((1 << (1)) | (1 << (3))):
574 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));
575 break;
577 case (unsigned int) ((1 << (2)) | (1 << (3))):
578 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));
579 break;
581 case (unsigned int) ((1 << (1)) | (1 << (2)) | (1 << (3))):
582 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));
583 break;
586 default:
587 M2RTS_HALT (-1);
588 __builtin_unreachable ();
589 break;
591 return s;
592 /* static analysis guarentees a RETURN statement will be used before here. */
593 __builtin_unreachable ();
598 init - initializes the error list.
601 static void init (void)
603 head = static_cast<mcError_error__opaque> (NULL);
604 inInternal = false;
609 checkIncludes - generates a sequence of error messages which determine the relevant
610 included file and line number.
611 For example:
613 gcc a.c
614 In file included from b.h:1,
615 from a.c:1:
616 c.h:1: parse error before `and'
618 where a.c is: #include "b.h"
619 b.h is: #include "c.h"
620 c.h is: and this and that
622 we attempt to follow the error messages that gcc issues.
625 static void checkIncludes (unsigned int token, unsigned int depth)
627 DynamicStrings_String included;
628 unsigned int lineno;
630 included = mcLexBuf_findFileNameFromToken (token, depth+1);
631 if (included != NULL)
633 lineno = mcLexBuf_tokenToLineNo (token, depth+1);
634 if (depth == 0)
636 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));
638 else
640 mcPrintf_printf2 ((const char *) " from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1));
642 if ((mcLexBuf_findFileNameFromToken (token, depth+2)) == NULL)
644 mcPrintf_printf0 ((const char *) ":\\n", 3);
646 else
648 mcPrintf_printf0 ((const char *) ",\\n", 3);
650 checkIncludes (token, depth+1);
656 flushAll - flushes all errors in list, e.
659 static bool flushAll (mcError_error__opaque e, bool FatalStatus)
661 mcError_error__opaque f;
662 bool written;
664 written = false;
665 if (e != NULL)
667 do {
668 if ((FatalStatus == e->fatal) && (e->s != NULL))
670 checkIncludes (e->token, 0);
671 if (e->fatal)
673 e->s = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " error: ", 8), DynamicStrings_Mark (e->s));
675 else
677 e->s = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " warning: ", 10), DynamicStrings_Mark (e->s));
679 outString (mcLexBuf_findFileNameFromToken (e->token, 0), mcLexBuf_tokenToLineNo (e->token, 0), mcLexBuf_tokenToColumnNo (e->token, 0), e->s);
680 if ((e->child != NULL) && (flushAll (e->child, FatalStatus)))
681 {} /* empty. */
682 e->s = static_cast<DynamicStrings_String> (NULL);
683 written = true;
685 f = e;
686 e = e->next;
687 if (! Debugging)
689 f->s = DynamicStrings_KillString (f->s);
690 Storage_DEALLOCATE ((void **) &f, sizeof (mcError__T2));
692 } while (! (e == NULL));
694 return written;
695 /* static analysis guarentees a RETURN statement will be used before here. */
696 __builtin_unreachable ();
701 internalError - displays an internal error message together with the compiler source
702 file and line number.
703 This function is not buffered and is used when the compiler is about
704 to give up.
707 extern "C" void mcError_internalError (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line)
709 char a[_a_high+1];
710 char file[_file_high+1];
712 /* make a local copy of each unbounded array. */
713 memcpy (a, a_, _a_high+1);
714 memcpy (file, file_, _file_high+1);
716 M2RTS_ExitOnHalt (1);
717 if (! inInternal)
719 inInternal = true;
720 mcError_flushErrors ();
721 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)));
723 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))));
724 M2RTS_HALT (-1);
725 __builtin_unreachable ();
730 writeFormat0 - displays the source module and line together
731 with the encapsulated format string.
732 Used for simple error messages tied to the current token.
735 extern "C" void mcError_writeFormat0 (const char *a_, unsigned int _a_high)
737 mcError_error__opaque e;
738 char a[_a_high+1];
740 /* make a local copy of each unbounded array. */
741 memcpy (a, a_, _a_high+1);
743 e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ()));
744 e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
749 writeFormat1 - displays the source module and line together
750 with the encapsulated format string.
751 Used for simple error messages tied to the current token.
754 extern "C" void mcError_writeFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
756 mcError_error__opaque e;
757 char a[_a_high+1];
758 unsigned char w[_w_high+1];
760 /* make a local copy of each unbounded array. */
761 memcpy (a, a_, _a_high+1);
762 memcpy (w, w_, _w_high+1);
764 e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ()));
765 e->s = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
770 writeFormat2 - displays the module and line together with the encapsulated
771 format strings.
772 Used for simple error messages tied to the current token.
775 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)
777 mcError_error__opaque e;
778 char a[_a_high+1];
779 unsigned char w1[_w1_high+1];
780 unsigned char w2[_w2_high+1];
782 /* make a local copy of each unbounded array. */
783 memcpy (a, a_, _a_high+1);
784 memcpy (w1, w1_, _w1_high+1);
785 memcpy (w2, w2_, _w2_high+1);
787 e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ()));
788 e->s = doFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
793 writeFormat3 - displays the module and line together with the encapsulated
794 format strings.
795 Used for simple error messages tied to the current token.
798 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)
800 mcError_error__opaque e;
801 char a[_a_high+1];
802 unsigned char w1[_w1_high+1];
803 unsigned char w2[_w2_high+1];
804 unsigned char w3[_w3_high+1];
806 /* make a local copy of each unbounded array. */
807 memcpy (a, a_, _a_high+1);
808 memcpy (w1, w1_, _w1_high+1);
809 memcpy (w2, w2_, _w2_high+1);
810 memcpy (w3, w3_, _w3_high+1);
812 e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ()));
813 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);
818 newError - creates and returns a new error handle.
821 extern "C" mcError_error mcError_newError (unsigned int atTokenNo)
823 mcError_error__opaque e;
824 mcError_error__opaque f;
826 Storage_ALLOCATE ((void **) &e, sizeof (mcError__T2));
827 e->s = static_cast<DynamicStrings_String> (NULL);
828 e->token = atTokenNo;
829 e->next = static_cast<mcError_error__opaque> (NULL);
830 e->parent = static_cast<mcError_error__opaque> (NULL);
831 e->child = static_cast<mcError_error__opaque> (NULL);
832 e->fatal = true;
833 if ((head == NULL) || (head->token > atTokenNo))
835 e->next = head;
836 head = e;
838 else
840 f = head;
841 while ((f->next != NULL) && (f->next->token < atTokenNo))
843 f = f->next;
845 e->next = f->next;
846 f->next = e;
848 return static_cast<mcError_error> (e);
849 /* static analysis guarentees a RETURN statement will be used before here. */
850 __builtin_unreachable ();
855 newWarning - creates and returns a new error handle suitable for a warning.
856 A warning will not stop compilation.
859 extern "C" mcError_error mcError_newWarning (unsigned int atTokenNo)
861 mcError_error__opaque e;
863 e = static_cast<mcError_error__opaque> (mcError_newError (atTokenNo));
864 e->fatal = false;
865 return static_cast<mcError_error> (e);
866 /* static analysis guarentees a RETURN statement will be used before here. */
867 __builtin_unreachable ();
872 chainError - creates and returns a new error handle, this new error
873 is associated with, e, and is chained onto the end of, e.
874 If, e, is NIL then the result to NewError is returned.
877 extern "C" mcError_error mcError_chainError (unsigned int atTokenNo, mcError_error e)
879 mcError_error__opaque f;
881 if (e == NULL)
883 return mcError_newError (atTokenNo);
885 else
887 Storage_ALLOCATE ((void **) &f, sizeof (mcError__T2));
888 f->s = static_cast<DynamicStrings_String> (NULL);
889 f->token = atTokenNo;
890 f->next = static_cast<mcError_error__opaque> (e)->child;
891 f->parent = static_cast<mcError_error__opaque> (e);
892 f->child = static_cast<mcError_error__opaque> (NULL);
893 f->fatal = static_cast<mcError_error__opaque> (e)->fatal;
894 static_cast<mcError_error__opaque> (e)->child = f;
896 return static_cast<mcError_error> (f);
897 /* static analysis guarentees a RETURN statement will be used before here. */
898 __builtin_unreachable ();
901 extern "C" void mcError_errorFormat0 (mcError_error e, const char *a_, unsigned int _a_high)
903 char a[_a_high+1];
905 /* make a local copy of each unbounded array. */
906 memcpy (a, a_, _a_high+1);
909 errorFormat routines provide a printf capability for the error handle.
911 if (static_cast<mcError_error__opaque> (e)->s == NULL)
913 static_cast<mcError_error__opaque> (e)->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
915 else
917 static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)))));
921 extern "C" void mcError_errorFormat1 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
923 DynamicStrings_String s1;
924 char a[_a_high+1];
925 unsigned char w[_w_high+1];
927 /* make a local copy of each unbounded array. */
928 memcpy (a, a_, _a_high+1);
929 memcpy (w, w_, _w_high+1);
931 s1 = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
932 if (static_cast<mcError_error__opaque> (e)->s == NULL)
934 static_cast<mcError_error__opaque> (e)->s = s1;
936 else
938 static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (s1));
942 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)
944 DynamicStrings_String s1;
945 char a[_a_high+1];
946 unsigned char w1[_w1_high+1];
947 unsigned char w2[_w2_high+1];
949 /* make a local copy of each unbounded array. */
950 memcpy (a, a_, _a_high+1);
951 memcpy (w1, w1_, _w1_high+1);
952 memcpy (w2, w2_, _w2_high+1);
954 s1 = doFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
955 if (static_cast<mcError_error__opaque> (e)->s == NULL)
957 static_cast<mcError_error__opaque> (e)->s = s1;
959 else
961 static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (s1));
965 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)
967 DynamicStrings_String s1;
968 char a[_a_high+1];
969 unsigned char w1[_w1_high+1];
970 unsigned char w2[_w2_high+1];
971 unsigned char w3[_w3_high+1];
973 /* make a local copy of each unbounded array. */
974 memcpy (a, a_, _a_high+1);
975 memcpy (w1, w1_, _w1_high+1);
976 memcpy (w2, w2_, _w2_high+1);
977 memcpy (w3, w3_, _w3_high+1);
979 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);
980 if (static_cast<mcError_error__opaque> (e)->s == NULL)
982 static_cast<mcError_error__opaque> (e)->s = s1;
984 else
986 static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (s1));
990 extern "C" void mcError_errorString (mcError_error e, DynamicStrings_String str)
992 static_cast<mcError_error__opaque> (e)->s = str;
997 errorStringAt - given an error string, s, it places this
998 string at token position, tok.
999 The string is consumed.
1002 extern "C" void mcError_errorStringAt (DynamicStrings_String s, unsigned int tok)
1004 mcError_error__opaque e;
1006 e = static_cast<mcError_error__opaque> (mcError_newError (tok));
1007 mcError_errorString (static_cast<mcError_error> (e), s);
1012 errorStringAt2 - given an error string, s, it places this
1013 string at token positions, tok1 and tok2, respectively.
1014 The string is consumed.
1017 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2)
1019 mcError_errorStringsAt2 (s, s, tok1, tok2);
1024 errorStringsAt2 - given error strings, s1, and, s2, it places these
1025 strings at token positions, tok1 and tok2, respectively.
1026 Both strings are consumed.
1029 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2)
1031 mcError_error__opaque e;
1033 if (s1 == s2)
1035 s2 = DynamicStrings_Dup (s1);
1037 e = static_cast<mcError_error__opaque> (mcError_newError (tok1));
1038 mcError_errorString (static_cast<mcError_error> (e), s1);
1039 mcError_errorString (mcError_chainError (tok2, static_cast<mcError_error> (e)), s2);
1044 warnStringAt - given an error string, s, it places this
1045 string at token position, tok.
1046 The string is consumed.
1049 extern "C" void mcError_warnStringAt (DynamicStrings_String s, unsigned int tok)
1051 mcError_error__opaque e;
1053 e = static_cast<mcError_error__opaque> (mcError_newWarning (tok));
1054 mcError_errorString (static_cast<mcError_error> (e), s);
1059 warnStringAt2 - given an warning string, s, it places this
1060 string at token positions, tok1 and tok2, respectively.
1061 The string is consumed.
1064 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2)
1066 mcError_warnStringsAt2 (s, s, tok1, tok2);
1071 warnStringsAt2 - given warning strings, s1, and, s2, it places these
1072 strings at token positions, tok1 and tok2, respectively.
1073 Both strings are consumed.
1076 extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2)
1078 mcError_error__opaque e;
1080 if (s1 == s2)
1082 s2 = DynamicStrings_Dup (s1);
1084 e = static_cast<mcError_error__opaque> (mcError_newWarning (tok1));
1085 mcError_errorString (static_cast<mcError_error> (e), s1);
1086 mcError_errorString (mcError_chainError (tok2, static_cast<mcError_error> (e)), s2);
1089 extern "C" void mcError_warnFormat0 (const char *a_, unsigned int _a_high)
1091 mcError_error__opaque e;
1092 char a[_a_high+1];
1094 /* make a local copy of each unbounded array. */
1095 memcpy (a, a_, _a_high+1);
1098 WarnFormat0 - displays the source module and line together
1099 with the encapsulated format string.
1100 Used for simple warning messages tied to the current token.
1102 e = static_cast<mcError_error__opaque> (mcError_newWarning (mcLexBuf_getTokenNo ()));
1103 e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
1108 warnFormat1 - displays the source module and line together
1109 with the encapsulated format string.
1110 Used for simple warning messages tied to the current token.
1113 extern "C" void mcError_warnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
1115 mcError_error__opaque e;
1116 char a[_a_high+1];
1117 unsigned char w[_w_high+1];
1119 /* make a local copy of each unbounded array. */
1120 memcpy (a, a_, _a_high+1);
1121 memcpy (w, w_, _w_high+1);
1123 e = static_cast<mcError_error__opaque> (mcError_newWarning (mcLexBuf_getTokenNo ()));
1124 e->s = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
1129 flushErrors - switches the output channel to the error channel
1130 and then writes out all errors.
1133 extern "C" void mcError_flushErrors (void)
1135 if (DebugTrace)
1137 mcPrintf_printf0 ((const char *) "\\nFlushing all errors\\n", 23);
1138 mcPrintf_printf0 ((const char *) "===================\\n", 21);
1140 if (flushAll (head, true))
1142 M2RTS_ExitOnHalt (1);
1143 M2RTS_HALT (-1);
1144 __builtin_unreachable ();
1150 flushWarnings - switches the output channel to the error channel
1151 and then writes out all warnings.
1152 If an error is present the compilation is terminated,
1153 if warnings only were emitted then compilation will
1154 continue.
1157 extern "C" void mcError_flushWarnings (void)
1159 if (flushAll (head, false))
1160 {} /* empty. */
1165 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
1168 extern "C" void mcError_errorAbort0 (const char *a_, unsigned int _a_high)
1170 char a[_a_high+1];
1172 /* make a local copy of each unbounded array. */
1173 memcpy (a, a_, _a_high+1);
1175 mcError_flushWarnings ();
1176 if (! (StrLib_StrEqual ((const char *) a, _a_high, (const char *) "", 0)))
1178 mcError_writeFormat0 ((const char *) a, _a_high);
1180 if (! (flushAll (head, true)))
1182 mcError_writeFormat0 ((const char *) "unidentified error", 18);
1183 if (flushAll (head, true))
1184 {} /* empty. */
1186 M2RTS_ExitOnHalt (1);
1187 M2RTS_HALT (-1);
1188 __builtin_unreachable ();
1191 extern "C" void _M2_mcError_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1193 init ();
1196 extern "C" void _M2_mcError_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])