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-2022 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)
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/>. */
25 # if !defined (PROC_D)
27 typedef void (*PROC_t
) (void);
28 typedef struct { PROC_t proc
; } PROC
;
39 # include "GStorage.h"
40 #if defined(__cplusplus)
48 # include "GDynamicStrings.h"
51 # include "GFormatStrings.h"
52 # include "GStorage.h"
56 # include "GnameKey.h"
57 # include "GmcLexBuf.h"
58 # include "GmcPrintf.h"
60 # define Debugging TRUE
61 # define DebugTrace FALSE
63 typedef struct _T2_r _T2
;
65 typedef _T2
*mcError_error
;
72 DynamicStrings_String s
;
76 static mcError_error head
;
77 static unsigned int inInternal
;
80 internalError - displays an internal error message together with the compiler source
82 This function is not buffered and is used when the compiler is about
86 extern "C" void mcError_internalError (const char *a_
, unsigned int _a_high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
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.
94 extern "C" void mcError_writeFormat0 (const char *a_
, unsigned int _a_high
);
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.
102 extern "C" void mcError_writeFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
105 writeFormat2 - displays the module and line together with the encapsulated
107 Used for simple error messages tied to the current token.
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
);
113 writeFormat3 - displays the module and line together with the encapsulated
115 Used for simple error messages tied to the current token.
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
);
121 newError - creates and returns a new error handle.
124 extern "C" mcError_error
mcError_newError (unsigned int atTokenNo
);
127 newWarning - creates and returns a new error handle suitable for a warning.
128 A warning will not stop compilation.
131 extern "C" mcError_error
mcError_newWarning (unsigned int atTokenNo
);
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.
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
);
147 errorStringAt - given an error string, s, it places this
148 string at token position, tok.
149 The string is consumed.
152 extern "C" void mcError_errorStringAt (DynamicStrings_String s
, unsigned int tok
);
155 errorStringAt2 - given an error string, s, it places this
156 string at token positions, tok1 and tok2, respectively.
157 The string is consumed.
160 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s
, unsigned int tok1
, unsigned int tok2
);
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.
168 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1
, DynamicStrings_String s2
, unsigned int tok1
, unsigned int tok2
);
171 warnStringAt - given an error string, s, it places this
172 string at token position, tok.
173 The string is consumed.
176 extern "C" void mcError_warnStringAt (DynamicStrings_String s
, unsigned int tok
);
179 warnStringAt2 - given an warning string, s, it places this
180 string at token positions, tok1 and tok2, respectively.
181 The string is consumed.
184 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s
, unsigned int tok1
, unsigned int tok2
);
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.
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
);
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.
201 extern "C" void mcError_warnFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
204 flushErrors - switches the output channel to the error channel
205 and then writes out all errors.
208 extern "C" void mcError_flushErrors (void);
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
218 extern "C" void mcError_flushWarnings (void);
221 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
224 extern "C" void mcError_errorAbort0 (const char *a_
, unsigned int _a_high
);
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
);
234 outString - writes the contents of String to stdout.
235 The string, s, is destroyed.
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
);
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
);
248 writeFormat2 - displays the module and line together with the encapsulated
250 Used for simple error messages tied to the current token.
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
);
256 init - initializes the error list.
259 static void init (void);
262 checkIncludes - generates a sequence of error messages which determine the relevant
263 included file and line number.
267 In file included from b.h:1,
269 c.h:1: parse error before `and'
271 where a.c is: #include "b.h"
272 b.h is: #include "c.h"
273 c.h is: and this and that
275 we attempt to follow the error messages that gcc issues.
278 static void checkIncludes (unsigned int token
, unsigned int depth
);
281 flushAll - flushes all errors in list, e.
284 static unsigned int flushAll (mcError_error e
, unsigned int FatalStatus
);
291 static void cast (unsigned char *a
, unsigned int _a_high
, const unsigned char *b_
, unsigned int _b_high
)
294 unsigned char b
[_b_high
+1];
296 /* make a local copy of each unbounded array. */
297 memcpy (b
, b_
, _b_high
+1);
299 if (_a_high
== _b_high
)
301 for (i
=0; i
<=_a_high
; i
++)
308 static unsigned int translateNameToCharStar (char *a
, unsigned int _a_high
, unsigned int n
)
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.
321 h
= StrLib_StrLen ((const char *) a
, _a_high
);
324 if ((a
[i
] == '%') && ((i
+1) < h
))
326 if ((a
[i
+1] == 'a') && (argno
== n
))
341 /* static analysis guarentees a RETURN statement will be used before here. */
342 __builtin_unreachable ();
347 outString - writes the contents of String to stdout.
348 The string, s, is destroyed.
351 static void outString (DynamicStrings_String file
, unsigned int line
, unsigned int col
, DynamicStrings_String s
)
355 DynamicStrings_String leader
;
359 unsigned int newline
;
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));
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));
370 p
= static_cast<_T1
> (DynamicStrings_string (s
));
373 while ((p
!= NULL
) && ((*p
) != ASCII_nul
))
377 q
= static_cast<_T1
> (DynamicStrings_string (leader
));
378 while ((q
!= NULL
) && ((*q
) != ASCII_nul
))
384 newline
= (*p
) == ASCII_nl
;
386 if (newline
&& Xcode
)
388 mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col
, (sizeof (col
)-1));
401 mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col
, (sizeof (col
)-1));
403 StdIO_Write (ASCII_nl
);
405 FIO_FlushBuffer (FIO_StdOut
);
408 s
= DynamicStrings_KillString (s
);
409 leader
= DynamicStrings_KillString (leader
);
413 static DynamicStrings_String
doFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
)
415 DynamicStrings_String s
;
418 unsigned char w
[_w_high
+1];
420 /* make a local copy of each unbounded array. */
421 memcpy (a
, a_
, _a_high
+1);
422 memcpy (w
, w_
, _w_high
+1);
427 if (translateNameToCharStar ((char *) a
, _a_high
, 1))
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));
435 s
= FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a
, _a_high
)), (const unsigned char *) w
, _w_high
);
438 /* static analysis guarentees a RETURN statement will be used before here. */
439 __builtin_unreachable ();
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
)
450 DynamicStrings_String s
;
451 DynamicStrings_String s1
;
452 DynamicStrings_String s2
;
455 unsigned char w1
[_w1_high
+1];
456 unsigned char w2
[_w2_high
+1];
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);
463 b
= (unsigned int) 0;
464 if (translateNameToCharStar ((char *) a
, _a_high
, 1))
466 cast ((unsigned char *) &n
, (sizeof (n
)-1), (const unsigned char *) w1
, _w1_high
);
467 s1
= DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)));
470 if (translateNameToCharStar ((char *) a
, _a_high
, 2))
472 cast ((unsigned char *) &n
, (sizeof (n
)-1), (const unsigned char *) w2
, _w2_high
);
473 s2
= DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)));
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
);
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
);
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));
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));
497 __builtin_unreachable ();
501 /* static analysis guarentees a RETURN statement will be used before here. */
502 __builtin_unreachable ();
507 writeFormat2 - displays the module and line together with the encapsulated
509 Used for simple error messages tied to the current token.
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
)
515 DynamicStrings_String s
;
516 DynamicStrings_String s1
;
517 DynamicStrings_String s2
;
518 DynamicStrings_String s3
;
521 unsigned char w1
[_w1_high
+1];
522 unsigned char w2
[_w2_high
+1];
523 unsigned char w3
[_w3_high
+1];
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);
531 b
= (unsigned int) 0;
532 if (translateNameToCharStar ((char *) a
, _a_high
, 1))
534 cast ((unsigned char *) &n
, (sizeof (n
)-1), (const unsigned char *) w1
, _w1_high
);
535 s1
= DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)));
538 if (translateNameToCharStar ((char *) a
, _a_high
, 2))
540 cast ((unsigned char *) &n
, (sizeof (n
)-1), (const unsigned char *) w2
, _w2_high
);
541 s2
= DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)));
544 if (translateNameToCharStar ((char *) a
, _a_high
, 3))
546 cast ((unsigned char *) &n
, (sizeof (n
)-1), (const unsigned char *) w3
, _w3_high
);
547 s3
= DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)));
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
);
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
);
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
);
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
);
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));
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));
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));
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));
587 __builtin_unreachable ();
591 /* static analysis guarentees a RETURN statement will be used before here. */
592 __builtin_unreachable ();
597 init - initializes the error list.
600 static void init (void)
608 checkIncludes - generates a sequence of error messages which determine the relevant
609 included file and line number.
613 In file included from b.h:1,
615 c.h:1: parse error before `and'
617 where a.c is: #include "b.h"
618 b.h is: #include "c.h"
619 c.h is: and this and that
621 we attempt to follow the error messages that gcc issues.
624 static void checkIncludes (unsigned int token
, unsigned int depth
)
626 DynamicStrings_String included
;
629 included
= mcLexBuf_findFileNameFromToken (token
, depth
+1);
630 if (included
!= NULL
)
632 lineno
= mcLexBuf_tokenToLineNo (token
, depth
+1);
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));
639 mcPrintf_printf2 ((const char *) " from %s:%d", 27, (const unsigned char *) &included
, (sizeof (included
)-1), (const unsigned char *) &lineno
, (sizeof (lineno
)-1));
641 if ((mcLexBuf_findFileNameFromToken (token
, depth
+2)) == NULL
)
643 mcPrintf_printf0 ((const char *) ":\\n", 3);
647 mcPrintf_printf0 ((const char *) ",\\n", 3);
649 checkIncludes (token
, depth
+1);
655 flushAll - flushes all errors in list, e.
658 static unsigned int flushAll (mcError_error e
, unsigned int FatalStatus
)
661 unsigned int written
;
667 if ((FatalStatus
== e
->fatal
) && (e
->s
!= NULL
))
669 checkIncludes (e
->token
, 0);
672 e
->s
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " error: ", 8), DynamicStrings_Mark (e
->s
));
676 e
->s
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " warning: ", 10), DynamicStrings_Mark (e
->s
));
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
)))
681 e
->s
= static_cast<DynamicStrings_String
> (NULL
);
688 f
->s
= DynamicStrings_KillString (f
->s
);
689 Storage_DEALLOCATE ((void **) &f
, sizeof (_T2
));
691 } while (! (e
== NULL
));
694 /* static analysis guarentees a RETURN statement will be used before here. */
695 __builtin_unreachable ();
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
706 extern "C" void mcError_internalError (const char *a_
, unsigned int _a_high
, const char *file_
, unsigned int _file_high
, unsigned int line
)
709 char file
[_file_high
+1];
711 /* make a local copy of each unbounded array. */
712 memcpy (a
, a_
, _a_high
+1);
713 memcpy (file
, file_
, _file_high
+1);
715 M2RTS_ExitOnHalt (1);
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)));
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
))));
724 __builtin_unreachable ();
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.
734 extern "C" void mcError_writeFormat0 (const char *a_
, unsigned int _a_high
)
739 /* make a local copy of each unbounded array. */
740 memcpy (a
, a_
, _a_high
+1);
742 e
= mcError_newError (mcLexBuf_getTokenNo ());
743 e
->s
= FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a
, _a_high
)));
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.
753 extern "C" void mcError_writeFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
)
757 unsigned char w
[_w_high
+1];
759 /* make a local copy of each unbounded array. */
760 memcpy (a
, a_
, _a_high
+1);
761 memcpy (w
, w_
, _w_high
+1);
763 e
= mcError_newError (mcLexBuf_getTokenNo ());
764 e
->s
= doFormat1 ((const char *) a
, _a_high
, (const unsigned char *) w
, _w_high
);
769 writeFormat2 - displays the module and line together with the encapsulated
771 Used for simple error messages tied to the current token.
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
)
778 unsigned char w1
[_w1_high
+1];
779 unsigned char w2
[_w2_high
+1];
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);
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
);
792 writeFormat3 - displays the module and line together with the encapsulated
794 Used for simple error messages tied to the current token.
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
)
801 unsigned char w1
[_w1_high
+1];
802 unsigned char w2
[_w2_high
+1];
803 unsigned char w3
[_w3_high
+1];
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);
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
);
817 newError - creates and returns a new error handle.
820 extern "C" mcError_error
mcError_newError (unsigned int atTokenNo
)
825 Storage_ALLOCATE ((void **) &e
, sizeof (_T2
));
826 e
->s
= static_cast<DynamicStrings_String
> (NULL
);
827 e
->token
= atTokenNo
;
832 if ((head
== NULL
) || (head
->token
> atTokenNo
))
840 while ((f
->next
!= NULL
) && (f
->next
->token
< atTokenNo
))
848 /* static analysis guarentees a RETURN statement will be used before here. */
849 __builtin_unreachable ();
854 newWarning - creates and returns a new error handle suitable for a warning.
855 A warning will not stop compilation.
858 extern "C" mcError_error
mcError_newWarning (unsigned int atTokenNo
)
862 e
= mcError_newError (atTokenNo
);
865 /* static analysis guarentees a RETURN statement will be used before here. */
866 __builtin_unreachable ();
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.
876 extern "C" mcError_error
mcError_chainError (unsigned int atTokenNo
, mcError_error e
)
882 return mcError_newError (atTokenNo
);
886 Storage_ALLOCATE ((void **) &f
, sizeof (_T2
));
887 f
->s
= static_cast<DynamicStrings_String
> (NULL
);
888 f
->token
= atTokenNo
;
896 /* static analysis guarentees a RETURN statement will be used before here. */
897 __builtin_unreachable ();
900 extern "C" void mcError_errorFormat0 (mcError_error e
, const char *a_
, unsigned int _a_high
)
904 /* make a local copy of each unbounded array. */
905 memcpy (a
, a_
, _a_high
+1);
908 errorFormat routines provide a printf capability for the error handle.
912 e
->s
= FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a
, _a_high
)));
916 e
->s
= DynamicStrings_ConCat (e
->s
, DynamicStrings_Mark (FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a
, _a_high
)))));
920 extern "C" void mcError_errorFormat1 (mcError_error e
, const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
)
922 DynamicStrings_String s1
;
924 unsigned char w
[_w_high
+1];
926 /* make a local copy of each unbounded array. */
927 memcpy (a
, a_
, _a_high
+1);
928 memcpy (w
, w_
, _w_high
+1);
930 s1
= doFormat1 ((const char *) a
, _a_high
, (const unsigned char *) w
, _w_high
);
937 e
->s
= DynamicStrings_ConCat (e
->s
, DynamicStrings_Mark (s1
));
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
)
943 DynamicStrings_String s1
;
945 unsigned char w1
[_w1_high
+1];
946 unsigned char w2
[_w2_high
+1];
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);
953 s1
= doFormat2 ((const char *) a
, _a_high
, (const unsigned char *) w1
, _w1_high
, (const unsigned char *) w2
, _w2_high
);
960 e
->s
= DynamicStrings_ConCat (e
->s
, DynamicStrings_Mark (s1
));
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
)
966 DynamicStrings_String s1
;
968 unsigned char w1
[_w1_high
+1];
969 unsigned char w2
[_w2_high
+1];
970 unsigned char w3
[_w3_high
+1];
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);
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
);
985 e
->s
= DynamicStrings_ConCat (e
->s
, DynamicStrings_Mark (s1
));
989 extern "C" void mcError_errorString (mcError_error e
, DynamicStrings_String str
)
996 errorStringAt - given an error string, s, it places this
997 string at token position, tok.
998 The string is consumed.
1001 extern "C" void mcError_errorStringAt (DynamicStrings_String s
, unsigned int tok
)
1005 e
= mcError_newError (tok
);
1006 mcError_errorString (e
, s
);
1011 errorStringAt2 - given an error string, s, it places this
1012 string at token positions, tok1 and tok2, respectively.
1013 The string is consumed.
1016 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s
, unsigned int tok1
, unsigned int tok2
)
1018 mcError_errorStringsAt2 (s
, s
, tok1
, tok2
);
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.
1028 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1
, DynamicStrings_String s2
, unsigned int tok1
, unsigned int tok2
)
1034 s2
= DynamicStrings_Dup (s1
);
1036 e
= mcError_newError (tok1
);
1037 mcError_errorString (e
, s1
);
1038 mcError_errorString (mcError_chainError (tok2
, e
), s2
);
1043 warnStringAt - given an error string, s, it places this
1044 string at token position, tok.
1045 The string is consumed.
1048 extern "C" void mcError_warnStringAt (DynamicStrings_String s
, unsigned int tok
)
1052 e
= mcError_newWarning (tok
);
1053 mcError_errorString (e
, s
);
1058 warnStringAt2 - given an warning string, s, it places this
1059 string at token positions, tok1 and tok2, respectively.
1060 The string is consumed.
1063 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s
, unsigned int tok1
, unsigned int tok2
)
1065 mcError_warnStringsAt2 (s
, s
, tok1
, tok2
);
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.
1075 extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1
, DynamicStrings_String s2
, unsigned int tok1
, unsigned int tok2
)
1081 s2
= DynamicStrings_Dup (s1
);
1083 e
= mcError_newWarning (tok1
);
1084 mcError_errorString (e
, s1
);
1085 mcError_errorString (mcError_chainError (tok2
, e
), s2
);
1088 extern "C" void mcError_warnFormat0 (const char *a_
, unsigned int _a_high
)
1093 /* make a local copy of each unbounded array. */
1094 memcpy (a
, a_
, _a_high
+1);
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.
1101 e
= mcError_newWarning (mcLexBuf_getTokenNo ());
1102 e
->s
= FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a
, _a_high
)));
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.
1112 extern "C" void mcError_warnFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
)
1116 unsigned char w
[_w_high
+1];
1118 /* make a local copy of each unbounded array. */
1119 memcpy (a
, a_
, _a_high
+1);
1120 memcpy (w
, w_
, _w_high
+1);
1122 e
= mcError_newWarning (mcLexBuf_getTokenNo ());
1123 e
->s
= doFormat1 ((const char *) a
, _a_high
, (const unsigned char *) w
, _w_high
);
1128 flushErrors - switches the output channel to the error channel
1129 and then writes out all errors.
1132 extern "C" void mcError_flushErrors (void)
1136 mcPrintf_printf0 ((const char *) "\\nFlushing all errors\\n", 23);
1137 mcPrintf_printf0 ((const char *) "===================\\n", 21);
1139 if (flushAll (head
, TRUE
))
1141 M2RTS_ExitOnHalt (1);
1143 __builtin_unreachable ();
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
1156 extern "C" void mcError_flushWarnings (void)
1158 if (flushAll (head
, FALSE
))
1164 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
1167 extern "C" void mcError_errorAbort0 (const char *a_
, unsigned int _a_high
)
1171 /* make a local copy of each unbounded array. */
1172 memcpy (a
, a_
, _a_high
+1);
1174 mcError_flushWarnings ();
1175 if (! (StrLib_StrEqual ((const char *) a
, _a_high
, (const char *) "", 0)))
1177 mcError_writeFormat0 ((const char *) a
, _a_high
);
1179 if (! (flushAll (head
, TRUE
)))
1181 mcError_writeFormat0 ((const char *) "unidentified error", 18);
1182 if (flushAll (head
, TRUE
))
1185 M2RTS_ExitOnHalt (1);
1187 __builtin_unreachable ();
1190 extern "C" void _M2_mcError_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
1195 extern "C" void _M2_mcError_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])