Branch data Line data Source code
1 : : /* do not edit automatically generated by mc from M2Error. */
2 : : /* M2Error.mod error reporting interface.
3 : :
4 : : Copyright (C) 2001-2025 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 : : #include "gcc-consolidation.h"
26 : :
27 : : #include <stdbool.h>
28 : : # if !defined (PROC_D)
29 : : # define PROC_D
30 : : typedef void (*PROC_t) (void);
31 : : typedef struct { PROC_t proc; } PROC;
32 : : # endif
33 : :
34 : : # if !defined (TRUE)
35 : : # define TRUE (1==1)
36 : : # endif
37 : :
38 : : # if !defined (FALSE)
39 : : # define FALSE (1==0)
40 : : # endif
41 : :
42 : : # include "GStorage.h"
43 : : # include "Gmcrts.h"
44 : : #if defined(__cplusplus)
45 : : # undef NULL
46 : : # define NULL 0
47 : : #endif
48 : : #define _M2Error_C
49 : :
50 : : #include "GM2Error.h"
51 : : # include "GNameKey.h"
52 : : # include "GDynamicStrings.h"
53 : : # include "GFIO.h"
54 : : # include "GStrLib.h"
55 : : # include "GFormatStrings.h"
56 : : # include "GM2LexBuf.h"
57 : : # include "GStorage.h"
58 : : # include "GM2Printf.h"
59 : : # include "GM2Options.h"
60 : : # include "GM2RTS.h"
61 : : # include "GSYSTEM.h"
62 : : # include "GM2Emit.h"
63 : : # include "GM2StackAddress.h"
64 : : # include "GIndexing.h"
65 : : # include "GM2Debug.h"
66 : : # include "GM2Pass.h"
67 : : # include "GSymbolTable.h"
68 : : # include "GM2ColorString.h"
69 : :
70 : : # define Debugging true
71 : : # define DebugTrace false
72 : : # define DebugError false
73 : : typedef struct M2Error__T1_r M2Error__T1;
74 : :
75 : : typedef struct M2Error__T2_r M2Error__T2;
76 : :
77 : : typedef enum {M2Error_noscope, M2Error_definition, M2Error_implementation, M2Error_program, M2Error_module, M2Error_procedure} M2Error_KindScope;
78 : :
79 : : typedef M2Error__T1 *M2Error_Error__opaque;
80 : :
81 : : typedef M2Error__T2 *M2Error_ErrorScope__opaque;
82 : :
83 : : struct M2Error__T1_r {
84 : : M2Error_Error__opaque parent;
85 : : M2Error_Error__opaque child;
86 : : M2Error_Error__opaque next;
87 : : bool note;
88 : : bool fatal;
89 : : DynamicStrings_String s;
90 : : unsigned int token;
91 : : bool color;
92 : : M2Error_ErrorScope__opaque scope;
93 : : };
94 : :
95 : : struct M2Error__T2_r {
96 : : M2Error_KindScope scopeKind;
97 : : NameKey_Name scopeName;
98 : : unsigned int symbol;
99 : : };
100 : :
101 : : static M2Error_Error__opaque head;
102 : : static bool InInternal;
103 : : static M2Error_ErrorScope__opaque lastScope;
104 : : static unsigned int scopeIndex;
105 : : static Indexing_Index scopeArray;
106 : : static M2Error_ErrorScope__opaque currentScope;
107 : : static M2StackAddress_StackOfAddress scopeStack;
108 : :
109 : : /*
110 : : InternalError - displays an internal error message together with the compiler source
111 : : file and line number.
112 : : This function is not buffered and is used when the compiler is about
113 : : to give up.
114 : : */
115 : :
116 : : extern "C" void M2Error_InternalError (const char *message_, unsigned int _message_high) __attribute__ ((noreturn));
117 : :
118 : : /*
119 : : WriteFormat0 - displays the source module and line together
120 : : with the encapsulated format string.
121 : : Used for simple error messages tied to the current token.
122 : : */
123 : :
124 : : extern "C" void M2Error_WriteFormat0 (const char *a_, unsigned int _a_high);
125 : :
126 : : /*
127 : : WriteFormat1 - displays the source module and line together
128 : : with the encapsulated format string.
129 : : Used for simple error messages tied to the current token.
130 : : */
131 : :
132 : : extern "C" void M2Error_WriteFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
133 : :
134 : : /*
135 : : WriteFormat2 - displays the module and line together with the encapsulated
136 : : format strings.
137 : : Used for simple error messages tied to the current token.
138 : : */
139 : :
140 : : extern "C" void M2Error_WriteFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
141 : :
142 : : /*
143 : : WriteFormat3 - displays the module and line together with the encapsulated
144 : : format strings.
145 : : Used for simple error messages tied to the current token.
146 : : */
147 : :
148 : : extern "C" void M2Error_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);
149 : :
150 : : /*
151 : : NewError - creates and returns a new error handle.
152 : : */
153 : :
154 : : extern "C" M2Error_Error M2Error_NewError (unsigned int AtTokenNo);
155 : :
156 : : /*
157 : : NewWarning - creates and returns a new error handle suitable for a warning.
158 : : A warning will not stop compilation.
159 : : */
160 : :
161 : : extern "C" M2Error_Error M2Error_NewWarning (unsigned int AtTokenNo);
162 : :
163 : : /*
164 : : NewNote - creates and returns a new error handle suitable for a note.
165 : : A note will not stop compilation.
166 : : */
167 : :
168 : : extern "C" M2Error_Error M2Error_NewNote (unsigned int AtTokenNo);
169 : :
170 : : /*
171 : : ChainError - creates and returns a new error handle, this new error
172 : : is associated with, e, and is chained onto the end of, e.
173 : : If, e, is NIL then the result to NewError is returned.
174 : : */
175 : :
176 : : extern "C" M2Error_Error M2Error_ChainError (unsigned int AtTokenNo, M2Error_Error e);
177 : :
178 : : /*
179 : : MoveError - repositions an error, e, to token, AtTokenNo, and returns, e.
180 : : */
181 : :
182 : : extern "C" M2Error_Error M2Error_MoveError (M2Error_Error e, unsigned int AtTokenNo);
183 : :
184 : : /*
185 : : SetColor - informs the error module that this error will have had colors
186 : : assigned to it. If an error is issued without colors assigned
187 : : then the default colors will be assigned to the legacy error
188 : : messages.
189 : : */
190 : :
191 : : extern "C" M2Error_Error M2Error_SetColor (M2Error_Error e);
192 : : extern "C" void M2Error_ErrorFormat0 (M2Error_Error e, const char *a_, unsigned int _a_high);
193 : : extern "C" void M2Error_ErrorFormat1 (M2Error_Error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
194 : : extern "C" void M2Error_ErrorFormat2 (M2Error_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);
195 : : extern "C" void M2Error_ErrorFormat3 (M2Error_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);
196 : : extern "C" void M2Error_ErrorString (M2Error_Error e, DynamicStrings_String str);
197 : :
198 : : /*
199 : : ErrorStringAt - given an error string, s, it places this
200 : : string at token position, tok.
201 : : The string is consumed.
202 : : */
203 : :
204 : : extern "C" void M2Error_ErrorStringAt (DynamicStrings_String s, unsigned int tok);
205 : :
206 : : /*
207 : : ErrorStringAt2 - given an error string, s, it places this
208 : : string at token positions, tok1 and tok2, respectively.
209 : : The string is consumed.
210 : : */
211 : :
212 : : extern "C" void M2Error_ErrorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2);
213 : :
214 : : /*
215 : : ErrorStringsAt2 - given error strings, s1, and, s2, it places these
216 : : strings at token positions, tok1 and tok2, respectively.
217 : : Both strings are consumed.
218 : : */
219 : :
220 : : extern "C" void M2Error_ErrorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2);
221 : :
222 : : /*
223 : : WarnStringAt - given an error string, s, it places this
224 : : string at token position, tok.
225 : : The string is consumed.
226 : : */
227 : :
228 : : extern "C" void M2Error_WarnStringAt (DynamicStrings_String s, unsigned int tok);
229 : :
230 : : /*
231 : : WarnStringAt2 - given an warning string, s, it places this
232 : : string at token positions, tok1 and tok2, respectively.
233 : : The string is consumed.
234 : : */
235 : :
236 : : extern "C" void M2Error_WarnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2);
237 : :
238 : : /*
239 : : WarnStringsAt2 - given warning strings, s1, and, s2, it places these
240 : : strings at token positions, tok1 and tok2, respectively.
241 : : Both strings are consumed.
242 : : */
243 : :
244 : : extern "C" void M2Error_WarnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2);
245 : :
246 : : /*
247 : : WarnFormat0 - displays the source module and line together
248 : : with the encapsulated format string.
249 : : Used for simple warning messages tied to the current token.
250 : : */
251 : :
252 : : extern "C" void M2Error_WarnFormat0 (const char *a_, unsigned int _a_high);
253 : :
254 : : /*
255 : : WarnFormat1 - displays the source module and line together
256 : : with the encapsulated format string.
257 : : Used for simple warning messages tied to the current token.
258 : : */
259 : :
260 : : extern "C" void M2Error_WarnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
261 : :
262 : : /*
263 : : FlushErrors - switches the output channel to the error channel
264 : : and then writes out all errors.
265 : : */
266 : :
267 : : extern "C" void M2Error_FlushErrors (void);
268 : :
269 : : /*
270 : : FlushWarnings - switches the output channel to the error channel
271 : : and then writes out all warnings.
272 : : If an error is present the compilation is terminated,
273 : : if warnings only were emitted then compilation will
274 : : continue.
275 : : */
276 : :
277 : : extern "C" void M2Error_FlushWarnings (void);
278 : :
279 : : /*
280 : : ErrorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
281 : : */
282 : :
283 : : extern "C" void M2Error_ErrorAbort0 (const char *a_, unsigned int _a_high) __attribute__ ((noreturn));
284 : :
285 : : /*
286 : : AnnounceScope - return the error string s with a scope description prepended
287 : : assuming that scope has changed.
288 : : */
289 : :
290 : : extern "C" DynamicStrings_String M2Error_AnnounceScope (M2Error_Error e, DynamicStrings_String message);
291 : :
292 : : /*
293 : : EnterImplementationScope - signifies to the error routines that the front end
294 : : has started to compile implementation module scopeName.
295 : : */
296 : :
297 : : extern "C" void M2Error_EnterImplementationScope (NameKey_Name scopename);
298 : :
299 : : /*
300 : : EnterProgramScope - signifies to the error routines that the front end
301 : : has started to compile program module scopeName.
302 : : */
303 : :
304 : : extern "C" void M2Error_EnterProgramScope (NameKey_Name scopename);
305 : :
306 : : /*
307 : : EnterModuleScope - signifies to the error routines that the front end
308 : : has started to compile an inner module scopeName.
309 : : */
310 : :
311 : : extern "C" void M2Error_EnterModuleScope (NameKey_Name scopename);
312 : :
313 : : /*
314 : : EnterDefinitionScope - signifies to the error routines that the front end
315 : : has started to compile definition module scopeName.
316 : : */
317 : :
318 : : extern "C" void M2Error_EnterDefinitionScope (NameKey_Name scopename);
319 : :
320 : : /*
321 : : EnterProcedureScope - signifies to the error routines that the front end
322 : : has started to compile definition module scopeName.
323 : : */
324 : :
325 : : extern "C" void M2Error_EnterProcedureScope (NameKey_Name scopename);
326 : :
327 : : /*
328 : : DepthScope - returns the depth of the scope stack.
329 : : */
330 : :
331 : : extern "C" unsigned int M2Error_DepthScope (void);
332 : :
333 : : /*
334 : : GetAnnounceScope - return message with the error scope attached to message.
335 : : filename and message are treated as read only by this
336 : : procedure function.
337 : : */
338 : :
339 : : extern "C" DynamicStrings_String M2Error_GetAnnounceScope (DynamicStrings_String filename, DynamicStrings_String message);
340 : :
341 : : /*
342 : : DefaultProgramModule - sets up an unnamed program scope before the Ident is seen.
343 : : */
344 : :
345 : : extern "C" void M2Error_DefaultProgramModule (void);
346 : :
347 : : /*
348 : : DefaultImplementationModule - sets up an unnamed implementation
349 : : scope before the Ident is seen.
350 : : */
351 : :
352 : : extern "C" void M2Error_DefaultImplementationModule (void);
353 : :
354 : : /*
355 : : DefaultDefinitionModule - sets up an unnamed definition
356 : : scope before the Ident is seen.
357 : : */
358 : :
359 : : extern "C" void M2Error_DefaultDefinitionModule (void);
360 : :
361 : : /*
362 : : DefaultInnerModule - sets up an unnamed inner
363 : : scope before the Ident is seen.
364 : : */
365 : :
366 : : extern "C" void M2Error_DefaultInnerModule (void);
367 : :
368 : : /*
369 : : DefaultProcedure - sets up an unnamed procedure
370 : : scope before the Ident is seen.
371 : : */
372 : :
373 : : extern "C" void M2Error_DefaultProcedure (void);
374 : :
375 : : /*
376 : : EnterErrorScope - pushes the currentScope and sets currentScope to scope.
377 : : */
378 : :
379 : : extern "C" void M2Error_EnterErrorScope (M2Error_ErrorScope scope);
380 : :
381 : : /*
382 : : LeaveErrorScope - leave the current scope and pop into the previous one.
383 : : */
384 : :
385 : : extern "C" void M2Error_LeaveErrorScope (void);
386 : :
387 : : /*
388 : : GetCurrentErrorScope - returns currentScope.
389 : : */
390 : :
391 : : extern "C" M2Error_ErrorScope M2Error_GetCurrentErrorScope (void);
392 : :
393 : : /*
394 : : ResetErrorScope - should be called at the start of each pass to
395 : : reset the error scope index.
396 : : */
397 : :
398 : : extern "C" void M2Error_ResetErrorScope (void);
399 : :
400 : : /*
401 : : Cast - casts a := b
402 : : */
403 : :
404 : : static void Cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high);
405 : : static bool TranslateNameToCharStar (char *a, unsigned int _a_high, unsigned int n);
406 : :
407 : : /*
408 : : DoFormat1 -
409 : : */
410 : :
411 : : static DynamicStrings_String DoFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
412 : :
413 : : /*
414 : : DoFormat2 -
415 : : */
416 : :
417 : : 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);
418 : :
419 : : /*
420 : : WriteFormat2 - displays the module and line together with the encapsulated
421 : : format strings.
422 : : Used for simple error messages tied to the current token.
423 : : */
424 : :
425 : : 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);
426 : :
427 : : /*
428 : : Init - initializes the error list.
429 : : */
430 : :
431 : : static void Init (void);
432 : :
433 : : /*
434 : : CheckIncludes - generates a sequence of error messages which determine the relevant
435 : : included file and line number.
436 : : For example:
437 : :
438 : : gcc a.c
439 : : In file included from b.h:1,
440 : : from a.c:1:
441 : : c.h:1: parse error before `and'
442 : :
443 : : where a.c is: #include "b.h"
444 : : b.h is: #include "c.h"
445 : : c.h is: and this and that
446 : :
447 : : we attempt to follow the error messages that gcc issues.
448 : : */
449 : :
450 : : static void CheckIncludes (unsigned int token, unsigned int depth);
451 : :
452 : : /*
453 : : FlushAll - flushes all errors in list, e.
454 : : */
455 : :
456 : : static bool FlushAll (M2Error_Error__opaque e, bool FatalStatus);
457 : :
458 : : /*
459 : : IsErrorScopeNul - returns TRUE if es is NIL or it has a NulName.
460 : : */
461 : :
462 : : static bool IsErrorScopeNul (M2Error_ErrorScope__opaque es);
463 : :
464 : : /*
465 : : IsSameScope - return TRUE if a and b refer to the same scope.
466 : : */
467 : :
468 : : static bool IsSameScope (M2Error_ErrorScope__opaque a, M2Error_ErrorScope__opaque b);
469 : :
470 : : /*
471 : : newErrorScope - create an ErrorScope of kindScope and return the object.
472 : : It is also added the a dynamic array.
473 : : */
474 : :
475 : : static M2Error_ErrorScope__opaque newErrorScope (M2Error_KindScope kind);
476 : :
477 : :
478 : : /*
479 : : Cast - casts a := b
480 : : */
481 : :
482 : 48 : static void Cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high)
483 : : {
484 : 48 : unsigned int i;
485 : 48 : unsigned char b[_b_high+1];
486 : :
487 : : /* make a local copy of each unbounded array. */
488 : 48 : memcpy (b, b_, _b_high+1);
489 : :
490 : 48 : if (_a_high == _b_high)
491 : : {
492 : 240 : for (i=0; i<=_a_high; i++)
493 : : {
494 : 192 : const_cast<unsigned char *>(a)[i] = b[i];
495 : : }
496 : : }
497 : 48 : }
498 : :
499 : 48 : static bool TranslateNameToCharStar (char *a, unsigned int _a_high, unsigned int n)
500 : : {
501 : 48 : unsigned int argno;
502 : 48 : unsigned int i;
503 : 48 : unsigned int h;
504 : :
505 : : /*
506 : : TranslateNameToString - takes a format specification string, a, and
507 : : if they consist of of %a then this is translated
508 : : into a String and %a is replaced by %s.
509 : : */
510 : 48 : argno = 1;
511 : 48 : i = 0;
512 : 48 : h = StrLib_StrLen ((const char *) a, _a_high);
513 : 1488 : while (i < h)
514 : : {
515 : 1440 : if ((a[i] == '%') && ((i+1) < h))
516 : : {
517 : 66 : if ((a[i+1] == 'a') && (argno == n))
518 : : {
519 : 48 : const_cast<char *>(a)[i+1] = 's';
520 : 48 : return true;
521 : : }
522 : 18 : argno += 1;
523 : 18 : if (argno > n)
524 : : {
525 : : /* all done */
526 : : return false;
527 : : }
528 : : }
529 : 1392 : i += 1;
530 : : }
531 : : return false;
532 : : /* static analysis guarentees a RETURN statement will be used before here. */
533 : : __builtin_unreachable ();
534 : : }
535 : :
536 : :
537 : : /*
538 : : DoFormat1 -
539 : : */
540 : :
541 : 12 : static DynamicStrings_String DoFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
542 : : {
543 : 12 : DynamicStrings_String s;
544 : 12 : NameKey_Name n;
545 : 12 : char a[_a_high+1];
546 : 12 : unsigned char w[_w_high+1];
547 : :
548 : : /* make a local copy of each unbounded array. */
549 : 12 : memcpy (a, a_, _a_high+1);
550 : 12 : memcpy (w, w_, _w_high+1);
551 : :
552 : 12 : n = NameKey_NulName;
553 : 12 : if (TranslateNameToCharStar ((char *) a, _a_high, 1))
554 : : {
555 : 12 : Cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w, _w_high);
556 : 12 : s = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (n)));
557 : 12 : s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s, (sizeof (s)-1));
558 : : }
559 : : else
560 : : {
561 : 0 : s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w, _w_high);
562 : : }
563 : 12 : return s;
564 : : /* static analysis guarentees a RETURN statement will be used before here. */
565 : : __builtin_unreachable ();
566 : 12 : }
567 : :
568 : :
569 : : /*
570 : : DoFormat2 -
571 : : */
572 : :
573 : 18 : 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)
574 : : {
575 : 18 : NameKey_Name n;
576 : 18 : DynamicStrings_String s;
577 : 18 : DynamicStrings_String s1;
578 : 18 : DynamicStrings_String s2;
579 : 18 : unsigned int b;
580 : 18 : char a[_a_high+1];
581 : 18 : unsigned char w1[_w1_high+1];
582 : 18 : unsigned char w2[_w2_high+1];
583 : :
584 : : /* make a local copy of each unbounded array. */
585 : 18 : memcpy (a, a_, _a_high+1);
586 : 18 : memcpy (w1, w1_, _w1_high+1);
587 : 18 : memcpy (w2, w2_, _w2_high+1);
588 : :
589 : 18 : b = (unsigned int) 0;
590 : 18 : n = NameKey_NulName;
591 : 18 : if (TranslateNameToCharStar ((char *) a, _a_high, 1))
592 : : {
593 : 18 : Cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high);
594 : 18 : s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (n)));
595 : 18 : b |= (1 << (1 ));
596 : : }
597 : 18 : if (TranslateNameToCharStar ((char *) a, _a_high, 2))
598 : : {
599 : 18 : Cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high);
600 : 18 : s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (n)));
601 : 18 : b |= (1 << (2 ));
602 : : }
603 : 18 : switch (b)
604 : : {
605 : 0 : case (unsigned int) 0:
606 : 0 : s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
607 : 0 : break;
608 : :
609 : 0 : case (unsigned int) ((1 << (1))):
610 : 0 : 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);
611 : 0 : break;
612 : :
613 : 0 : case (unsigned int) ((1 << (2))):
614 : 0 : 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));
615 : 0 : break;
616 : :
617 : 18 : case (unsigned int) ((1 << (1)) | (1 << (2))):
618 : 18 : 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));
619 : 18 : break;
620 : :
621 : :
622 : 0 : default:
623 : 0 : M2RTS_HALT (-1);
624 : : __builtin_unreachable ();
625 : 18 : break;
626 : : }
627 : 18 : return s;
628 : : /* static analysis guarentees a RETURN statement will be used before here. */
629 : : __builtin_unreachable ();
630 : 18 : }
631 : :
632 : :
633 : : /*
634 : : WriteFormat2 - displays the module and line together with the encapsulated
635 : : format strings.
636 : : Used for simple error messages tied to the current token.
637 : : */
638 : :
639 : 0 : 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)
640 : : {
641 : 0 : NameKey_Name n;
642 : 0 : DynamicStrings_String s;
643 : 0 : DynamicStrings_String s1;
644 : 0 : DynamicStrings_String s2;
645 : 0 : DynamicStrings_String s3;
646 : 0 : unsigned int b;
647 : 0 : char a[_a_high+1];
648 : 0 : unsigned char w1[_w1_high+1];
649 : 0 : unsigned char w2[_w2_high+1];
650 : 0 : unsigned char w3[_w3_high+1];
651 : :
652 : : /* make a local copy of each unbounded array. */
653 : 0 : memcpy (a, a_, _a_high+1);
654 : 0 : memcpy (w1, w1_, _w1_high+1);
655 : 0 : memcpy (w2, w2_, _w2_high+1);
656 : 0 : memcpy (w3, w3_, _w3_high+1);
657 : :
658 : 0 : b = (unsigned int) 0;
659 : 0 : n = NameKey_NulName;
660 : 0 : if (TranslateNameToCharStar ((char *) a, _a_high, 1))
661 : : {
662 : 0 : Cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high);
663 : 0 : s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (n)));
664 : 0 : b |= (1 << (1 ));
665 : : }
666 : 0 : if (TranslateNameToCharStar ((char *) a, _a_high, 2))
667 : : {
668 : 0 : Cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high);
669 : 0 : s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (n)));
670 : 0 : b |= (1 << (2 ));
671 : : }
672 : 0 : if (TranslateNameToCharStar ((char *) a, _a_high, 3))
673 : : {
674 : 0 : Cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w3, _w3_high);
675 : 0 : s3 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (n)));
676 : 0 : b |= (1 << (3 ));
677 : : }
678 : 0 : switch (b)
679 : : {
680 : 0 : case (unsigned int) 0:
681 : 0 : 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);
682 : 0 : break;
683 : :
684 : 0 : case (unsigned int) ((1 << (1))):
685 : 0 : 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);
686 : 0 : break;
687 : :
688 : 0 : case (unsigned int) ((1 << (2))):
689 : 0 : 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);
690 : 0 : break;
691 : :
692 : 0 : case (unsigned int) ((1 << (1)) | (1 << (2))):
693 : 0 : 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);
694 : 0 : break;
695 : :
696 : 0 : case (unsigned int) ((1 << (3))):
697 : 0 : 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));
698 : 0 : break;
699 : :
700 : 0 : case (unsigned int) ((1 << (1)) | (1 << (3))):
701 : 0 : 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));
702 : 0 : break;
703 : :
704 : 0 : case (unsigned int) ((1 << (2)) | (1 << (3))):
705 : 0 : 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));
706 : 0 : break;
707 : :
708 : 0 : case (unsigned int) ((1 << (1)) | (1 << (2)) | (1 << (3))):
709 : 0 : 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));
710 : 0 : break;
711 : :
712 : :
713 : 0 : default:
714 : 0 : M2RTS_HALT (-1);
715 : : __builtin_unreachable ();
716 : 0 : break;
717 : : }
718 : 0 : return s;
719 : : /* static analysis guarentees a RETURN statement will be used before here. */
720 : : __builtin_unreachable ();
721 : 0 : }
722 : :
723 : :
724 : : /*
725 : : Init - initializes the error list.
726 : : */
727 : :
728 : 15260 : static void Init (void)
729 : : {
730 : 15260 : head = static_cast<M2Error_Error__opaque> (NULL);
731 : 15260 : InInternal = false;
732 : 15260 : scopeStack = M2StackAddress_InitStackAddress ();
733 : 15260 : scopeArray = Indexing_InitIndex (1);
734 : 15260 : currentScope = static_cast<M2Error_ErrorScope__opaque> (NULL);
735 : 15260 : scopeIndex = 0;
736 : 15260 : }
737 : :
738 : :
739 : : /*
740 : : CheckIncludes - generates a sequence of error messages which determine the relevant
741 : : included file and line number.
742 : : For example:
743 : :
744 : : gcc a.c
745 : : In file included from b.h:1,
746 : : from a.c:1:
747 : : c.h:1: parse error before `and'
748 : :
749 : : where a.c is: #include "b.h"
750 : : b.h is: #include "c.h"
751 : : c.h is: and this and that
752 : :
753 : : we attempt to follow the error messages that gcc issues.
754 : : */
755 : :
756 : 3837 : static void CheckIncludes (unsigned int token, unsigned int depth)
757 : : {
758 : 3837 : DynamicStrings_String included;
759 : 3837 : unsigned int lineno;
760 : :
761 : 3837 : included = M2LexBuf_FindFileNameFromToken (token, depth+1);
762 : 3837 : if (included != NULL)
763 : : {
764 : 0 : lineno = M2LexBuf_TokenToLineNo (token, depth+1);
765 : 0 : if (depth == 0)
766 : : {
767 : 0 : M2Printf_printf2 ((const char *) "In file included from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1));
768 : : }
769 : : else
770 : : {
771 : 0 : M2Printf_printf2 ((const char *) " from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1));
772 : : }
773 : 0 : if ((M2LexBuf_FindFileNameFromToken (token, depth+2)) == NULL)
774 : : {
775 : 0 : M2Printf_printf0 ((const char *) ":\\n", 3);
776 : : }
777 : : else
778 : : {
779 : 0 : M2Printf_printf0 ((const char *) ",\\n", 3);
780 : : }
781 : 0 : CheckIncludes (token, depth+1);
782 : : }
783 : 3837 : }
784 : :
785 : :
786 : : /*
787 : : FlushAll - flushes all errors in list, e.
788 : : */
789 : :
790 : 207845 : static bool FlushAll (M2Error_Error__opaque e, bool FatalStatus)
791 : : {
792 : 207845 : M2Error_Error__opaque f;
793 : 207845 : bool written;
794 : :
795 : 207845 : written = false;
796 : 207845 : if (e != NULL)
797 : : {
798 : 7003 : do {
799 : 7003 : if ((FatalStatus == e->fatal) && (e->s != NULL))
800 : : {
801 : 3837 : currentScope = e->scope;
802 : 3837 : CheckIncludes (e->token, 0);
803 : 3837 : M2Emit_EmitError (e->fatal, e->note, e->token, M2Error_AnnounceScope (static_cast<M2Error_Error> (e), e->s));
804 : 3837 : if ((e->child != NULL) && (FlushAll (e->child, FatalStatus)))
805 : : {} /* empty. */
806 : 3837 : e->s = static_cast<DynamicStrings_String> (NULL);
807 : 3837 : written = true;
808 : : }
809 : 7003 : f = e;
810 : 7003 : e = e->next;
811 : 7003 : if (! Debugging)
812 : : {
813 : : f->s = DynamicStrings_KillString (f->s);
814 : : Storage_DEALLOCATE ((void **) &f, sizeof (M2Error__T1));
815 : : }
816 : 7003 : } while (! (e == NULL));
817 : : }
818 : 207845 : return written;
819 : : /* static analysis guarentees a RETURN statement will be used before here. */
820 : : __builtin_unreachable ();
821 : : }
822 : :
823 : :
824 : : /*
825 : : IsErrorScopeNul - returns TRUE if es is NIL or it has a NulName.
826 : : */
827 : :
828 : 3843 : static bool IsErrorScopeNul (M2Error_ErrorScope__opaque es)
829 : : {
830 : 3759 : return (es == NULL) || (es->scopeName == NameKey_NulName);
831 : : /* static analysis guarentees a RETURN statement will be used before here. */
832 : : __builtin_unreachable ();
833 : : }
834 : :
835 : :
836 : : /*
837 : : IsSameScope - return TRUE if a and b refer to the same scope.
838 : : */
839 : :
840 : 3837 : static bool IsSameScope (M2Error_ErrorScope__opaque a, M2Error_ErrorScope__opaque b)
841 : : {
842 : 3837 : if (a == b)
843 : : {
844 : : return true;
845 : : }
846 : 1345 : else if ((a == NULL) || (b == NULL))
847 : : {
848 : : /* avoid dangling else. */
849 : : return false;
850 : : }
851 : : else
852 : : {
853 : : /* avoid dangling else. */
854 : : /* this does not compare the symbol field. */
855 : 108 : return (a->scopeKind == b->scopeKind) && (a->scopeName == b->scopeName);
856 : : }
857 : : /* static analysis guarentees a RETURN statement will be used before here. */
858 : : __builtin_unreachable ();
859 : : }
860 : :
861 : :
862 : : /*
863 : : newErrorScope - create an ErrorScope of kindScope and return the object.
864 : : It is also added the a dynamic array.
865 : : */
866 : :
867 : 15942499 : static M2Error_ErrorScope__opaque newErrorScope (M2Error_KindScope kind)
868 : : {
869 : 15942499 : M2Error_ErrorScope__opaque es;
870 : 15942499 : unsigned int c;
871 : :
872 : 15942499 : if (M2Pass_IsPass0 ())
873 : : {
874 : : /* avoid dangling else. */
875 : 3203374 : Storage_ALLOCATE ((void **) &es, sizeof (M2Error__T2));
876 : 3203374 : es->scopeKind = kind;
877 : 3203374 : es->scopeName = NameKey_NulName;
878 : 3203374 : es->symbol = SymbolTable_NulSym;
879 : 3203374 : Indexing_PutIndice (scopeArray, (Indexing_HighIndice (scopeArray))+1, reinterpret_cast <void *> (es));
880 : 3203374 : if (DebugError)
881 : : {
882 : : c = Indexing_HighIndice (scopeArray);
883 : : M2Printf_printf2 ((const char *) "pass 0: %d %d\\n", 17, (const unsigned char *) &c, (sizeof (c)-1), (const unsigned char *) &kind, (sizeof (kind)-1));
884 : : }
885 : : }
886 : : else
887 : : {
888 : 12739125 : scopeIndex += 1;
889 : 12739125 : es = static_cast<M2Error_ErrorScope__opaque> (Indexing_GetIndice (scopeArray, scopeIndex));
890 : 12739125 : if (DebugError)
891 : : {
892 : : /* avoid gcc warning by using compound statement even if not strictly necessary. */
893 : : if (M2Pass_IsPass1 ())
894 : : {
895 : : M2Printf_printf3 ((const char *) "pass 1: %d %d %d\\n", 21, (const unsigned char *) &scopeIndex, (sizeof (scopeIndex)-1), (const unsigned char *) &es->scopeKind, (sizeof (es->scopeKind)-1), (const unsigned char *) &kind, (sizeof (kind)-1));
896 : : }
897 : : else
898 : : {
899 : : M2Printf_printf3 ((const char *) "pass 2: %d %d %d\\n", 21, (const unsigned char *) &scopeIndex, (sizeof (scopeIndex)-1), (const unsigned char *) &es->scopeKind, (sizeof (es->scopeKind)-1), (const unsigned char *) &kind, (sizeof (kind)-1));
900 : : }
901 : : }
902 : 12739125 : M2Debug_Assert (es->scopeKind == kind);
903 : : }
904 : 15942499 : return es;
905 : : /* static analysis guarentees a RETURN statement will be used before here. */
906 : : __builtin_unreachable ();
907 : : }
908 : :
909 : :
910 : : /*
911 : : InternalError - displays an internal error message together with the compiler source
912 : : file and line number.
913 : : This function is not buffered and is used when the compiler is about
914 : : to give up.
915 : : */
916 : :
917 : 73 : extern "C" void M2Error_InternalError (const char *message_, unsigned int _message_high)
918 : : {
919 : 73 : char message[_message_high+1];
920 : :
921 : : /* make a local copy of each unbounded array. */
922 : 73 : memcpy (message, message_, _message_high+1);
923 : :
924 : 73 : if (! InInternal)
925 : : {
926 : 73 : InInternal = true;
927 : 73 : M2Error_FlushErrors ();
928 : : }
929 : 0 : M2Emit_InternalError ((const char *) message, _message_high);
930 : 0 : M2RTS_HALT (-1);
931 : : __builtin_unreachable ();
932 : 73 : }
933 : :
934 : :
935 : : /*
936 : : WriteFormat0 - displays the source module and line together
937 : : with the encapsulated format string.
938 : : Used for simple error messages tied to the current token.
939 : : */
940 : :
941 : 66 : extern "C" void M2Error_WriteFormat0 (const char *a_, unsigned int _a_high)
942 : : {
943 : 66 : M2Error_Error__opaque e;
944 : 66 : char a[_a_high+1];
945 : :
946 : : /* make a local copy of each unbounded array. */
947 : 66 : memcpy (a, a_, _a_high+1);
948 : :
949 : 66 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (M2LexBuf_GetTokenNo ()));
950 : 66 : e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
951 : 66 : }
952 : :
953 : :
954 : : /*
955 : : WriteFormat1 - displays the source module and line together
956 : : with the encapsulated format string.
957 : : Used for simple error messages tied to the current token.
958 : : */
959 : :
960 : 6 : extern "C" void M2Error_WriteFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
961 : : {
962 : 6 : M2Error_Error__opaque e;
963 : 6 : char a[_a_high+1];
964 : 6 : unsigned char w[_w_high+1];
965 : :
966 : : /* make a local copy of each unbounded array. */
967 : 6 : memcpy (a, a_, _a_high+1);
968 : 6 : memcpy (w, w_, _w_high+1);
969 : :
970 : 6 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (M2LexBuf_GetTokenNo ()));
971 : 6 : e->s = DoFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
972 : 6 : }
973 : :
974 : :
975 : : /*
976 : : WriteFormat2 - displays the module and line together with the encapsulated
977 : : format strings.
978 : : Used for simple error messages tied to the current token.
979 : : */
980 : :
981 : 18 : extern "C" void M2Error_WriteFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high)
982 : : {
983 : 18 : M2Error_Error__opaque e;
984 : 18 : char a[_a_high+1];
985 : 18 : unsigned char w1[_w1_high+1];
986 : 18 : unsigned char w2[_w2_high+1];
987 : :
988 : : /* make a local copy of each unbounded array. */
989 : 18 : memcpy (a, a_, _a_high+1);
990 : 18 : memcpy (w1, w1_, _w1_high+1);
991 : 18 : memcpy (w2, w2_, _w2_high+1);
992 : :
993 : 18 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (M2LexBuf_GetTokenNo ()));
994 : 18 : e->s = DoFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
995 : 18 : }
996 : :
997 : :
998 : : /*
999 : : WriteFormat3 - displays the module and line together with the encapsulated
1000 : : format strings.
1001 : : Used for simple error messages tied to the current token.
1002 : : */
1003 : :
1004 : 0 : extern "C" void M2Error_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)
1005 : : {
1006 : 0 : M2Error_Error__opaque e;
1007 : 0 : char a[_a_high+1];
1008 : 0 : unsigned char w1[_w1_high+1];
1009 : 0 : unsigned char w2[_w2_high+1];
1010 : 0 : unsigned char w3[_w3_high+1];
1011 : :
1012 : : /* make a local copy of each unbounded array. */
1013 : 0 : memcpy (a, a_, _a_high+1);
1014 : 0 : memcpy (w1, w1_, _w1_high+1);
1015 : 0 : memcpy (w2, w2_, _w2_high+1);
1016 : 0 : memcpy (w3, w3_, _w3_high+1);
1017 : :
1018 : 0 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (M2LexBuf_GetTokenNo ()));
1019 : 0 : 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);
1020 : 0 : }
1021 : :
1022 : :
1023 : : /*
1024 : : NewError - creates and returns a new error handle.
1025 : : */
1026 : :
1027 : 3562 : extern "C" M2Error_Error M2Error_NewError (unsigned int AtTokenNo)
1028 : : {
1029 : 3562 : M2Error_Error__opaque e;
1030 : 3562 : M2Error_Error__opaque f;
1031 : :
1032 : 3562 : if (AtTokenNo == M2LexBuf_UnknownTokenNo)
1033 : : {} /* empty. */
1034 : : /* This could be used as a useful debugging hook as the front end
1035 : : has forgotten the token no. */
1036 : 3562 : Storage_ALLOCATE ((void **) &e, sizeof (M2Error__T1));
1037 : 3562 : e->s = static_cast<DynamicStrings_String> (NULL);
1038 : 3562 : e->token = AtTokenNo;
1039 : 3562 : e->next = static_cast<M2Error_Error__opaque> (NULL);
1040 : 3562 : e->parent = static_cast<M2Error_Error__opaque> (NULL);
1041 : 3562 : e->child = static_cast<M2Error_Error__opaque> (NULL);
1042 : 3562 : e->note = false;
1043 : 3562 : e->fatal = true;
1044 : 3562 : e->color = false;
1045 : : /* Assert (scopeKind # noscope) ; */
1046 : 3562 : e->scope = currentScope;
1047 : 3562 : if ((head == NULL) || (head->token > AtTokenNo))
1048 : : {
1049 : 2106 : e->next = head;
1050 : 2106 : head = e;
1051 : : }
1052 : : else
1053 : : {
1054 : : f = head;
1055 : 2087 : while ((f->next != NULL) && (f->next->token < AtTokenNo))
1056 : : {
1057 : : f = f->next;
1058 : : }
1059 : 1456 : e->next = f->next;
1060 : 1456 : f->next = e;
1061 : : }
1062 : 3562 : return static_cast<M2Error_Error> (e);
1063 : : /* static analysis guarentees a RETURN statement will be used before here. */
1064 : : __builtin_unreachable ();
1065 : : }
1066 : :
1067 : :
1068 : : /*
1069 : : NewWarning - creates and returns a new error handle suitable for a warning.
1070 : : A warning will not stop compilation.
1071 : : */
1072 : :
1073 : 594 : extern "C" M2Error_Error M2Error_NewWarning (unsigned int AtTokenNo)
1074 : : {
1075 : 594 : M2Error_Error__opaque e;
1076 : :
1077 : 594 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (AtTokenNo));
1078 : 594 : e->fatal = false;
1079 : 594 : e->note = false;
1080 : 594 : return static_cast<M2Error_Error> (e);
1081 : : /* static analysis guarentees a RETURN statement will be used before here. */
1082 : : __builtin_unreachable ();
1083 : : }
1084 : :
1085 : :
1086 : : /*
1087 : : NewNote - creates and returns a new error handle suitable for a note.
1088 : : A note will not stop compilation.
1089 : : */
1090 : :
1091 : 19 : extern "C" M2Error_Error M2Error_NewNote (unsigned int AtTokenNo)
1092 : : {
1093 : 19 : M2Error_Error__opaque e;
1094 : :
1095 : 19 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (AtTokenNo));
1096 : 19 : e->fatal = false;
1097 : 19 : e->note = true;
1098 : 19 : return static_cast<M2Error_Error> (e);
1099 : : /* static analysis guarentees a RETURN statement will be used before here. */
1100 : : __builtin_unreachable ();
1101 : : }
1102 : :
1103 : :
1104 : : /*
1105 : : ChainError - creates and returns a new error handle, this new error
1106 : : is associated with, e, and is chained onto the end of, e.
1107 : : If, e, is NIL then the result to NewError is returned.
1108 : : */
1109 : :
1110 : 396 : extern "C" M2Error_Error M2Error_ChainError (unsigned int AtTokenNo, M2Error_Error e)
1111 : : {
1112 : 396 : M2Error_Error__opaque f;
1113 : :
1114 : 396 : if (e == NULL)
1115 : : {
1116 : 0 : return M2Error_NewError (AtTokenNo);
1117 : : }
1118 : : else
1119 : : {
1120 : 396 : Storage_ALLOCATE ((void **) &f, sizeof (M2Error__T1));
1121 : 396 : f->s = static_cast<DynamicStrings_String> (NULL);
1122 : 396 : f->token = AtTokenNo;
1123 : 396 : f->next = static_cast<M2Error_Error__opaque> (e)->child;
1124 : 396 : f->parent = static_cast<M2Error_Error__opaque> (e);
1125 : 396 : f->child = static_cast<M2Error_Error__opaque> (NULL);
1126 : 396 : f->fatal = static_cast<M2Error_Error__opaque> (e)->fatal;
1127 : 396 : f->scope = static_cast<M2Error_Error__opaque> (e)->scope;
1128 : 396 : static_cast<M2Error_Error__opaque> (e)->child = f;
1129 : : }
1130 : 396 : return static_cast<M2Error_Error> (f);
1131 : : /* static analysis guarentees a RETURN statement will be used before here. */
1132 : : __builtin_unreachable ();
1133 : : }
1134 : :
1135 : :
1136 : : /*
1137 : : MoveError - repositions an error, e, to token, AtTokenNo, and returns, e.
1138 : : */
1139 : :
1140 : 0 : extern "C" M2Error_Error M2Error_MoveError (M2Error_Error e, unsigned int AtTokenNo)
1141 : : {
1142 : 0 : if (e != NULL)
1143 : : {
1144 : 0 : static_cast<M2Error_Error__opaque> (e)->token = AtTokenNo;
1145 : : }
1146 : 0 : return e;
1147 : : /* static analysis guarentees a RETURN statement will be used before here. */
1148 : : __builtin_unreachable ();
1149 : : }
1150 : :
1151 : :
1152 : : /*
1153 : : SetColor - informs the error module that this error will have had colors
1154 : : assigned to it. If an error is issued without colors assigned
1155 : : then the default colors will be assigned to the legacy error
1156 : : messages.
1157 : : */
1158 : :
1159 : 3112 : extern "C" M2Error_Error M2Error_SetColor (M2Error_Error e)
1160 : : {
1161 : 3112 : static_cast<M2Error_Error__opaque> (e)->color = true;
1162 : 3112 : return e;
1163 : : /* static analysis guarentees a RETURN statement will be used before here. */
1164 : : __builtin_unreachable ();
1165 : : }
1166 : :
1167 : 36 : extern "C" void M2Error_ErrorFormat0 (M2Error_Error e, const char *a_, unsigned int _a_high)
1168 : : {
1169 : 36 : char a[_a_high+1];
1170 : :
1171 : : /* make a local copy of each unbounded array. */
1172 : 36 : memcpy (a, a_, _a_high+1);
1173 : :
1174 : : /*
1175 : : ErrorFormat routines provide a printf capability for the error handle.
1176 : : */
1177 : 36 : if (static_cast<M2Error_Error__opaque> (e)->s == NULL)
1178 : : {
1179 : 36 : static_cast<M2Error_Error__opaque> (e)->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
1180 : : }
1181 : : else
1182 : : {
1183 : 0 : static_cast<M2Error_Error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<M2Error_Error__opaque> (e)->s, DynamicStrings_Mark (FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)))));
1184 : : }
1185 : 36 : }
1186 : :
1187 : 6 : extern "C" void M2Error_ErrorFormat1 (M2Error_Error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
1188 : : {
1189 : 6 : DynamicStrings_String s1;
1190 : 6 : char a[_a_high+1];
1191 : 6 : unsigned char w[_w_high+1];
1192 : :
1193 : : /* make a local copy of each unbounded array. */
1194 : 6 : memcpy (a, a_, _a_high+1);
1195 : 6 : memcpy (w, w_, _w_high+1);
1196 : :
1197 : 12 : s1 = DoFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
1198 : 6 : if (static_cast<M2Error_Error__opaque> (e)->s == NULL)
1199 : : {
1200 : 6 : static_cast<M2Error_Error__opaque> (e)->s = s1;
1201 : : }
1202 : : else
1203 : : {
1204 : 0 : static_cast<M2Error_Error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<M2Error_Error__opaque> (e)->s, DynamicStrings_Mark (s1));
1205 : : }
1206 : 6 : }
1207 : :
1208 : 0 : extern "C" void M2Error_ErrorFormat2 (M2Error_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)
1209 : : {
1210 : 0 : DynamicStrings_String s1;
1211 : 0 : char a[_a_high+1];
1212 : 0 : unsigned char w1[_w1_high+1];
1213 : 0 : unsigned char w2[_w2_high+1];
1214 : :
1215 : : /* make a local copy of each unbounded array. */
1216 : 0 : memcpy (a, a_, _a_high+1);
1217 : 0 : memcpy (w1, w1_, _w1_high+1);
1218 : 0 : memcpy (w2, w2_, _w2_high+1);
1219 : :
1220 : 0 : s1 = DoFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high);
1221 : 0 : if (static_cast<M2Error_Error__opaque> (e)->s == NULL)
1222 : : {
1223 : 0 : static_cast<M2Error_Error__opaque> (e)->s = s1;
1224 : : }
1225 : : else
1226 : : {
1227 : 0 : static_cast<M2Error_Error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<M2Error_Error__opaque> (e)->s, DynamicStrings_Mark (s1));
1228 : : }
1229 : 0 : }
1230 : :
1231 : 0 : extern "C" void M2Error_ErrorFormat3 (M2Error_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)
1232 : : {
1233 : 0 : DynamicStrings_String s1;
1234 : 0 : char a[_a_high+1];
1235 : 0 : unsigned char w1[_w1_high+1];
1236 : 0 : unsigned char w2[_w2_high+1];
1237 : 0 : unsigned char w3[_w3_high+1];
1238 : :
1239 : : /* make a local copy of each unbounded array. */
1240 : 0 : memcpy (a, a_, _a_high+1);
1241 : 0 : memcpy (w1, w1_, _w1_high+1);
1242 : 0 : memcpy (w2, w2_, _w2_high+1);
1243 : 0 : memcpy (w3, w3_, _w3_high+1);
1244 : :
1245 : 0 : 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);
1246 : 0 : if (static_cast<M2Error_Error__opaque> (e)->s == NULL)
1247 : : {
1248 : 0 : static_cast<M2Error_Error__opaque> (e)->s = s1;
1249 : : }
1250 : : else
1251 : : {
1252 : 0 : static_cast<M2Error_Error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<M2Error_Error__opaque> (e)->s, DynamicStrings_Mark (s1));
1253 : : }
1254 : 0 : }
1255 : :
1256 : 3712 : extern "C" void M2Error_ErrorString (M2Error_Error e, DynamicStrings_String str)
1257 : : {
1258 : 3712 : static_cast<M2Error_Error__opaque> (e)->s = str;
1259 : 3712 : }
1260 : :
1261 : :
1262 : : /*
1263 : : ErrorStringAt - given an error string, s, it places this
1264 : : string at token position, tok.
1265 : : The string is consumed.
1266 : : */
1267 : :
1268 : 12 : extern "C" void M2Error_ErrorStringAt (DynamicStrings_String s, unsigned int tok)
1269 : : {
1270 : 12 : M2Error_Error__opaque e;
1271 : :
1272 : 12 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (tok));
1273 : 12 : M2Error_ErrorString (static_cast<M2Error_Error> (e), s);
1274 : 12 : }
1275 : :
1276 : :
1277 : : /*
1278 : : ErrorStringAt2 - given an error string, s, it places this
1279 : : string at token positions, tok1 and tok2, respectively.
1280 : : The string is consumed.
1281 : : */
1282 : :
1283 : 0 : extern "C" void M2Error_ErrorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2)
1284 : : {
1285 : 0 : M2Error_ErrorStringsAt2 (s, s, tok1, tok2);
1286 : 0 : }
1287 : :
1288 : :
1289 : : /*
1290 : : ErrorStringsAt2 - given error strings, s1, and, s2, it places these
1291 : : strings at token positions, tok1 and tok2, respectively.
1292 : : Both strings are consumed.
1293 : : */
1294 : :
1295 : 0 : extern "C" void M2Error_ErrorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2)
1296 : : {
1297 : 0 : M2Error_Error__opaque e;
1298 : :
1299 : 0 : if (s1 == s2)
1300 : : {
1301 : 0 : s2 = DynamicStrings_Dup (s1);
1302 : : }
1303 : 0 : e = static_cast<M2Error_Error__opaque> (M2Error_NewError (tok1));
1304 : 0 : M2Error_ErrorString (static_cast<M2Error_Error> (e), s1);
1305 : 0 : M2Error_ErrorString (M2Error_ChainError (tok2, static_cast<M2Error_Error> (e)), s2);
1306 : 0 : }
1307 : :
1308 : :
1309 : : /*
1310 : : WarnStringAt - given an error string, s, it places this
1311 : : string at token position, tok.
1312 : : The string is consumed.
1313 : : */
1314 : :
1315 : 0 : extern "C" void M2Error_WarnStringAt (DynamicStrings_String s, unsigned int tok)
1316 : : {
1317 : 0 : M2Error_Error__opaque e;
1318 : :
1319 : 0 : e = static_cast<M2Error_Error__opaque> (M2Error_NewWarning (tok));
1320 : 0 : M2Error_ErrorString (static_cast<M2Error_Error> (e), s);
1321 : 0 : }
1322 : :
1323 : :
1324 : : /*
1325 : : WarnStringAt2 - given an warning string, s, it places this
1326 : : string at token positions, tok1 and tok2, respectively.
1327 : : The string is consumed.
1328 : : */
1329 : :
1330 : 0 : extern "C" void M2Error_WarnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2)
1331 : : {
1332 : 0 : M2Error_WarnStringsAt2 (s, s, tok1, tok2);
1333 : 0 : }
1334 : :
1335 : :
1336 : : /*
1337 : : WarnStringsAt2 - given warning strings, s1, and, s2, it places these
1338 : : strings at token positions, tok1 and tok2, respectively.
1339 : : Both strings are consumed.
1340 : : */
1341 : :
1342 : 0 : extern "C" void M2Error_WarnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2)
1343 : : {
1344 : 0 : M2Error_Error__opaque e;
1345 : :
1346 : 0 : if (s1 == s2)
1347 : : {
1348 : 0 : s2 = DynamicStrings_Dup (s1);
1349 : : }
1350 : 0 : e = static_cast<M2Error_Error__opaque> (M2Error_NewWarning (tok1));
1351 : 0 : M2Error_ErrorString (static_cast<M2Error_Error> (e), s1);
1352 : 0 : M2Error_ErrorString (M2Error_ChainError (tok2, static_cast<M2Error_Error> (e)), s2);
1353 : 0 : }
1354 : :
1355 : :
1356 : : /*
1357 : : WarnFormat0 - displays the source module and line together
1358 : : with the encapsulated format string.
1359 : : Used for simple warning messages tied to the current token.
1360 : : */
1361 : :
1362 : 0 : extern "C" void M2Error_WarnFormat0 (const char *a_, unsigned int _a_high)
1363 : : {
1364 : 0 : M2Error_Error__opaque e;
1365 : 0 : char a[_a_high+1];
1366 : :
1367 : : /* make a local copy of each unbounded array. */
1368 : 0 : memcpy (a, a_, _a_high+1);
1369 : :
1370 : 0 : e = static_cast<M2Error_Error__opaque> (M2Error_NewWarning (M2LexBuf_GetTokenNo ()));
1371 : 0 : e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
1372 : 0 : }
1373 : :
1374 : :
1375 : : /*
1376 : : WarnFormat1 - displays the source module and line together
1377 : : with the encapsulated format string.
1378 : : Used for simple warning messages tied to the current token.
1379 : : */
1380 : :
1381 : 0 : extern "C" void M2Error_WarnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
1382 : : {
1383 : 0 : M2Error_Error__opaque e;
1384 : 0 : char a[_a_high+1];
1385 : 0 : unsigned char w[_w_high+1];
1386 : :
1387 : : /* make a local copy of each unbounded array. */
1388 : 0 : memcpy (a, a_, _a_high+1);
1389 : 0 : memcpy (w, w_, _w_high+1);
1390 : :
1391 : 0 : e = static_cast<M2Error_Error__opaque> (M2Error_NewWarning (M2LexBuf_GetTokenNo ()));
1392 : 0 : e->s = DoFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high);
1393 : 0 : }
1394 : :
1395 : :
1396 : : /*
1397 : : FlushErrors - switches the output channel to the error channel
1398 : : and then writes out all errors.
1399 : : */
1400 : :
1401 : 103905 : extern "C" void M2Error_FlushErrors (void)
1402 : : {
1403 : 103905 : if (DebugTrace)
1404 : : {
1405 : : M2Printf_printf0 ((const char *) "\\nFlushing all errors\\n", 23);
1406 : : M2Printf_printf0 ((const char *) "===================\\n", 21);
1407 : : }
1408 : 103905 : if (FlushAll (head, true))
1409 : : {
1410 : 1418 : M2RTS_ExitOnHalt (1);
1411 : 1418 : M2RTS_HALT (-1);
1412 : : __builtin_unreachable ();
1413 : : }
1414 : 102487 : }
1415 : :
1416 : :
1417 : : /*
1418 : : FlushWarnings - switches the output channel to the error channel
1419 : : and then writes out all warnings.
1420 : : If an error is present the compilation is terminated,
1421 : : if warnings only were emitted then compilation will
1422 : : continue.
1423 : : */
1424 : :
1425 : 103532 : extern "C" void M2Error_FlushWarnings (void)
1426 : : {
1427 : 103532 : if (FlushAll (head, false))
1428 : : {} /* empty. */
1429 : 103532 : }
1430 : :
1431 : :
1432 : : /*
1433 : : ErrorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
1434 : : */
1435 : :
1436 : 18 : extern "C" void M2Error_ErrorAbort0 (const char *a_, unsigned int _a_high)
1437 : : {
1438 : 18 : char a[_a_high+1];
1439 : :
1440 : : /* make a local copy of each unbounded array. */
1441 : 18 : memcpy (a, a_, _a_high+1);
1442 : :
1443 : 18 : M2Error_FlushWarnings ();
1444 : 18 : if (! (StrLib_StrEqual ((const char *) a, _a_high, (const char *) "", 0)))
1445 : : {
1446 : 0 : M2Error_WriteFormat0 ((const char *) a, _a_high);
1447 : : }
1448 : 18 : if (! (FlushAll (head, true)))
1449 : : {
1450 : 0 : M2Error_WriteFormat0 ((const char *) "unidentified error", 18);
1451 : 0 : if (FlushAll (head, true))
1452 : : {} /* empty. */
1453 : : }
1454 : 18 : M2RTS_ExitOnHalt (1);
1455 : 18 : M2RTS_HALT (-1);
1456 : : __builtin_unreachable ();
1457 : 18 : }
1458 : :
1459 : :
1460 : : /*
1461 : : AnnounceScope - return the error string s with a scope description prepended
1462 : : assuming that scope has changed.
1463 : : */
1464 : :
1465 : 3837 : extern "C" DynamicStrings_String M2Error_AnnounceScope (M2Error_Error e, DynamicStrings_String message)
1466 : : {
1467 : 3837 : if (! (IsSameScope (lastScope, static_cast<M2Error_Error__opaque> (e)->scope)))
1468 : : {
1469 : 1345 : lastScope = static_cast<M2Error_Error__opaque> (e)->scope;
1470 : 1345 : if (IsErrorScopeNul (lastScope))
1471 : : {
1472 : 96 : return DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "no scope active: ", 17), message);
1473 : : }
1474 : : else
1475 : : {
1476 : 1249 : M2Debug_Assert ((static_cast<M2Error_Error__opaque> (e)->scope != NULL) && (static_cast<M2Error_Error__opaque> (e)->scope->scopeKind != M2Error_noscope));
1477 : : /* filename := FindFileNameFromToken (e^.token, 0) ; */
1478 : 1249 : message = M2Error_GetAnnounceScope (static_cast<DynamicStrings_String> (NULL), message);
1479 : : }
1480 : : }
1481 : : return message;
1482 : : /* static analysis guarentees a RETURN statement will be used before here. */
1483 : : __builtin_unreachable ();
1484 : : }
1485 : :
1486 : :
1487 : : /*
1488 : : EnterImplementationScope - signifies to the error routines that the front end
1489 : : has started to compile implementation module scopeName.
1490 : : */
1491 : :
1492 : 216892 : extern "C" void M2Error_EnterImplementationScope (NameKey_Name scopename)
1493 : : {
1494 : 216892 : M2Debug_Assert (currentScope != NULL);
1495 : 216892 : M2Debug_Assert (currentScope->scopeKind == M2Error_implementation);
1496 : 216892 : if (currentScope->scopeName == NameKey_NulName)
1497 : : {
1498 : 54337 : if (DebugError)
1499 : : {
1500 : : M2Printf_printf1 ((const char *) "seen implementation: %a\\n", 25, (const unsigned char *) &scopename, (sizeof (scopename)-1));
1501 : : }
1502 : 54337 : currentScope->scopeName = scopename;
1503 : : }
1504 : 216892 : }
1505 : :
1506 : :
1507 : : /*
1508 : : EnterProgramScope - signifies to the error routines that the front end
1509 : : has started to compile program module scopeName.
1510 : : */
1511 : :
1512 : 45894 : extern "C" void M2Error_EnterProgramScope (NameKey_Name scopename)
1513 : : {
1514 : 45894 : M2Debug_Assert (currentScope != NULL);
1515 : 45894 : M2Debug_Assert (currentScope->scopeKind == M2Error_program);
1516 : 45894 : if (currentScope->scopeName == NameKey_NulName)
1517 : : {
1518 : 11622 : if (DebugError)
1519 : : {
1520 : : M2Printf_printf1 ((const char *) "seen program: %a\\n", 18, (const unsigned char *) &scopename, (sizeof (scopename)-1));
1521 : : }
1522 : 11622 : currentScope->scopeName = scopename;
1523 : : }
1524 : 45894 : }
1525 : :
1526 : :
1527 : : /*
1528 : : EnterModuleScope - signifies to the error routines that the front end
1529 : : has started to compile an inner module scopeName.
1530 : : */
1531 : :
1532 : 1680 : extern "C" void M2Error_EnterModuleScope (NameKey_Name scopename)
1533 : : {
1534 : 1680 : M2Debug_Assert (currentScope != NULL);
1535 : 1680 : M2Debug_Assert (currentScope->scopeKind == M2Error_module);
1536 : 1680 : if (currentScope->scopeName == NameKey_NulName)
1537 : : {
1538 : 426 : if (DebugError)
1539 : : {
1540 : : M2Printf_printf1 ((const char *) "seen module: %a\\n", 17, (const unsigned char *) &scopename, (sizeof (scopename)-1));
1541 : : }
1542 : 426 : currentScope->scopeName = scopename;
1543 : : }
1544 : 1680 : }
1545 : :
1546 : :
1547 : : /*
1548 : : EnterDefinitionScope - signifies to the error routines that the front end
1549 : : has started to compile definition module scopeName.
1550 : : */
1551 : :
1552 : 483145 : extern "C" void M2Error_EnterDefinitionScope (NameKey_Name scopename)
1553 : : {
1554 : 483145 : M2Debug_Assert (currentScope != NULL);
1555 : 483145 : M2Debug_Assert (currentScope->scopeKind == M2Error_definition);
1556 : 483145 : if (currentScope->scopeName == NameKey_NulName)
1557 : : {
1558 : 121517 : if (DebugError)
1559 : : {
1560 : : M2Printf_printf1 ((const char *) "seen definition: %a\\n", 21, (const unsigned char *) &scopename, (sizeof (scopename)-1));
1561 : : }
1562 : 121517 : currentScope->scopeName = scopename;
1563 : : }
1564 : 483145 : }
1565 : :
1566 : :
1567 : : /*
1568 : : EnterProcedureScope - signifies to the error routines that the front end
1569 : : has started to compile definition module scopeName.
1570 : : */
1571 : :
1572 : 9959900 : extern "C" void M2Error_EnterProcedureScope (NameKey_Name scopename)
1573 : : {
1574 : 9959900 : M2Debug_Assert (currentScope != NULL);
1575 : 9959900 : M2Debug_Assert (currentScope->scopeKind == M2Error_procedure);
1576 : 9959900 : if (currentScope->scopeName == NameKey_NulName)
1577 : : {
1578 : 3004534 : if (DebugError)
1579 : : {
1580 : : M2Printf_printf1 ((const char *) "seen procedure: %a\\n", 20, (const unsigned char *) &scopename, (sizeof (scopename)-1));
1581 : : }
1582 : 3004534 : currentScope->scopeName = scopename;
1583 : : }
1584 : 9959900 : }
1585 : :
1586 : :
1587 : : /*
1588 : : DepthScope - returns the depth of the scope stack.
1589 : : */
1590 : :
1591 : 0 : extern "C" unsigned int M2Error_DepthScope (void)
1592 : : {
1593 : 0 : return M2StackAddress_NoOfItemsInStackAddress (scopeStack);
1594 : : /* static analysis guarentees a RETURN statement will be used before here. */
1595 : : __builtin_unreachable ();
1596 : : }
1597 : :
1598 : :
1599 : : /*
1600 : : GetAnnounceScope - return message with the error scope attached to message.
1601 : : filename and message are treated as read only by this
1602 : : procedure function.
1603 : : */
1604 : :
1605 : 1249 : extern "C" DynamicStrings_String M2Error_GetAnnounceScope (DynamicStrings_String filename, DynamicStrings_String message)
1606 : : {
1607 : 1249 : DynamicStrings_String pre;
1608 : 1249 : DynamicStrings_String fmt;
1609 : 1249 : DynamicStrings_String desc;
1610 : 1249 : DynamicStrings_String quoted;
1611 : :
1612 : 1249 : if (filename == NULL)
1613 : : {
1614 : 1249 : pre = DynamicStrings_InitString ((const char *) "", 0);
1615 : : }
1616 : : else
1617 : : {
1618 : 0 : pre = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%s: ", 4)), (const unsigned char *) &filename, (sizeof (filename)-1));
1619 : : }
1620 : 1249 : if (! (IsErrorScopeNul (currentScope)))
1621 : : {
1622 : 1249 : quoted = DynamicStrings_InitString ((const char *) "", 0);
1623 : 1249 : quoted = M2ColorString_quoteOpen (quoted);
1624 : 1249 : quoted = DynamicStrings_ConCat (quoted, DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (currentScope->scopeName))));
1625 : 1249 : quoted = M2ColorString_quoteClose (quoted);
1626 : : }
1627 : 1249 : if (currentScope == NULL)
1628 : : {
1629 : 0 : desc = DynamicStrings_InitString ((const char *) "no scope active", 15);
1630 : : }
1631 : : else
1632 : : {
1633 : 1249 : switch (currentScope->scopeKind)
1634 : : {
1635 : 30 : case M2Error_definition:
1636 : 30 : desc = DynamicStrings_InitString ((const char *) "In definition module", 20);
1637 : 30 : break;
1638 : :
1639 : 24 : case M2Error_implementation:
1640 : 24 : desc = DynamicStrings_InitString ((const char *) "In implementation module", 24);
1641 : 24 : break;
1642 : :
1643 : 664 : case M2Error_program:
1644 : 664 : desc = DynamicStrings_InitString ((const char *) "In program module", 17);
1645 : 664 : break;
1646 : :
1647 : 12 : case M2Error_module:
1648 : 12 : desc = DynamicStrings_InitString ((const char *) "In inner module", 15);
1649 : 12 : break;
1650 : :
1651 : 519 : case M2Error_procedure:
1652 : 519 : desc = DynamicStrings_InitString ((const char *) "In procedure", 12);
1653 : 519 : break;
1654 : :
1655 : 0 : case M2Error_noscope:
1656 : 0 : desc = DynamicStrings_InitString ((const char *) "Unknown scope", 13);
1657 : 0 : break;
1658 : :
1659 : :
1660 : 0 : default:
1661 : 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2Error.def", 20, 1);
1662 : 0 : __builtin_unreachable ();
1663 : : }
1664 : : }
1665 : 1249 : fmt = DynamicStrings_ConCat (pre, DynamicStrings_Mark (desc));
1666 : 1249 : if (IsErrorScopeNul (currentScope))
1667 : : {
1668 : 0 : fmt = DynamicStrings_ConCat (fmt, FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ": ", 2))));
1669 : : }
1670 : : else
1671 : : {
1672 : 1249 : fmt = DynamicStrings_ConCat (fmt, FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) " %s: ", 5)), (const unsigned char *) "ed, (sizeof (quoted)-1)));
1673 : : }
1674 : 1249 : return DynamicStrings_ConCat (fmt, message);
1675 : : /* static analysis guarentees a RETURN statement will be used before here. */
1676 : : __builtin_unreachable ();
1677 : : }
1678 : :
1679 : :
1680 : : /*
1681 : : DefaultProgramModule - sets up an unnamed program scope before the Ident is seen.
1682 : : */
1683 : :
1684 : 57408 : extern "C" void M2Error_DefaultProgramModule (void)
1685 : : {
1686 : 57408 : M2StackAddress_PushAddress (scopeStack, reinterpret_cast <void *> (currentScope));
1687 : 57408 : currentScope = newErrorScope (M2Error_program);
1688 : 57408 : }
1689 : :
1690 : :
1691 : : /*
1692 : : DefaultImplementationModule - sets up an unnamed implementation
1693 : : scope before the Ident is seen.
1694 : : */
1695 : :
1696 : 271175 : extern "C" void M2Error_DefaultImplementationModule (void)
1697 : : {
1698 : 271175 : M2StackAddress_PushAddress (scopeStack, reinterpret_cast <void *> (currentScope));
1699 : 271175 : currentScope = newErrorScope (M2Error_implementation);
1700 : 271175 : }
1701 : :
1702 : :
1703 : : /*
1704 : : DefaultDefinitionModule - sets up an unnamed definition
1705 : : scope before the Ident is seen.
1706 : : */
1707 : :
1708 : 604230 : extern "C" void M2Error_DefaultDefinitionModule (void)
1709 : : {
1710 : 604230 : M2StackAddress_PushAddress (scopeStack, reinterpret_cast <void *> (currentScope));
1711 : 604230 : currentScope = newErrorScope (M2Error_definition);
1712 : 604230 : }
1713 : :
1714 : :
1715 : : /*
1716 : : DefaultInnerModule - sets up an unnamed inner
1717 : : scope before the Ident is seen.
1718 : : */
1719 : :
1720 : 2100 : extern "C" void M2Error_DefaultInnerModule (void)
1721 : : {
1722 : 2100 : M2StackAddress_PushAddress (scopeStack, reinterpret_cast <void *> (currentScope));
1723 : 2100 : currentScope = newErrorScope (M2Error_module);
1724 : 2100 : }
1725 : :
1726 : :
1727 : : /*
1728 : : DefaultProcedure - sets up an unnamed procedure
1729 : : scope before the Ident is seen.
1730 : : */
1731 : :
1732 : 15007586 : extern "C" void M2Error_DefaultProcedure (void)
1733 : : {
1734 : 15007586 : M2StackAddress_PushAddress (scopeStack, reinterpret_cast <void *> (currentScope));
1735 : 15007586 : currentScope = newErrorScope (M2Error_procedure);
1736 : 15007586 : }
1737 : :
1738 : :
1739 : : /*
1740 : : EnterErrorScope - pushes the currentScope and sets currentScope to scope.
1741 : : */
1742 : :
1743 : 83154704 : extern "C" void M2Error_EnterErrorScope (M2Error_ErrorScope scope)
1744 : : {
1745 : 83154704 : M2StackAddress_PushAddress (scopeStack, reinterpret_cast <void *> (currentScope));
1746 : 83154704 : currentScope = static_cast<M2Error_ErrorScope__opaque> (scope);
1747 : 83154704 : }
1748 : :
1749 : :
1750 : : /*
1751 : : LeaveErrorScope - leave the current scope and pop into the previous one.
1752 : : */
1753 : :
1754 : 97935834 : extern "C" void M2Error_LeaveErrorScope (void)
1755 : : {
1756 : 97935834 : currentScope = static_cast<M2Error_ErrorScope__opaque> (M2StackAddress_PopAddress (scopeStack));
1757 : 97935834 : }
1758 : :
1759 : :
1760 : : /*
1761 : : GetCurrentErrorScope - returns currentScope.
1762 : : */
1763 : :
1764 : 10432906 : extern "C" M2Error_ErrorScope M2Error_GetCurrentErrorScope (void)
1765 : : {
1766 : 10432906 : return static_cast<M2Error_ErrorScope> (currentScope);
1767 : : /* static analysis guarentees a RETURN statement will be used before here. */
1768 : : __builtin_unreachable ();
1769 : : }
1770 : :
1771 : :
1772 : : /*
1773 : : ResetErrorScope - should be called at the start of each pass to
1774 : : reset the error scope index.
1775 : : */
1776 : :
1777 : 60156 : extern "C" void M2Error_ResetErrorScope (void)
1778 : : {
1779 : 60156 : scopeIndex = 0;
1780 : 60156 : }
1781 : :
1782 : 15260 : extern "C" void _M2_M2Error_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1783 : : {
1784 : 15260 : Init ();
1785 : 15260 : }
1786 : :
1787 : 0 : extern "C" void _M2_M2Error_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1788 : : {
1789 : 0 : }
|