1988-10-26 15:21:11 +00:00
|
|
|
/* E R R O R A N D D I A G N O S T I C R O U T I N E S */
|
|
|
|
|
|
|
|
/* This file contains the (non-portable) error-message and diagnostic
|
|
|
|
giving functions. Be aware that they are called with a variable
|
|
|
|
number of arguments!
|
|
|
|
*/
|
|
|
|
|
2013-05-14 19:47:04 +00:00
|
|
|
#include "parameters.h"
|
1988-10-26 15:21:11 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
1995-08-17 16:34:29 +00:00
|
|
|
#if __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
1989-10-30 17:51:31 +00:00
|
|
|
#include <varargs.h>
|
1995-08-17 16:34:29 +00:00
|
|
|
#endif
|
1988-10-26 15:21:11 +00:00
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
1993-10-26 09:59:06 +00:00
|
|
|
#include <em_code.h>
|
2019-02-23 17:15:23 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "print.h"
|
2019-02-23 16:44:50 +00:00
|
|
|
#include "system.h"
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "f_info.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "node.h"
|
|
|
|
|
|
|
|
/* error classes */
|
|
|
|
#define ERROR 1
|
|
|
|
#define WARNING 2
|
|
|
|
#define LEXERROR 3
|
|
|
|
#define LEXWARNING 4
|
|
|
|
#define CRASH 5
|
|
|
|
#define FATAL 6
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define VDEBUG 7
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int err_occurred;
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
static void _error(int, struct node *, char *, register va_list);
|
2016-11-10 21:04:18 +00:00
|
|
|
|
1988-10-26 15:21:11 +00:00
|
|
|
/* There are three general error-message functions:
|
|
|
|
lexerror() lexical and pre-processor error messages
|
|
|
|
error() syntactic and pre-processor messagese
|
|
|
|
node_error() errors in nodes
|
|
|
|
The difference lies in the place where the file name and line
|
|
|
|
number come from.
|
|
|
|
Lexical errors report from the global variables LineNumber and
|
|
|
|
FileName, node errors get their information from the
|
|
|
|
node, whereas other errors use the information in the token.
|
|
|
|
*/
|
|
|
|
|
1995-08-17 16:34:29 +00:00
|
|
|
#if __STDC__
|
|
|
|
#ifdef DEBUG
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void debug(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(VDEBUG, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void error(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(ERROR, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void node_error(struct node *node, char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(ERROR, node, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void warning(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(WARNING, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void node_warning(struct node *node, char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(WARNING, node, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void lexerror(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(LEXERROR, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void lexwarning(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(LEXWARNING, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void fatal(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(FATAL, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
2019-02-23 16:44:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
1995-08-17 16:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void crash(char *fmt, ...)
|
1995-08-17 16:34:29 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
{
|
|
|
|
_error(CRASH, NULLNODE, fmt, ap);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
#ifdef DEBUG
|
2019-02-23 16:44:50 +00:00
|
|
|
abort();
|
1995-08-17 16:34:29 +00:00
|
|
|
#else
|
2019-02-23 16:44:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
1995-08-17 16:34:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#else
|
1988-10-26 15:21:11 +00:00
|
|
|
#ifdef DEBUG
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void debug(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(VDEBUG, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* DEBUG */
|
1988-10-26 15:21:11 +00:00
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void error(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(ERROR, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void node_error(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
|
|
|
struct node *node = va_arg(ap, struct node *);
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(ERROR, node, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void warning(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(WARNING, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void node_warning(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
1989-10-30 17:51:31 +00:00
|
|
|
struct node *node = va_arg(ap, struct node *);
|
1995-08-17 16:34:29 +00:00
|
|
|
_error(WARNING, node, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void lexerror(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(LEXERROR, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void lexwarning(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(LEXWARNING, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void fatal(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(FATAL, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
2019-02-23 16:44:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
/*VARARGS*/
|
2019-02-23 16:44:50 +00:00
|
|
|
void crash(va_alist)
|
1989-10-30 17:51:31 +00:00
|
|
|
va_dcl
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
1989-10-30 17:51:31 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap);
|
|
|
|
{
|
1995-08-17 16:34:29 +00:00
|
|
|
char *fmt = va_arg(ap, char *);
|
|
|
|
_error(CRASH, NULLNODE, fmt, ap);
|
1989-10-30 17:51:31 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
1988-10-26 15:21:11 +00:00
|
|
|
#ifdef DEBUG
|
2019-02-23 16:44:50 +00:00
|
|
|
abort();
|
1988-10-26 15:21:11 +00:00
|
|
|
#else
|
2019-02-23 16:44:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
1988-10-26 15:21:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
1995-08-17 16:34:29 +00:00
|
|
|
#endif
|
1988-10-26 15:21:11 +00:00
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
static void _error(int class, struct node *node, char *fmt, register va_list ap)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
/* _error attempts to limit the number of error messages
|
|
|
|
for a given line to MAXERR_LINE.
|
|
|
|
*/
|
|
|
|
static unsigned int last_ln = 0;
|
|
|
|
unsigned int ln = 0;
|
|
|
|
static char * last_fn = 0;
|
1989-05-03 10:30:22 +00:00
|
|
|
static int e_seen = 0, w_seen = 0;
|
1988-10-26 15:21:11 +00:00
|
|
|
register char *remark = 0;
|
|
|
|
|
|
|
|
/* Since name and number are gathered from different places
|
|
|
|
depending on the class, we first collect the relevant
|
|
|
|
values and then decide what to print.
|
|
|
|
*/
|
|
|
|
/* preliminaries */
|
|
|
|
switch( class ) {
|
|
|
|
case ERROR:
|
|
|
|
case LEXERROR:
|
|
|
|
case CRASH:
|
|
|
|
case FATAL:
|
|
|
|
if( C_busy() ) C_ms_err();
|
|
|
|
err_occurred = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the remark */
|
|
|
|
switch( class ) {
|
|
|
|
case WARNING:
|
|
|
|
case LEXWARNING:
|
1989-10-30 17:51:31 +00:00
|
|
|
if (options['w']) return;
|
1988-10-26 15:21:11 +00:00
|
|
|
remark = "(warning)";
|
|
|
|
break;
|
|
|
|
case CRASH:
|
|
|
|
remark = "CRASH\007";
|
|
|
|
break;
|
|
|
|
case FATAL:
|
|
|
|
remark = "fatal error --";
|
|
|
|
break;
|
|
|
|
#ifdef DEBUG
|
|
|
|
case VDEBUG:
|
|
|
|
remark = "(debug)";
|
|
|
|
break;
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* DEBUG */
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the place */
|
|
|
|
switch( class ) {
|
|
|
|
case ERROR:
|
|
|
|
case WARNING:
|
|
|
|
ln = node ? node->nd_lineno : dot.tk_lineno;
|
|
|
|
break;
|
|
|
|
case LEXWARNING:
|
|
|
|
case LEXERROR:
|
|
|
|
case CRASH:
|
|
|
|
case FATAL:
|
|
|
|
#ifdef DEBUG
|
|
|
|
case VDEBUG:
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* DEBUG */
|
1988-10-26 15:21:11 +00:00
|
|
|
ln = LineNumber;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( class != VDEBUG ) {
|
|
|
|
#endif
|
|
|
|
if( FileName == last_fn && ln == last_ln ) {
|
|
|
|
/* we've seen this place before */
|
1989-05-03 10:30:22 +00:00
|
|
|
if( class != WARNING && class != LEXWARNING ) {
|
|
|
|
e_seen++;
|
|
|
|
if( e_seen == MAXERR_LINE ) fmt = "etc ...";
|
|
|
|
else if( e_seen > MAXERR_LINE )
|
|
|
|
/* and too often, I'd say ! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
w_seen++;
|
|
|
|
if( w_seen == MAXERR_LINE ) fmt = "etc ...";
|
|
|
|
else if( w_seen > MAXERR_LINE )
|
|
|
|
return;
|
|
|
|
}
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* brand new place */
|
|
|
|
last_ln = ln;
|
|
|
|
last_fn = FileName;
|
1989-05-03 10:30:22 +00:00
|
|
|
e_seen = w_seen = 0;
|
1988-10-26 15:21:11 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
}
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* DEBUG */
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
if( FileName ) fprint(ERROUT, "\"%s\", line %u: ", FileName, ln);
|
|
|
|
|
|
|
|
if( remark ) fprint(ERROUT, "%s ", remark);
|
|
|
|
|
1989-10-30 17:51:31 +00:00
|
|
|
doprnt(ERROUT, fmt, ap); /* contents of error */
|
1988-10-26 15:21:11 +00:00
|
|
|
fprint(ERROUT, "\n");
|
|
|
|
}
|