Line data Source code
1 : /* do not edit automatically generated by mc from M2MetaError. */
2 : /* M2MetaError.mod provides a set of high level error routines.
3 :
4 : Copyright (C) 2008-2026 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 : #include <safe-ctype.h>
45 : #if defined(__cplusplus)
46 : # undef NULL
47 : # define NULL 0
48 : #endif
49 : #define _M2MetaError_C
50 :
51 : #include "GM2MetaError.h"
52 : # include "GM2Base.h"
53 : # include "GNameKey.h"
54 : # include "GStrLib.h"
55 : # include "GM2LexBuf.h"
56 : # include "GM2Error.h"
57 : # include "GFIO.h"
58 : # include "GSFIO.h"
59 : # include "GStringConvert.h"
60 : # include "GM2Printf.h"
61 : # include "GM2Options.h"
62 : # include "GStrCase.h"
63 : # include "Glibc.h"
64 : # include "GSYSTEM.h"
65 : # include "GM2Debug.h"
66 : # include "GStorage.h"
67 : # include "GIndexing.h"
68 : # include "GDynamicStrings.h"
69 : # include "GSymbolTable.h"
70 : # include "GM2ColorString.h"
71 : # include "GFilterError.h"
72 : # include "GM2StackSpell.h"
73 : # include "GM2RTS.h"
74 :
75 : # define MaxStack 10
76 : # define Debugging false
77 : # define ColorDebug false
78 : typedef struct M2MetaError_GetTokProcedure_p M2MetaError_GetTokProcedure;
79 :
80 : typedef struct M2MetaError_errorBlock_r M2MetaError_errorBlock;
81 :
82 : typedef struct M2MetaError__T1_a M2MetaError__T1;
83 :
84 : typedef struct M2MetaError__T2_r M2MetaError__T2;
85 :
86 : typedef M2MetaError__T2 *M2MetaError_dictionaryEntry;
87 :
88 : typedef enum {M2MetaError_none, M2MetaError_error, M2MetaError_warning, M2MetaError_note, M2MetaError_chained, M2MetaError_aborta} M2MetaError_errorType;
89 :
90 : typedef enum {M2MetaError_unsetColor, M2MetaError_noColor, M2MetaError_quoteColor, M2MetaError_filenameColor, M2MetaError_errorColor, M2MetaError_warningColor, M2MetaError_noteColor, M2MetaError_keywordColor, M2MetaError_locusColor, M2MetaError_insertColor, M2MetaError_deleteColor, M2MetaError_typeColor, M2MetaError_range1Color, M2MetaError_range2Color} M2MetaError_colorType;
91 :
92 : typedef unsigned int (*M2MetaError_GetTokProcedure_t) (unsigned int);
93 : struct M2MetaError_GetTokProcedure_p { M2MetaError_GetTokProcedure_t proc; };
94 :
95 : struct M2MetaError__T1_a { M2MetaError_colorType array[MaxStack+1]; };
96 : struct M2MetaError__T2_r {
97 : DynamicStrings_String key;
98 : DynamicStrings_String value;
99 : M2MetaError_dictionaryEntry next;
100 : };
101 :
102 : struct M2MetaError_errorBlock_r {
103 : bool useError;
104 : M2Error_Error e;
105 : unsigned int symcause;
106 : unsigned int token;
107 : M2MetaError_errorType type;
108 : DynamicStrings_String out;
109 : DynamicStrings_String in;
110 : unsigned int highplus1;
111 : int len;
112 : int ini;
113 : bool vowel;
114 : bool filterDef;
115 : bool filterVar;
116 : bool filterType;
117 : bool filterConst;
118 : bool importHint;
119 : bool exportHint;
120 : bool withStackHint;
121 : bool glyph;
122 : bool chain;
123 : bool root;
124 : bool quotes;
125 : bool positive;
126 : M2MetaError_colorType currentCol;
127 : M2MetaError_colorType beginCol;
128 : M2MetaError_colorType endCol;
129 : M2MetaError__T1 colorStack;
130 : unsigned int stackPtr;
131 : };
132 :
133 : static M2Error_Error lastRoot;
134 : static M2MetaError_colorType lastColor;
135 : static bool seenAbort;
136 : static Indexing_Index dictionary;
137 : static Indexing_Index outputStack;
138 : static M2MetaError_dictionaryEntry freeEntry;
139 : static FilterError_Filter FilterUnknown;
140 : extern "C" void M2MetaError_MetaError0 (const char *m_, unsigned int _m_high);
141 : extern "C" void M2MetaError_MetaError1 (const char *m_, unsigned int _m_high, unsigned int s);
142 : extern "C" void M2MetaError_MetaError2 (const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2);
143 : extern "C" void M2MetaError_MetaError3 (const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3);
144 : extern "C" void M2MetaError_MetaError4 (const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
145 :
146 : /*
147 : wrapErrors -
148 : */
149 :
150 : extern "C" void M2MetaError_MetaErrors1 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s);
151 :
152 : /*
153 : wrapErrors -
154 : */
155 :
156 : extern "C" void M2MetaError_MetaErrors2 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2);
157 :
158 : /*
159 : wrapErrors -
160 : */
161 :
162 : extern "C" void M2MetaError_MetaErrors3 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3);
163 :
164 : /*
165 : wrapErrors -
166 : */
167 :
168 : extern "C" void M2MetaError_MetaErrors4 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
169 : extern "C" void M2MetaError_MetaErrorT0 (unsigned int tok, const char *m_, unsigned int _m_high);
170 : extern "C" void M2MetaError_MetaErrorT1 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s);
171 : extern "C" void M2MetaError_MetaErrorT2 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2);
172 : extern "C" void M2MetaError_MetaErrorT3 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3);
173 : extern "C" void M2MetaError_MetaErrorT4 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
174 :
175 : /*
176 : wrapErrors -
177 : */
178 :
179 : extern "C" void M2MetaError_MetaErrorsT1 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s);
180 :
181 : /*
182 : wrapErrors -
183 : */
184 :
185 : extern "C" void M2MetaError_MetaErrorsT2 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2);
186 :
187 : /*
188 : wrapErrors -
189 : */
190 :
191 : extern "C" void M2MetaError_MetaErrorsT3 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3);
192 :
193 : /*
194 : wrapErrors -
195 : */
196 :
197 : extern "C" void M2MetaError_MetaErrorsT4 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
198 :
199 : /*
200 : wrapErrors -
201 : */
202 :
203 : extern "C" void M2MetaError_MetaErrorString0 (DynamicStrings_String m);
204 :
205 : /*
206 : wrapErrors -
207 : */
208 :
209 : extern "C" void M2MetaError_MetaErrorString1 (DynamicStrings_String m, unsigned int s);
210 :
211 : /*
212 : wrapErrors -
213 : */
214 :
215 : extern "C" void M2MetaError_MetaErrorString2 (DynamicStrings_String m, unsigned int s1, unsigned int s2);
216 :
217 : /*
218 : wrapErrors -
219 : */
220 :
221 : extern "C" void M2MetaError_MetaErrorString3 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3);
222 :
223 : /*
224 : wrapErrors -
225 : */
226 :
227 : extern "C" void M2MetaError_MetaErrorString4 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
228 : extern "C" void M2MetaError_MetaErrorStringT0 (unsigned int tok, DynamicStrings_String m);
229 : extern "C" void M2MetaError_MetaErrorStringT1 (unsigned int tok, DynamicStrings_String m, unsigned int s);
230 : extern "C" void M2MetaError_MetaErrorStringT2 (unsigned int tok, DynamicStrings_String m, unsigned int s1, unsigned int s2);
231 : extern "C" void M2MetaError_MetaErrorStringT3 (unsigned int tok, DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3);
232 : extern "C" void M2MetaError_MetaErrorStringT4 (unsigned int tok, DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
233 :
234 : /*
235 : MetaErrorN1 -
236 : */
237 :
238 : extern "C" void M2MetaError_MetaErrorN1 (const char *m_, unsigned int _m_high, NameKey_Name n);
239 :
240 : /*
241 : MetaErrorN2 -
242 : */
243 :
244 : extern "C" void M2MetaError_MetaErrorN2 (const char *m_, unsigned int _m_high, NameKey_Name n1, NameKey_Name n2);
245 :
246 : /*
247 : MetaErrorNT0 - generate an error message at tok using format.
248 : */
249 :
250 : extern "C" void M2MetaError_MetaErrorNT0 (unsigned int tok, const char *format_, unsigned int _format_high);
251 :
252 : /*
253 : MetaErrorNT1 - generate an error message at tok using format and name.
254 : The format should contain %a for name substitution.
255 : */
256 :
257 : extern "C" void M2MetaError_MetaErrorNT1 (unsigned int tok, const char *format_, unsigned int _format_high, NameKey_Name name);
258 : extern "C" void M2MetaError_MetaErrorNT2 (unsigned int tok, const char *format_, unsigned int _format_high, NameKey_Name name1, NameKey_Name name2);
259 :
260 : /*
261 : wrapString - return a string which has been formatted with the specifier codes.
262 : Color is disabled. The result string is returned.
263 : */
264 :
265 : extern "C" DynamicStrings_String M2MetaError_MetaString0 (DynamicStrings_String m);
266 :
267 : /*
268 : wrapString - return a string which has been formatted with the specifier codes.
269 : Color is disabled. The result string is returned.
270 : */
271 :
272 : extern "C" DynamicStrings_String M2MetaError_MetaString1 (DynamicStrings_String m, unsigned int s);
273 :
274 : /*
275 : wrapString - return a string which has been formatted with the specifier codes.
276 : Color is disabled. The result string is returned.
277 : */
278 :
279 : extern "C" DynamicStrings_String M2MetaError_MetaString2 (DynamicStrings_String m, unsigned int s1, unsigned int s2);
280 :
281 : /*
282 : wrapString - return a string which has been formatted with the specifier codes.
283 : Color is disabled. The result string is returned.
284 : */
285 :
286 : extern "C" DynamicStrings_String M2MetaError_MetaString3 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3);
287 :
288 : /*
289 : wrapString - return a string which has been formatted with the specifier codes.
290 : Color is disabled. The result string is returned.
291 : */
292 :
293 : extern "C" DynamicStrings_String M2MetaError_MetaString4 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4);
294 :
295 : /*
296 : MetaErrorDecl - if sym is a variable or parameter then generate a
297 : declaration error or warning message. If error is
298 : FALSE then a warning is issued.
299 : */
300 :
301 : extern "C" void M2MetaError_MetaErrorDecl (unsigned int sym, bool error);
302 :
303 : /*
304 : pushOutput -
305 : */
306 :
307 : static void pushOutput (M2MetaError_errorBlock *eb);
308 :
309 : /*
310 : readWord - reads and returns a word delimited by '}' it uses '%' as
311 : the escape character.
312 : */
313 :
314 : static DynamicStrings_String readWord (M2MetaError_errorBlock *eb);
315 :
316 : /*
317 : addEntry -
318 : */
319 :
320 : static void addEntry (DynamicStrings_String key, DynamicStrings_String value);
321 :
322 : /*
323 : popOutput -
324 : */
325 :
326 : static void popOutput (M2MetaError_errorBlock *eb);
327 :
328 : /*
329 : newEntry -
330 : */
331 :
332 : static M2MetaError_dictionaryEntry newEntry (void);
333 :
334 : /*
335 : killEntry - dispose e and delete any strings.
336 : */
337 :
338 : static void killEntry (M2MetaError_dictionaryEntry e);
339 :
340 : /*
341 : resetDictionary - remove all entries in the dictionary.
342 : */
343 :
344 : static void resetDictionary (void);
345 :
346 : /*
347 : lookupString - lookup and return a duplicate of the string value for key s.
348 : NIL is returned if the key s is unknown.
349 : */
350 :
351 : static DynamicStrings_String lookupString (DynamicStrings_String s);
352 :
353 : /*
354 : lookupDefine - looks up the word in the input string (ending with '}').
355 : It uses this word as a key into the dictionary and returns
356 : the entry.
357 : */
358 :
359 : static DynamicStrings_String lookupDefine (M2MetaError_errorBlock *eb);
360 :
361 : /*
362 : processDefine - place contents of dictionary entry name onto the output string.
363 : */
364 :
365 : static void processDefine (M2MetaError_errorBlock *eb);
366 :
367 : /*
368 : lookupColor - looks up the color enum from the string.
369 : */
370 :
371 : static M2MetaError_colorType lookupColor (DynamicStrings_String s);
372 :
373 : /*
374 : readColor -
375 : */
376 :
377 : static M2MetaError_colorType readColor (M2MetaError_errorBlock *eb);
378 :
379 : /*
380 : keyword - copy characters until the '}' in the input string and convert them to
381 : the keyword color/font.
382 : */
383 :
384 : static void keyword (M2MetaError_errorBlock *eb);
385 :
386 : /*
387 : filename - copy characters until the '}' in the input string and convert them to
388 : the filename color/font.
389 : */
390 :
391 : static void filename (M2MetaError_errorBlock *eb);
392 :
393 : /*
394 : pushColor -
395 : */
396 :
397 : static void pushColor (M2MetaError_errorBlock *eb);
398 :
399 : /*
400 : popColor -
401 : */
402 :
403 : static void popColor (M2MetaError_errorBlock *eb);
404 :
405 : /*
406 : initErrorBlock - initialise an error block with the, input, string.
407 : */
408 :
409 : static void initErrorBlock (M2MetaError_errorBlock *eb, DynamicStrings_String input, const unsigned int *sym_, unsigned int _sym_high);
410 :
411 : /*
412 : push - performs a push from the oldblock to the newblock.
413 : It copies all fields except the output string.
414 : */
415 :
416 : static void push (M2MetaError_errorBlock *newblock, M2MetaError_errorBlock oldblock);
417 :
418 : /*
419 : pop - copies contents of fromblock into toblock. It only copies the error
420 : handle if the toblock.e is NIL.
421 : */
422 :
423 : static void pop (M2MetaError_errorBlock *toblock, M2MetaError_errorBlock *fromblock);
424 :
425 : /*
426 : OutOpenQuote -
427 : */
428 :
429 : static void OutOpenQuote (M2MetaError_errorBlock *eb);
430 :
431 : /*
432 : OutCloseQuote -
433 : */
434 :
435 : static void OutCloseQuote (M2MetaError_errorBlock *eb);
436 :
437 : /*
438 : findColorType - return the color of the string. This is determined by the first
439 : occurrance of an error, warning or note marker. An error message
440 : is assumed to either be: a keyword category, error category, note
441 : category, warning category or to be chained from a previous error.
442 : */
443 :
444 : static M2MetaError_colorType findColorType (DynamicStrings_String s);
445 :
446 : /*
447 : killErrorBlock - deallocates the dynamic strings associated with the error block.
448 : */
449 :
450 : static void killErrorBlock (M2MetaError_errorBlock *eb);
451 :
452 : /*
453 : InternalFormat - produces an informative internal error.
454 : */
455 :
456 : static void InternalFormat (M2MetaError_errorBlock eb, const char *m_, unsigned int _m_high, unsigned int line);
457 :
458 : /*
459 : x - checks to see that a=b.
460 : */
461 :
462 : static DynamicStrings_String x (DynamicStrings_String a, DynamicStrings_String b);
463 :
464 : /*
465 : IsWhite - returns TRUE if, ch, is a space.
466 : */
467 :
468 : static bool IsWhite (char ch);
469 :
470 : /*
471 : skip - skips over this level input until the next '}'.
472 : */
473 :
474 : static void skip (M2MetaError_errorBlock *sb);
475 :
476 : /*
477 : ifNonNulThen := [ ':' ebnf ] =:
478 : */
479 :
480 : static void ifNonNulThen (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high);
481 :
482 : /*
483 : doNumber -
484 : */
485 :
486 : static void doNumber (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
487 :
488 : /*
489 : doCount -
490 : */
491 :
492 : static void doCount (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
493 :
494 : /*
495 : doCount -
496 : */
497 :
498 : static void doAscii (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
499 :
500 : /*
501 : unquotedKeyword -
502 : */
503 :
504 : static void unquotedKeyword (M2MetaError_errorBlock *eb);
505 :
506 : /*
507 : OutArray -
508 : */
509 :
510 : static void OutArray (M2MetaError_errorBlock *eb, const char *a_, unsigned int _a_high);
511 :
512 : /*
513 : OutGlyphS - outputs a string of glyphs.
514 : */
515 :
516 : static void OutGlyphS (M2MetaError_errorBlock *eb, DynamicStrings_String s);
517 :
518 : /*
519 : empty - returns TRUE if the output string is empty.
520 : It ignores color changes.
521 : */
522 :
523 : static bool empty (M2MetaError_errorBlock *eb);
524 :
525 : /*
526 : checkVowel - checks to see if the from block word starts with
527 : a vowel and if so adds an n to the to block output.
528 : */
529 :
530 : static void checkVowel (M2MetaError_errorBlock *to, M2MetaError_errorBlock from);
531 :
532 : /*
533 : isVowel - returns TRUE if ch is a, e, i, o or u.
534 : */
535 :
536 : static bool isVowel (char ch);
537 :
538 : /*
539 : clear - remove the output string.
540 : */
541 :
542 : static void clear (M2MetaError_errorBlock *eb);
543 :
544 : /*
545 : clear - remove the output string.
546 : */
547 :
548 : static void doName (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
549 :
550 : /*
551 : clear - remove the output string.
552 : */
553 :
554 : static void doQualified (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
555 :
556 : /*
557 : doType - returns a string containing the type name of
558 : sym.
559 : */
560 :
561 : static void doType (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
562 :
563 : /*
564 : doSkipType - will skip all pseudonym types. It also
565 : returns the type symbol found and name.
566 : */
567 :
568 : static void doSkipType (M2MetaError_errorBlock eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
569 :
570 : /*
571 : doGetType - attempts to get the type of sym[bol].
572 : */
573 :
574 : static void doGetType (M2MetaError_errorBlock *eb, unsigned int *sym, unsigned int _sym_high, unsigned int bol);
575 :
576 : /*
577 : doGetSkipType - will skip all pseudonym types. It also
578 : returns the type symbol found and name.
579 : */
580 :
581 : static void doGetSkipType (M2MetaError_errorBlock *eb, unsigned int *sym, unsigned int _sym_high, unsigned int bol);
582 :
583 : /*
584 : doChain -
585 : */
586 :
587 : static void doChain (M2MetaError_errorBlock *eb, unsigned int tok);
588 :
589 : /*
590 : doError - creates and returns an error note.
591 : */
592 :
593 : static void doError (M2MetaError_errorBlock *eb, unsigned int tok, unsigned int sym);
594 :
595 : /*
596 : defaultError - adds the default error location to, tok,
597 : if one has not already been assigned.
598 : */
599 :
600 : static void defaultError (M2MetaError_errorBlock *eb, unsigned int tok);
601 :
602 : /*
603 : updateTokSym - assign symcause to sym if not NulSym.
604 : Update token.
605 : */
606 :
607 : static void updateTokSym (M2MetaError_errorBlock *eb, unsigned int tok, unsigned int sym);
608 :
609 : /*
610 : chooseError - choose the error kind dependant upon type.
611 : Either an error, warning or note will be generated.
612 : */
613 :
614 : static void chooseError (M2MetaError_errorBlock *eb, unsigned int tok, unsigned int sym);
615 :
616 : /*
617 : doErrorScopeModule -
618 : */
619 :
620 : static void doErrorScopeModule (M2MetaError_errorBlock *eb, unsigned int sym);
621 :
622 : /*
623 : doErrorScopeForward -
624 : */
625 :
626 : static void doErrorScopeForward (M2MetaError_errorBlock *eb, unsigned int sym);
627 :
628 : /*
629 : doErrorScopeMod - potentially create an error referring to the definition
630 : module, fall back to the implementation or program module if
631 : there is no declaration in the definition module.
632 : */
633 :
634 : static void doErrorScopeMod (M2MetaError_errorBlock *eb, unsigned int sym);
635 :
636 : /*
637 : doErrorScopeFor - potentially create an error referring to the
638 : forward declaration, definition module, fall back
639 : to the implementation or program module if
640 : there is no declaration in the definition module.
641 : */
642 :
643 : static void doErrorScopeFor (M2MetaError_errorBlock *eb, unsigned int sym);
644 : static void declaredMod (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
645 :
646 : /*
647 : doErrorScopeDefinition - use the declaration in the definitio module if one is available.
648 : */
649 :
650 : static void doErrorScopeDefinition (M2MetaError_errorBlock *eb, unsigned int sym);
651 :
652 : /*
653 : doErrorScopeDef - potentially create an error referring to the definition
654 : module, fall back to the implementation or program module if
655 : there is no declaration in the definition module.
656 : */
657 :
658 : static void doErrorScopeDef (M2MetaError_errorBlock *eb, unsigned int sym);
659 : static void declaredDef (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
660 : static void declaredFor (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
661 :
662 : /*
663 : doErrorScopeProc - determine the location for the error or warning from
664 : the default declaration. For example parameters can be
665 : declared in definition, forward or in modules (proper procedure).
666 : Use GetVarParamTok to obtain a variable or parameter location.
667 : */
668 :
669 : static void doErrorScopeProc (M2MetaError_errorBlock *eb, unsigned int sym, M2MetaError_GetTokProcedure GetVarParamTok);
670 : static void declaredVar (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
671 : static void declaredType (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
672 : static void declaredFull (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
673 :
674 : /*
675 : used - creates an error note where sym[bol] was first used.
676 : */
677 :
678 : static void used (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
679 :
680 : /*
681 : symDesc -
682 : */
683 :
684 : static DynamicStrings_String symDesc (unsigned int sym);
685 :
686 : /*
687 : doDesc -
688 : */
689 :
690 : static void doDesc (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
691 :
692 : /*
693 : op := {'!'|'a'|'c'|'d'|'k'|'n'|'p'|'q'|'s'|'t'|'u'|'v'|
694 : 'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'K'|'M'|'N'|
695 : 'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'|
696 : '&' } then =:
697 : */
698 :
699 : static void op (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
700 :
701 : /*
702 : continuation := {':'|'1'|'2'|'3'|'4'|'i'|'s'|'x'|'w'|'D'|'T'|'V'|'C'} =:
703 : */
704 :
705 : static void continuation (M2MetaError_errorBlock *eb, unsigned int *sym, unsigned int _sym_high, unsigned int bol);
706 :
707 : /*
708 : percenttoken := '%' (
709 : '1' % doOperand(1) %
710 : op
711 : | '2' % doOperand(2) %
712 : op
713 : | '3' % doOperand(3) %
714 : op
715 : | '4' % doOperand(4) %
716 : op
717 : )
718 : } =:
719 : */
720 :
721 : static void percenttoken (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high);
722 :
723 : /*
724 : IsPunct - returns TRUE if ch is a punctuation character.
725 : */
726 :
727 : static bool IsPunct (char ch);
728 :
729 : /*
730 : JoinSentances - join s onto eb. It removes trailing
731 : spaces from eb if s starts with a punctuation
732 : character.
733 : */
734 :
735 : static void JoinSentances (M2MetaError_errorBlock *eb, DynamicStrings_String s);
736 :
737 : /*
738 : ConfigureFilter -
739 : */
740 :
741 : static void ConfigureFilter (M2MetaError_errorBlock eb);
742 :
743 : /*
744 : SpellHint -
745 : */
746 :
747 : static void SpellHint (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol);
748 :
749 : /*
750 : AddImportsHint -
751 : */
752 :
753 : static void AddImportsHint (M2MetaError_errorBlock *eb);
754 :
755 : /*
756 : AddExportsHint -
757 : */
758 :
759 : static void AddExportsHint (M2MetaError_errorBlock *eb);
760 :
761 : /*
762 : AddWithStackHint -
763 : */
764 :
765 : static void AddWithStackHint (M2MetaError_errorBlock *eb);
766 :
767 : /*
768 : FilterOnDefinitionModule - turn on filtering and include all the definition modules.
769 : */
770 :
771 : static void FilterOnDefinitionModule (M2MetaError_errorBlock *eb);
772 :
773 : /*
774 : FilterOnType -
775 : */
776 :
777 : static void FilterOnType (M2MetaError_errorBlock *eb);
778 :
779 : /*
780 : FilterOnConst -
781 : */
782 :
783 : static void FilterOnConst (M2MetaError_errorBlock *eb);
784 :
785 : /*
786 : FilterOnVariable -
787 : */
788 :
789 : static void FilterOnVariable (M2MetaError_errorBlock *eb);
790 :
791 : /*
792 : changeColor - changes to color, c.
793 : */
794 :
795 : static void changeColor (M2MetaError_errorBlock *eb, M2MetaError_colorType c);
796 :
797 : /*
798 : shutdownColor - shutdown existing color if it exists.
799 : */
800 :
801 : static void shutdownColor (M2MetaError_errorBlock *eb);
802 :
803 : /*
804 : flushColor - flushes any outstanding color change.
805 : */
806 :
807 : static void flushColor (M2MetaError_errorBlock *eb);
808 :
809 : /*
810 : emitColorGCC -
811 : */
812 :
813 : static void emitColorGCC (M2MetaError_errorBlock *eb, M2MetaError_colorType c);
814 :
815 : /*
816 : emitColorTag -
817 : */
818 :
819 : static void emitColorTag (M2MetaError_errorBlock *eb, M2MetaError_colorType c);
820 :
821 : /*
822 : emitColor - adds the appropriate color string to the output string.
823 : */
824 :
825 : static void emitColor (M2MetaError_errorBlock *eb, M2MetaError_colorType c);
826 :
827 : /*
828 : openQuote -
829 : */
830 :
831 : static DynamicStrings_String openQuote (DynamicStrings_String s);
832 :
833 : /*
834 : closeQuote -
835 : */
836 :
837 : static DynamicStrings_String closeQuote (DynamicStrings_String s);
838 :
839 : /*
840 : colorEnd -
841 : */
842 :
843 : static DynamicStrings_String colorEnd (DynamicStrings_String s);
844 :
845 : /*
846 : copyChar - copies a character from in string to out string.
847 : */
848 :
849 : static void copyChar (M2MetaError_errorBlock *eb);
850 :
851 : /*
852 : copyKeywordChar - copies a character from in string to out string
853 : it will convert the character to lower case if the
854 : -fm2-lower-case option was specified.
855 : */
856 :
857 : static void copyKeywordChar (M2MetaError_errorBlock *eb);
858 :
859 : /*
860 : percent := '%' anych % copy anych %
861 : =:
862 : */
863 :
864 : static void percent (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high);
865 :
866 : /*
867 : lbra := '{' [ '!' ] percenttoken '}' =:
868 : */
869 :
870 : static void lbra (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high);
871 :
872 : /*
873 : lbra := '{' [ '!' ] percenttoken '}' =:
874 : */
875 :
876 : static void stop (void);
877 :
878 : /*
879 : lbra := '{' [ '!' ] percenttoken '}' =:
880 : */
881 :
882 : static void checkMe (void);
883 :
884 : /*
885 : dumpErrorType -
886 : */
887 :
888 : static void dumpErrorType (M2MetaError_errorType e);
889 :
890 : /*
891 : dumpColorType -
892 : */
893 :
894 : static void dumpColorType (M2MetaError_colorType c);
895 :
896 : /*
897 : dump -
898 :
899 : */
900 :
901 : static void dump (M2MetaError_errorBlock eb);
902 :
903 : /*
904 : ebnf := { percent
905 : | lbra
906 : | any % copy ch %
907 : }
908 : =:
909 : */
910 :
911 : static void ebnf (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high);
912 :
913 : /*
914 : isUniqueError - return TRUE if the symbol associated with the
915 : error block is unknown and we have seen the same
916 : token before.
917 : */
918 :
919 : static bool isUniqueError (M2MetaError_errorBlock *eb);
920 :
921 : /*
922 : wrapErrors -
923 : */
924 :
925 : static void wrapErrors (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, const unsigned int *sym_, unsigned int _sym_high);
926 :
927 : /*
928 : checkAbort - checks to see if the boolean flag seenAbort has been set,
929 : if so it flushes all existing errors and terminates.
930 : */
931 :
932 : static void checkAbort (void);
933 :
934 : /*
935 : translate -
936 : */
937 :
938 : static DynamicStrings_String translate (DynamicStrings_String m, DynamicStrings_String s, int *i, NameKey_Name name);
939 :
940 : /*
941 : wrapString - return a string which has been formatted with the specifier codes.
942 : Color is disabled. The result string is returned.
943 : */
944 :
945 : static DynamicStrings_String wrapString (DynamicStrings_String m, const unsigned int *sym_, unsigned int _sym_high);
946 :
947 :
948 : /*
949 : pushOutput -
950 : */
951 :
952 0 : static void pushOutput (M2MetaError_errorBlock *eb)
953 : {
954 0 : Indexing_PutIndice (outputStack, (Indexing_HighIndice (outputStack))+1, reinterpret_cast <void *> ((*eb).out));
955 0 : (*eb).out = DynamicStrings_InitString ((const char *) "", 0);
956 0 : (*eb).glyph = false;
957 0 : }
958 :
959 :
960 : /*
961 : readWord - reads and returns a word delimited by '}' it uses '%' as
962 : the escape character.
963 : */
964 :
965 0 : static DynamicStrings_String readWord (M2MetaError_errorBlock *eb)
966 : {
967 0 : DynamicStrings_String word;
968 :
969 0 : word = DynamicStrings_InitString ((const char *) "", 0);
970 0 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
971 : {
972 0 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
973 : {
974 0 : (*eb).ini += 1;
975 : }
976 0 : word = DynamicStrings_ConCatChar (word, DynamicStrings_char ((*eb).in, (*eb).ini));
977 0 : (*eb).ini += 1;
978 : }
979 0 : return word;
980 : /* static analysis guarentees a RETURN statement will be used before here. */
981 : __builtin_unreachable ();
982 : }
983 :
984 :
985 : /*
986 : addEntry -
987 : */
988 :
989 0 : static void addEntry (DynamicStrings_String key, DynamicStrings_String value)
990 : {
991 0 : M2MetaError_dictionaryEntry e;
992 0 : DynamicStrings_String s;
993 0 : unsigned int i;
994 :
995 0 : s = lookupString (key);
996 0 : if (s == NULL)
997 : {
998 0 : e = newEntry ();
999 0 : e->key = key;
1000 0 : e->value = value;
1001 0 : Indexing_PutIndice (dictionary, (Indexing_HighIndice (dictionary))+1, reinterpret_cast <void *> (e));
1002 : }
1003 : else
1004 : {
1005 : i = 1;
1006 0 : while (i <= (Indexing_HighIndice (dictionary)))
1007 : {
1008 0 : e = static_cast<M2MetaError_dictionaryEntry> (Indexing_GetIndice (dictionary, i));
1009 0 : if (DynamicStrings_Equal (e->key, key))
1010 : {
1011 0 : e->value = DynamicStrings_KillString (e->value);
1012 0 : e->value = value;
1013 0 : return;
1014 : }
1015 0 : i += 1;
1016 : }
1017 : }
1018 : }
1019 :
1020 :
1021 : /*
1022 : popOutput -
1023 : */
1024 :
1025 0 : static void popOutput (M2MetaError_errorBlock *eb)
1026 : {
1027 0 : DynamicStrings_String key;
1028 0 : DynamicStrings_String previous;
1029 :
1030 0 : if ((Indexing_HighIndice (outputStack)) >= 1)
1031 : {
1032 0 : previous = static_cast<DynamicStrings_String> (Indexing_GetIndice (outputStack, Indexing_HighIndice (outputStack)));
1033 0 : Indexing_DeleteIndice (outputStack, Indexing_HighIndice (outputStack));
1034 0 : key = readWord (eb);
1035 0 : addEntry (key, (*eb).out);
1036 0 : (*eb).out = previous;
1037 : }
1038 0 : }
1039 :
1040 :
1041 : /*
1042 : newEntry -
1043 : */
1044 :
1045 0 : static M2MetaError_dictionaryEntry newEntry (void)
1046 : {
1047 0 : M2MetaError_dictionaryEntry e;
1048 :
1049 0 : if (freeEntry == NULL)
1050 : {
1051 0 : Storage_ALLOCATE ((void **) &e, sizeof (M2MetaError__T2));
1052 : }
1053 : else
1054 : {
1055 0 : e = freeEntry;
1056 0 : freeEntry = freeEntry->next;
1057 : }
1058 0 : e->key = static_cast<DynamicStrings_String> (NULL);
1059 0 : e->value = static_cast<DynamicStrings_String> (NULL);
1060 0 : e->next = NULL;
1061 0 : return e;
1062 : /* static analysis guarentees a RETURN statement will be used before here. */
1063 : __builtin_unreachable ();
1064 : }
1065 :
1066 :
1067 : /*
1068 : killEntry - dispose e and delete any strings.
1069 : */
1070 :
1071 0 : static void killEntry (M2MetaError_dictionaryEntry e)
1072 : {
1073 0 : e->next = freeEntry;
1074 0 : freeEntry = e;
1075 0 : if (e->key != NULL)
1076 : {
1077 0 : e->key = DynamicStrings_KillString (e->key);
1078 : }
1079 0 : if (e->value != NULL)
1080 : {
1081 0 : e->value = DynamicStrings_KillString (e->value);
1082 : }
1083 0 : }
1084 :
1085 :
1086 : /*
1087 : resetDictionary - remove all entries in the dictionary.
1088 : */
1089 :
1090 0 : static void resetDictionary (void)
1091 : {
1092 0 : unsigned int i;
1093 0 : M2MetaError_dictionaryEntry e;
1094 :
1095 0 : i = 1;
1096 0 : while (i <= (Indexing_HighIndice (dictionary)))
1097 : {
1098 0 : e = static_cast<M2MetaError_dictionaryEntry> (Indexing_GetIndice (dictionary, i));
1099 0 : killEntry (e);
1100 0 : i += 1;
1101 : }
1102 0 : dictionary = Indexing_KillIndex (dictionary);
1103 0 : dictionary = Indexing_InitIndex (1);
1104 0 : }
1105 :
1106 :
1107 : /*
1108 : lookupString - lookup and return a duplicate of the string value for key s.
1109 : NIL is returned if the key s is unknown.
1110 : */
1111 :
1112 0 : static DynamicStrings_String lookupString (DynamicStrings_String s)
1113 : {
1114 0 : unsigned int i;
1115 0 : M2MetaError_dictionaryEntry e;
1116 :
1117 0 : i = 1;
1118 0 : while (i <= (Indexing_HighIndice (dictionary)))
1119 : {
1120 0 : e = static_cast<M2MetaError_dictionaryEntry> (Indexing_GetIndice (dictionary, i));
1121 0 : if (DynamicStrings_Equal (e->key, s))
1122 : {
1123 0 : return DynamicStrings_Dup (e->value);
1124 : }
1125 0 : i += 1;
1126 : }
1127 : return static_cast<DynamicStrings_String> (NULL);
1128 : /* static analysis guarentees a RETURN statement will be used before here. */
1129 : __builtin_unreachable ();
1130 : }
1131 :
1132 :
1133 : /*
1134 : lookupDefine - looks up the word in the input string (ending with '}').
1135 : It uses this word as a key into the dictionary and returns
1136 : the entry.
1137 : */
1138 :
1139 0 : static DynamicStrings_String lookupDefine (M2MetaError_errorBlock *eb)
1140 : {
1141 0 : DynamicStrings_String s;
1142 :
1143 0 : s = DynamicStrings_InitString ((const char *) "", 0);
1144 0 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
1145 : {
1146 0 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
1147 : {
1148 0 : (*eb).ini += 1;
1149 : }
1150 0 : s = DynamicStrings_ConCatChar (s, DynamicStrings_char ((*eb).in, (*eb).ini));
1151 0 : (*eb).ini += 1;
1152 : }
1153 0 : s = lookupString (s);
1154 0 : if (s == NULL)
1155 : {
1156 0 : s = DynamicStrings_InitString ((const char *) "", 0);
1157 : }
1158 0 : return s;
1159 : /* static analysis guarentees a RETURN statement will be used before here. */
1160 : __builtin_unreachable ();
1161 : }
1162 :
1163 :
1164 : /*
1165 : processDefine - place contents of dictionary entry name onto the output string.
1166 : */
1167 :
1168 0 : static void processDefine (M2MetaError_errorBlock *eb)
1169 : {
1170 0 : (*eb).out = DynamicStrings_ConCat ((*eb).out, lookupDefine (eb));
1171 0 : }
1172 :
1173 :
1174 : /*
1175 : lookupColor - looks up the color enum from the string.
1176 : */
1177 :
1178 0 : static M2MetaError_colorType lookupColor (DynamicStrings_String s)
1179 : {
1180 0 : if (DynamicStrings_EqualArray (s, (const char *) "filename", 8))
1181 : {
1182 : return M2MetaError_filenameColor;
1183 : }
1184 0 : else if (DynamicStrings_EqualArray (s, (const char *) "quote", 5))
1185 : {
1186 : /* avoid dangling else. */
1187 : return M2MetaError_quoteColor;
1188 : }
1189 0 : else if (DynamicStrings_EqualArray (s, (const char *) "error", 5))
1190 : {
1191 : /* avoid dangling else. */
1192 : return M2MetaError_errorColor;
1193 : }
1194 0 : else if (DynamicStrings_EqualArray (s, (const char *) "warning", 7))
1195 : {
1196 : /* avoid dangling else. */
1197 : return M2MetaError_warningColor;
1198 : }
1199 0 : else if (DynamicStrings_EqualArray (s, (const char *) "note", 4))
1200 : {
1201 : /* avoid dangling else. */
1202 : return M2MetaError_warningColor;
1203 : }
1204 0 : else if (DynamicStrings_EqualArray (s, (const char *) "locus", 5))
1205 : {
1206 : /* avoid dangling else. */
1207 : return M2MetaError_locusColor;
1208 : }
1209 0 : else if (DynamicStrings_EqualArray (s, (const char *) "insert", 6))
1210 : {
1211 : /* avoid dangling else. */
1212 : return M2MetaError_insertColor;
1213 : }
1214 0 : else if (DynamicStrings_EqualArray (s, (const char *) "delete", 6))
1215 : {
1216 : /* avoid dangling else. */
1217 : return M2MetaError_deleteColor;
1218 : }
1219 0 : else if (DynamicStrings_EqualArray (s, (const char *) "type", 4))
1220 : {
1221 : /* avoid dangling else. */
1222 : return M2MetaError_typeColor;
1223 : }
1224 0 : else if (DynamicStrings_EqualArray (s, (const char *) "range1", 6))
1225 : {
1226 : /* avoid dangling else. */
1227 : return M2MetaError_range1Color;
1228 : }
1229 0 : else if (DynamicStrings_EqualArray (s, (const char *) "range2", 6))
1230 : {
1231 : /* avoid dangling else. */
1232 0 : return M2MetaError_range2Color;
1233 : }
1234 : return M2MetaError_noColor;
1235 : /* static analysis guarentees a RETURN statement will be used before here. */
1236 : __builtin_unreachable ();
1237 : }
1238 :
1239 :
1240 : /*
1241 : readColor -
1242 : */
1243 :
1244 0 : static M2MetaError_colorType readColor (M2MetaError_errorBlock *eb)
1245 : {
1246 0 : DynamicStrings_String s;
1247 0 : M2MetaError_colorType c;
1248 :
1249 0 : s = DynamicStrings_InitString ((const char *) "", 0);
1250 0 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
1251 : {
1252 0 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
1253 : {
1254 0 : (*eb).ini += 1;
1255 : }
1256 0 : s = DynamicStrings_ConCatChar (s, DynamicStrings_char ((*eb).in, (*eb).ini));
1257 0 : (*eb).ini += 1;
1258 : }
1259 0 : c = lookupColor (s);
1260 0 : s = DynamicStrings_KillString (s);
1261 0 : return c;
1262 : /* static analysis guarentees a RETURN statement will be used before here. */
1263 : __builtin_unreachable ();
1264 : }
1265 :
1266 :
1267 : /*
1268 : keyword - copy characters until the '}' in the input string and convert them to
1269 : the keyword color/font.
1270 : */
1271 :
1272 1186 : static void keyword (M2MetaError_errorBlock *eb)
1273 : {
1274 1186 : if (TOUPPER (DynamicStrings_char ((*eb).in, (*eb).ini)) == 'K')
1275 : {
1276 1186 : (*eb).ini += 1;
1277 1186 : pushColor (eb);
1278 1186 : changeColor (eb, M2MetaError_keywordColor);
1279 6295 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
1280 : {
1281 5109 : if (Debugging)
1282 : {
1283 : dump ((*eb));
1284 : }
1285 5109 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
1286 : {
1287 12 : (*eb).ini += 1;
1288 : }
1289 5109 : copyKeywordChar (eb);
1290 5109 : (*eb).ini += 1;
1291 : }
1292 1186 : popColor (eb);
1293 : }
1294 : else
1295 : {
1296 0 : M2Error_InternalError ((const char *) "expecting index to be on the K for keyword", 42);
1297 : }
1298 1186 : }
1299 :
1300 :
1301 : /*
1302 : filename - copy characters until the '}' in the input string and convert them to
1303 : the filename color/font.
1304 : */
1305 :
1306 0 : static void filename (M2MetaError_errorBlock *eb)
1307 : {
1308 0 : if (TOUPPER (DynamicStrings_char ((*eb).in, (*eb).ini)) == 'F')
1309 : {
1310 0 : (*eb).ini += 1;
1311 0 : pushColor (eb);
1312 0 : changeColor (eb, M2MetaError_filenameColor);
1313 0 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
1314 : {
1315 0 : if (Debugging)
1316 : {
1317 : dump ((*eb));
1318 : }
1319 0 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
1320 : {
1321 0 : (*eb).ini += 1;
1322 : }
1323 0 : copyChar (eb);
1324 0 : (*eb).ini += 1;
1325 : }
1326 0 : popColor (eb);
1327 : }
1328 : else
1329 : {
1330 0 : M2Error_InternalError ((const char *) "expecting index to be on the F for filename", 43);
1331 : }
1332 0 : }
1333 :
1334 :
1335 : /*
1336 : pushColor -
1337 : */
1338 :
1339 53183 : static void pushColor (M2MetaError_errorBlock *eb)
1340 : {
1341 53183 : if ((*eb).stackPtr > MaxStack)
1342 : {
1343 0 : M2RTS_HALT (-1);
1344 : __builtin_unreachable ();
1345 : }
1346 : else
1347 : {
1348 53183 : (*eb).colorStack.array[(*eb).stackPtr] = (*eb).currentCol;
1349 53183 : (*eb).stackPtr += 1;
1350 : }
1351 53183 : }
1352 :
1353 :
1354 : /*
1355 : popColor -
1356 : */
1357 :
1358 13761 : static void popColor (M2MetaError_errorBlock *eb)
1359 : {
1360 13761 : if ((*eb).stackPtr > 0)
1361 : {
1362 13761 : (*eb).stackPtr -= 1;
1363 : }
1364 : else
1365 : {
1366 0 : M2RTS_HALT (-1);
1367 : __builtin_unreachable ();
1368 : }
1369 13761 : (*eb).currentCol = (*eb).colorStack.array[(*eb).stackPtr];
1370 13761 : if ((*eb).currentCol == M2MetaError_unsetColor)
1371 : {
1372 0 : (*eb).currentCol = M2MetaError_noColor;
1373 : }
1374 13761 : }
1375 :
1376 :
1377 : /*
1378 : initErrorBlock - initialise an error block with the, input, string.
1379 : */
1380 :
1381 16820 : static void initErrorBlock (M2MetaError_errorBlock *eb, DynamicStrings_String input, const unsigned int *sym_, unsigned int _sym_high)
1382 : {
1383 16820 : unsigned int sym[_sym_high+1];
1384 :
1385 : /* make a local copy of each unbounded array. */
1386 16820 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
1387 :
1388 16820 : (*eb).useError = true;
1389 16820 : (*eb).e = static_cast<M2Error_Error> (NULL);
1390 16820 : (*eb).symcause = SymbolTable_NulSym;
1391 16820 : (*eb).token = M2LexBuf_UnknownTokenNo;
1392 16820 : (*eb).type = M2MetaError_error; /* Default to the error color. */
1393 33640 : (*eb).out = DynamicStrings_InitString ((const char *) "", 0); /* Default to the error color. */
1394 16820 : (*eb).in = input;
1395 16820 : (*eb).highplus1 = _sym_high+1;
1396 16820 : (*eb).len = DynamicStrings_Length (input);
1397 16820 : (*eb).ini = 0;
1398 16820 : (*eb).glyph = false; /* Nothing to output yet. */
1399 16820 : (*eb).vowel = false; /* Check for a vowel when outputing string? */
1400 16820 : (*eb).filterDef = false; /* Filter on definition module list. */
1401 16820 : (*eb).filterType = false; /* Filter on type. */
1402 16820 : (*eb).filterConst = false; /* Filter on const. */
1403 16820 : (*eb).filterVar = false; /* Filter on variable. */
1404 16820 : (*eb).importHint = false; /* Filter on variable. */
1405 16820 : (*eb).exportHint = false;
1406 16820 : (*eb).withStackHint = false;
1407 16820 : (*eb).quotes = true;
1408 16820 : (*eb).positive = true;
1409 16820 : (*eb).root = false;
1410 16820 : (*eb).chain = false;
1411 16820 : (*eb).currentCol = findColorType (input);
1412 16820 : (*eb).beginCol = M2MetaError_unsetColor;
1413 16820 : (*eb).endCol = M2MetaError_unsetColor;
1414 16820 : (*eb).stackPtr = 0;
1415 16820 : }
1416 :
1417 :
1418 : /*
1419 : push - performs a push from the oldblock to the newblock.
1420 : It copies all fields except the output string.
1421 : */
1422 :
1423 42609 : static void push (M2MetaError_errorBlock *newblock, M2MetaError_errorBlock oldblock)
1424 : {
1425 42609 : pushColor (&oldblock); /* Save the current color. */
1426 42609 : (*newblock) = oldblock; /* Now copy all the fields. */
1427 42609 : (*newblock).out = static_cast<DynamicStrings_String> (NULL); /* We must do this before a clear as we have copied the address. */
1428 42609 : clear (newblock); /* We must do this before a clear as we have copied the address. */
1429 42609 : (*newblock).quotes = true;
1430 42609 : }
1431 :
1432 :
1433 : /*
1434 : pop - copies contents of fromblock into toblock. It only copies the error
1435 : handle if the toblock.e is NIL.
1436 : */
1437 :
1438 42609 : static void pop (M2MetaError_errorBlock *toblock, M2MetaError_errorBlock *fromblock)
1439 : {
1440 42609 : M2MetaError_colorType c;
1441 :
1442 42609 : checkVowel (toblock, (*fromblock));
1443 42609 : if (empty (fromblock))
1444 : {
1445 3187 : (*toblock).stackPtr = (*fromblock).stackPtr;
1446 3187 : (*toblock).colorStack = (*fromblock).colorStack;
1447 3187 : popColor (toblock); /* Lastly restore the color from the push start. */
1448 : }
1449 : else
1450 : {
1451 39422 : if ((*fromblock).quotes)
1452 : {
1453 : /* The string needs to be quoted. */
1454 30034 : if ((*toblock).currentCol == M2MetaError_unsetColor)
1455 : {
1456 : /* The caller has not yet assigned a color, so use the callee color at the end. */
1457 0 : OutOpenQuote (toblock);
1458 0 : OutGlyphS (toblock, (*fromblock).out);
1459 0 : OutCloseQuote (toblock);
1460 0 : changeColor (toblock, (*fromblock).currentCol);
1461 : }
1462 : else
1463 : {
1464 30034 : shutdownColor (fromblock);
1465 : /* The caller has assigned a color, so use it after the new string. */
1466 30034 : c = (*toblock).currentCol;
1467 30034 : OutOpenQuote (toblock);
1468 30034 : OutGlyphS (toblock, (*fromblock).out);
1469 30034 : OutCloseQuote (toblock);
1470 30034 : (*toblock).currentCol = c;
1471 : }
1472 : }
1473 : else
1474 : {
1475 9388 : if ((*toblock).currentCol == M2MetaError_unsetColor)
1476 : {
1477 0 : JoinSentances (toblock, (*fromblock).out);
1478 0 : (*toblock).endCol = (*fromblock).endCol;
1479 0 : changeColor (toblock, (*fromblock).endCol);
1480 : }
1481 : else
1482 : {
1483 9388 : pushColor (toblock);
1484 9388 : JoinSentances (toblock, (*fromblock).out);
1485 9388 : (*toblock).endCol = (*fromblock).endCol;
1486 9388 : popColor (toblock);
1487 : }
1488 : }
1489 : }
1490 42609 : if ((*toblock).e == NULL)
1491 : {
1492 42229 : (*toblock).e = (*fromblock).e;
1493 : }
1494 42609 : if ((*toblock).symcause == SymbolTable_NulSym)
1495 : {
1496 20671 : (*toblock).symcause = (*fromblock).symcause;
1497 : }
1498 42609 : (*toblock).chain = (*fromblock).chain;
1499 42609 : (*toblock).root = (*fromblock).root;
1500 42609 : (*toblock).ini = (*fromblock).ini;
1501 42609 : (*toblock).type = (*fromblock).type; /* It might have been changed by the callee. */
1502 42609 : }
1503 :
1504 :
1505 : /*
1506 : OutOpenQuote -
1507 : */
1508 :
1509 30034 : static void OutOpenQuote (M2MetaError_errorBlock *eb)
1510 : {
1511 30034 : (*eb).currentCol = M2MetaError_noColor;
1512 30034 : flushColor (eb);
1513 60068 : (*eb).out = DynamicStrings_ConCat ((*eb).out, openQuote (DynamicStrings_InitString ((const char *) "", 0)));
1514 30034 : }
1515 :
1516 :
1517 : /*
1518 : OutCloseQuote -
1519 : */
1520 :
1521 30034 : static void OutCloseQuote (M2MetaError_errorBlock *eb)
1522 : {
1523 60068 : (*eb).out = DynamicStrings_ConCat ((*eb).out, closeQuote (DynamicStrings_InitString ((const char *) "", 0)));
1524 30034 : (*eb).currentCol = M2MetaError_noColor;
1525 30034 : (*eb).endCol = M2MetaError_noColor;
1526 30034 : }
1527 :
1528 :
1529 : /*
1530 : findColorType - return the color of the string. This is determined by the first
1531 : occurrance of an error, warning or note marker. An error message
1532 : is assumed to either be: a keyword category, error category, note
1533 : category, warning category or to be chained from a previous error.
1534 : */
1535 :
1536 16862 : static M2MetaError_colorType findColorType (DynamicStrings_String s)
1537 : {
1538 16862 : unsigned int i;
1539 :
1540 16862 : i = 0;
1541 758200 : while (i < (DynamicStrings_Length (s)))
1542 : {
1543 754787 : if ((DynamicStrings_char (s, static_cast<int> (i))) == '{')
1544 : {
1545 19999 : i += 1;
1546 19999 : if ((DynamicStrings_char (s, static_cast<int> (i))) == '%')
1547 : {
1548 19998 : i += 1;
1549 57942 : while ((i < (DynamicStrings_Length (s))) && ((DynamicStrings_char (s, static_cast<int> (i))) != '}'))
1550 : {
1551 51393 : if ((DynamicStrings_char (s, static_cast<int> (i))) == '%')
1552 : {
1553 66 : i += 1;
1554 : }
1555 51393 : switch (DynamicStrings_char (s, static_cast<int> (i)))
1556 : {
1557 : case 'K':
1558 : return M2MetaError_errorColor; /* keyword errors start with the fatal error color. */
1559 : break;
1560 :
1561 : case 'E':
1562 : return M2MetaError_errorColor; /* keyword errors start with the fatal error color. */
1563 : break;
1564 :
1565 : case 'A':
1566 : return M2MetaError_errorColor;
1567 38 : break;
1568 :
1569 38 : case 'O':
1570 38 : return M2MetaError_noteColor;
1571 11220 : break;
1572 :
1573 11220 : case 'W':
1574 11220 : return M2MetaError_warningColor;
1575 186 : break;
1576 :
1577 186 : case 'C':
1578 186 : return lastColor;
1579 37944 : break;
1580 :
1581 :
1582 37944 : default:
1583 37944 : break;
1584 : }
1585 37944 : i += 1;
1586 : }
1587 : }
1588 : }
1589 741338 : i += 1;
1590 : }
1591 : return M2MetaError_errorColor; /* default to the error color. */
1592 : /* static analysis guarentees a RETURN statement will be used before here. */
1593 : __builtin_unreachable ();
1594 : }
1595 :
1596 :
1597 : /*
1598 : killErrorBlock - deallocates the dynamic strings associated with the error block.
1599 : */
1600 :
1601 16820 : static void killErrorBlock (M2MetaError_errorBlock *eb)
1602 : {
1603 16820 : (*eb).out = DynamicStrings_KillString ((*eb).out);
1604 16820 : (*eb).in = DynamicStrings_KillString ((*eb).in);
1605 16820 : }
1606 :
1607 :
1608 : /*
1609 : InternalFormat - produces an informative internal error.
1610 : */
1611 :
1612 0 : static void InternalFormat (M2MetaError_errorBlock eb, const char *m_, unsigned int _m_high, unsigned int line)
1613 : {
1614 0 : char m[_m_high+1];
1615 :
1616 : /* make a local copy of each unbounded array. */
1617 0 : memcpy (m, m_, _m_high+1);
1618 :
1619 0 : M2Printf_printf1 ((const char *) "M2MetaError.mod:%d:internalformat error detected\\n", 50, (const unsigned char *) &line, (sizeof (line)-1));
1620 0 : dump (eb);
1621 0 : M2Error_InternalError ((const char *) m, _m_high);
1622 : }
1623 :
1624 :
1625 : /*
1626 : x - checks to see that a=b.
1627 : */
1628 :
1629 1538556 : static DynamicStrings_String x (DynamicStrings_String a, DynamicStrings_String b)
1630 : {
1631 0 : if (a != b)
1632 : {
1633 0 : M2Error_InternalError ((const char *) "different string returned", 25);
1634 : }
1635 0 : return a;
1636 : /* static analysis guarentees a RETURN statement will be used before here. */
1637 : __builtin_unreachable ();
1638 : }
1639 :
1640 :
1641 : /*
1642 : IsWhite - returns TRUE if, ch, is a space.
1643 : */
1644 :
1645 0 : static bool IsWhite (char ch)
1646 : {
1647 0 : return ch == ' ';
1648 : /* static analysis guarentees a RETURN statement will be used before here. */
1649 : __builtin_unreachable ();
1650 : }
1651 :
1652 :
1653 : /*
1654 : skip - skips over this level input until the next '}'.
1655 : */
1656 :
1657 1238 : static void skip (M2MetaError_errorBlock *sb)
1658 : {
1659 1238 : int level;
1660 :
1661 1238 : level = 0;
1662 20840 : while ((*sb).ini < (*sb).len)
1663 : {
1664 20840 : if ((level == 0) && ((DynamicStrings_char ((*sb).in, (*sb).ini)) == '}'))
1665 : {
1666 : return;
1667 : }
1668 19602 : if ((DynamicStrings_char ((*sb).in, (*sb).ini)) == '}')
1669 : {
1670 3036 : level -= 1;
1671 : }
1672 16566 : else if ((DynamicStrings_char ((*sb).in, (*sb).ini)) == '{')
1673 : {
1674 : /* avoid dangling else. */
1675 3036 : level += 1;
1676 : }
1677 19602 : (*sb).ini += 1;
1678 : }
1679 : }
1680 :
1681 :
1682 : /*
1683 : ifNonNulThen := [ ':' ebnf ] =:
1684 : */
1685 :
1686 6880 : static void ifNonNulThen (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high)
1687 : {
1688 6880 : unsigned int sym[_sym_high+1];
1689 :
1690 : /* make a local copy of each unbounded array. */
1691 6880 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
1692 :
1693 6880 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == ':')
1694 : {
1695 6880 : (*eb).ini += 1;
1696 6880 : if ((*eb).positive)
1697 : {
1698 : /* avoid dangling else. */
1699 1112 : if ((empty (eb)) && ((DynamicStrings_Length ((*eb).out)) != 0))
1700 : {
1701 0 : M2Printf_printf0 ((const char *) "inconsistency found\\n", 21);
1702 0 : dump ((*eb));
1703 : }
1704 6752 : if (empty (eb))
1705 : {
1706 1112 : if (Debugging)
1707 : {
1708 : M2Printf_printf0 ((const char *) "empty expression, skip\\n", 24);
1709 : }
1710 1112 : clear (eb);
1711 : /* skip over this level of input text. */
1712 1112 : skip (eb);
1713 : }
1714 : else
1715 : {
1716 5640 : if (Debugging)
1717 : {
1718 : dump ((*eb));
1719 : M2Printf_printf0 ((const char *) "non empty expression, clear and continue\\n", 42);
1720 : }
1721 5640 : clear (eb);
1722 5640 : if (Debugging)
1723 : {
1724 : dump ((*eb));
1725 : M2Printf_printf0 ((const char *) "cleared, continue\\n", 19);
1726 : dump ((*eb));
1727 : }
1728 : /* carry on processing input text. */
1729 5640 : ebnf (eb, (const unsigned int *) sym, _sym_high);
1730 5640 : if (Debugging)
1731 : {
1732 : M2Printf_printf0 ((const char *) "evaluated\\n", 11);
1733 : dump ((*eb));
1734 : }
1735 : }
1736 : }
1737 : else
1738 : {
1739 128 : if (empty (eb))
1740 : {
1741 2 : clear (eb);
1742 : /* carry on processing input text. */
1743 2 : ebnf (eb, (const unsigned int *) sym, _sym_high);
1744 : }
1745 : else
1746 : {
1747 126 : clear (eb);
1748 : /* skip over this level of input text. */
1749 126 : skip (eb);
1750 : }
1751 : }
1752 6880 : if (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
1753 : {
1754 0 : InternalFormat ((*eb), (const char *) "expecting to see }", 18, 889);
1755 : }
1756 : }
1757 6880 : }
1758 :
1759 :
1760 : /*
1761 : doNumber -
1762 : */
1763 :
1764 0 : static void doNumber (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
1765 : {
1766 0 : unsigned int sym[_sym_high+1];
1767 :
1768 : /* make a local copy of each unbounded array. */
1769 0 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
1770 :
1771 0 : if (empty (eb))
1772 : {
1773 0 : (*eb).quotes = false;
1774 0 : OutGlyphS (eb, StringConvert_ctos (sym[bol], 0, ' '));
1775 : }
1776 0 : }
1777 :
1778 :
1779 : /*
1780 : doCount -
1781 : */
1782 :
1783 2148 : static void doCount (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
1784 : {
1785 2148 : unsigned int sym[_sym_high+1];
1786 :
1787 : /* make a local copy of each unbounded array. */
1788 2148 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
1789 :
1790 2148 : if (empty (eb))
1791 : {
1792 2148 : (*eb).quotes = false;
1793 2148 : OutGlyphS (eb, StringConvert_ctos (sym[bol], 0, ' '));
1794 2148 : if (((sym[bol] % 100) >= 11) && ((sym[bol] % 100) <= 13))
1795 : {
1796 0 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "th", 2)));
1797 : }
1798 :
1799 : else {
1800 2148 : switch (sym[bol] % 10)
1801 : {
1802 1740 : case 1:
1803 1740 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "st", 2)));
1804 1740 : break;
1805 :
1806 348 : case 2:
1807 348 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "nd", 2)));
1808 348 : break;
1809 :
1810 24 : case 3:
1811 24 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "rd", 2)));
1812 24 : break;
1813 :
1814 :
1815 36 : default:
1816 36 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "th", 2)));
1817 36 : break;
1818 : }
1819 : }
1820 : }
1821 4296 : }
1822 :
1823 :
1824 : /*
1825 : doCount -
1826 : */
1827 :
1828 35293 : static void doAscii (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
1829 : {
1830 35293 : unsigned int sym[_sym_high+1];
1831 :
1832 : /* make a local copy of each unbounded array. */
1833 35293 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
1834 :
1835 35251 : if ((((sym[bol] == SymbolTable_NulSym) || (! (empty (eb)))) || (SymbolTable_IsTemporary (sym[bol]))) || (SymbolTable_IsNameAnonymous (sym[bol])))
1836 : {
1837 156 : return;
1838 : }
1839 : else
1840 : {
1841 35137 : OutGlyphS (eb, DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (sym[bol]))));
1842 : }
1843 35293 : }
1844 :
1845 :
1846 : /*
1847 : unquotedKeyword -
1848 : */
1849 :
1850 637 : static void unquotedKeyword (M2MetaError_errorBlock *eb)
1851 : {
1852 637 : (*eb).quotes = false;
1853 0 : keyword (eb);
1854 0 : }
1855 :
1856 :
1857 : /*
1858 : OutArray -
1859 : */
1860 :
1861 78 : static void OutArray (M2MetaError_errorBlock *eb, const char *a_, unsigned int _a_high)
1862 : {
1863 78 : char a[_a_high+1];
1864 :
1865 : /* make a local copy of each unbounded array. */
1866 78 : memcpy (a, a_, _a_high+1);
1867 :
1868 78 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)));
1869 78 : }
1870 :
1871 :
1872 : /*
1873 : OutGlyphS - outputs a string of glyphs.
1874 : */
1875 :
1876 70650 : static void OutGlyphS (M2MetaError_errorBlock *eb, DynamicStrings_String s)
1877 : {
1878 70650 : if ((DynamicStrings_Length (s)) > 0)
1879 : {
1880 70650 : flushColor (eb);
1881 70650 : checkMe ();
1882 70650 : (*eb).glyph = true;
1883 70650 : (*eb).out = DynamicStrings_ConCat ((*eb).out, s);
1884 : }
1885 70650 : }
1886 :
1887 :
1888 : /*
1889 : empty - returns TRUE if the output string is empty.
1890 : It ignores color changes.
1891 : */
1892 :
1893 157268 : static bool empty (M2MetaError_errorBlock *eb)
1894 : {
1895 88000 : return ! (*eb).glyph;
1896 : /* static analysis guarentees a RETURN statement will be used before here. */
1897 : __builtin_unreachable ();
1898 : }
1899 :
1900 :
1901 : /*
1902 : checkVowel - checks to see if the from block word starts with
1903 : a vowel and if so adds an n to the to block output.
1904 : */
1905 :
1906 42609 : static void checkVowel (M2MetaError_errorBlock *to, M2MetaError_errorBlock from)
1907 : {
1908 42609 : if (from.vowel && (! (empty (&from))))
1909 : {
1910 180 : if (isVowel (DynamicStrings_char (from.out, 0)))
1911 : {
1912 24 : if ((DynamicStrings_Length ((*to).out)) > 0)
1913 : {
1914 24 : (*to).out = DynamicStrings_RemoveWhitePostfix (DynamicStrings_Mark ((*to).out));
1915 24 : (*to).out = DynamicStrings_ConCat ((*to).out, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "n ", 2)));
1916 24 : from.vowel = false;
1917 : }
1918 : }
1919 : }
1920 42609 : }
1921 :
1922 :
1923 : /*
1924 : isVowel - returns TRUE if ch is a, e, i, o or u.
1925 : */
1926 :
1927 180 : static bool isVowel (char ch)
1928 : {
1929 180 : return ((((ch == 'a') || (ch == 'e')) || (ch == 'i')) || (ch == 'o')) || (ch == 'u');
1930 : /* static analysis guarentees a RETURN statement will be used before here. */
1931 : __builtin_unreachable ();
1932 : }
1933 :
1934 :
1935 : /*
1936 : clear - remove the output string.
1937 : */
1938 :
1939 49489 : static void clear (M2MetaError_errorBlock *eb)
1940 : {
1941 49489 : (*eb).out = DynamicStrings_KillString ((*eb).out);
1942 49489 : (*eb).out = DynamicStrings_InitString ((const char *) "", 0);
1943 49489 : (*eb).glyph = false;
1944 49489 : (*eb).beginCol = M2MetaError_unsetColor;
1945 49489 : (*eb).quotes = false;
1946 49489 : }
1947 :
1948 :
1949 : /*
1950 : clear - remove the output string.
1951 : */
1952 :
1953 28962 : static void doName (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
1954 : {
1955 28962 : unsigned int sym[_sym_high+1];
1956 :
1957 : /* make a local copy of each unbounded array. */
1958 28962 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
1959 :
1960 23432 : if ((((! (empty (eb))) || (sym[bol] == SymbolTable_NulSym)) || (SymbolTable_IsTemporary (sym[bol]))) || (SymbolTable_IsNameAnonymous (sym[bol])))
1961 : {
1962 8405 : return;
1963 : }
1964 : else
1965 : {
1966 20557 : if (sym[bol] == M2Base_ZType)
1967 : {
1968 60 : (*eb).quotes = false;
1969 60 : OutArray (eb, (const char *) "the ZType", 9);
1970 : }
1971 20497 : else if (sym[bol] == M2Base_RType)
1972 : {
1973 : /* avoid dangling else. */
1974 18 : (*eb).quotes = false;
1975 18 : OutArray (eb, (const char *) "the RType", 9);
1976 : }
1977 : else
1978 : {
1979 : /* avoid dangling else. */
1980 20479 : doAscii (eb, (const unsigned int *) sym, _sym_high, bol);
1981 : }
1982 : }
1983 28962 : }
1984 :
1985 :
1986 : /*
1987 : clear - remove the output string.
1988 : */
1989 :
1990 0 : static void doQualified (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
1991 : {
1992 0 : typedef struct doQualified__T3_a doQualified__T3;
1993 :
1994 0 : struct doQualified__T3_a { unsigned int array[1+1]; };
1995 0 : doQualified__T3 mod;
1996 0 : unsigned int sym[_sym_high+1];
1997 :
1998 : /* make a local copy of each unbounded array. */
1999 0 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2000 :
2001 0 : if ((((! (empty (eb))) || (sym[bol] == SymbolTable_NulSym)) || (SymbolTable_IsTemporary (sym[bol]))) || (SymbolTable_IsNameAnonymous (sym[bol])))
2002 : {
2003 0 : return;
2004 : }
2005 : else
2006 : {
2007 0 : mod.array[0] = SymbolTable_GetScope (sym[bol]);
2008 0 : if ((SymbolTable_IsDefImp (mod.array[0])) && (SymbolTable_IsExported (mod.array[0], sym[bol])))
2009 : {
2010 0 : doAscii (eb, (const unsigned int *) &mod.array[0], 1, 0);
2011 0 : OutArray (eb, (const char *) ".", 1);
2012 0 : OutGlyphS (eb, DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (SymbolTable_GetSymName (sym[bol])))));
2013 : }
2014 : else
2015 : {
2016 0 : doAscii (eb, (const unsigned int *) sym, _sym_high, bol);
2017 : }
2018 : }
2019 0 : }
2020 :
2021 :
2022 : /*
2023 : doType - returns a string containing the type name of
2024 : sym.
2025 : */
2026 :
2027 14796 : static void doType (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2028 : {
2029 14796 : unsigned int sym[_sym_high+1];
2030 :
2031 : /* make a local copy of each unbounded array. */
2032 14796 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2033 :
2034 14790 : if ((! (empty (eb))) || (sym[bol] == SymbolTable_NulSym))
2035 : {
2036 6 : return;
2037 : }
2038 : else
2039 : {
2040 14790 : const_cast<unsigned int *>(sym)[bol] = SymbolTable_GetType (sym[bol]);
2041 14790 : doAscii (eb, (const unsigned int *) sym, _sym_high, bol);
2042 : }
2043 14796 : }
2044 :
2045 :
2046 : /*
2047 : doSkipType - will skip all pseudonym types. It also
2048 : returns the type symbol found and name.
2049 : */
2050 :
2051 9534 : static void doSkipType (M2MetaError_errorBlock eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2052 : {
2053 9534 : unsigned int sym[_sym_high+1];
2054 :
2055 : /* make a local copy of each unbounded array. */
2056 9534 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2057 :
2058 24 : if ((! (empty (&eb))) || (sym[bol] == SymbolTable_NulSym))
2059 : {
2060 9510 : return;
2061 : }
2062 : else
2063 : {
2064 24 : const_cast<unsigned int *>(sym)[bol] = SymbolTable_SkipType (sym[bol]);
2065 24 : while ((SymbolTable_IsType (sym[bol])) && (((SymbolTable_GetSymName (sym[bol])) == NameKey_NulName) || (SymbolTable_IsNameAnonymous (sym[bol]))))
2066 : {
2067 0 : const_cast<unsigned int *>(sym)[bol] = SymbolTable_GetType (sym[bol]);
2068 : }
2069 24 : doAscii (&eb, (const unsigned int *) sym, _sym_high, bol);
2070 : }
2071 9534 : }
2072 :
2073 :
2074 : /*
2075 : doGetType - attempts to get the type of sym[bol].
2076 : */
2077 :
2078 0 : static void doGetType (M2MetaError_errorBlock *eb, unsigned int *sym, unsigned int _sym_high, unsigned int bol)
2079 : {
2080 0 : if (((bol > _sym_high) || (! (empty (eb)))) || (sym[bol] == SymbolTable_NulSym))
2081 : {
2082 : return;
2083 : }
2084 : else
2085 : {
2086 0 : const_cast<unsigned int *>(sym)[bol] = SymbolTable_GetType (sym[bol]);
2087 : }
2088 : }
2089 :
2090 :
2091 : /*
2092 : doGetSkipType - will skip all pseudonym types. It also
2093 : returns the type symbol found and name.
2094 : */
2095 :
2096 0 : static void doGetSkipType (M2MetaError_errorBlock *eb, unsigned int *sym, unsigned int _sym_high, unsigned int bol)
2097 : {
2098 0 : unsigned int prev;
2099 :
2100 0 : if (((bol > _sym_high) || (! (empty (eb)))) || (sym[bol] == SymbolTable_NulSym))
2101 : {
2102 : return;
2103 : }
2104 : else
2105 : {
2106 0 : do {
2107 0 : prev = sym[bol];
2108 0 : const_cast<unsigned int *>(sym)[bol] = SymbolTable_SkipType (sym[bol]);
2109 0 : if (((SymbolTable_IsType (sym[bol])) && (((SymbolTable_GetSymName (sym[bol])) == NameKey_NulName) || (SymbolTable_IsNameAnonymous (sym[bol])))) && ((SymbolTable_GetType (sym[bol])) != SymbolTable_NulSym))
2110 : {
2111 0 : const_cast<unsigned int *>(sym)[bol] = SymbolTable_GetType (sym[bol]);
2112 : }
2113 0 : } while (! (sym[bol] == prev));
2114 : }
2115 : }
2116 :
2117 :
2118 : /*
2119 : doChain -
2120 : */
2121 :
2122 162 : static void doChain (M2MetaError_errorBlock *eb, unsigned int tok)
2123 : {
2124 162 : if (lastRoot == NULL)
2125 : {
2126 0 : M2Error_InternalError ((const char *) "should not be chaining an error onto an empty error note", 56);
2127 : }
2128 : else
2129 : {
2130 162 : (*eb).e = M2Error_ChainError (tok, lastRoot);
2131 : }
2132 162 : }
2133 :
2134 :
2135 : /*
2136 : doError - creates and returns an error note.
2137 : */
2138 :
2139 3163 : static void doError (M2MetaError_errorBlock *eb, unsigned int tok, unsigned int sym)
2140 : {
2141 0 : if ((*eb).useError)
2142 : {
2143 3163 : chooseError (eb, tok, sym);
2144 : }
2145 0 : }
2146 :
2147 :
2148 : /*
2149 : defaultError - adds the default error location to, tok,
2150 : if one has not already been assigned.
2151 : */
2152 :
2153 3157 : static void defaultError (M2MetaError_errorBlock *eb, unsigned int tok)
2154 : {
2155 3157 : if ((*eb).e == NULL)
2156 : {
2157 2296 : doError (eb, tok, SymbolTable_NulSym);
2158 : }
2159 3157 : if ((*eb).token == M2LexBuf_UnknownTokenNo)
2160 : {
2161 921 : (*eb).token = tok;
2162 : }
2163 3157 : }
2164 :
2165 :
2166 : /*
2167 : updateTokSym - assign symcause to sym if not NulSym.
2168 : Update token.
2169 : */
2170 :
2171 3001 : static void updateTokSym (M2MetaError_errorBlock *eb, unsigned int tok, unsigned int sym)
2172 : {
2173 0 : if (sym != SymbolTable_NulSym)
2174 : {
2175 753 : (*eb).symcause = sym;
2176 : }
2177 3001 : (*eb).token = tok;
2178 0 : }
2179 :
2180 :
2181 : /*
2182 : chooseError - choose the error kind dependant upon type.
2183 : Either an error, warning or note will be generated.
2184 : */
2185 :
2186 3163 : static void chooseError (M2MetaError_errorBlock *eb, unsigned int tok, unsigned int sym)
2187 : {
2188 3163 : if ((*eb).chain)
2189 : {
2190 48 : doChain (eb, tok);
2191 : }
2192 : else
2193 : {
2194 3115 : switch ((*eb).type)
2195 : {
2196 114 : case M2MetaError_chained:
2197 114 : doChain (eb, tok);
2198 114 : break;
2199 :
2200 2367 : case M2MetaError_none:
2201 2367 : case M2MetaError_aborta:
2202 2367 : case M2MetaError_error:
2203 2367 : if ((*eb).e == NULL)
2204 : {
2205 2367 : (*eb).e = M2Error_NewError (tok);
2206 : }
2207 : else
2208 : {
2209 0 : (*eb).e = M2Error_MoveError ((*eb).e, tok);
2210 : }
2211 2367 : updateTokSym (eb, tok, sym);
2212 2367 : break;
2213 :
2214 600 : case M2MetaError_warning:
2215 600 : if ((*eb).e == NULL)
2216 : {
2217 600 : (*eb).e = M2Error_NewWarning (tok);
2218 : }
2219 : else
2220 : {
2221 0 : (*eb).e = M2Error_MoveError ((*eb).e, tok);
2222 : }
2223 600 : updateTokSym (eb, tok, sym);
2224 600 : break;
2225 :
2226 34 : case M2MetaError_note:
2227 34 : if ((*eb).e == NULL)
2228 : {
2229 34 : (*eb).e = M2Error_NewNote (tok);
2230 : }
2231 : else
2232 : {
2233 0 : (*eb).e = M2Error_MoveError ((*eb).e, tok);
2234 : }
2235 34 : updateTokSym (eb, tok, sym);
2236 34 : break;
2237 :
2238 :
2239 0 : default:
2240 0 : M2Error_InternalError ((const char *) "unexpected enumeration value", 28);
2241 3163 : break;
2242 : }
2243 : }
2244 3163 : if ((*eb).root)
2245 : {
2246 42 : lastRoot = (*eb).e;
2247 42 : lastColor = findColorType ((*eb).in);
2248 : }
2249 3163 : (*eb).e = M2Error_SetColor ((*eb).e);
2250 3163 : }
2251 :
2252 :
2253 : /*
2254 : doErrorScopeModule -
2255 : */
2256 :
2257 36 : static void doErrorScopeModule (M2MetaError_errorBlock *eb, unsigned int sym)
2258 : {
2259 36 : unsigned int scope;
2260 :
2261 36 : scope = SymbolTable_GetScope (sym);
2262 36 : if (SymbolTable_IsModule (scope))
2263 : {
2264 30 : if (SymbolTable_IsInnerModule (scope))
2265 : {
2266 0 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2267 : }
2268 : else
2269 : {
2270 30 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2271 : }
2272 : }
2273 : else
2274 : {
2275 6 : M2Debug_Assert (SymbolTable_IsDefImp (scope));
2276 : /* if this fails then we need to skip to the outer scope.
2277 : REPEAT
2278 : OuterModule := GetScope(OuterModule)
2279 : UNTIL GetScope(OuterModule)=NulSym. */
2280 6 : if ((SymbolTable_GetDeclaredModule (sym)) == M2LexBuf_UnknownTokenNo)
2281 : {
2282 0 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2283 : }
2284 : else
2285 : {
2286 6 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2287 : }
2288 : }
2289 36 : }
2290 :
2291 :
2292 : /*
2293 : doErrorScopeForward -
2294 : */
2295 :
2296 0 : static void doErrorScopeForward (M2MetaError_errorBlock *eb, unsigned int sym)
2297 : {
2298 0 : unsigned int scope;
2299 :
2300 0 : scope = SymbolTable_GetScope (sym);
2301 0 : if (SymbolTable_IsModule (scope))
2302 : {
2303 0 : if (SymbolTable_IsInnerModule (scope))
2304 : {
2305 0 : doError (eb, SymbolTable_GetDeclaredFor (sym), sym);
2306 : }
2307 : else
2308 : {
2309 0 : doError (eb, SymbolTable_GetDeclaredFor (sym), sym);
2310 : }
2311 : }
2312 : else
2313 : {
2314 0 : M2Debug_Assert (SymbolTable_IsDefImp (scope));
2315 : /* if this fails then we need to skip to the outer scope.
2316 : REPEAT
2317 : OuterModule := GetScope(OuterModule)
2318 : UNTIL GetScope(OuterModule)=NulSym. */
2319 0 : if ((SymbolTable_GetDeclaredModule (sym)) == M2LexBuf_UnknownTokenNo)
2320 : {
2321 0 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2322 : }
2323 : else
2324 : {
2325 0 : doError (eb, SymbolTable_GetDeclaredFor (sym), sym);
2326 : }
2327 : }
2328 0 : }
2329 :
2330 :
2331 : /*
2332 : doErrorScopeMod - potentially create an error referring to the definition
2333 : module, fall back to the implementation or program module if
2334 : there is no declaration in the definition module.
2335 : */
2336 :
2337 59 : static void doErrorScopeMod (M2MetaError_errorBlock *eb, unsigned int sym)
2338 : {
2339 59 : unsigned int scope;
2340 :
2341 59 : scope = SymbolTable_GetScope (sym);
2342 59 : if (scope == SymbolTable_NulSym)
2343 : {
2344 23 : M2Error_EnterErrorScope (static_cast<M2Error_ErrorScope> (NULL));
2345 23 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2346 : }
2347 : else
2348 : {
2349 36 : M2Error_EnterErrorScope (SymbolTable_GetErrorScope (scope));
2350 36 : if (SymbolTable_IsProcedure (scope))
2351 : {
2352 0 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2353 : }
2354 : else
2355 : {
2356 36 : doErrorScopeModule (eb, sym);
2357 : }
2358 : }
2359 59 : M2Error_LeaveErrorScope ();
2360 59 : }
2361 :
2362 :
2363 : /*
2364 : doErrorScopeFor - potentially create an error referring to the
2365 : forward declaration, definition module, fall back
2366 : to the implementation or program module if
2367 : there is no declaration in the definition module.
2368 : */
2369 :
2370 0 : static void doErrorScopeFor (M2MetaError_errorBlock *eb, unsigned int sym)
2371 : {
2372 0 : unsigned int scope;
2373 :
2374 0 : scope = SymbolTable_GetScope (sym);
2375 0 : if (scope == SymbolTable_NulSym)
2376 : {
2377 0 : M2Error_EnterErrorScope (static_cast<M2Error_ErrorScope> (NULL));
2378 0 : doError (eb, SymbolTable_GetDeclaredFor (sym), sym);
2379 : }
2380 : else
2381 : {
2382 0 : M2Error_EnterErrorScope (SymbolTable_GetErrorScope (scope));
2383 0 : if (SymbolTable_IsProcedure (scope))
2384 : {
2385 0 : doError (eb, SymbolTable_GetDeclaredFor (sym), sym);
2386 : }
2387 : else
2388 : {
2389 0 : doErrorScopeForward (eb, sym);
2390 : }
2391 : }
2392 0 : M2Error_LeaveErrorScope ();
2393 0 : }
2394 :
2395 59 : static void declaredMod (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2396 : {
2397 59 : unsigned int sym[_sym_high+1];
2398 :
2399 : /* make a local copy of each unbounded array. */
2400 59 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2401 :
2402 : /*
2403 : doDeclaredMod - creates an error note where sym[bol] was declared.
2404 : */
2405 59 : if (bol <= _sym_high)
2406 : {
2407 59 : doErrorScopeMod (eb, sym[bol]);
2408 : }
2409 59 : }
2410 :
2411 :
2412 : /*
2413 : doErrorScopeDefinition - use the declaration in the definitio module if one is available.
2414 : */
2415 :
2416 403 : static void doErrorScopeDefinition (M2MetaError_errorBlock *eb, unsigned int sym)
2417 : {
2418 403 : unsigned int scope;
2419 :
2420 403 : scope = SymbolTable_GetScope (sym);
2421 403 : if (SymbolTable_IsModule (scope))
2422 : {
2423 : /* No definition module for a program module. */
2424 403 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2425 : }
2426 : else
2427 : {
2428 0 : M2Debug_Assert (SymbolTable_IsDefImp (scope));
2429 0 : if ((SymbolTable_GetDeclaredDefinition (sym)) == M2LexBuf_UnknownTokenNo)
2430 : {
2431 : /* Fall back to the implementation module if no declaration exists
2432 : in the definition module. */
2433 0 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2434 : }
2435 : else
2436 : {
2437 0 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2438 : }
2439 : }
2440 403 : }
2441 :
2442 :
2443 : /*
2444 : doErrorScopeDef - potentially create an error referring to the definition
2445 : module, fall back to the implementation or program module if
2446 : there is no declaration in the definition module.
2447 : */
2448 :
2449 433 : static void doErrorScopeDef (M2MetaError_errorBlock *eb, unsigned int sym)
2450 : {
2451 433 : unsigned int scope;
2452 :
2453 433 : scope = SymbolTable_GetScope (sym);
2454 433 : if (scope == SymbolTable_NulSym)
2455 : {
2456 0 : M2Error_EnterErrorScope (static_cast<M2Error_ErrorScope> (NULL));
2457 0 : doError (eb, SymbolTable_GetDeclaredFor (sym), sym);
2458 : }
2459 : else
2460 : {
2461 433 : M2Error_EnterErrorScope (SymbolTable_GetErrorScope (scope));
2462 433 : if (SymbolTable_IsProcedure (scope))
2463 : {
2464 30 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2465 : }
2466 : else
2467 : {
2468 403 : doErrorScopeDefinition (eb, sym);
2469 : }
2470 : }
2471 433 : M2Error_LeaveErrorScope ();
2472 433 : }
2473 :
2474 433 : static void declaredDef (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2475 : {
2476 433 : unsigned int sym[_sym_high+1];
2477 :
2478 : /* make a local copy of each unbounded array. */
2479 433 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2480 :
2481 : /*
2482 : doDeclaredDef - creates an error note where sym[bol] was declared.
2483 : */
2484 433 : if (bol <= _sym_high)
2485 : {
2486 433 : doErrorScopeDef (eb, sym[bol]);
2487 : }
2488 433 : }
2489 :
2490 0 : static void declaredFor (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2491 : {
2492 0 : unsigned int sym[_sym_high+1];
2493 :
2494 : /* make a local copy of each unbounded array. */
2495 0 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2496 :
2497 : /*
2498 : doDeclaredFor - creates an error note where sym[bol] was declared.
2499 : */
2500 0 : if (bol <= _sym_high)
2501 : {
2502 0 : doErrorScopeFor (eb, sym[bol]);
2503 : }
2504 0 : }
2505 :
2506 :
2507 : /*
2508 : doErrorScopeProc - determine the location for the error or warning from
2509 : the default declaration. For example parameters can be
2510 : declared in definition, forward or in modules (proper procedure).
2511 : Use GetVarParamTok to obtain a variable or parameter location.
2512 : */
2513 :
2514 156 : static void doErrorScopeProc (M2MetaError_errorBlock *eb, unsigned int sym, M2MetaError_GetTokProcedure GetVarParamTok)
2515 : {
2516 156 : unsigned int scope;
2517 :
2518 156 : scope = SymbolTable_GetScope (sym);
2519 156 : if (scope == SymbolTable_NulSym)
2520 : {
2521 0 : M2Error_EnterErrorScope (static_cast<M2Error_ErrorScope> (NULL));
2522 0 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2523 : }
2524 : else
2525 : {
2526 156 : M2Error_EnterErrorScope (SymbolTable_GetErrorScope (scope));
2527 156 : if ((SymbolTable_IsVar (sym)) || (SymbolTable_IsParameter (sym)))
2528 : {
2529 156 : doError (eb, (unsigned int ) ((*GetVarParamTok.proc) (sym)), sym);
2530 : }
2531 0 : else if (SymbolTable_IsProcedure (scope))
2532 : {
2533 : /* avoid dangling else. */
2534 0 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2535 : }
2536 0 : else if (SymbolTable_IsModule (scope))
2537 : {
2538 : /* avoid dangling else. */
2539 0 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2540 : }
2541 : else
2542 : {
2543 : /* avoid dangling else. */
2544 0 : M2Debug_Assert (SymbolTable_IsDefImp (scope));
2545 0 : if ((SymbolTable_GetDeclaredDefinition (sym)) == M2LexBuf_UnknownTokenNo)
2546 : {
2547 0 : doError (eb, SymbolTable_GetDeclaredMod (sym), sym);
2548 : }
2549 : else
2550 : {
2551 0 : doError (eb, SymbolTable_GetDeclaredDef (sym), sym);
2552 : }
2553 : }
2554 : }
2555 156 : M2Error_LeaveErrorScope ();
2556 156 : }
2557 :
2558 96 : static void declaredVar (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2559 : {
2560 96 : unsigned int sym[_sym_high+1];
2561 :
2562 : /* make a local copy of each unbounded array. */
2563 96 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2564 :
2565 : /*
2566 : doDeclaredVar - creates an error note where sym[bol] was declared.
2567 : */
2568 96 : if (bol <= _sym_high)
2569 : {
2570 96 : doErrorScopeProc (eb, sym[bol], (M2MetaError_GetTokProcedure) {(M2MetaError_GetTokProcedure_t) SymbolTable_GetVarDeclTok});
2571 : }
2572 96 : }
2573 :
2574 0 : static void declaredType (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2575 : {
2576 0 : unsigned int sym[_sym_high+1];
2577 :
2578 : /* make a local copy of each unbounded array. */
2579 0 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2580 :
2581 : /*
2582 : doDeclaredType - creates an error note where sym[bol] was declared.
2583 : */
2584 0 : if (bol <= _sym_high)
2585 : {
2586 0 : doErrorScopeProc (eb, sym[bol], (M2MetaError_GetTokProcedure) {(M2MetaError_GetTokProcedure_t) SymbolTable_GetVarDeclTypeTok});
2587 : }
2588 0 : }
2589 :
2590 60 : static void declaredFull (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2591 : {
2592 60 : unsigned int sym[_sym_high+1];
2593 :
2594 : /* make a local copy of each unbounded array. */
2595 60 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2596 :
2597 : /*
2598 : doDeclaredFull - creates an error note where sym[bol] was declared.
2599 : */
2600 60 : if (bol <= _sym_high)
2601 : {
2602 60 : doErrorScopeProc (eb, sym[bol], (M2MetaError_GetTokProcedure) {(M2MetaError_GetTokProcedure_t) SymbolTable_GetVarDeclFullTok});
2603 : }
2604 60 : }
2605 :
2606 :
2607 : /*
2608 : used - creates an error note where sym[bol] was first used.
2609 : */
2610 :
2611 219 : static void used (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2612 : {
2613 219 : unsigned int sym[_sym_high+1];
2614 :
2615 : /* make a local copy of each unbounded array. */
2616 219 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2617 :
2618 219 : if (bol <= _sym_high)
2619 : {
2620 219 : doError (eb, SymbolTable_GetFirstUsed (sym[bol]), sym[bol]);
2621 : }
2622 219 : }
2623 :
2624 :
2625 : /*
2626 : symDesc -
2627 : */
2628 :
2629 1105 : static DynamicStrings_String symDesc (unsigned int sym)
2630 : {
2631 1105 : if (SymbolTable_IsConstLit (sym))
2632 : {
2633 6 : return DynamicStrings_InitString ((const char *) "constant literal", 16);
2634 : }
2635 1099 : else if (SymbolTable_IsConstSet (sym))
2636 : {
2637 : /* avoid dangling else. */
2638 48 : return DynamicStrings_InitString ((const char *) "constant set", 12);
2639 : }
2640 1051 : else if (SymbolTable_IsConstructor (sym))
2641 : {
2642 : /* avoid dangling else. */
2643 12 : return DynamicStrings_InitString ((const char *) "constructor", 11);
2644 : }
2645 1039 : else if (SymbolTable_IsConst (sym))
2646 : {
2647 : /* avoid dangling else. */
2648 24 : return DynamicStrings_InitString ((const char *) "constant", 8);
2649 : }
2650 1015 : else if (SymbolTable_IsArray (sym))
2651 : {
2652 : /* avoid dangling else. */
2653 72 : return DynamicStrings_InitString ((const char *) "array", 5);
2654 : }
2655 943 : else if (SymbolTable_IsVar (sym))
2656 : {
2657 : /* avoid dangling else. */
2658 624 : if (SymbolTable_IsTemporary (sym))
2659 : {
2660 432 : return DynamicStrings_InitString ((const char *) "expression", 10);
2661 : }
2662 : else
2663 : {
2664 192 : return DynamicStrings_InitString ((const char *) "variable", 8);
2665 : }
2666 : }
2667 319 : else if (SymbolTable_IsEnumeration (sym))
2668 : {
2669 : /* avoid dangling else. */
2670 6 : return DynamicStrings_InitString ((const char *) "enumeration type", 16);
2671 : }
2672 313 : else if (SymbolTable_IsFieldEnumeration (sym))
2673 : {
2674 : /* avoid dangling else. */
2675 0 : return DynamicStrings_InitString ((const char *) "enumeration field", 17);
2676 : }
2677 313 : else if (SymbolTable_IsUnbounded (sym))
2678 : {
2679 : /* avoid dangling else. */
2680 24 : return DynamicStrings_InitString ((const char *) "unbounded parameter", 19);
2681 : }
2682 289 : else if (SymbolTable_IsProcType (sym))
2683 : {
2684 : /* avoid dangling else. */
2685 18 : return DynamicStrings_InitString ((const char *) "procedure type", 14);
2686 : }
2687 271 : else if (M2Base_IsPseudoBaseFunction (sym))
2688 : {
2689 : /* avoid dangling else. */
2690 6 : return DynamicStrings_InitString ((const char *) "standard function procedure", 27);
2691 : }
2692 265 : else if (M2Base_IsPseudoBaseProcedure (sym))
2693 : {
2694 : /* avoid dangling else. */
2695 0 : return DynamicStrings_InitString ((const char *) "standard procedure", 18);
2696 : }
2697 265 : else if (SymbolTable_IsProcedure (sym))
2698 : {
2699 : /* avoid dangling else. */
2700 18 : return DynamicStrings_InitString ((const char *) "procedure", 9);
2701 : }
2702 247 : else if (SymbolTable_IsPointer (sym))
2703 : {
2704 : /* avoid dangling else. */
2705 0 : return DynamicStrings_InitString ((const char *) "pointer", 7);
2706 : }
2707 247 : else if (SymbolTable_IsParameter (sym))
2708 : {
2709 : /* avoid dangling else. */
2710 18 : if (SymbolTable_IsParameterVar (sym))
2711 : {
2712 12 : return DynamicStrings_InitString ((const char *) "var parameter", 13);
2713 : }
2714 : else
2715 : {
2716 6 : return DynamicStrings_InitString ((const char *) "parameter", 9);
2717 : }
2718 : }
2719 229 : else if (SymbolTable_IsType (sym))
2720 : {
2721 : /* avoid dangling else. */
2722 0 : if (SymbolTable_IsHiddenType (sym))
2723 : {
2724 0 : return DynamicStrings_InitString ((const char *) "opaque type", 11);
2725 : }
2726 : else
2727 : {
2728 0 : return DynamicStrings_InitString ((const char *) "type", 4);
2729 : }
2730 : }
2731 229 : else if (SymbolTable_IsRecord (sym))
2732 : {
2733 : /* avoid dangling else. */
2734 6 : return DynamicStrings_InitString ((const char *) "record", 6);
2735 : }
2736 223 : else if (SymbolTable_IsRecordField (sym))
2737 : {
2738 : /* avoid dangling else. */
2739 0 : return DynamicStrings_InitString ((const char *) "record field", 12);
2740 : }
2741 223 : else if (SymbolTable_IsVarient (sym))
2742 : {
2743 : /* avoid dangling else. */
2744 0 : return DynamicStrings_InitString ((const char *) "varient record", 14);
2745 : }
2746 223 : else if (SymbolTable_IsModule (sym))
2747 : {
2748 : /* avoid dangling else. */
2749 0 : return DynamicStrings_InitString ((const char *) "module", 6);
2750 : }
2751 223 : else if (SymbolTable_IsDefImp (sym))
2752 : {
2753 : /* avoid dangling else. */
2754 0 : return DynamicStrings_InitString ((const char *) "definition or implementation module", 35);
2755 : }
2756 223 : else if (SymbolTable_IsSet (sym))
2757 : {
2758 : /* avoid dangling else. */
2759 72 : return DynamicStrings_InitString ((const char *) "set", 3);
2760 : }
2761 151 : else if (SymbolTable_IsUnknown (sym))
2762 : {
2763 : /* avoid dangling else. */
2764 25 : return DynamicStrings_InitString ((const char *) "unknown", 7);
2765 : }
2766 126 : else if (SymbolTable_IsSubrange (sym))
2767 : {
2768 : /* avoid dangling else. */
2769 126 : return DynamicStrings_InitString ((const char *) "subrange", 8);
2770 : }
2771 : else
2772 : {
2773 : /* avoid dangling else. */
2774 0 : return DynamicStrings_InitString ((const char *) "", 0);
2775 : }
2776 : /* static analysis guarentees a RETURN statement will be used before here. */
2777 : __builtin_unreachable ();
2778 : }
2779 :
2780 :
2781 : /*
2782 : doDesc -
2783 : */
2784 :
2785 9051 : static void doDesc (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2786 : {
2787 9051 : unsigned int sym[_sym_high+1];
2788 :
2789 : /* make a local copy of each unbounded array. */
2790 9051 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2791 :
2792 9051 : if (empty (eb))
2793 : {
2794 1105 : OutGlyphS (eb, symDesc (sym[bol]));
2795 1105 : if (! (empty (eb)))
2796 : {
2797 1105 : (*eb).quotes = false;
2798 : }
2799 : }
2800 9051 : }
2801 :
2802 :
2803 : /*
2804 : op := {'!'|'a'|'c'|'d'|'k'|'n'|'p'|'q'|'s'|'t'|'u'|'v'|
2805 : 'A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'K'|'M'|'N'|
2806 : 'O'|'P'|'Q'|'R'|'S'|'T'|'U'|'V'|'W'|'X'|'Y'|'Z'|
2807 : '&' } then =:
2808 : */
2809 :
2810 42609 : static void op (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
2811 : {
2812 42609 : unsigned int sym[_sym_high+1];
2813 :
2814 : /* make a local copy of each unbounded array. */
2815 42609 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
2816 :
2817 129989 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
2818 : {
2819 87380 : if (Debugging)
2820 : {
2821 : M2Printf_printf0 ((const char *) "while loop in op\\n", 18);
2822 : dump ((*eb));
2823 : }
2824 87380 : switch (DynamicStrings_char ((*eb).in, (*eb).ini))
2825 : {
2826 0 : case '!':
2827 0 : (*eb).positive = ! (*eb).positive;
2828 0 : break;
2829 :
2830 28962 : case 'a':
2831 28962 : doName (eb, (const unsigned int *) sym, _sym_high, bol);
2832 28962 : break;
2833 :
2834 0 : case 'c':
2835 0 : (*eb).currentCol = readColor (eb);
2836 0 : (*eb).ini -= 1;
2837 0 : break;
2838 :
2839 9051 : case 'd':
2840 9051 : doDesc (eb, (const unsigned int *) sym, _sym_high, bol);
2841 9051 : break;
2842 :
2843 637 : case 'k':
2844 637 : unquotedKeyword (eb);
2845 637 : (*eb).ini -= 1;
2846 637 : break;
2847 :
2848 0 : case 'n':
2849 0 : doNumber (eb, (const unsigned int *) sym, _sym_high, bol);
2850 0 : break;
2851 :
2852 0 : case 'p':
2853 0 : popColor (eb);
2854 0 : break;
2855 :
2856 0 : case 'q':
2857 0 : doQualified (eb, (const unsigned int *) sym, _sym_high, bol);
2858 0 : break;
2859 :
2860 9534 : case 's':
2861 9534 : doSkipType ((*eb), (const unsigned int *) sym, _sym_high, bol);
2862 9534 : break;
2863 :
2864 14796 : case 't':
2865 14796 : doType (eb, (const unsigned int *) sym, _sym_high, bol);
2866 14796 : break;
2867 :
2868 0 : case 'u':
2869 0 : (*eb).quotes = false;
2870 0 : break;
2871 :
2872 180 : case 'v':
2873 180 : (*eb).vowel = true;
2874 180 : break;
2875 :
2876 95 : case 'A':
2877 95 : (*eb).type = M2MetaError_aborta;
2878 95 : seenAbort = true;
2879 95 : break;
2880 :
2881 0 : case 'B':
2882 0 : declaredType (eb, (const unsigned int *) sym, _sym_high, bol);
2883 0 : break;
2884 :
2885 42 : case 'C':
2886 42 : (*eb).chain = true;
2887 42 : break;
2888 :
2889 433 : case 'D':
2890 433 : declaredDef (eb, (const unsigned int *) sym, _sym_high, bol);
2891 433 : break;
2892 :
2893 1931 : case 'E':
2894 1931 : (*eb).type = M2MetaError_error;
2895 1931 : (*eb).symcause = sym[bol];
2896 1931 : break;
2897 :
2898 0 : case 'F':
2899 0 : filename (eb);
2900 0 : (*eb).ini -= 1;
2901 0 : break;
2902 :
2903 0 : case 'G':
2904 0 : declaredFor (eb, (const unsigned int *) sym, _sym_high, bol);
2905 0 : break;
2906 :
2907 60 : case 'H':
2908 60 : declaredFull (eb, (const unsigned int *) sym, _sym_high, bol);
2909 60 : break;
2910 :
2911 549 : case 'K':
2912 549 : keyword (eb);
2913 549 : (*eb).ini -= 1;
2914 549 : break;
2915 :
2916 59 : case 'M':
2917 59 : declaredMod (eb, (const unsigned int *) sym, _sym_high, bol);
2918 59 : break;
2919 :
2920 2148 : case 'N':
2921 2148 : doCount (eb, (const unsigned int *) sym, _sym_high, bol);
2922 2148 : break;
2923 :
2924 34 : case 'O':
2925 34 : (*eb).type = M2MetaError_note;
2926 34 : (*eb).symcause = sym[bol];
2927 34 : break;
2928 :
2929 0 : case 'P':
2930 0 : pushColor (eb);
2931 0 : break;
2932 :
2933 0 : case 'Q':
2934 0 : resetDictionary ();
2935 0 : break;
2936 :
2937 42 : case 'R':
2938 42 : (*eb).root = true;
2939 42 : break;
2940 :
2941 0 : case 'S':
2942 0 : doGetSkipType (eb, (unsigned int *) sym, _sym_high, bol);
2943 0 : break;
2944 :
2945 0 : case 'T':
2946 0 : doGetType (eb, (unsigned int *) sym, _sym_high, bol);
2947 0 : break;
2948 :
2949 219 : case 'U':
2950 219 : used (eb, (const unsigned int *) sym, _sym_high, bol);
2951 219 : break;
2952 :
2953 96 : case 'V':
2954 96 : declaredVar (eb, (const unsigned int *) sym, _sym_high, bol);
2955 96 : break;
2956 :
2957 11220 : case 'W':
2958 11220 : (*eb).type = M2MetaError_warning;
2959 11220 : (*eb).symcause = sym[bol];
2960 11220 : break;
2961 :
2962 0 : case 'X':
2963 0 : pushOutput (eb);
2964 0 : break;
2965 :
2966 0 : case 'Y':
2967 0 : processDefine (eb);
2968 0 : break;
2969 :
2970 0 : case 'Z':
2971 0 : popOutput (eb);
2972 0 : break;
2973 :
2974 412 : case '&':
2975 412 : continuation (eb, (unsigned int *) sym, _sym_high, bol);
2976 412 : (*eb).ini -= 1;
2977 412 : break;
2978 :
2979 6880 : case ':':
2980 6880 : ifNonNulThen (eb, (const unsigned int *) sym, _sym_high);
2981 6880 : (*eb).ini -= 1;
2982 6880 : break;
2983 :
2984 0 : case '1':
2985 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %1 rather than % spec 1", 56);
2986 0 : break;
2987 :
2988 0 : case '2':
2989 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %2 rather than % spec 2", 56);
2990 0 : break;
2991 :
2992 0 : case '3':
2993 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %3 rather than % spec 3", 56);
2994 0 : break;
2995 :
2996 0 : case '4':
2997 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %4 rather than % spec 4", 56);
2998 0 : break;
2999 :
3000 :
3001 0 : default:
3002 0 : InternalFormat ((*eb), (const char *) "expecting one of [akqtdnpsuCDEFGKNOPQRSTUWXYZ:<>%]", 50, 1840);
3003 : break;
3004 : }
3005 87380 : (*eb).ini += 1;
3006 : }
3007 42609 : if (Debugging)
3008 : {
3009 : M2Printf_printf0 ((const char *) "finishing op\\n", 14);
3010 : dump ((*eb));
3011 : }
3012 42609 : }
3013 :
3014 :
3015 : /*
3016 : continuation := {':'|'1'|'2'|'3'|'4'|'i'|'s'|'x'|'w'|'D'|'T'|'V'|'C'} =:
3017 : */
3018 :
3019 412 : static void continuation (M2MetaError_errorBlock *eb, unsigned int *sym, unsigned int _sym_high, unsigned int bol)
3020 : {
3021 412 : M2Debug_Assert (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '&'));
3022 412 : (*eb).ini += 1;
3023 862 : while (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
3024 : {
3025 450 : switch (DynamicStrings_char ((*eb).in, (*eb).ini))
3026 : {
3027 0 : case ':':
3028 0 : ifNonNulThen (eb, (const unsigned int *) sym, _sym_high);
3029 0 : (*eb).ini -= 1;
3030 0 : break;
3031 :
3032 0 : case '1':
3033 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %1 rather than % spec 1", 56);
3034 0 : break;
3035 :
3036 0 : case '2':
3037 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %2 rather than % spec 2", 56);
3038 0 : break;
3039 :
3040 0 : case '3':
3041 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %3 rather than % spec 3", 56);
3042 0 : break;
3043 :
3044 0 : case '4':
3045 0 : M2Error_InternalError ((const char *) "incorrect format spec, expecting %4 rather than % spec 4", 56);
3046 2 : break;
3047 :
3048 2 : case 'i':
3049 2 : AddImportsHint (eb);
3050 2 : break;
3051 :
3052 412 : case 's':
3053 412 : SpellHint (eb, (const unsigned int *) sym, _sym_high, bol);
3054 412 : break;
3055 :
3056 0 : case 'x':
3057 0 : AddExportsHint (eb);
3058 0 : break;
3059 :
3060 0 : case 'w':
3061 0 : AddWithStackHint (eb);
3062 0 : break;
3063 :
3064 25 : case 'D':
3065 25 : FilterOnDefinitionModule (eb);
3066 25 : break;
3067 :
3068 7 : case 'T':
3069 7 : FilterOnType (eb);
3070 7 : break;
3071 :
3072 2 : case 'V':
3073 2 : FilterOnVariable (eb);
3074 2 : break;
3075 :
3076 2 : case 'C':
3077 2 : FilterOnConst (eb);
3078 2 : break;
3079 :
3080 :
3081 0 : default:
3082 0 : InternalFormat ((*eb), (const char *) "expecting one of [:1234isxwDT]", 30, 1881);
3083 : break;
3084 : }
3085 450 : (*eb).ini += 1;
3086 : }
3087 412 : if (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
3088 : {
3089 0 : (*eb).ini -= 1;
3090 : }
3091 412 : }
3092 :
3093 :
3094 : /*
3095 : percenttoken := '%' (
3096 : '1' % doOperand(1) %
3097 : op
3098 : | '2' % doOperand(2) %
3099 : op
3100 : | '3' % doOperand(3) %
3101 : op
3102 : | '4' % doOperand(4) %
3103 : op
3104 : )
3105 : } =:
3106 : */
3107 :
3108 42609 : static void percenttoken (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high)
3109 : {
3110 42609 : unsigned int sym[_sym_high+1];
3111 :
3112 : /* make a local copy of each unbounded array. */
3113 42609 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
3114 :
3115 42609 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
3116 : {
3117 42609 : (*eb).ini += 1;
3118 42609 : switch (DynamicStrings_char ((*eb).in, (*eb).ini))
3119 : {
3120 25068 : case '1':
3121 25068 : (*eb).ini += 1;
3122 25068 : op (eb, (const unsigned int *) sym, _sym_high, 0);
3123 25068 : break;
3124 :
3125 13785 : case '2':
3126 13785 : (*eb).ini += 1;
3127 13785 : op (eb, (const unsigned int *) sym, _sym_high, 1);
3128 13785 : break;
3129 :
3130 2064 : case '3':
3131 2064 : (*eb).ini += 1;
3132 2064 : op (eb, (const unsigned int *) sym, _sym_high, 2);
3133 2064 : break;
3134 :
3135 228 : case '4':
3136 228 : (*eb).ini += 1;
3137 228 : op (eb, (const unsigned int *) sym, _sym_high, 3);
3138 228 : break;
3139 :
3140 :
3141 1464 : default:
3142 1464 : op (eb, (const unsigned int *) sym, _sym_high, 0);
3143 1464 : break;
3144 : }
3145 42609 : if (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
3146 : {
3147 0 : InternalFormat ((*eb), (const char *) "expecting to see }", 18, 1927);
3148 : }
3149 : }
3150 42609 : }
3151 :
3152 :
3153 : /*
3154 : IsPunct - returns TRUE if ch is a punctuation character.
3155 : */
3156 :
3157 9466 : static bool IsPunct (char ch)
3158 : {
3159 9466 : return ((((((((ch == '.') || (ch == ',')) || (ch == ':')) || (ch == ';')) || (ch == '!')) || (ch == '(')) || (ch == ')')) || (ch == '[')) || (ch == ']');
3160 : /* static analysis guarentees a RETURN statement will be used before here. */
3161 : __builtin_unreachable ();
3162 : }
3163 :
3164 :
3165 : /*
3166 : JoinSentances - join s onto eb. It removes trailing
3167 : spaces from eb if s starts with a punctuation
3168 : character.
3169 : */
3170 :
3171 9674 : static void JoinSentances (M2MetaError_errorBlock *eb, DynamicStrings_String s)
3172 : {
3173 9674 : if ((s != NULL) && ((DynamicStrings_Length (s)) > 0))
3174 : {
3175 9466 : if (IsPunct (DynamicStrings_char (s, 0)))
3176 : {
3177 156 : (*eb).out = DynamicStrings_RemoveWhitePostfix ((*eb).out);
3178 : }
3179 9466 : flushColor (eb);
3180 9466 : (*eb).out = DynamicStrings_ConCat ((*eb).out, s);
3181 9466 : (*eb).glyph = true;
3182 9466 : (*eb).quotes = false;
3183 : }
3184 9674 : }
3185 :
3186 :
3187 : /*
3188 : ConfigureFilter -
3189 : */
3190 :
3191 263 : static void ConfigureFilter (M2MetaError_errorBlock eb)
3192 : {
3193 263 : if (eb.filterType)
3194 : {
3195 7 : M2StackSpell_FilterType ();
3196 : }
3197 263 : if (eb.filterVar)
3198 : {
3199 2 : M2StackSpell_FilterVariable ();
3200 : }
3201 263 : if (eb.filterConst)
3202 : {
3203 2 : M2StackSpell_FilterConst ();
3204 : }
3205 263 : }
3206 :
3207 :
3208 : /*
3209 : SpellHint -
3210 : */
3211 :
3212 412 : static void SpellHint (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high, unsigned int bol)
3213 : {
3214 412 : unsigned int sym[_sym_high+1];
3215 :
3216 : /* make a local copy of each unbounded array. */
3217 412 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
3218 :
3219 412 : if (bol <= _sym_high)
3220 : {
3221 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
3222 412 : if ((*eb).filterDef && (SymbolTable_IsDefImp (sym[bol])))
3223 : {
3224 23 : JoinSentances (eb, M2StackSpell_GetDefModuleSpellHint (sym[bol]));
3225 : }
3226 389 : else if ((SymbolTable_IsUnknown (sym[bol])) || (SymbolTable_IsError (sym[bol])))
3227 : {
3228 : /* avoid dangling else. */
3229 263 : ConfigureFilter ((*eb));
3230 263 : JoinSentances (eb, M2StackSpell_GetSpellHint (sym[bol]));
3231 : }
3232 : }
3233 412 : }
3234 :
3235 :
3236 : /*
3237 : AddImportsHint -
3238 : */
3239 :
3240 2 : static void AddImportsHint (M2MetaError_errorBlock *eb)
3241 : {
3242 2 : (*eb).importHint = true;
3243 0 : }
3244 :
3245 :
3246 : /*
3247 : AddExportsHint -
3248 : */
3249 :
3250 0 : static void AddExportsHint (M2MetaError_errorBlock *eb)
3251 : {
3252 0 : (*eb).exportHint = true;
3253 0 : }
3254 :
3255 :
3256 : /*
3257 : AddWithStackHint -
3258 : */
3259 :
3260 0 : static void AddWithStackHint (M2MetaError_errorBlock *eb)
3261 : {
3262 0 : (*eb).withStackHint = true;
3263 0 : }
3264 :
3265 :
3266 : /*
3267 : FilterOnDefinitionModule - turn on filtering and include all the definition modules.
3268 : */
3269 :
3270 25 : static void FilterOnDefinitionModule (M2MetaError_errorBlock *eb)
3271 : {
3272 25 : (*eb).filterDef = true;
3273 0 : }
3274 :
3275 :
3276 : /*
3277 : FilterOnType -
3278 : */
3279 :
3280 7 : static void FilterOnType (M2MetaError_errorBlock *eb)
3281 : {
3282 7 : (*eb).filterType = true;
3283 0 : }
3284 :
3285 :
3286 : /*
3287 : FilterOnConst -
3288 : */
3289 :
3290 2 : static void FilterOnConst (M2MetaError_errorBlock *eb)
3291 : {
3292 2 : (*eb).filterConst = true;
3293 0 : }
3294 :
3295 :
3296 : /*
3297 : FilterOnVariable -
3298 : */
3299 :
3300 2 : static void FilterOnVariable (M2MetaError_errorBlock *eb)
3301 : {
3302 2 : (*eb).filterVar = true;
3303 0 : }
3304 :
3305 :
3306 : /*
3307 : changeColor - changes to color, c.
3308 : */
3309 :
3310 1186 : static void changeColor (M2MetaError_errorBlock *eb, M2MetaError_colorType c)
3311 : {
3312 1186 : (*eb).currentCol = c;
3313 0 : }
3314 :
3315 :
3316 : /*
3317 : shutdownColor - shutdown existing color if it exists.
3318 : */
3319 :
3320 107263 : static void shutdownColor (M2MetaError_errorBlock *eb)
3321 : {
3322 107263 : if (((*eb).endCol != M2MetaError_unsetColor) && ((*eb).endCol != M2MetaError_noColor))
3323 : {
3324 137394 : (*eb).out = colorEnd ((*eb).out);
3325 68697 : (*eb).endCol = M2MetaError_noColor;
3326 : }
3327 107263 : }
3328 :
3329 :
3330 : /*
3331 : flushColor - flushes any outstanding color change.
3332 : */
3333 :
3334 1682340 : static void flushColor (M2MetaError_errorBlock *eb)
3335 : {
3336 1682340 : if ((*eb).endCol != (*eb).currentCol)
3337 : {
3338 77229 : shutdownColor (eb);
3339 77229 : if ((*eb).endCol != (*eb).currentCol)
3340 : {
3341 79674 : emitColor (eb, (*eb).currentCol);
3342 39837 : (*eb).endCol = (*eb).currentCol;
3343 : }
3344 77229 : if ((*eb).beginCol == M2MetaError_unsetColor)
3345 : {
3346 23608 : (*eb).beginCol = (*eb).currentCol;
3347 : }
3348 : }
3349 1682340 : }
3350 :
3351 :
3352 : /*
3353 : emitColorGCC -
3354 : */
3355 :
3356 39837 : static void emitColorGCC (M2MetaError_errorBlock *eb, M2MetaError_colorType c)
3357 : {
3358 39837 : switch (c)
3359 : {
3360 : case M2MetaError_unsetColor:
3361 : break;
3362 :
3363 416 : case M2MetaError_noColor:
3364 416 : (*eb).out = M2ColorString_endColor ((*eb).out);
3365 416 : break;
3366 :
3367 0 : case M2MetaError_quoteColor:
3368 0 : (*eb).out = M2ColorString_quoteColor ((*eb).out);
3369 0 : break;
3370 :
3371 0 : case M2MetaError_filenameColor:
3372 0 : (*eb).out = M2ColorString_filenameColor ((*eb).out);
3373 0 : break;
3374 :
3375 11224 : case M2MetaError_errorColor:
3376 11224 : (*eb).out = M2ColorString_errorColor ((*eb).out);
3377 11224 : break;
3378 :
3379 26952 : case M2MetaError_warningColor:
3380 26952 : (*eb).out = M2ColorString_warningColor ((*eb).out);
3381 26952 : break;
3382 :
3383 59 : case M2MetaError_noteColor:
3384 59 : (*eb).out = M2ColorString_noteColor ((*eb).out);
3385 59 : break;
3386 :
3387 1186 : case M2MetaError_keywordColor:
3388 1186 : (*eb).out = M2ColorString_locusColor ((*eb).out);
3389 1186 : break;
3390 :
3391 0 : case M2MetaError_locusColor:
3392 0 : (*eb).out = M2ColorString_locusColor ((*eb).out);
3393 0 : break;
3394 :
3395 0 : case M2MetaError_insertColor:
3396 0 : (*eb).out = M2ColorString_insertColor ((*eb).out);
3397 0 : break;
3398 :
3399 0 : case M2MetaError_deleteColor:
3400 0 : (*eb).out = M2ColorString_deleteColor ((*eb).out);
3401 0 : break;
3402 :
3403 0 : case M2MetaError_typeColor:
3404 0 : (*eb).out = M2ColorString_typeColor ((*eb).out);
3405 0 : break;
3406 :
3407 0 : case M2MetaError_range1Color:
3408 0 : (*eb).out = M2ColorString_range1Color ((*eb).out);
3409 0 : break;
3410 :
3411 0 : case M2MetaError_range2Color:
3412 0 : (*eb).out = M2ColorString_range2Color ((*eb).out);
3413 0 : break;
3414 :
3415 :
3416 0 : default:
3417 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2MetaError.def", 20, 1);
3418 0 : __builtin_unreachable ();
3419 : }
3420 39837 : }
3421 :
3422 :
3423 : /*
3424 : emitColorTag -
3425 : */
3426 :
3427 0 : static void emitColorTag (M2MetaError_errorBlock *eb, M2MetaError_colorType c)
3428 : {
3429 0 : DynamicStrings_String s;
3430 :
3431 0 : switch (c)
3432 : {
3433 0 : case M2MetaError_unsetColor:
3434 0 : s = DynamicStrings_InitString ((const char *) "<unset>", 7);
3435 0 : break;
3436 :
3437 0 : case M2MetaError_noColor:
3438 0 : s = DynamicStrings_InitString ((const char *) "<nocol>", 7);
3439 0 : stop ();
3440 0 : break;
3441 :
3442 0 : case M2MetaError_quoteColor:
3443 0 : s = DynamicStrings_InitString ((const char *) "<quote>", 7);
3444 0 : break;
3445 :
3446 0 : case M2MetaError_filenameColor:
3447 0 : s = DynamicStrings_InitString ((const char *) "<filename>", 10);
3448 0 : break;
3449 :
3450 0 : case M2MetaError_errorColor:
3451 0 : s = DynamicStrings_InitString ((const char *) "<error>", 7);
3452 0 : break;
3453 :
3454 0 : case M2MetaError_warningColor:
3455 0 : s = DynamicStrings_InitString ((const char *) "<warn>", 6);
3456 0 : break;
3457 :
3458 0 : case M2MetaError_noteColor:
3459 0 : s = DynamicStrings_InitString ((const char *) "<note>", 6);
3460 0 : break;
3461 :
3462 0 : case M2MetaError_keywordColor:
3463 0 : s = DynamicStrings_InitString ((const char *) "<key>", 5);
3464 0 : break;
3465 :
3466 0 : case M2MetaError_locusColor:
3467 0 : s = DynamicStrings_InitString ((const char *) "<locus>", 7);
3468 0 : break;
3469 :
3470 0 : case M2MetaError_insertColor:
3471 0 : s = DynamicStrings_InitString ((const char *) "<insert>", 8);
3472 0 : break;
3473 :
3474 0 : case M2MetaError_deleteColor:
3475 0 : s = DynamicStrings_InitString ((const char *) "<delete>", 8);
3476 0 : break;
3477 :
3478 0 : case M2MetaError_typeColor:
3479 0 : s = DynamicStrings_InitString ((const char *) "<type>", 6);
3480 0 : break;
3481 :
3482 0 : case M2MetaError_range1Color:
3483 0 : s = DynamicStrings_InitString ((const char *) "<range1>", 8);
3484 0 : break;
3485 :
3486 0 : case M2MetaError_range2Color:
3487 0 : s = DynamicStrings_InitString ((const char *) "<range2>", 8);
3488 0 : break;
3489 :
3490 :
3491 0 : default:
3492 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2MetaError.def", 20, 1);
3493 0 : __builtin_unreachable ();
3494 : }
3495 0 : (*eb).out = DynamicStrings_ConCat ((*eb).out, DynamicStrings_Mark (s));
3496 0 : }
3497 :
3498 :
3499 : /*
3500 : emitColor - adds the appropriate color string to the output string.
3501 : */
3502 :
3503 39837 : static void emitColor (M2MetaError_errorBlock *eb, M2MetaError_colorType c)
3504 : {
3505 39837 : if (ColorDebug)
3506 : {
3507 : emitColorTag (eb, c);
3508 : }
3509 : else
3510 : {
3511 39837 : emitColorGCC (eb, c);
3512 : }
3513 0 : }
3514 :
3515 :
3516 : /*
3517 : openQuote -
3518 : */
3519 :
3520 30034 : static DynamicStrings_String openQuote (DynamicStrings_String s)
3521 : {
3522 30034 : if (ColorDebug)
3523 : {
3524 : return DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "<openquote>", 11)));
3525 : }
3526 : else
3527 : {
3528 30034 : return M2ColorString_quoteOpen (s);
3529 : }
3530 : /* static analysis guarentees a RETURN statement will be used before here. */
3531 : __builtin_unreachable ();
3532 : }
3533 :
3534 :
3535 : /*
3536 : closeQuote -
3537 : */
3538 :
3539 30034 : static DynamicStrings_String closeQuote (DynamicStrings_String s)
3540 : {
3541 30034 : if (ColorDebug)
3542 : {
3543 : return DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "<closequote>", 12)));
3544 : }
3545 : else
3546 : {
3547 30034 : return M2ColorString_quoteClose (s);
3548 : }
3549 : /* static analysis guarentees a RETURN statement will be used before here. */
3550 : __builtin_unreachable ();
3551 : }
3552 :
3553 :
3554 : /*
3555 : colorEnd -
3556 : */
3557 :
3558 68697 : static DynamicStrings_String colorEnd (DynamicStrings_String s)
3559 : {
3560 68697 : stop ();
3561 68697 : if (ColorDebug)
3562 : {
3563 : return DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "<nocol>", 7)));
3564 : }
3565 : else
3566 : {
3567 68697 : return M2ColorString_endColor (s);
3568 : }
3569 : /* static analysis guarentees a RETURN statement will be used before here. */
3570 : __builtin_unreachable ();
3571 : }
3572 :
3573 :
3574 : /*
3575 : copyChar - copies a character from in string to out string.
3576 : */
3577 :
3578 1533447 : static void copyChar (M2MetaError_errorBlock *eb)
3579 : {
3580 1533447 : if ((*eb).ini < (*eb).len)
3581 : {
3582 1533447 : flushColor (eb);
3583 1533447 : checkMe ();
3584 1533447 : (*eb).glyph = true;
3585 1533447 : (*eb).out = x ((*eb).out, DynamicStrings_ConCatChar ((*eb).out, DynamicStrings_char ((*eb).in, (*eb).ini)));
3586 : }
3587 1533447 : }
3588 :
3589 :
3590 : /*
3591 : copyKeywordChar - copies a character from in string to out string
3592 : it will convert the character to lower case if the
3593 : -fm2-lower-case option was specified.
3594 : */
3595 :
3596 5109 : static void copyKeywordChar (M2MetaError_errorBlock *eb)
3597 : {
3598 5109 : char ch;
3599 :
3600 5109 : if ((*eb).ini < (*eb).len)
3601 : {
3602 5109 : flushColor (eb);
3603 5109 : ch = DynamicStrings_char ((*eb).in, (*eb).ini);
3604 5109 : if (M2Options_LowerCaseKeywords)
3605 : {
3606 0 : ch = StrCase_Lower (ch);
3607 : }
3608 5109 : (*eb).glyph = true;
3609 5109 : (*eb).out = x ((*eb).out, DynamicStrings_ConCatChar ((*eb).out, ch));
3610 : }
3611 5109 : }
3612 :
3613 :
3614 : /*
3615 : percent := '%' anych % copy anych %
3616 : =:
3617 : */
3618 :
3619 0 : static void percent (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high)
3620 : {
3621 0 : unsigned int sym[_sym_high+1];
3622 :
3623 : /* make a local copy of each unbounded array. */
3624 0 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
3625 :
3626 0 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '%')
3627 : {
3628 0 : (*eb).ini += 1;
3629 0 : if ((*eb).ini < (*eb).len)
3630 : {
3631 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
3632 0 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '<')
3633 : {
3634 : /* %< is a quotation symbol. */
3635 0 : pushColor (eb);
3636 0 : (*eb).currentCol = M2MetaError_noColor;
3637 0 : flushColor (eb);
3638 0 : changeColor (eb, M2MetaError_quoteColor);
3639 0 : (*eb).endCol = M2MetaError_quoteColor; /* the openQuote will change the color. */
3640 : /* OutGlyphS performs a flush and we are emitting the open quote glyph. */
3641 0 : OutGlyphS (eb, openQuote (DynamicStrings_InitString ((const char *) "", 0)));
3642 : }
3643 0 : else if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '>')
3644 : {
3645 : /* avoid dangling else. */
3646 0 : OutGlyphS (eb, closeQuote (DynamicStrings_InitString ((const char *) "", 0)));
3647 0 : (*eb).endCol = M2MetaError_noColor; /* closeQuote also turns off color. */
3648 0 : popColor (eb); /* closeQuote also turns off color. */
3649 : }
3650 : else
3651 : {
3652 : /* avoid dangling else. */
3653 0 : copyChar (eb);
3654 : }
3655 : }
3656 : }
3657 0 : }
3658 :
3659 :
3660 : /*
3661 : lbra := '{' [ '!' ] percenttoken '}' =:
3662 : */
3663 :
3664 42609 : static void lbra (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high)
3665 : {
3666 42609 : unsigned int sym[_sym_high+1];
3667 :
3668 : /* make a local copy of each unbounded array. */
3669 42609 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
3670 :
3671 42609 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '{')
3672 : {
3673 42609 : (*eb).positive = true;
3674 42609 : (*eb).ini += 1;
3675 42609 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) == '!')
3676 : {
3677 128 : (*eb).positive = false;
3678 128 : (*eb).ini += 1;
3679 : }
3680 42609 : if ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '%')
3681 : {
3682 0 : InternalFormat ((*eb), (const char *) "expecting to see %", 18, 2334);
3683 : }
3684 42609 : percenttoken (eb, (const unsigned int *) sym, _sym_high);
3685 42609 : if (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
3686 : {
3687 0 : InternalFormat ((*eb), (const char *) "expecting to see }", 18, 2339);
3688 : }
3689 : }
3690 42609 : }
3691 :
3692 :
3693 : /*
3694 : lbra := '{' [ '!' ] percenttoken '}' =:
3695 : */
3696 :
3697 0 : static void stop (void)
3698 : {
3699 0 : }
3700 :
3701 :
3702 : /*
3703 : lbra := '{' [ '!' ] percenttoken '}' =:
3704 : */
3705 :
3706 0 : static void checkMe (void)
3707 : {
3708 0 : }
3709 :
3710 :
3711 : /*
3712 : dumpErrorType -
3713 : */
3714 :
3715 0 : static void dumpErrorType (M2MetaError_errorType e)
3716 : {
3717 0 : switch (e)
3718 : {
3719 0 : case M2MetaError_none:
3720 0 : M2Printf_printf0 ((const char *) "none", 4);
3721 0 : break;
3722 :
3723 0 : case M2MetaError_error:
3724 0 : M2Printf_printf0 ((const char *) "error", 5);
3725 0 : break;
3726 :
3727 0 : case M2MetaError_warning:
3728 0 : M2Printf_printf0 ((const char *) "warning", 7);
3729 0 : break;
3730 :
3731 0 : case M2MetaError_note:
3732 0 : M2Printf_printf0 ((const char *) "note", 4);
3733 0 : break;
3734 :
3735 0 : case M2MetaError_chained:
3736 0 : M2Printf_printf0 ((const char *) "chained", 7);
3737 0 : break;
3738 :
3739 0 : case M2MetaError_aborta:
3740 0 : M2Printf_printf0 ((const char *) "abort", 5);
3741 0 : break;
3742 :
3743 :
3744 0 : default:
3745 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2MetaError.def", 20, 1);
3746 0 : __builtin_unreachable ();
3747 : }
3748 0 : }
3749 :
3750 :
3751 : /*
3752 : dumpColorType -
3753 : */
3754 :
3755 0 : static void dumpColorType (M2MetaError_colorType c)
3756 : {
3757 0 : switch (c)
3758 : {
3759 0 : case M2MetaError_unsetColor:
3760 0 : M2Printf_printf0 ((const char *) "unsetColor", 10);
3761 0 : break;
3762 :
3763 0 : case M2MetaError_noColor:
3764 0 : M2Printf_printf0 ((const char *) "noColor", 7);
3765 0 : break;
3766 :
3767 0 : case M2MetaError_quoteColor:
3768 0 : M2Printf_printf0 ((const char *) "quoteColor", 10);
3769 0 : break;
3770 :
3771 0 : case M2MetaError_filenameColor:
3772 0 : M2Printf_printf0 ((const char *) "filenameColor", 13);
3773 0 : break;
3774 :
3775 0 : case M2MetaError_errorColor:
3776 0 : M2Printf_printf0 ((const char *) "errorColor", 10);
3777 0 : break;
3778 :
3779 0 : case M2MetaError_warningColor:
3780 0 : M2Printf_printf0 ((const char *) "warningColor", 12);
3781 0 : break;
3782 :
3783 0 : case M2MetaError_noteColor:
3784 0 : M2Printf_printf0 ((const char *) "noteColor", 9);
3785 0 : break;
3786 :
3787 0 : case M2MetaError_keywordColor:
3788 0 : M2Printf_printf0 ((const char *) "keywordColor", 12);
3789 0 : break;
3790 :
3791 0 : case M2MetaError_locusColor:
3792 0 : M2Printf_printf0 ((const char *) "locusColor", 10);
3793 0 : break;
3794 :
3795 0 : case M2MetaError_insertColor:
3796 0 : M2Printf_printf0 ((const char *) "insertColor", 11);
3797 0 : break;
3798 :
3799 0 : case M2MetaError_deleteColor:
3800 0 : M2Printf_printf0 ((const char *) "deleteColor", 11);
3801 0 : break;
3802 :
3803 0 : case M2MetaError_typeColor:
3804 0 : M2Printf_printf0 ((const char *) "typeColor", 9);
3805 0 : break;
3806 :
3807 0 : case M2MetaError_range1Color:
3808 0 : M2Printf_printf0 ((const char *) "range1Color", 11);
3809 0 : break;
3810 :
3811 0 : case M2MetaError_range2Color:
3812 0 : M2Printf_printf0 ((const char *) "range2Color", 11);
3813 0 : break;
3814 :
3815 :
3816 0 : default:
3817 0 : CaseException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2MetaError.def", 20, 1);
3818 0 : __builtin_unreachable ();
3819 : }
3820 0 : }
3821 :
3822 :
3823 : /*
3824 : dump -
3825 :
3826 : */
3827 :
3828 0 : static void dump (M2MetaError_errorBlock eb)
3829 : {
3830 0 : char ch;
3831 0 : unsigned int l;
3832 0 : int i;
3833 :
3834 0 : l = DynamicStrings_Length (eb.out);
3835 0 : M2Printf_printf0 ((const char *) "\\n\\nerrorBlock\\n", 16);
3836 0 : M2Printf_printf0 ((const char *) "\\ntype = ", 14);
3837 0 : dumpErrorType (eb.type);
3838 0 : M2Printf_printf1 ((const char *) "\\nout = |%s|", 18, (const unsigned char *) &eb.out, (sizeof (eb.out)-1));
3839 0 : M2Printf_printf1 ((const char *) "\\nin = |%s|", 18, (const unsigned char *) &eb.in, (sizeof (eb.in)-1));
3840 0 : M2Printf_printf1 ((const char *) "\\nLength (out) = %d", 19, (const unsigned char *) &l, (sizeof (l)-1));
3841 0 : M2Printf_printf1 ((const char *) "\\nlen = %d", 16, (const unsigned char *) &eb.len, (sizeof (eb.len)-1));
3842 0 : M2Printf_printf1 ((const char *) "\\nhighplus1 = %d", 16, (const unsigned char *) &eb.highplus1, (sizeof (eb.highplus1)-1));
3843 : /* printf1 ("
3844 : glyph = %d", eb.glyph) ;
3845 : printf1 ("
3846 : quotes = %d", eb.quotes) ;
3847 : printf1 ("
3848 : positive = %d", eb.positive) ;
3849 : */
3850 0 : M2Printf_printf0 ((const char *) "\\nbeginCol = ", 14);
3851 0 : dumpColorType (eb.beginCol);
3852 0 : M2Printf_printf0 ((const char *) "\\nendCol = ", 14);
3853 0 : dumpColorType (eb.endCol);
3854 0 : M2Printf_printf0 ((const char *) "\\ncurrentCol = ", 15);
3855 0 : dumpColorType (eb.currentCol);
3856 0 : M2Printf_printf1 ((const char *) "\\nini = %d", 17, (const unsigned char *) &eb.ini, (sizeof (eb.ini)-1));
3857 0 : if (eb.ini < eb.len)
3858 : {
3859 0 : ch = DynamicStrings_char (eb.in, eb.ini);
3860 0 : M2Printf_printf1 ((const char *) "\\ncurrent char = %c", 19, (const unsigned char *) &ch, (sizeof (ch)-1));
3861 0 : M2Printf_printf1 ((const char *) "\\n%s\\n", 6, (const unsigned char *) &eb.in, (sizeof (eb.in)-1));
3862 0 : i = 0;
3863 0 : while (i < eb.ini)
3864 : {
3865 0 : M2Printf_printf0 ((const char *) " ", 1);
3866 0 : i += 1;
3867 : }
3868 0 : M2Printf_printf0 ((const char *) "^\\n", 3);
3869 : }
3870 0 : M2Printf_printf0 ((const char *) "\\n", 2);
3871 0 : }
3872 :
3873 :
3874 : /*
3875 : ebnf := { percent
3876 : | lbra
3877 : | any % copy ch %
3878 : }
3879 : =:
3880 : */
3881 :
3882 22462 : static void ebnf (M2MetaError_errorBlock *eb, const unsigned int *sym_, unsigned int _sym_high)
3883 : {
3884 22462 : M2MetaError_errorBlock nb;
3885 22462 : unsigned int sym[_sym_high+1];
3886 :
3887 : /* make a local copy of each unbounded array. */
3888 22462 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
3889 :
3890 22462 : if (Debugging)
3891 : {
3892 : M2Printf_printf0 ((const char *) "top of ebnf\\n", 13);
3893 : dump ((*eb));
3894 : }
3895 1600811 : while ((*eb).ini < (*eb).len)
3896 : {
3897 1583997 : if (Debugging)
3898 : {
3899 : M2Printf_printf0 ((const char *) "while loop ebnf\\n", 17);
3900 : dump ((*eb));
3901 : }
3902 1583997 : switch (DynamicStrings_char ((*eb).in, (*eb).ini))
3903 : {
3904 0 : case '!':
3905 0 : (*eb).positive = ! (*eb).positive;
3906 0 : break;
3907 :
3908 0 : case '%':
3909 0 : percent (eb, (const unsigned int *) sym, _sym_high);
3910 0 : break;
3911 :
3912 42609 : case '{':
3913 42609 : push (&nb, (*eb));
3914 42609 : lbra (&nb, (const unsigned int *) sym, _sym_high);
3915 42609 : pop (eb, &nb);
3916 42609 : if (((*eb).ini < (*eb).len) && ((DynamicStrings_char ((*eb).in, (*eb).ini)) != '}'))
3917 : {
3918 0 : InternalFormat ((*eb), (const char *) "expecting to see }", 18, 2471);
3919 : }
3920 : break;
3921 :
3922 5648 : case '}':
3923 5648 : return;
3924 1535740 : break;
3925 :
3926 :
3927 1535740 : default:
3928 1535740 : if (((((IsWhite (DynamicStrings_char ((*eb).in, (*eb).ini))) && ((DynamicStrings_Length ((*eb).out)) > 0)) && (! (IsWhite (DynamicStrings_char ((*eb).out, -1))))) || (! (IsWhite (DynamicStrings_char ((*eb).in, (*eb).ini))))) && ((*eb).highplus1 > 0))
3929 : {
3930 1533447 : (*eb).quotes = false; /* copying a normal character, don't quote the result. */
3931 1533447 : copyChar (eb); /* copying a normal character, don't quote the result. */
3932 : }
3933 : break;
3934 : }
3935 1578349 : (*eb).ini += 1;
3936 : }
3937 16814 : (*eb).currentCol = M2MetaError_noColor;
3938 16814 : flushColor (eb);
3939 16814 : if (Debugging)
3940 : {
3941 : M2Printf_printf0 ((const char *) "finishing ebnf\\n", 16);
3942 : dump ((*eb));
3943 : }
3944 22462 : }
3945 :
3946 :
3947 : /*
3948 : isUniqueError - return TRUE if the symbol associated with the
3949 : error block is unknown and we have seen the same
3950 : token before.
3951 : */
3952 :
3953 2610 : static bool isUniqueError (M2MetaError_errorBlock *eb)
3954 : {
3955 2610 : if (((*eb).symcause != SymbolTable_NulSym) && (SymbolTable_IsUnknown ((*eb).symcause)))
3956 : {
3957 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
3958 : /* A candidate for filtering. */
3959 232 : if (FilterError_IsSymError (FilterUnknown, (*eb).symcause, (*eb).token))
3960 : {
3961 : /* Seen and reported about this unknown and token
3962 : location before. */
3963 : return false;
3964 : }
3965 : else
3966 : {
3967 : /* Remember this combination. */
3968 213 : FilterError_AddSymError (FilterUnknown, (*eb).symcause, (*eb).token);
3969 : }
3970 : }
3971 : return true;
3972 : /* static analysis guarentees a RETURN statement will be used before here. */
3973 : __builtin_unreachable ();
3974 : }
3975 :
3976 :
3977 : /*
3978 : wrapErrors -
3979 : */
3980 :
3981 114 : static void wrapErrors (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, const unsigned int *sym_, unsigned int _sym_high)
3982 : {
3983 114 : M2MetaError_errorBlock eb;
3984 114 : char m1[_m1_high+1];
3985 114 : char m2[_m2_high+1];
3986 114 : unsigned int sym[_sym_high+1];
3987 :
3988 : /* make a local copy of each unbounded array. */
3989 114 : memcpy (m1, m1_, _m1_high+1);
3990 114 : memcpy (m2, m2_, _m2_high+1);
3991 114 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
3992 :
3993 114 : initErrorBlock (&eb, DynamicStrings_InitString ((const char *) m1, _m1_high), (const unsigned int *) sym, _sym_high);
3994 114 : ebnf (&eb, (const unsigned int *) sym, _sym_high);
3995 114 : flushColor (&eb);
3996 114 : defaultError (&eb, tok);
3997 114 : if (isUniqueError (&eb))
3998 : {
3999 114 : lastRoot = eb.e;
4000 114 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4001 114 : killErrorBlock (&eb);
4002 114 : initErrorBlock (&eb, DynamicStrings_InitString ((const char *) m2, _m2_high), (const unsigned int *) sym, _sym_high);
4003 114 : eb.type = M2MetaError_chained;
4004 114 : ebnf (&eb, (const unsigned int *) sym, _sym_high);
4005 114 : flushColor (&eb);
4006 114 : defaultError (&eb, tok);
4007 114 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4008 : }
4009 : else
4010 : {
4011 0 : M2Error_KillError (&eb.e);
4012 : }
4013 114 : killErrorBlock (&eb);
4014 114 : }
4015 :
4016 :
4017 : /*
4018 : checkAbort - checks to see if the boolean flag seenAbort has been set,
4019 : if so it flushes all existing errors and terminates.
4020 : */
4021 :
4022 2929 : static void checkAbort (void)
4023 : {
4024 2929 : if (seenAbort)
4025 : {
4026 95 : M2Error_FlushWarnings ();
4027 95 : M2Error_FlushErrors ();
4028 : }
4029 2834 : }
4030 :
4031 :
4032 : /*
4033 : translate -
4034 : */
4035 :
4036 0 : static DynamicStrings_String translate (DynamicStrings_String m, DynamicStrings_String s, int *i, NameKey_Name name)
4037 : {
4038 0 : int l;
4039 0 : char ch;
4040 :
4041 0 : l = DynamicStrings_Length (m);
4042 0 : while (((*i) >= 0) && ((*i) < l))
4043 : {
4044 0 : ch = DynamicStrings_char (m, (*i));
4045 0 : if ((ch == '%') && ((*i) < l))
4046 : {
4047 0 : (*i) += 1;
4048 0 : ch = DynamicStrings_char (m, (*i));
4049 0 : (*i) += 1;
4050 0 : if (ch == 'a')
4051 : {
4052 0 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%<", 2)));
4053 0 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (name))));
4054 0 : s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%>", 2)));
4055 0 : return s;
4056 : }
4057 0 : s = DynamicStrings_ConCatChar (s, '%');
4058 : }
4059 0 : s = DynamicStrings_ConCatChar (s, ch);
4060 0 : (*i) += 1;
4061 : }
4062 : return s;
4063 : /* static analysis guarentees a RETURN statement will be used before here. */
4064 : __builtin_unreachable ();
4065 : }
4066 :
4067 :
4068 : /*
4069 : wrapString - return a string which has been formatted with the specifier codes.
4070 : Color is disabled. The result string is returned.
4071 : */
4072 :
4073 13663 : static DynamicStrings_String wrapString (DynamicStrings_String m, const unsigned int *sym_, unsigned int _sym_high)
4074 : {
4075 13663 : M2MetaError_errorBlock eb;
4076 13663 : DynamicStrings_String s;
4077 13663 : bool old;
4078 13663 : unsigned int sym[_sym_high+1];
4079 :
4080 : /* make a local copy of each unbounded array. */
4081 13663 : memcpy (sym, sym_, (_sym_high+1) * sizeof (unsigned int));
4082 :
4083 27326 : old = M2ColorString_SetEnableColor (false);
4084 13663 : initErrorBlock (&eb, DynamicStrings_Dup (m), (const unsigned int *) sym, _sym_high);
4085 13663 : eb.useError = false;
4086 13663 : ebnf (&eb, (const unsigned int *) sym, _sym_high);
4087 13663 : flushColor (&eb);
4088 13663 : s = DynamicStrings_Dup (eb.out);
4089 13663 : killErrorBlock (&eb);
4090 13663 : old = M2ColorString_SetEnableColor (old);
4091 13663 : return s;
4092 : /* static analysis guarentees a RETURN statement will be used before here. */
4093 : __builtin_unreachable ();
4094 13663 : }
4095 :
4096 0 : extern "C" void M2MetaError_MetaError0 (const char *m_, unsigned int _m_high)
4097 : {
4098 0 : char m[_m_high+1];
4099 :
4100 : /* make a local copy of each unbounded array. */
4101 0 : memcpy (m, m_, _m_high+1);
4102 :
4103 0 : M2MetaError_MetaErrorT0 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high);
4104 0 : }
4105 :
4106 420 : extern "C" void M2MetaError_MetaError1 (const char *m_, unsigned int _m_high, unsigned int s)
4107 : {
4108 420 : char m[_m_high+1];
4109 :
4110 : /* make a local copy of each unbounded array. */
4111 420 : memcpy (m, m_, _m_high+1);
4112 :
4113 420 : M2MetaError_MetaErrorT1 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high, s);
4114 420 : }
4115 :
4116 30 : extern "C" void M2MetaError_MetaError2 (const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2)
4117 : {
4118 30 : char m[_m_high+1];
4119 :
4120 : /* make a local copy of each unbounded array. */
4121 30 : memcpy (m, m_, _m_high+1);
4122 :
4123 30 : M2MetaError_MetaErrorT2 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high, s1, s2);
4124 30 : }
4125 :
4126 0 : extern "C" void M2MetaError_MetaError3 (const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3)
4127 : {
4128 0 : char m[_m_high+1];
4129 :
4130 : /* make a local copy of each unbounded array. */
4131 0 : memcpy (m, m_, _m_high+1);
4132 :
4133 0 : M2MetaError_MetaErrorT3 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high, s1, s2, s3);
4134 0 : }
4135 :
4136 0 : extern "C" void M2MetaError_MetaError4 (const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4137 : {
4138 0 : char m[_m_high+1];
4139 :
4140 : /* make a local copy of each unbounded array. */
4141 0 : memcpy (m, m_, _m_high+1);
4142 :
4143 0 : M2MetaError_MetaErrorT4 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high, s1, s2, s3, s4);
4144 0 : }
4145 :
4146 :
4147 : /*
4148 : wrapErrors -
4149 : */
4150 :
4151 18 : extern "C" void M2MetaError_MetaErrors1 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s)
4152 : {
4153 18 : char m1[_m1_high+1];
4154 18 : char m2[_m2_high+1];
4155 :
4156 : /* make a local copy of each unbounded array. */
4157 18 : memcpy (m1, m1_, _m1_high+1);
4158 18 : memcpy (m2, m2_, _m2_high+1);
4159 :
4160 18 : M2MetaError_MetaErrorsT1 (M2LexBuf_GetTokenNo (), (const char *) m1, _m1_high, (const char *) m2, _m2_high, s);
4161 18 : }
4162 :
4163 :
4164 : /*
4165 : wrapErrors -
4166 : */
4167 :
4168 6 : extern "C" void M2MetaError_MetaErrors2 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2)
4169 : {
4170 6 : char m1[_m1_high+1];
4171 6 : char m2[_m2_high+1];
4172 :
4173 : /* make a local copy of each unbounded array. */
4174 6 : memcpy (m1, m1_, _m1_high+1);
4175 6 : memcpy (m2, m2_, _m2_high+1);
4176 :
4177 6 : M2MetaError_MetaErrorsT2 (M2LexBuf_GetTokenNo (), (const char *) m1, _m1_high, (const char *) m2, _m2_high, s1, s2);
4178 6 : }
4179 :
4180 :
4181 : /*
4182 : wrapErrors -
4183 : */
4184 :
4185 0 : extern "C" void M2MetaError_MetaErrors3 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3)
4186 : {
4187 0 : char m1[_m1_high+1];
4188 0 : char m2[_m2_high+1];
4189 :
4190 : /* make a local copy of each unbounded array. */
4191 0 : memcpy (m1, m1_, _m1_high+1);
4192 0 : memcpy (m2, m2_, _m2_high+1);
4193 :
4194 0 : M2MetaError_MetaErrorsT3 (M2LexBuf_GetTokenNo (), (const char *) m1, _m1_high, (const char *) m2, _m2_high, s1, s2, s3);
4195 0 : }
4196 :
4197 :
4198 : /*
4199 : wrapErrors -
4200 : */
4201 :
4202 0 : extern "C" void M2MetaError_MetaErrors4 (const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4203 : {
4204 0 : char m1[_m1_high+1];
4205 0 : char m2[_m2_high+1];
4206 :
4207 : /* make a local copy of each unbounded array. */
4208 0 : memcpy (m1, m1_, _m1_high+1);
4209 0 : memcpy (m2, m2_, _m2_high+1);
4210 :
4211 0 : M2MetaError_MetaErrorsT4 (M2LexBuf_GetTokenNo (), (const char *) m1, _m1_high, (const char *) m2, _m2_high, s1, s2, s3, s4);
4212 0 : }
4213 :
4214 59 : extern "C" void M2MetaError_MetaErrorT0 (unsigned int tok, const char *m_, unsigned int _m_high)
4215 : {
4216 59 : char m[_m_high+1];
4217 :
4218 : /* make a local copy of each unbounded array. */
4219 59 : memcpy (m, m_, _m_high+1);
4220 :
4221 59 : M2MetaError_MetaErrorStringT0 (tok, DynamicStrings_InitString ((const char *) m, _m_high));
4222 59 : }
4223 :
4224 1188 : extern "C" void M2MetaError_MetaErrorT1 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s)
4225 : {
4226 1188 : char m[_m_high+1];
4227 :
4228 : /* make a local copy of each unbounded array. */
4229 1188 : memcpy (m, m_, _m_high+1);
4230 :
4231 1188 : M2MetaError_MetaErrorStringT1 (tok, DynamicStrings_InitString ((const char *) m, _m_high), s);
4232 1188 : }
4233 :
4234 542 : extern "C" void M2MetaError_MetaErrorT2 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2)
4235 : {
4236 542 : char m[_m_high+1];
4237 :
4238 : /* make a local copy of each unbounded array. */
4239 542 : memcpy (m, m_, _m_high+1);
4240 :
4241 542 : M2MetaError_MetaErrorStringT2 (tok, DynamicStrings_InitString ((const char *) m, _m_high), s1, s2);
4242 542 : }
4243 :
4244 60 : extern "C" void M2MetaError_MetaErrorT3 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3)
4245 : {
4246 60 : char m[_m_high+1];
4247 :
4248 : /* make a local copy of each unbounded array. */
4249 60 : memcpy (m, m_, _m_high+1);
4250 :
4251 60 : M2MetaError_MetaErrorStringT3 (tok, DynamicStrings_InitString ((const char *) m, _m_high), s1, s2, s3);
4252 60 : }
4253 :
4254 12 : extern "C" void M2MetaError_MetaErrorT4 (unsigned int tok, const char *m_, unsigned int _m_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4255 : {
4256 12 : char m[_m_high+1];
4257 :
4258 : /* make a local copy of each unbounded array. */
4259 12 : memcpy (m, m_, _m_high+1);
4260 :
4261 12 : M2MetaError_MetaErrorStringT4 (tok, DynamicStrings_InitString ((const char *) m, _m_high), s1, s2, s3, s4);
4262 12 : }
4263 :
4264 :
4265 : /*
4266 : wrapErrors -
4267 : */
4268 :
4269 18 : extern "C" void M2MetaError_MetaErrorsT1 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s)
4270 : {
4271 18 : typedef struct MetaErrorsT1__T4_a MetaErrorsT1__T4;
4272 :
4273 18 : struct MetaErrorsT1__T4_a { unsigned int array[0+1]; };
4274 18 : MetaErrorsT1__T4 sym;
4275 18 : char m1[_m1_high+1];
4276 18 : char m2[_m2_high+1];
4277 :
4278 : /* make a local copy of each unbounded array. */
4279 18 : memcpy (m1, m1_, _m1_high+1);
4280 18 : memcpy (m2, m2_, _m2_high+1);
4281 :
4282 18 : sym.array[0] = s;
4283 18 : wrapErrors (tok, (const char *) m1, _m1_high, (const char *) m2, _m2_high, (const unsigned int *) &sym.array[0], 0);
4284 18 : }
4285 :
4286 :
4287 : /*
4288 : wrapErrors -
4289 : */
4290 :
4291 96 : extern "C" void M2MetaError_MetaErrorsT2 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2)
4292 : {
4293 96 : typedef struct MetaErrorsT2__T5_a MetaErrorsT2__T5;
4294 :
4295 96 : struct MetaErrorsT2__T5_a { unsigned int array[1+1]; };
4296 96 : MetaErrorsT2__T5 sym;
4297 96 : char m1[_m1_high+1];
4298 96 : char m2[_m2_high+1];
4299 :
4300 : /* make a local copy of each unbounded array. */
4301 96 : memcpy (m1, m1_, _m1_high+1);
4302 96 : memcpy (m2, m2_, _m2_high+1);
4303 :
4304 96 : sym.array[0] = s1;
4305 96 : sym.array[1] = s2;
4306 96 : wrapErrors (tok, (const char *) m1, _m1_high, (const char *) m2, _m2_high, (const unsigned int *) &sym.array[0], 1);
4307 96 : }
4308 :
4309 :
4310 : /*
4311 : wrapErrors -
4312 : */
4313 :
4314 0 : extern "C" void M2MetaError_MetaErrorsT3 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3)
4315 : {
4316 0 : typedef struct MetaErrorsT3__T6_a MetaErrorsT3__T6;
4317 :
4318 0 : struct MetaErrorsT3__T6_a { unsigned int array[2+1]; };
4319 0 : MetaErrorsT3__T6 sym;
4320 0 : char m1[_m1_high+1];
4321 0 : char m2[_m2_high+1];
4322 :
4323 : /* make a local copy of each unbounded array. */
4324 0 : memcpy (m1, m1_, _m1_high+1);
4325 0 : memcpy (m2, m2_, _m2_high+1);
4326 :
4327 0 : sym.array[0] = s1;
4328 0 : sym.array[1] = s2;
4329 0 : sym.array[2] = s3;
4330 0 : wrapErrors (tok, (const char *) m1, _m1_high, (const char *) m2, _m2_high, (const unsigned int *) &sym.array[0], 2);
4331 0 : }
4332 :
4333 :
4334 : /*
4335 : wrapErrors -
4336 : */
4337 :
4338 0 : extern "C" void M2MetaError_MetaErrorsT4 (unsigned int tok, const char *m1_, unsigned int _m1_high, const char *m2_, unsigned int _m2_high, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4339 : {
4340 0 : typedef struct MetaErrorsT4__T7_a MetaErrorsT4__T7;
4341 :
4342 0 : struct MetaErrorsT4__T7_a { unsigned int array[3+1]; };
4343 0 : MetaErrorsT4__T7 sym;
4344 0 : char m1[_m1_high+1];
4345 0 : char m2[_m2_high+1];
4346 :
4347 : /* make a local copy of each unbounded array. */
4348 0 : memcpy (m1, m1_, _m1_high+1);
4349 0 : memcpy (m2, m2_, _m2_high+1);
4350 :
4351 0 : sym.array[0] = s1;
4352 0 : sym.array[1] = s2;
4353 0 : sym.array[2] = s3;
4354 0 : sym.array[3] = s4;
4355 0 : wrapErrors (tok, (const char *) m1, _m1_high, (const char *) m2, _m2_high, (const unsigned int *) &sym.array[0], 3);
4356 0 : }
4357 :
4358 :
4359 : /*
4360 : wrapErrors -
4361 : */
4362 :
4363 0 : extern "C" void M2MetaError_MetaErrorString0 (DynamicStrings_String m)
4364 : {
4365 0 : M2MetaError_MetaErrorStringT0 (M2LexBuf_GetTokenNo (), m);
4366 0 : }
4367 :
4368 :
4369 : /*
4370 : wrapErrors -
4371 : */
4372 :
4373 0 : extern "C" void M2MetaError_MetaErrorString1 (DynamicStrings_String m, unsigned int s)
4374 : {
4375 0 : M2MetaError_MetaErrorStringT1 (M2LexBuf_GetTokenNo (), m, s);
4376 0 : }
4377 :
4378 :
4379 : /*
4380 : wrapErrors -
4381 : */
4382 :
4383 0 : extern "C" void M2MetaError_MetaErrorString2 (DynamicStrings_String m, unsigned int s1, unsigned int s2)
4384 : {
4385 0 : M2MetaError_MetaErrorStringT2 (M2LexBuf_GetTokenNo (), m, s1, s2);
4386 0 : }
4387 :
4388 :
4389 : /*
4390 : wrapErrors -
4391 : */
4392 :
4393 132 : extern "C" void M2MetaError_MetaErrorString3 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3)
4394 : {
4395 132 : M2MetaError_MetaErrorStringT3 (M2LexBuf_GetTokenNo (), m, s1, s2, s3);
4396 132 : }
4397 :
4398 :
4399 : /*
4400 : wrapErrors -
4401 : */
4402 :
4403 0 : extern "C" void M2MetaError_MetaErrorString4 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4404 : {
4405 0 : M2MetaError_MetaErrorStringT4 (M2LexBuf_GetTokenNo (), m, s1, s2, s3, s4);
4406 0 : }
4407 :
4408 433 : extern "C" void M2MetaError_MetaErrorStringT0 (unsigned int tok, DynamicStrings_String m)
4409 : {
4410 433 : typedef struct MetaErrorStringT0__T8_a MetaErrorStringT0__T8;
4411 :
4412 433 : struct MetaErrorStringT0__T8_a { unsigned int array[0+1]; };
4413 433 : M2MetaError_errorBlock eb;
4414 433 : MetaErrorStringT0__T8 sym;
4415 :
4416 433 : sym.array[0] = SymbolTable_NulSym;
4417 433 : initErrorBlock (&eb, m, (const unsigned int *) &sym.array[0], 0);
4418 433 : ebnf (&eb, (const unsigned int *) &sym.array[0], 0);
4419 433 : flushColor (&eb);
4420 433 : defaultError (&eb, tok);
4421 433 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4422 433 : killErrorBlock (&eb);
4423 433 : checkAbort ();
4424 421 : }
4425 :
4426 1671 : extern "C" void M2MetaError_MetaErrorStringT1 (unsigned int tok, DynamicStrings_String m, unsigned int s)
4427 : {
4428 1671 : typedef struct MetaErrorStringT1__T9_a MetaErrorStringT1__T9;
4429 :
4430 1671 : struct MetaErrorStringT1__T9_a { unsigned int array[0+1]; };
4431 1671 : M2MetaError_errorBlock eb;
4432 1671 : MetaErrorStringT1__T9 sym;
4433 :
4434 1671 : sym.array[0] = s;
4435 1671 : initErrorBlock (&eb, m, (const unsigned int *) &sym.array[0], 0);
4436 1671 : ebnf (&eb, (const unsigned int *) &sym.array[0], 0);
4437 1671 : flushColor (&eb);
4438 1671 : defaultError (&eb, tok);
4439 1671 : if (isUniqueError (&eb))
4440 : {
4441 1652 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4442 : }
4443 : else
4444 : {
4445 19 : M2Error_KillError (&eb.e);
4446 : }
4447 1671 : killErrorBlock (&eb);
4448 1671 : checkAbort ();
4449 1588 : }
4450 :
4451 621 : extern "C" void M2MetaError_MetaErrorStringT2 (unsigned int tok, DynamicStrings_String m, unsigned int s1, unsigned int s2)
4452 : {
4453 621 : typedef struct MetaErrorStringT2__T10_a MetaErrorStringT2__T10;
4454 :
4455 621 : struct MetaErrorStringT2__T10_a { unsigned int array[1+1]; };
4456 621 : M2MetaError_errorBlock eb;
4457 621 : MetaErrorStringT2__T10 sym;
4458 :
4459 621 : sym.array[0] = s1;
4460 621 : sym.array[1] = s2;
4461 621 : initErrorBlock (&eb, m, (const unsigned int *) &sym.array[0], 1);
4462 621 : ebnf (&eb, (const unsigned int *) &sym.array[0], 1);
4463 621 : flushColor (&eb);
4464 621 : defaultError (&eb, tok);
4465 621 : if (isUniqueError (&eb))
4466 : {
4467 621 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4468 : }
4469 : else
4470 : {
4471 0 : M2Error_KillError (&eb.e);
4472 : }
4473 621 : killErrorBlock (&eb);
4474 621 : checkAbort ();
4475 621 : }
4476 :
4477 192 : extern "C" void M2MetaError_MetaErrorStringT3 (unsigned int tok, DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3)
4478 : {
4479 192 : typedef struct MetaErrorStringT3__T11_a MetaErrorStringT3__T11;
4480 :
4481 192 : struct MetaErrorStringT3__T11_a { unsigned int array[2+1]; };
4482 192 : M2MetaError_errorBlock eb;
4483 192 : MetaErrorStringT3__T11 sym;
4484 :
4485 192 : sym.array[0] = s1;
4486 192 : sym.array[1] = s2;
4487 192 : sym.array[2] = s3;
4488 192 : initErrorBlock (&eb, m, (const unsigned int *) &sym.array[0], 2);
4489 192 : eb.highplus1 = 2+1;
4490 192 : ebnf (&eb, (const unsigned int *) &sym.array[0], 2);
4491 192 : flushColor (&eb);
4492 192 : defaultError (&eb, tok);
4493 192 : if (isUniqueError (&eb))
4494 : {
4495 192 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4496 : }
4497 : else
4498 : {
4499 0 : M2Error_KillError (&eb.e);
4500 : }
4501 192 : killErrorBlock (&eb);
4502 192 : checkAbort ();
4503 192 : }
4504 :
4505 12 : extern "C" void M2MetaError_MetaErrorStringT4 (unsigned int tok, DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4506 : {
4507 12 : typedef struct MetaErrorStringT4__T12_a MetaErrorStringT4__T12;
4508 :
4509 12 : struct MetaErrorStringT4__T12_a { unsigned int array[3+1]; };
4510 12 : M2MetaError_errorBlock eb;
4511 12 : MetaErrorStringT4__T12 sym;
4512 :
4513 12 : sym.array[0] = s1;
4514 12 : sym.array[1] = s2;
4515 12 : sym.array[2] = s3;
4516 12 : sym.array[3] = s4;
4517 12 : initErrorBlock (&eb, m, (const unsigned int *) &sym.array[0], 3);
4518 12 : ebnf (&eb, (const unsigned int *) &sym.array[0], 3);
4519 12 : flushColor (&eb);
4520 12 : defaultError (&eb, tok);
4521 12 : if (isUniqueError (&eb))
4522 : {
4523 12 : M2Error_ErrorString (eb.e, DynamicStrings_Dup (eb.out));
4524 : }
4525 : else
4526 : {
4527 0 : M2Error_KillError (&eb.e);
4528 : }
4529 12 : killErrorBlock (&eb);
4530 12 : checkAbort ();
4531 12 : }
4532 :
4533 :
4534 : /*
4535 : MetaErrorN1 -
4536 : */
4537 :
4538 0 : extern "C" void M2MetaError_MetaErrorN1 (const char *m_, unsigned int _m_high, NameKey_Name n)
4539 : {
4540 0 : char m[_m_high+1];
4541 :
4542 : /* make a local copy of each unbounded array. */
4543 0 : memcpy (m, m_, _m_high+1);
4544 :
4545 0 : M2MetaError_MetaErrorNT1 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high, n);
4546 0 : }
4547 :
4548 :
4549 : /*
4550 : MetaErrorN2 -
4551 : */
4552 :
4553 0 : extern "C" void M2MetaError_MetaErrorN2 (const char *m_, unsigned int _m_high, NameKey_Name n1, NameKey_Name n2)
4554 : {
4555 0 : char m[_m_high+1];
4556 :
4557 : /* make a local copy of each unbounded array. */
4558 0 : memcpy (m, m_, _m_high+1);
4559 :
4560 0 : M2MetaError_MetaErrorNT2 (M2LexBuf_GetTokenNo (), (const char *) m, _m_high, n1, n2);
4561 0 : }
4562 :
4563 :
4564 : /*
4565 : MetaErrorNT0 - generate an error message at tok using format.
4566 : */
4567 :
4568 0 : extern "C" void M2MetaError_MetaErrorNT0 (unsigned int tok, const char *format_, unsigned int _format_high)
4569 : {
4570 0 : char format[_format_high+1];
4571 :
4572 : /* make a local copy of each unbounded array. */
4573 0 : memcpy (format, format_, _format_high+1);
4574 :
4575 0 : M2MetaError_MetaErrorStringT0 (tok, DynamicStrings_InitString ((const char *) format, _format_high));
4576 0 : }
4577 :
4578 :
4579 : /*
4580 : MetaErrorNT1 - generate an error message at tok using format and name.
4581 : The format should contain %a for name substitution.
4582 : */
4583 :
4584 0 : extern "C" void M2MetaError_MetaErrorNT1 (unsigned int tok, const char *format_, unsigned int _format_high, NameKey_Name name)
4585 : {
4586 0 : int i;
4587 0 : DynamicStrings_String s;
4588 0 : DynamicStrings_String fmt;
4589 0 : char format[_format_high+1];
4590 :
4591 : /* make a local copy of each unbounded array. */
4592 0 : memcpy (format, format_, _format_high+1);
4593 :
4594 0 : i = 0;
4595 0 : fmt = DynamicStrings_InitString ((const char *) format, _format_high);
4596 0 : s = DynamicStrings_InitString ((const char *) "", 0);
4597 0 : s = translate (fmt, s, &i, name);
4598 0 : M2MetaError_MetaErrorStringT0 (tok, s);
4599 0 : fmt = DynamicStrings_KillString (fmt);
4600 0 : }
4601 :
4602 0 : extern "C" void M2MetaError_MetaErrorNT2 (unsigned int tok, const char *format_, unsigned int _format_high, NameKey_Name name1, NameKey_Name name2)
4603 : {
4604 0 : int i;
4605 0 : DynamicStrings_String s;
4606 0 : DynamicStrings_String fmt;
4607 0 : char format[_format_high+1];
4608 :
4609 : /* make a local copy of each unbounded array. */
4610 0 : memcpy (format, format_, _format_high+1);
4611 :
4612 : /*
4613 : MetaErrorNT1 - generate an error message at tok using format, name1
4614 : and name2. The format should contain two occurances of %a
4615 : for name substitution.
4616 : */
4617 0 : i = 0;
4618 0 : fmt = DynamicStrings_InitString ((const char *) format, _format_high);
4619 0 : s = DynamicStrings_InitString ((const char *) "", 0);
4620 0 : s = translate (fmt, s, &i, name1);
4621 0 : s = translate (fmt, s, &i, name2);
4622 0 : M2MetaError_MetaErrorStringT0 (tok, s);
4623 0 : fmt = DynamicStrings_KillString (fmt);
4624 0 : }
4625 :
4626 :
4627 : /*
4628 : wrapString - return a string which has been formatted with the specifier codes.
4629 : Color is disabled. The result string is returned.
4630 : */
4631 :
4632 18 : extern "C" DynamicStrings_String M2MetaError_MetaString0 (DynamicStrings_String m)
4633 : {
4634 18 : typedef struct MetaString0__T13_a MetaString0__T13;
4635 :
4636 18 : struct MetaString0__T13_a { unsigned int array[0+1]; };
4637 18 : MetaString0__T13 sym;
4638 :
4639 18 : sym.array[0] = SymbolTable_NulSym;
4640 18 : return wrapString (m, (const unsigned int *) &sym.array[0], 0);
4641 : /* static analysis guarentees a RETURN statement will be used before here. */
4642 : __builtin_unreachable ();
4643 : }
4644 :
4645 :
4646 : /*
4647 : wrapString - return a string which has been formatted with the specifier codes.
4648 : Color is disabled. The result string is returned.
4649 : */
4650 :
4651 66 : extern "C" DynamicStrings_String M2MetaError_MetaString1 (DynamicStrings_String m, unsigned int s)
4652 : {
4653 66 : typedef struct MetaString1__T14_a MetaString1__T14;
4654 :
4655 66 : struct MetaString1__T14_a { unsigned int array[0+1]; };
4656 66 : MetaString1__T14 sym;
4657 :
4658 66 : sym.array[0] = s;
4659 66 : return wrapString (m, (const unsigned int *) &sym.array[0], 0);
4660 : /* static analysis guarentees a RETURN statement will be used before here. */
4661 : __builtin_unreachable ();
4662 : }
4663 :
4664 :
4665 : /*
4666 : wrapString - return a string which has been formatted with the specifier codes.
4667 : Color is disabled. The result string is returned.
4668 : */
4669 :
4670 576 : extern "C" DynamicStrings_String M2MetaError_MetaString2 (DynamicStrings_String m, unsigned int s1, unsigned int s2)
4671 : {
4672 576 : typedef struct MetaString2__T15_a MetaString2__T15;
4673 :
4674 576 : struct MetaString2__T15_a { unsigned int array[1+1]; };
4675 576 : MetaString2__T15 sym;
4676 :
4677 576 : sym.array[0] = s1;
4678 576 : sym.array[1] = s2;
4679 576 : return wrapString (m, (const unsigned int *) &sym.array[0], 1);
4680 : /* static analysis guarentees a RETURN statement will be used before here. */
4681 : __builtin_unreachable ();
4682 : }
4683 :
4684 :
4685 : /*
4686 : wrapString - return a string which has been formatted with the specifier codes.
4687 : Color is disabled. The result string is returned.
4688 : */
4689 :
4690 12895 : extern "C" DynamicStrings_String M2MetaError_MetaString3 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3)
4691 : {
4692 12895 : typedef struct MetaString3__T16_a MetaString3__T16;
4693 :
4694 12895 : struct MetaString3__T16_a { unsigned int array[2+1]; };
4695 12895 : MetaString3__T16 sym;
4696 :
4697 12895 : sym.array[0] = s1;
4698 12895 : sym.array[1] = s2;
4699 12895 : sym.array[2] = s3;
4700 12895 : return wrapString (m, (const unsigned int *) &sym.array[0], 2);
4701 : /* static analysis guarentees a RETURN statement will be used before here. */
4702 : __builtin_unreachable ();
4703 : }
4704 :
4705 :
4706 : /*
4707 : wrapString - return a string which has been formatted with the specifier codes.
4708 : Color is disabled. The result string is returned.
4709 : */
4710 :
4711 108 : extern "C" DynamicStrings_String M2MetaError_MetaString4 (DynamicStrings_String m, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4)
4712 : {
4713 108 : typedef struct MetaString4__T17_a MetaString4__T17;
4714 :
4715 108 : struct MetaString4__T17_a { unsigned int array[3+1]; };
4716 108 : MetaString4__T17 sym;
4717 :
4718 108 : sym.array[0] = s1;
4719 108 : sym.array[1] = s2;
4720 108 : sym.array[2] = s3;
4721 108 : sym.array[3] = s4;
4722 108 : return wrapString (m, (const unsigned int *) &sym.array[0], 3);
4723 : /* static analysis guarentees a RETURN statement will be used before here. */
4724 : __builtin_unreachable ();
4725 : }
4726 :
4727 :
4728 : /*
4729 : MetaErrorDecl - if sym is a variable or parameter then generate a
4730 : declaration error or warning message. If error is
4731 : FALSE then a warning is issued.
4732 : */
4733 :
4734 264 : extern "C" void M2MetaError_MetaErrorDecl (unsigned int sym, bool error)
4735 : {
4736 264 : if ((sym != SymbolTable_NulSym) && (SymbolTable_IsVar (sym)))
4737 : {
4738 : /* avoid gcc warning by using compound statement even if not strictly necessary. */
4739 222 : if (error)
4740 : {
4741 222 : if (SymbolTable_IsVarAParam (sym))
4742 : {
4743 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetVarDeclFullTok (sym), (const char *) "parameter declaration for {%1ad}", 32, sym);
4744 : }
4745 : else
4746 : {
4747 222 : M2MetaError_MetaErrorT1 (SymbolTable_GetVarDeclFullTok (sym), (const char *) "variable declaration for {%1ad}", 31, sym);
4748 : }
4749 : }
4750 : else
4751 : {
4752 0 : if (SymbolTable_IsVarAParam (sym))
4753 : {
4754 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetVarDeclFullTok (sym), (const char *) "parameter declaration for {%1Wad}", 33, sym);
4755 : }
4756 : else
4757 : {
4758 0 : M2MetaError_MetaErrorT1 (SymbolTable_GetVarDeclFullTok (sym), (const char *) "variable declaration for {%1Wad}", 32, sym);
4759 : }
4760 : }
4761 : }
4762 264 : }
4763 :
4764 15451 : extern "C" void _M2_M2MetaError_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
4765 : {
4766 15451 : lastRoot = static_cast<M2Error_Error> (NULL);
4767 15451 : lastColor = M2MetaError_noColor;
4768 15451 : seenAbort = false;
4769 15451 : outputStack = Indexing_InitIndex (1);
4770 15451 : dictionary = Indexing_InitIndex (1);
4771 15451 : freeEntry = NULL;
4772 15451 : FilterUnknown = FilterError_Init ();
4773 15451 : }
4774 :
4775 0 : extern "C" void _M2_M2MetaError_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
4776 : {
4777 0 : }
|