2004-10-12 09:57:38 -07:00
|
|
|
/*
|
2004-10-19 09:50:27 -07:00
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
2004-10-12 09:57:38 -07:00
|
|
|
*
|
|
|
|
* Small compiler - Error message system
|
2004-03-24 01:48:28 -08:00
|
|
|
* In fact a very simple system, using only 'panic mode'.
|
|
|
|
*
|
|
|
|
* Copyright (c) ITB CompuPhase, 1997-2003
|
|
|
|
*
|
|
|
|
* This software is provided "as-is", without any express or implied warranty.
|
|
|
|
* In no event will the authors be held liable for any damages arising from
|
|
|
|
* the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software in
|
|
|
|
* a product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
2005-04-13 13:01:23 -07:00
|
|
|
|
2008-04-11 12:06:18 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
2005-04-13 13:01:23 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-24 01:48:28 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-04-19 20:50:11 -07:00
|
|
|
#include <stdarg.h>
|
2004-03-24 01:48:28 -08:00
|
|
|
#include <string.h>
|
2009-12-08 09:34:57 -08:00
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-24 01:48:28 -08:00
|
|
|
#include "embryo_cc_sc.h"
|
|
|
|
#include "embryo_cc_sc5.scp"
|
|
|
|
|
|
|
|
static int errflag;
|
2004-04-19 20:50:11 -07:00
|
|
|
static int errstart; /* line number at which the instruction started */
|
2004-03-24 01:48:28 -08:00
|
|
|
|
|
|
|
/* error
|
|
|
|
*
|
|
|
|
* Outputs an error message (note: msg is passed optionally).
|
|
|
|
* If an error is found, the variable "errflag" is set and subsequent
|
|
|
|
* errors are ignored until lex() finds a semicolumn or a keyword
|
|
|
|
* (lex() resets "errflag" in that case).
|
|
|
|
*
|
|
|
|
* Global references: inpfname (reffered to only)
|
|
|
|
* fline (reffered to only)
|
|
|
|
* fcurrent (reffered to only)
|
|
|
|
* errflag (altered)
|
|
|
|
*/
|
2004-04-19 20:50:11 -07:00
|
|
|
int
|
|
|
|
error(int number, ...)
|
2004-03-24 01:48:28 -08:00
|
|
|
{
|
2004-04-19 20:50:11 -07:00
|
|
|
static int lastline, lastfile, errorcount;
|
2010-01-15 11:44:25 -08:00
|
|
|
char *msg;
|
2004-04-19 20:50:11 -07:00
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
2004-10-12 09:57:38 -07:00
|
|
|
int start;
|
2004-03-24 01:48:28 -08:00
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
/* errflag is reset on each semicolon.
|
|
|
|
* In a two-pass compiler, an error should not be reported twice. Therefore
|
|
|
|
* the error reporting is enabled only in the second pass (and only when
|
|
|
|
* actually producing output). Fatal errors may never be ignored.
|
|
|
|
*/
|
2008-04-11 12:06:18 -07:00
|
|
|
if (((errflag) || (sc_status != statWRITE)) &&
|
2004-04-19 20:50:11 -07:00
|
|
|
((number < 100) || (number >= 200)))
|
|
|
|
return 0;
|
2008-04-11 12:06:18 -07:00
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
if (number < 100)
|
|
|
|
{
|
|
|
|
msg = errmsg[number - 1];
|
|
|
|
errflag = TRUE; /* set errflag (skip rest of erroneous expression) */
|
|
|
|
errnum++;
|
|
|
|
}
|
|
|
|
else if (number < 200)
|
|
|
|
{
|
|
|
|
msg = fatalmsg[number - 100];
|
|
|
|
errnum++; /* a fatal error also counts as an error */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = warnmsg[number - 200];
|
|
|
|
warnnum++;
|
|
|
|
}
|
2004-03-24 01:48:28 -08:00
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
strexpand(string, (unsigned char *)msg, sizeof string, SCPACK_TABLE);
|
2004-03-24 01:48:28 -08:00
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
va_start(argptr, number);
|
2004-03-24 01:48:28 -08:00
|
|
|
|
2004-10-12 09:57:38 -07:00
|
|
|
start = (errstart == fline) ? -1 : errstart;
|
|
|
|
|
|
|
|
if (sc_error(number, string, inpfname, start, fline, argptr))
|
|
|
|
{
|
2005-03-26 08:44:12 -08:00
|
|
|
sc_closeasm(outf);
|
2004-10-12 09:57:38 -07:00
|
|
|
outf = NULL;
|
|
|
|
longjmp(errbuf, 3);
|
|
|
|
}
|
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
va_end(argptr);
|
2004-03-24 01:48:28 -08:00
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
if (((number >= 100) && (number < 200)) || (errnum > 250))
|
|
|
|
{
|
2004-10-12 09:57:38 -07:00
|
|
|
va_start(argptr, number);
|
|
|
|
sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
if (outf != NULL)
|
|
|
|
{
|
2005-03-26 08:44:12 -08:00
|
|
|
sc_closeasm(outf);
|
2004-04-19 20:50:11 -07:00
|
|
|
outf = NULL;
|
|
|
|
} /* if */
|
|
|
|
longjmp(errbuf, 2); /* fatal error, quit */
|
|
|
|
} /* if */
|
2004-03-24 01:48:28 -08:00
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
/* check whether we are seeing many errors on the same line */
|
2008-04-11 12:06:18 -07:00
|
|
|
if (((errstart < 0) && (lastline != fline)) ||
|
2004-04-19 20:50:11 -07:00
|
|
|
(lastline < errstart) || (lastline > fline) || (fcurrent != lastfile))
|
|
|
|
errorcount = 0;
|
|
|
|
lastline = fline;
|
|
|
|
lastfile = fcurrent;
|
|
|
|
if (number < 200)
|
|
|
|
errorcount++;
|
|
|
|
if (errorcount >= 3)
|
|
|
|
error(107); /* too many error/warning messages on one line */
|
|
|
|
return 0;
|
2004-03-24 01:48:28 -08:00
|
|
|
}
|
|
|
|
|
2004-04-19 20:50:11 -07:00
|
|
|
void
|
|
|
|
errorset(int code)
|
2004-03-24 01:48:28 -08:00
|
|
|
{
|
2004-04-19 20:50:11 -07:00
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case sRESET:
|
|
|
|
errflag = FALSE; /* start reporting errors */
|
|
|
|
break;
|
|
|
|
case sFORCESET:
|
|
|
|
errflag = TRUE; /* stop reporting errors */
|
|
|
|
break;
|
|
|
|
case sEXPRMARK:
|
|
|
|
errstart = fline; /* save start line number */
|
|
|
|
break;
|
|
|
|
case sEXPRRELEASE:
|
|
|
|
errstart = -1; /* forget start line number */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-03-24 01:48:28 -08:00
|
|
|
}
|