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