| 1 |
/* do not edit automatically generated by mc from mcError. */ |
| 2 |
/* mcError.mod provides an interface between the string handling modules. |
| 3 |
|
| 4 |
Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 5 |
Contributed by Gaius Mulley <[email protected]>. |
| 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 <stdbool.h> |
| 26 |
# if !defined (PROC_D) |
| 27 |
# define PROC_D |
| 28 |
typedef void (*PROC_t) (void); |
| 29 |
typedef struct { PROC_t proc; } PROC; |
| 30 |
# endif |
| 31 |
|
| 32 |
# if !defined (TRUE) |
| 33 |
# define TRUE (1==1) |
| 34 |
# endif |
| 35 |
|
| 36 |
# if !defined (FALSE) |
| 37 |
# define FALSE (1==0) |
| 38 |
# endif |
| 39 |
|
| 40 |
# include "GStorage.h" |
| 41 |
#if defined(__cplusplus) |
| 42 |
# undef NULL |
| 43 |
# define NULL 0 |
| 44 |
#endif |
| 45 |
#define _mcError_C |
| 46 |
|
| 47 |
#include "GmcError.h" |
| 48 |
# include "GASCII.h" |
| 49 |
# include "GDynamicStrings.h" |
| 50 |
# include "GFIO.h" |
| 51 |
# include "GStrLib.h" |
| 52 |
# include "GFormatStrings.h" |
| 53 |
# include "GStorage.h" |
| 54 |
# include "GM2RTS.h" |
| 55 |
# include "GSYSTEM.h" |
| 56 |
# include "GStdIO.h" |
| 57 |
# include "GnameKey.h" |
| 58 |
# include "GmcLexBuf.h" |
| 59 |
# include "GmcPrintf.h" |
| 60 |
|
| 61 |
# define Debugging true |
| 62 |
# define DebugTrace false |
| 63 |
# define Xcode true |
| 64 |
typedef struct mcError__T2_r mcError__T2; |
| 65 |
|
| 66 |
typedef mcError__T2 *mcError_error__opaque; |
| 67 |
|
| 68 |
struct mcError__T2_r { |
| 69 |
mcError_error__opaque parent; |
| 70 |
mcError_error__opaque child; |
| 71 |
mcError_error__opaque next; |
| 72 |
bool fatal; |
| 73 |
DynamicStrings_String s; |
| 74 |
unsigned int token; |
| 75 |
}; |
| 76 |
|
| 77 |
static mcError_error__opaque head; |
| 78 |
static bool inInternal; |
| 79 |
|
| 80 |
/* |
| 81 |
internalError - displays an internal error message together with the compiler source |
| 82 |
file and line number. |
| 83 |
This function is not buffered and is used when the compiler is about |
| 84 |
to give up. |
| 85 |
*/ |
| 86 |
|
| 87 |
extern "C" void mcError_internalError (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line); |
| 88 |
|
| 89 |
/* |
| 90 |
writeFormat0 - displays the source module and line together |
| 91 |
with the encapsulated format string. |
| 92 |
Used for simple error messages tied to the current token. |
| 93 |
*/ |
| 94 |
|
| 95 |
extern "C" void mcError_writeFormat0 (const char *a_, unsigned int _a_high); |
| 96 |
|
| 97 |
/* |
| 98 |
writeFormat1 - displays the source module and line together |
| 99 |
with the encapsulated format string. |
| 100 |
Used for simple error messages tied to the current token. |
| 101 |
*/ |
| 102 |
|
| 103 |
extern "C" void mcError_writeFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high); |
| 104 |
|
| 105 |
/* |
| 106 |
writeFormat2 - displays the module and line together with the encapsulated |
| 107 |
format strings. |
| 108 |
Used for simple error messages tied to the current token. |
| 109 |
*/ |
| 110 |
|
| 111 |
extern "C" void mcError_writeFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high); |
| 112 |
|
| 113 |
/* |
| 114 |
writeFormat3 - displays the module and line together with the encapsulated |
| 115 |
format strings. |
| 116 |
Used for simple error messages tied to the current token. |
| 117 |
*/ |
| 118 |
|
| 119 |
extern "C" void mcError_writeFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high); |
| 120 |
|
| 121 |
/* |
| 122 |
newError - creates and returns a new error handle. |
| 123 |
*/ |
| 124 |
|
| 125 |
extern "C" mcError_error mcError_newError (unsigned int atTokenNo); |
| 126 |
|
| 127 |
/* |
| 128 |
newWarning - creates and returns a new error handle suitable for a warning. |
| 129 |
A warning will not stop compilation. |
| 130 |
*/ |
| 131 |
|
| 132 |
extern "C" mcError_error mcError_newWarning (unsigned int atTokenNo); |
| 133 |
|
| 134 |
/* |
| 135 |
chainError - creates and returns a new error handle, this new error |
| 136 |
is associated with, e, and is chained onto the end of, e. |
| 137 |
If, e, is NIL then the result to NewError is returned. |
| 138 |
*/ |
| 139 |
|
| 140 |
extern "C" mcError_error mcError_chainError (unsigned int atTokenNo, mcError_error e); |
| 141 |
extern "C" void mcError_errorFormat0 (mcError_error e, const char *a_, unsigned int _a_high); |
| 142 |
extern "C" void mcError_errorFormat1 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high); |
| 143 |
extern "C" void mcError_errorFormat2 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high); |
| 144 |
extern "C" void mcError_errorFormat3 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high); |
| 145 |
extern "C" void mcError_errorString (mcError_error e, DynamicStrings_String str); |
| 146 |
|
| 147 |
/* |
| 148 |
errorStringAt - given an error string, s, it places this |
| 149 |
string at token position, tok. |
| 150 |
The string is consumed. |
| 151 |
*/ |
| 152 |
|
| 153 |
extern "C" void mcError_errorStringAt (DynamicStrings_String s, unsigned int tok); |
| 154 |
|
| 155 |
/* |
| 156 |
errorStringAt2 - given an error string, s, it places this |
| 157 |
string at token positions, tok1 and tok2, respectively. |
| 158 |
The string is consumed. |
| 159 |
*/ |
| 160 |
|
| 161 |
extern "C" void mcError_errorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2); |
| 162 |
|
| 163 |
/* |
| 164 |
errorStringsAt2 - given error strings, s1, and, s2, it places these |
| 165 |
strings at token positions, tok1 and tok2, respectively. |
| 166 |
Both strings are consumed. |
| 167 |
*/ |
| 168 |
|
| 169 |
extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2); |
| 170 |
|
| 171 |
/* |
| 172 |
warnStringAt - given an error string, s, it places this |
| 173 |
string at token position, tok. |
| 174 |
The string is consumed. |
| 175 |
*/ |
| 176 |
|
| 177 |
extern "C" void mcError_warnStringAt (DynamicStrings_String s, unsigned int tok); |
| 178 |
|
| 179 |
/* |
| 180 |
warnStringAt2 - given an warning string, s, it places this |
| 181 |
string at token positions, tok1 and tok2, respectively. |
| 182 |
The string is consumed. |
| 183 |
*/ |
| 184 |
|
| 185 |
extern "C" void mcError_warnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2); |
| 186 |
|
| 187 |
/* |
| 188 |
warnStringsAt2 - given warning strings, s1, and, s2, it places these |
| 189 |
strings at token positions, tok1 and tok2, respectively. |
| 190 |
Both strings are consumed. |
| 191 |
*/ |
| 192 |
|
| 193 |
extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2); |
| 194 |
extern "C" void mcError_warnFormat0 (const char *a_, unsigned int _a_high); |
| 195 |
|
| 196 |
/* |
| 197 |
warnFormat1 - displays the source module and line together |
| 198 |
with the encapsulated format string. |
| 199 |
Used for simple warning messages tied to the current token. |
| 200 |
*/ |
| 201 |
|
| 202 |
extern "C" void mcError_warnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high); |
| 203 |
|
| 204 |
/* |
| 205 |
flushErrors - switches the output channel to the error channel |
| 206 |
and then writes out all errors. |
| 207 |
*/ |
| 208 |
|
| 209 |
extern "C" void mcError_flushErrors (void); |
| 210 |
|
| 211 |
/* |
| 212 |
flushWarnings - switches the output channel to the error channel |
| 213 |
and then writes out all warnings. |
| 214 |
If an error is present the compilation is terminated, |
| 215 |
if warnings only were emitted then compilation will |
| 216 |
continue. |
| 217 |
*/ |
| 218 |
|
| 219 |
extern "C" void mcError_flushWarnings (void); |
| 220 |
|
| 221 |
/* |
| 222 |
errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting. |
| 223 |
*/ |
| 224 |
|
| 225 |
extern "C" void mcError_errorAbort0 (const char *a_, unsigned int _a_high); |
| 226 |
|
| 227 |
/* |
| 228 |
cast - casts a := b |
| 229 |
*/ |
| 230 |
|
| 231 |
static void cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high); |
| 232 |
static bool translateNameToCharStar (char *a, unsigned int _a_high, unsigned int n); |
| 233 |
|
| 234 |
/* |
| 235 |
outString - writes the contents of String to stdout. |
| 236 |
The string, s, is destroyed. |
| 237 |
*/ |
| 238 |
|
| 239 |
static void outString (DynamicStrings_String file, unsigned int line, unsigned int col, DynamicStrings_String s); |
| 240 |
static DynamicStrings_String doFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high); |
| 241 |
|
| 242 |
/* |
| 243 |
doFormat2 - |
| 244 |
*/ |
| 245 |
|
| 246 |
static DynamicStrings_String doFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high); |
| 247 |
|
| 248 |
/* |
| 249 |
writeFormat2 - displays the module and line together with the encapsulated |
| 250 |
format strings. |
| 251 |
Used for simple error messages tied to the current token. |
| 252 |
*/ |
| 253 |
|
| 254 |
static DynamicStrings_String doFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high); |
| 255 |
|
| 256 |
/* |
| 257 |
init - initializes the error list. |
| 258 |
*/ |
| 259 |
|
| 260 |
static void init (void); |
| 261 |
|
| 262 |
/* |
| 263 |
checkIncludes - generates a sequence of error messages which determine the relevant |
| 264 |
included file and line number. |
| 265 |
For example: |
| 266 |
|
| 267 |
gcc a.c |
| 268 |
In file included from b.h:1, |
| 269 |
from a.c:1: |
| 270 |
c.h:1: parse error before `and' |
| 271 |
|
| 272 |
where a.c is: #include "b.h" |
| 273 |
b.h is: #include "c.h" |
| 274 |
c.h is: and this and that |
| 275 |
|
| 276 |
we attempt to follow the error messages that gcc issues. |
| 277 |
*/ |
| 278 |
|
| 279 |
static void checkIncludes (unsigned int token, unsigned int depth); |
| 280 |
|
| 281 |
/* |
| 282 |
flushAll - flushes all errors in list, e. |
| 283 |
*/ |
| 284 |
|
| 285 |
static bool flushAll (mcError_error__opaque e, bool FatalStatus); |
| 286 |
|
| 287 |
|
| 288 |
/* |
| 289 |
cast - casts a := b |
| 290 |
*/ |
| 291 |
|
| 292 |
static void cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high) |
| 293 |
{ |
| 294 |
unsigned int i; |
| 295 |
unsigned char b[_b_high+1]; |
| 296 |
|
| 297 |
/* make a local copy of each unbounded array. */ |
| 298 |
memcpy (b, b_, _b_high+1); |
| 299 |
|
| 300 |
if (_a_high == _b_high) |
| 301 |
{ |
| 302 |
for (i=0; i<=_a_high; i++) |
| 303 |
{ |
| 304 |
const_cast<unsigned char *>(a)[i] = b[i]; |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
static bool translateNameToCharStar (char *a, unsigned int _a_high, unsigned int n) |
| 310 |
{ |
| 311 |
unsigned int argno; |
| 312 |
unsigned int i; |
| 313 |
unsigned int h; |
| 314 |
|
| 315 |
/* |
| 316 |
translateNameToString - takes a format specification string, a, and |
| 317 |
if they consist of of %a then this is translated |
| 318 |
into a String and %a is replaced by %s. |
| 319 |
*/ |
| 320 |
argno = 1; |
| 321 |
i = 0; |
| 322 |
h = StrLib_StrLen ((const char *) a, _a_high); |
| 323 |
while (i < h) |
| 324 |
{ |
| 325 |
if ((a[i] == '%') && ((i+1) < h)) |
| 326 |
{ |
| 327 |
if ((a[i+1] == 'a') && (argno == n)) |
| 328 |
{ |
| 329 |
const_cast<char *>(a)[i+1] = 's'; |
| 330 |
return true; |
| 331 |
} |
| 332 |
argno += 1; |
| 333 |
if (argno > n) |
| 334 |
{ |
| 335 |
/* all done */ |
| 336 |
return false; |
| 337 |
} |
| 338 |
} |
| 339 |
i += 1; |
| 340 |
} |
| 341 |
return false; |
| 342 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 343 |
__builtin_unreachable (); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
/* |
| 348 |
outString - writes the contents of String to stdout. |
| 349 |
The string, s, is destroyed. |
| 350 |
*/ |
| 351 |
|
| 352 |
static void outString (DynamicStrings_String file, unsigned int line, unsigned int col, DynamicStrings_String s) |
| 353 |
{ |
| 354 |
typedef char *outString__T1; |
| 355 |
|
| 356 |
DynamicStrings_String leader; |
| 357 |
outString__T1 p; |
| 358 |
outString__T1 q; |
| 359 |
bool space; |
| 360 |
bool newline; |
| 361 |
|
| 362 |
col += 1; |
| 363 |
if (Xcode) |
| 364 |
{ |
| 365 |
leader = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%s:%d:", 6)), (const unsigned char *) &file, (sizeof (file)-1), (const unsigned char *) &line, (sizeof (line)-1)); |
| 366 |
} |
| 367 |
else |
| 368 |
{ |
| 369 |
leader = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%s:%d:%d:", 9)), (const unsigned char *) &file, (sizeof (file)-1), (const unsigned char *) &line, (sizeof (line)-1), (const unsigned char *) &col, (sizeof (col)-1)); |
| 370 |
} |
| 371 |
p = static_cast<outString__T1> (DynamicStrings_string (s)); |
| 372 |
newline = true; |
| 373 |
space = false; |
| 374 |
while ((p != NULL) && ((*p) != ASCII_nul)) |
| 375 |
{ |
| 376 |
if (newline) |
| 377 |
{ |
| 378 |
q = static_cast<outString__T1> (DynamicStrings_string (leader)); |
| 379 |
while ((q != NULL) && ((*q) != ASCII_nul)) |
| 380 |
{ |
| 381 |
StdIO_Write ((*q)); |
| 382 |
q += 1; |
| 383 |
} |
| 384 |
} |
| 385 |
newline = (*p) == ASCII_nl; |
| 386 |
space = (*p) == ' '; |
| 387 |
if (newline && Xcode) |
| 388 |
{ |
| 389 |
mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col, (sizeof (col)-1)); |
| 390 |
} |
| 391 |
StdIO_Write ((*p)); |
| 392 |
p += 1; |
| 393 |
} |
| 394 |
if (! newline) |
| 395 |
{ |
| 396 |
if (Xcode) |
| 397 |
{ |
| 398 |
if (! space) |
| 399 |
{ |
| 400 |
StdIO_Write (' '); |
| 401 |
} |
| 402 |
mcPrintf_printf1 ((const char *) "(pos: %d)", 9, (const unsigned char *) &col, (sizeof (col)-1)); |
| 403 |
} |
| 404 |
StdIO_Write (ASCII_nl); |
| 405 |
} |
| 406 |
FIO_FlushBuffer (FIO_StdOut); |
| 407 |
if (! Debugging) |
| 408 |
{ |
| 409 |
s = DynamicStrings_KillString (s); |
| 410 |
leader = DynamicStrings_KillString (leader); |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
static DynamicStrings_String doFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high) |
| 415 |
{ |
| 416 |
DynamicStrings_String s; |
| 417 |
nameKey_Name n; |
| 418 |
char a[_a_high+1]; |
| 419 |
unsigned char w[_w_high+1]; |
| 420 |
|
| 421 |
/* make a local copy of each unbounded array. */ |
| 422 |
memcpy (a, a_, _a_high+1); |
| 423 |
memcpy (w, w_, _w_high+1); |
| 424 |
|
| 425 |
/* |
| 426 |
DoFormat1 - |
| 427 |
*/ |
| 428 |
if (translateNameToCharStar ((char *) a, _a_high, 1)) |
| 429 |
{ |
| 430 |
cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w, _w_high); |
| 431 |
s = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n))); |
| 432 |
s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s, (sizeof (s)-1)); |
| 433 |
} |
| 434 |
else |
| 435 |
{ |
| 436 |
s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w, _w_high); |
| 437 |
} |
| 438 |
return s; |
| 439 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 440 |
__builtin_unreachable (); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
/* |
| 445 |
doFormat2 - |
| 446 |
*/ |
| 447 |
|
| 448 |
static DynamicStrings_String doFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high) |
| 449 |
{ |
| 450 |
nameKey_Name n; |
| 451 |
DynamicStrings_String s; |
| 452 |
DynamicStrings_String s1; |
| 453 |
DynamicStrings_String s2; |
| 454 |
unsigned int b; |
| 455 |
char a[_a_high+1]; |
| 456 |
unsigned char w1[_w1_high+1]; |
| 457 |
unsigned char w2[_w2_high+1]; |
| 458 |
|
| 459 |
/* make a local copy of each unbounded array. */ |
| 460 |
memcpy (a, a_, _a_high+1); |
| 461 |
memcpy (w1, w1_, _w1_high+1); |
| 462 |
memcpy (w2, w2_, _w2_high+1); |
| 463 |
|
| 464 |
b = (unsigned int) 0; |
| 465 |
if (translateNameToCharStar ((char *) a, _a_high, 1)) |
| 466 |
{ |
| 467 |
cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high); |
| 468 |
s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n))); |
| 469 |
b |= (1 << (1 )); |
| 470 |
} |
| 471 |
if (translateNameToCharStar ((char *) a, _a_high, 2)) |
| 472 |
{ |
| 473 |
cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high); |
| 474 |
s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n))); |
| 475 |
b |= (1 << (2 )); |
| 476 |
} |
| 477 |
switch (b) |
| 478 |
{ |
| 479 |
case (unsigned int) 0: |
| 480 |
s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high); |
| 481 |
break; |
| 482 |
|
| 483 |
case (unsigned int) ((1 << (1))): |
| 484 |
s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) w2, _w2_high); |
| 485 |
break; |
| 486 |
|
| 487 |
case (unsigned int) ((1 << (2))): |
| 488 |
s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) &s2, (sizeof (s2)-1)); |
| 489 |
break; |
| 490 |
|
| 491 |
case (unsigned int) ((1 << (1)) | (1 << (2))): |
| 492 |
s = FormatStrings_Sprintf2 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1)); |
| 493 |
break; |
| 494 |
|
| 495 |
|
| 496 |
default: |
| 497 |
M2RTS_HALT (-1); |
| 498 |
__builtin_unreachable (); |
| 499 |
break; |
| 500 |
} |
| 501 |
return s; |
| 502 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 503 |
__builtin_unreachable (); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
/* |
| 508 |
writeFormat2 - displays the module and line together with the encapsulated |
| 509 |
format strings. |
| 510 |
Used for simple error messages tied to the current token. |
| 511 |
*/ |
| 512 |
|
| 513 |
static DynamicStrings_String doFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high) |
| 514 |
{ |
| 515 |
nameKey_Name n; |
| 516 |
DynamicStrings_String s; |
| 517 |
DynamicStrings_String s1; |
| 518 |
DynamicStrings_String s2; |
| 519 |
DynamicStrings_String s3; |
| 520 |
unsigned int b; |
| 521 |
char a[_a_high+1]; |
| 522 |
unsigned char w1[_w1_high+1]; |
| 523 |
unsigned char w2[_w2_high+1]; |
| 524 |
unsigned char w3[_w3_high+1]; |
| 525 |
|
| 526 |
/* make a local copy of each unbounded array. */ |
| 527 |
memcpy (a, a_, _a_high+1); |
| 528 |
memcpy (w1, w1_, _w1_high+1); |
| 529 |
memcpy (w2, w2_, _w2_high+1); |
| 530 |
memcpy (w3, w3_, _w3_high+1); |
| 531 |
|
| 532 |
b = (unsigned int) 0; |
| 533 |
if (translateNameToCharStar ((char *) a, _a_high, 1)) |
| 534 |
{ |
| 535 |
cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w1, _w1_high); |
| 536 |
s1 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n))); |
| 537 |
b |= (1 << (1 )); |
| 538 |
} |
| 539 |
if (translateNameToCharStar ((char *) a, _a_high, 2)) |
| 540 |
{ |
| 541 |
cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w2, _w2_high); |
| 542 |
s2 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n))); |
| 543 |
b |= (1 << (2 )); |
| 544 |
} |
| 545 |
if (translateNameToCharStar ((char *) a, _a_high, 3)) |
| 546 |
{ |
| 547 |
cast ((unsigned char *) &n, (sizeof (n)-1), (const unsigned char *) w3, _w3_high); |
| 548 |
s3 = DynamicStrings_Mark (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n))); |
| 549 |
b |= (1 << (3 )); |
| 550 |
} |
| 551 |
switch (b) |
| 552 |
{ |
| 553 |
case (unsigned int) 0: |
| 554 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high); |
| 555 |
break; |
| 556 |
|
| 557 |
case (unsigned int) ((1 << (1))): |
| 558 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high); |
| 559 |
break; |
| 560 |
|
| 561 |
case (unsigned int) ((1 << (2))): |
| 562 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) w3, _w3_high); |
| 563 |
break; |
| 564 |
|
| 565 |
case (unsigned int) ((1 << (1)) | (1 << (2))): |
| 566 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) w3, _w3_high); |
| 567 |
break; |
| 568 |
|
| 569 |
case (unsigned int) ((1 << (3))): |
| 570 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) &s3, (sizeof (s3)-1)); |
| 571 |
break; |
| 572 |
|
| 573 |
case (unsigned int) ((1 << (1)) | (1 << (3))): |
| 574 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) w2, _w2_high, (const unsigned char *) &s3, (sizeof (s3)-1)); |
| 575 |
break; |
| 576 |
|
| 577 |
case (unsigned int) ((1 << (2)) | (1 << (3))): |
| 578 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) w1, _w1_high, (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) &s3, (sizeof (s3)-1)); |
| 579 |
break; |
| 580 |
|
| 581 |
case (unsigned int) ((1 << (1)) | (1 << (2)) | (1 << (3))): |
| 582 |
s = FormatStrings_Sprintf3 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)), (const unsigned char *) &s1, (sizeof (s1)-1), (const unsigned char *) &s2, (sizeof (s2)-1), (const unsigned char *) &s3, (sizeof (s3)-1)); |
| 583 |
break; |
| 584 |
|
| 585 |
|
| 586 |
default: |
| 587 |
M2RTS_HALT (-1); |
| 588 |
__builtin_unreachable (); |
| 589 |
break; |
| 590 |
} |
| 591 |
return s; |
| 592 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 593 |
__builtin_unreachable (); |
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
/* |
| 598 |
init - initializes the error list. |
| 599 |
*/ |
| 600 |
|
| 601 |
static void init (void) |
| 602 |
{ |
| 603 |
head = static_cast<mcError_error__opaque> (NULL); |
| 604 |
inInternal = false; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
/* |
| 609 |
checkIncludes - generates a sequence of error messages which determine the relevant |
| 610 |
included file and line number. |
| 611 |
For example: |
| 612 |
|
| 613 |
gcc a.c |
| 614 |
In file included from b.h:1, |
| 615 |
from a.c:1: |
| 616 |
c.h:1: parse error before `and' |
| 617 |
|
| 618 |
where a.c is: #include "b.h" |
| 619 |
b.h is: #include "c.h" |
| 620 |
c.h is: and this and that |
| 621 |
|
| 622 |
we attempt to follow the error messages that gcc issues. |
| 623 |
*/ |
| 624 |
|
| 625 |
static void checkIncludes (unsigned int token, unsigned int depth) |
| 626 |
{ |
| 627 |
DynamicStrings_String included; |
| 628 |
unsigned int lineno; |
| 629 |
|
| 630 |
included = mcLexBuf_findFileNameFromToken (token, depth+1); |
| 631 |
if (included != NULL) |
| 632 |
{ |
| 633 |
lineno = mcLexBuf_tokenToLineNo (token, depth+1); |
| 634 |
if (depth == 0) |
| 635 |
{ |
| 636 |
mcPrintf_printf2 ((const char *) "In file included from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1)); |
| 637 |
} |
| 638 |
else |
| 639 |
{ |
| 640 |
mcPrintf_printf2 ((const char *) " from %s:%d", 27, (const unsigned char *) &included, (sizeof (included)-1), (const unsigned char *) &lineno, (sizeof (lineno)-1)); |
| 641 |
} |
| 642 |
if ((mcLexBuf_findFileNameFromToken (token, depth+2)) == NULL) |
| 643 |
{ |
| 644 |
mcPrintf_printf0 ((const char *) ":\\n", 3); |
| 645 |
} |
| 646 |
else |
| 647 |
{ |
| 648 |
mcPrintf_printf0 ((const char *) ",\\n", 3); |
| 649 |
} |
| 650 |
checkIncludes (token, depth+1); |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
/* |
| 656 |
flushAll - flushes all errors in list, e. |
| 657 |
*/ |
| 658 |
|
| 659 |
static bool flushAll (mcError_error__opaque e, bool FatalStatus) |
| 660 |
{ |
| 661 |
mcError_error__opaque f; |
| 662 |
bool written; |
| 663 |
|
| 664 |
written = false; |
| 665 |
if (e != NULL) |
| 666 |
{ |
| 667 |
do { |
| 668 |
if ((FatalStatus == e->fatal) && (e->s != NULL)) |
| 669 |
{ |
| 670 |
checkIncludes (e->token, 0); |
| 671 |
if (e->fatal) |
| 672 |
{ |
| 673 |
e->s = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " error: ", 8), DynamicStrings_Mark (e->s)); |
| 674 |
} |
| 675 |
else |
| 676 |
{ |
| 677 |
e->s = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " warning: ", 10), DynamicStrings_Mark (e->s)); |
| 678 |
} |
| 679 |
outString (mcLexBuf_findFileNameFromToken (e->token, 0), mcLexBuf_tokenToLineNo (e->token, 0), mcLexBuf_tokenToColumnNo (e->token, 0), e->s); |
| 680 |
if ((e->child != NULL) && (flushAll (e->child, FatalStatus))) |
| 681 |
{} /* empty. */ |
| 682 |
e->s = static_cast<DynamicStrings_String> (NULL); |
| 683 |
written = true; |
| 684 |
} |
| 685 |
f = e; |
| 686 |
e = e->next; |
| 687 |
if (! Debugging) |
| 688 |
{ |
| 689 |
f->s = DynamicStrings_KillString (f->s); |
| 690 |
Storage_DEALLOCATE ((void **) &f, sizeof (mcError__T2)); |
| 691 |
} |
| 692 |
} while (! (e == NULL)); |
| 693 |
} |
| 694 |
return written; |
| 695 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 696 |
__builtin_unreachable (); |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
/* |
| 701 |
internalError - displays an internal error message together with the compiler source |
| 702 |
file and line number. |
| 703 |
This function is not buffered and is used when the compiler is about |
| 704 |
to give up. |
| 705 |
*/ |
| 706 |
|
| 707 |
extern "C" void mcError_internalError (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line) |
| 708 |
{ |
| 709 |
char a[_a_high+1]; |
| 710 |
char file[_file_high+1]; |
| 711 |
|
| 712 |
/* make a local copy of each unbounded array. */ |
| 713 |
memcpy (a, a_, _a_high+1); |
| 714 |
memcpy (file, file_, _file_high+1); |
| 715 |
|
| 716 |
M2RTS_ExitOnHalt (1); |
| 717 |
if (! inInternal) |
| 718 |
{ |
| 719 |
inInternal = true; |
| 720 |
mcError_flushErrors (); |
| 721 |
outString (mcLexBuf_findFileNameFromToken (mcLexBuf_getTokenNo (), 0), mcLexBuf_tokenToLineNo (mcLexBuf_getTokenNo (), 0), mcLexBuf_tokenToColumnNo (mcLexBuf_getTokenNo (), 0), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "*** fatal error ***", 19))); |
| 722 |
} |
| 723 |
outString (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) file, _file_high)), line, 0, DynamicStrings_ConCat (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "*** internal error *** ", 23)), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high)))); |
| 724 |
M2RTS_HALT (-1); |
| 725 |
__builtin_unreachable (); |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
/* |
| 730 |
writeFormat0 - displays the source module and line together |
| 731 |
with the encapsulated format string. |
| 732 |
Used for simple error messages tied to the current token. |
| 733 |
*/ |
| 734 |
|
| 735 |
extern "C" void mcError_writeFormat0 (const char *a_, unsigned int _a_high) |
| 736 |
{ |
| 737 |
mcError_error__opaque e; |
| 738 |
char a[_a_high+1]; |
| 739 |
|
| 740 |
/* make a local copy of each unbounded array. */ |
| 741 |
memcpy (a, a_, _a_high+1); |
| 742 |
|
| 743 |
e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ())); |
| 744 |
e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high))); |
| 745 |
} |
| 746 |
|
| 747 |
|
| 748 |
/* |
| 749 |
writeFormat1 - displays the source module and line together |
| 750 |
with the encapsulated format string. |
| 751 |
Used for simple error messages tied to the current token. |
| 752 |
*/ |
| 753 |
|
| 754 |
extern "C" void mcError_writeFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high) |
| 755 |
{ |
| 756 |
mcError_error__opaque e; |
| 757 |
char a[_a_high+1]; |
| 758 |
unsigned char w[_w_high+1]; |
| 759 |
|
| 760 |
/* make a local copy of each unbounded array. */ |
| 761 |
memcpy (a, a_, _a_high+1); |
| 762 |
memcpy (w, w_, _w_high+1); |
| 763 |
|
| 764 |
e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ())); |
| 765 |
e->s = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high); |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
/* |
| 770 |
writeFormat2 - displays the module and line together with the encapsulated |
| 771 |
format strings. |
| 772 |
Used for simple error messages tied to the current token. |
| 773 |
*/ |
| 774 |
|
| 775 |
extern "C" void mcError_writeFormat2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high) |
| 776 |
{ |
| 777 |
mcError_error__opaque e; |
| 778 |
char a[_a_high+1]; |
| 779 |
unsigned char w1[_w1_high+1]; |
| 780 |
unsigned char w2[_w2_high+1]; |
| 781 |
|
| 782 |
/* make a local copy of each unbounded array. */ |
| 783 |
memcpy (a, a_, _a_high+1); |
| 784 |
memcpy (w1, w1_, _w1_high+1); |
| 785 |
memcpy (w2, w2_, _w2_high+1); |
| 786 |
|
| 787 |
e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ())); |
| 788 |
e->s = doFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
/* |
| 793 |
writeFormat3 - displays the module and line together with the encapsulated |
| 794 |
format strings. |
| 795 |
Used for simple error messages tied to the current token. |
| 796 |
*/ |
| 797 |
|
| 798 |
extern "C" void mcError_writeFormat3 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high) |
| 799 |
{ |
| 800 |
mcError_error__opaque e; |
| 801 |
char a[_a_high+1]; |
| 802 |
unsigned char w1[_w1_high+1]; |
| 803 |
unsigned char w2[_w2_high+1]; |
| 804 |
unsigned char w3[_w3_high+1]; |
| 805 |
|
| 806 |
/* make a local copy of each unbounded array. */ |
| 807 |
memcpy (a, a_, _a_high+1); |
| 808 |
memcpy (w1, w1_, _w1_high+1); |
| 809 |
memcpy (w2, w2_, _w2_high+1); |
| 810 |
memcpy (w3, w3_, _w3_high+1); |
| 811 |
|
| 812 |
e = static_cast<mcError_error__opaque> (mcError_newError (mcLexBuf_getTokenNo ())); |
| 813 |
e->s = doFormat3 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high); |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
/* |
| 818 |
newError - creates and returns a new error handle. |
| 819 |
*/ |
| 820 |
|
| 821 |
extern "C" mcError_error mcError_newError (unsigned int atTokenNo) |
| 822 |
{ |
| 823 |
mcError_error__opaque e; |
| 824 |
mcError_error__opaque f; |
| 825 |
|
| 826 |
Storage_ALLOCATE ((void **) &e, sizeof (mcError__T2)); |
| 827 |
e->s = static_cast<DynamicStrings_String> (NULL); |
| 828 |
e->token = atTokenNo; |
| 829 |
e->next = static_cast<mcError_error__opaque> (NULL); |
| 830 |
e->parent = static_cast<mcError_error__opaque> (NULL); |
| 831 |
e->child = static_cast<mcError_error__opaque> (NULL); |
| 832 |
e->fatal = true; |
| 833 |
if ((head == NULL) || (head->token > atTokenNo)) |
| 834 |
{ |
| 835 |
e->next = head; |
| 836 |
head = e; |
| 837 |
} |
| 838 |
else |
| 839 |
{ |
| 840 |
f = head; |
| 841 |
while ((f->next != NULL) && (f->next->token < atTokenNo)) |
| 842 |
{ |
| 843 |
f = f->next; |
| 844 |
} |
| 845 |
e->next = f->next; |
| 846 |
f->next = e; |
| 847 |
} |
| 848 |
return static_cast<mcError_error> (e); |
| 849 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 850 |
__builtin_unreachable (); |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
/* |
| 855 |
newWarning - creates and returns a new error handle suitable for a warning. |
| 856 |
A warning will not stop compilation. |
| 857 |
*/ |
| 858 |
|
| 859 |
extern "C" mcError_error mcError_newWarning (unsigned int atTokenNo) |
| 860 |
{ |
| 861 |
mcError_error__opaque e; |
| 862 |
|
| 863 |
e = static_cast<mcError_error__opaque> (mcError_newError (atTokenNo)); |
| 864 |
e->fatal = false; |
| 865 |
return static_cast<mcError_error> (e); |
| 866 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 867 |
__builtin_unreachable (); |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
/* |
| 872 |
chainError - creates and returns a new error handle, this new error |
| 873 |
is associated with, e, and is chained onto the end of, e. |
| 874 |
If, e, is NIL then the result to NewError is returned. |
| 875 |
*/ |
| 876 |
|
| 877 |
extern "C" mcError_error mcError_chainError (unsigned int atTokenNo, mcError_error e) |
| 878 |
{ |
| 879 |
mcError_error__opaque f; |
| 880 |
|
| 881 |
if (e == NULL) |
| 882 |
{ |
| 883 |
return mcError_newError (atTokenNo); |
| 884 |
} |
| 885 |
else |
| 886 |
{ |
| 887 |
Storage_ALLOCATE ((void **) &f, sizeof (mcError__T2)); |
| 888 |
f->s = static_cast<DynamicStrings_String> (NULL); |
| 889 |
f->token = atTokenNo; |
| 890 |
f->next = static_cast<mcError_error__opaque> (e)->child; |
| 891 |
f->parent = static_cast<mcError_error__opaque> (e); |
| 892 |
f->child = static_cast<mcError_error__opaque> (NULL); |
| 893 |
f->fatal = static_cast<mcError_error__opaque> (e)->fatal; |
| 894 |
static_cast<mcError_error__opaque> (e)->child = f; |
| 895 |
} |
| 896 |
return static_cast<mcError_error> (f); |
| 897 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 898 |
__builtin_unreachable (); |
| 899 |
} |
| 900 |
|
| 901 |
extern "C" void mcError_errorFormat0 (mcError_error e, const char *a_, unsigned int _a_high) |
| 902 |
{ |
| 903 |
char a[_a_high+1]; |
| 904 |
|
| 905 |
/* make a local copy of each unbounded array. */ |
| 906 |
memcpy (a, a_, _a_high+1); |
| 907 |
|
| 908 |
/* |
| 909 |
errorFormat routines provide a printf capability for the error handle. |
| 910 |
*/ |
| 911 |
if (static_cast<mcError_error__opaque> (e)->s == NULL) |
| 912 |
{ |
| 913 |
static_cast<mcError_error__opaque> (e)->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high))); |
| 914 |
} |
| 915 |
else |
| 916 |
{ |
| 917 |
static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high))))); |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
extern "C" void mcError_errorFormat1 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high) |
| 922 |
{ |
| 923 |
DynamicStrings_String s1; |
| 924 |
char a[_a_high+1]; |
| 925 |
unsigned char w[_w_high+1]; |
| 926 |
|
| 927 |
/* make a local copy of each unbounded array. */ |
| 928 |
memcpy (a, a_, _a_high+1); |
| 929 |
memcpy (w, w_, _w_high+1); |
| 930 |
|
| 931 |
s1 = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high); |
| 932 |
if (static_cast<mcError_error__opaque> (e)->s == NULL) |
| 933 |
{ |
| 934 |
static_cast<mcError_error__opaque> (e)->s = s1; |
| 935 |
} |
| 936 |
else |
| 937 |
{ |
| 938 |
static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (s1)); |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
extern "C" void mcError_errorFormat2 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high) |
| 943 |
{ |
| 944 |
DynamicStrings_String s1; |
| 945 |
char a[_a_high+1]; |
| 946 |
unsigned char w1[_w1_high+1]; |
| 947 |
unsigned char w2[_w2_high+1]; |
| 948 |
|
| 949 |
/* make a local copy of each unbounded array. */ |
| 950 |
memcpy (a, a_, _a_high+1); |
| 951 |
memcpy (w1, w1_, _w1_high+1); |
| 952 |
memcpy (w2, w2_, _w2_high+1); |
| 953 |
|
| 954 |
s1 = doFormat2 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high); |
| 955 |
if (static_cast<mcError_error__opaque> (e)->s == NULL) |
| 956 |
{ |
| 957 |
static_cast<mcError_error__opaque> (e)->s = s1; |
| 958 |
} |
| 959 |
else |
| 960 |
{ |
| 961 |
static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (s1)); |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
extern "C" void mcError_errorFormat3 (mcError_error e, const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high) |
| 966 |
{ |
| 967 |
DynamicStrings_String s1; |
| 968 |
char a[_a_high+1]; |
| 969 |
unsigned char w1[_w1_high+1]; |
| 970 |
unsigned char w2[_w2_high+1]; |
| 971 |
unsigned char w3[_w3_high+1]; |
| 972 |
|
| 973 |
/* make a local copy of each unbounded array. */ |
| 974 |
memcpy (a, a_, _a_high+1); |
| 975 |
memcpy (w1, w1_, _w1_high+1); |
| 976 |
memcpy (w2, w2_, _w2_high+1); |
| 977 |
memcpy (w3, w3_, _w3_high+1); |
| 978 |
|
| 979 |
s1 = doFormat3 ((const char *) a, _a_high, (const unsigned char *) w1, _w1_high, (const unsigned char *) w2, _w2_high, (const unsigned char *) w3, _w3_high); |
| 980 |
if (static_cast<mcError_error__opaque> (e)->s == NULL) |
| 981 |
{ |
| 982 |
static_cast<mcError_error__opaque> (e)->s = s1; |
| 983 |
} |
| 984 |
else |
| 985 |
{ |
| 986 |
static_cast<mcError_error__opaque> (e)->s = DynamicStrings_ConCat (static_cast<mcError_error__opaque> (e)->s, DynamicStrings_Mark (s1)); |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
extern "C" void mcError_errorString (mcError_error e, DynamicStrings_String str) |
| 991 |
{ |
| 992 |
static_cast<mcError_error__opaque> (e)->s = str; |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
/* |
| 997 |
errorStringAt - given an error string, s, it places this |
| 998 |
string at token position, tok. |
| 999 |
The string is consumed. |
| 1000 |
*/ |
| 1001 |
|
| 1002 |
extern "C" void mcError_errorStringAt (DynamicStrings_String s, unsigned int tok) |
| 1003 |
{ |
| 1004 |
mcError_error__opaque e; |
| 1005 |
|
| 1006 |
e = static_cast<mcError_error__opaque> (mcError_newError (tok)); |
| 1007 |
mcError_errorString (static_cast<mcError_error> (e), s); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
/* |
| 1012 |
errorStringAt2 - given an error string, s, it places this |
| 1013 |
string at token positions, tok1 and tok2, respectively. |
| 1014 |
The string is consumed. |
| 1015 |
*/ |
| 1016 |
|
| 1017 |
extern "C" void mcError_errorStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2) |
| 1018 |
{ |
| 1019 |
mcError_errorStringsAt2 (s, s, tok1, tok2); |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
/* |
| 1024 |
errorStringsAt2 - given error strings, s1, and, s2, it places these |
| 1025 |
strings at token positions, tok1 and tok2, respectively. |
| 1026 |
Both strings are consumed. |
| 1027 |
*/ |
| 1028 |
|
| 1029 |
extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2) |
| 1030 |
{ |
| 1031 |
mcError_error__opaque e; |
| 1032 |
|
| 1033 |
if (s1 == s2) |
| 1034 |
{ |
| 1035 |
s2 = DynamicStrings_Dup (s1); |
| 1036 |
} |
| 1037 |
e = static_cast<mcError_error__opaque> (mcError_newError (tok1)); |
| 1038 |
mcError_errorString (static_cast<mcError_error> (e), s1); |
| 1039 |
mcError_errorString (mcError_chainError (tok2, static_cast<mcError_error> (e)), s2); |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
/* |
| 1044 |
warnStringAt - given an error string, s, it places this |
| 1045 |
string at token position, tok. |
| 1046 |
The string is consumed. |
| 1047 |
*/ |
| 1048 |
|
| 1049 |
extern "C" void mcError_warnStringAt (DynamicStrings_String s, unsigned int tok) |
| 1050 |
{ |
| 1051 |
mcError_error__opaque e; |
| 1052 |
|
| 1053 |
e = static_cast<mcError_error__opaque> (mcError_newWarning (tok)); |
| 1054 |
mcError_errorString (static_cast<mcError_error> (e), s); |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
/* |
| 1059 |
warnStringAt2 - given an warning string, s, it places this |
| 1060 |
string at token positions, tok1 and tok2, respectively. |
| 1061 |
The string is consumed. |
| 1062 |
*/ |
| 1063 |
|
| 1064 |
extern "C" void mcError_warnStringAt2 (DynamicStrings_String s, unsigned int tok1, unsigned int tok2) |
| 1065 |
{ |
| 1066 |
mcError_warnStringsAt2 (s, s, tok1, tok2); |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
/* |
| 1071 |
warnStringsAt2 - given warning strings, s1, and, s2, it places these |
| 1072 |
strings at token positions, tok1 and tok2, respectively. |
| 1073 |
Both strings are consumed. |
| 1074 |
*/ |
| 1075 |
|
| 1076 |
extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1, DynamicStrings_String s2, unsigned int tok1, unsigned int tok2) |
| 1077 |
{ |
| 1078 |
mcError_error__opaque e; |
| 1079 |
|
| 1080 |
if (s1 == s2) |
| 1081 |
{ |
| 1082 |
s2 = DynamicStrings_Dup (s1); |
| 1083 |
} |
| 1084 |
e = static_cast<mcError_error__opaque> (mcError_newWarning (tok1)); |
| 1085 |
mcError_errorString (static_cast<mcError_error> (e), s1); |
| 1086 |
mcError_errorString (mcError_chainError (tok2, static_cast<mcError_error> (e)), s2); |
| 1087 |
} |
| 1088 |
|
| 1089 |
extern "C" void mcError_warnFormat0 (const char *a_, unsigned int _a_high) |
| 1090 |
{ |
| 1091 |
mcError_error__opaque e; |
| 1092 |
char a[_a_high+1]; |
| 1093 |
|
| 1094 |
/* make a local copy of each unbounded array. */ |
| 1095 |
memcpy (a, a_, _a_high+1); |
| 1096 |
|
| 1097 |
/* |
| 1098 |
WarnFormat0 - displays the source module and line together |
| 1099 |
with the encapsulated format string. |
| 1100 |
Used for simple warning messages tied to the current token. |
| 1101 |
*/ |
| 1102 |
e = static_cast<mcError_error__opaque> (mcError_newWarning (mcLexBuf_getTokenNo ())); |
| 1103 |
e->s = FormatStrings_Sprintf0 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a, _a_high))); |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
/* |
| 1108 |
warnFormat1 - displays the source module and line together |
| 1109 |
with the encapsulated format string. |
| 1110 |
Used for simple warning messages tied to the current token. |
| 1111 |
*/ |
| 1112 |
|
| 1113 |
extern "C" void mcError_warnFormat1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high) |
| 1114 |
{ |
| 1115 |
mcError_error__opaque e; |
| 1116 |
char a[_a_high+1]; |
| 1117 |
unsigned char w[_w_high+1]; |
| 1118 |
|
| 1119 |
/* make a local copy of each unbounded array. */ |
| 1120 |
memcpy (a, a_, _a_high+1); |
| 1121 |
memcpy (w, w_, _w_high+1); |
| 1122 |
|
| 1123 |
e = static_cast<mcError_error__opaque> (mcError_newWarning (mcLexBuf_getTokenNo ())); |
| 1124 |
e->s = doFormat1 ((const char *) a, _a_high, (const unsigned char *) w, _w_high); |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
/* |
| 1129 |
flushErrors - switches the output channel to the error channel |
| 1130 |
and then writes out all errors. |
| 1131 |
*/ |
| 1132 |
|
| 1133 |
extern "C" void mcError_flushErrors (void) |
| 1134 |
{ |
| 1135 |
if (DebugTrace) |
| 1136 |
{ |
| 1137 |
mcPrintf_printf0 ((const char *) "\\nFlushing all errors\\n", 23); |
| 1138 |
mcPrintf_printf0 ((const char *) "===================\\n", 21); |
| 1139 |
} |
| 1140 |
if (flushAll (head, true)) |
| 1141 |
{ |
| 1142 |
M2RTS_ExitOnHalt (1); |
| 1143 |
M2RTS_HALT (-1); |
| 1144 |
__builtin_unreachable (); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
|
| 1149 |
/* |
| 1150 |
flushWarnings - switches the output channel to the error channel |
| 1151 |
and then writes out all warnings. |
| 1152 |
If an error is present the compilation is terminated, |
| 1153 |
if warnings only were emitted then compilation will |
| 1154 |
continue. |
| 1155 |
*/ |
| 1156 |
|
| 1157 |
extern "C" void mcError_flushWarnings (void) |
| 1158 |
{ |
| 1159 |
if (flushAll (head, false)) |
| 1160 |
{} /* empty. */ |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
/* |
| 1165 |
errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting. |
| 1166 |
*/ |
| 1167 |
|
| 1168 |
extern "C" void mcError_errorAbort0 (const char *a_, unsigned int _a_high) |
| 1169 |
{ |
| 1170 |
char a[_a_high+1]; |
| 1171 |
|
| 1172 |
/* make a local copy of each unbounded array. */ |
| 1173 |
memcpy (a, a_, _a_high+1); |
| 1174 |
|
| 1175 |
mcError_flushWarnings (); |
| 1176 |
if (! (StrLib_StrEqual ((const char *) a, _a_high, (const char *) "", 0))) |
| 1177 |
{ |
| 1178 |
mcError_writeFormat0 ((const char *) a, _a_high); |
| 1179 |
} |
| 1180 |
if (! (flushAll (head, true))) |
| 1181 |
{ |
| 1182 |
mcError_writeFormat0 ((const char *) "unidentified error", 18); |
| 1183 |
if (flushAll (head, true)) |
| 1184 |
{} /* empty. */ |
| 1185 |
} |
| 1186 |
M2RTS_ExitOnHalt (1); |
| 1187 |
M2RTS_HALT (-1); |
| 1188 |
__builtin_unreachable (); |
| 1189 |
} |
| 1190 |
|
| 1191 |
extern "C" void _M2_mcError_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 1192 |
{ |
| 1193 |
init (); |
| 1194 |
} |
| 1195 |
|
| 1196 |
extern "C" void _M2_mcError_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 1197 |
{ |
| 1198 |
} |