2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* 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 */
10 /* $Id: error.c,v 1.32 1995/12/04 15:29:36 ceriel Exp $ */
12 /* This file contains the (non-portable) error-message and diagnostic
13 giving functions. Be aware that they are called with a variable
31 #include "strict3rd.h"
53 extern char *symbol2str();
55 /* There are three general error-message functions:
56 lexerror() lexical and pre-processor error messages
57 error() syntactic and semantic error messages
58 node_error() errors in nodes
59 The difference lies in the place where the file name and line
61 Lexical errors report from the global variables LineNumber and
62 FileName, node errors get their information from the
63 node, whereas other errors use the information in the token.
75 _error(VDEBUG, NULLNODE, ap, 0);
88 _error(ERROR, NULLNODE, fmt, ap, 0);
94 node_error(t_node *node, char *fmt, ...)
100 _error(ERROR, node, fmt, ap, 0);
106 warning(int class, char *fmt, ...)
112 _error(WARNING, NULLNODE, fmt, ap, class);
118 node_warning(t_node *node, int class, char *fmt, ...)
124 _error(WARNING, node, fmt, ap, class);
130 lexerror(char *fmt, ...)
136 _error(LEXERROR, NULLNODE, fmt, ap, 0);
142 lexwarning(int class, char *fmt, ...)
148 _error(LEXWARNING, NULLNODE, fmt, ap, class);
154 fatal(char *fmt, ...)
160 _error(FATAL, NULLNODE, fmt, ap, 0);
167 crash(char *fmt, ...)
173 _error(CRASH, NULLNODE, fmt, ap, 0);
192 char *fmt = va_arg(ap, char *);
193 _error(VDEBUG, NULLNODE, fmt, ap, 0);
207 char *fmt = va_arg(ap, char *);
208 _error(ERROR, NULLNODE, fmt, ap, 0);
221 t_node *node = va_arg(ap, t_node *);
222 char *fmt = va_arg(ap, char *);
223 _error(ERROR, node, fmt, ap, 0);
236 int class = va_arg(ap, int);
237 char *fmt = va_arg(ap, char *);
238 _error(WARNING, NULLNODE, fmt, ap, class);
244 node_warning(va_alist)
251 t_node *nd = va_arg(ap, t_node *);
252 int class = va_arg(ap, int);
253 char *fmt = va_arg(ap, char *);
254 _error(WARNING, nd, fmt, ap, class);
267 char *fmt = va_arg(ap, char *);
268 _error(LEXERROR, NULLNODE, fmt, ap, 0);
281 int class = va_arg(ap, int);
282 char *fmt = va_arg(ap, char *);
283 _error(LEXWARNING, NULLNODE, fmt, ap, class);
296 char *fmt = va_arg(ap, char *);
297 _error(FATAL, NULLNODE, fmt, ap, 0);
311 char *fmt = va_arg(ap, char *);
312 _error(CRASH, NULLNODE, fmt, ap, 0);
323 _error(class, node, fmt, ap, warn_class)
330 /* _error attempts to limit the number of error messages
331 for a given line to MAXERR_LINE.
334 register char *remark = 0;
336 /* check visibility of message */
337 if (class == ERROR || class == WARNING) {
338 if (token_nmb < tk_nmb_at_last_syn_err + ERR_SHADOW)
339 /* warning or error message overshadowed */
342 /* Since name and number are gathered from different places
343 depending on the class, we first collect the relevant
344 values and then decide what to print.
352 if (C_busy()) C_ms_err();
361 if (! (warn_class & warning_classes)) return;
363 #ifndef STRICT_3RD_ED
365 remark = "(old-fashioned use)";
374 remark = "(warning)";
379 remark = "CRASH\007";
382 remark = "fatal error --";
395 ln = node ? node->nd_lineno : dot.tk_lineno;
408 if (FileName) fprint(ERROUT, "\"%s\", line %u: ", FileName, ln);
410 if (remark) fprint(ERROUT, "%s ", remark);
412 doprnt(ERROUT, fmt, ap); /* contents of error */
413 fprint(ERROUT, "\n");