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 /* $Id: error.c,v 3.20 1995/08/17 16:34:29 ceriel Exp $ */
6 /* 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 */
25 #include "tokenname.h"
32 /* This file contains the error-message and diagnostic
33 functions. Beware, they are called with a variable number of
45 extern char options[];
47 extern char loptions[];
50 /* There are three general error-message functions:
51 lexerror() lexical and pre-processor error messages
52 error() syntactic and semantic error messages
53 expr_error() errors in expressions
54 The difference lies in the place where the file name and line
56 Lexical errors report from the global variables LineNumber and
57 FileName, expression errors get their information from the
58 expression, whereas other errors use the information in the token.
71 _error(ERROR, dot.tk_file, dot.tk_line, fmt, ap);
77 expr_error(struct expr *expr, char *fmt, ...)
83 if (!(expr->ex_flags & EX_ERROR)) {
84 /* to prevent proliferation */
85 _error(ERROR, expr->ex_file, expr->ex_line, fmt, ap);
86 expr->ex_flags |= EX_ERROR;
93 warning(char *fmt, ...)
99 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
105 expr_warning(struct expr *expr, char *fmt, ...)
111 if (!(expr->ex_flags & EX_ERROR)) {
112 /* to prevent proliferation */
113 _error(WARNING, expr->ex_file, expr->ex_line, fmt, ap);
122 def_warning(struct def *def, char *fmt, ...)
128 _error(WARNING, def->df_file, def->df_line, fmt, ap);
135 hwarning(char *fmt, ...)
142 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
148 awarning(char *fmt, ...)
155 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
163 lexerror(char *fmt, ...)
169 _error(ERROR, FileName, LineNumber, fmt, ap);
176 lexwarning(char *fmt, ...)
182 _error(WARNING, FileName, LineNumber, fmt, ap);
189 crash(char *fmt, ...)
195 _error(CRASH, FileName, LineNumber, fmt, ap);
209 fatal(char *fmt, ...)
215 _error(FATAL, FileName, LineNumber, fmt, ap);
219 if (C_busy()) C_close();
225 error(va_alist) /* fmt, args */
232 char *fmt = va_arg(ap, char *);
233 _error(ERROR, dot.tk_file, dot.tk_line, fmt, ap);
239 expr_error(va_alist) /* expr, fmt, args */
246 register struct expr *expr = va_arg(ap, struct expr *);
247 char *fmt = va_arg(ap, char *);
249 if (!(expr->ex_flags & EX_ERROR)) {
250 /* to prevent proliferation */
251 _error(ERROR, expr->ex_file, expr->ex_line, fmt, ap);
252 expr->ex_flags |= EX_ERROR;
259 warning(va_alist) /* fmt, args */
266 char *fmt = va_arg(ap, char *);
267 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
273 expr_warning(va_alist) /* expr, fmt, args */
280 struct expr *expr = va_arg(ap, struct expr *);
281 char *fmt = va_arg(ap, char *);
283 if (!(expr->ex_flags & EX_ERROR)) {
284 /* to prevent proliferation */
285 _error(WARNING, expr->ex_file, expr->ex_line, fmt, ap);
294 def_warning(va_alist) /* def, fmt, args */
301 register struct def *def = va_arg(ap, struct def *);
302 char *fmt = va_arg(ap, char *);
304 _error(WARNING, def->df_file, def->df_line, fmt, ap);
311 hwarning(va_alist) /* fmt, args */
318 char *fmt = va_arg(ap, char *);
320 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
326 awarning(va_alist) /* fmt, args */
333 char *fmt = va_arg(ap, char *);
335 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
343 lexerror(va_alist) /* fmt, args */
350 char *fmt = va_arg(ap, char *);
351 _error(ERROR, FileName, LineNumber, fmt, ap);
358 lexwarning(va_alist) /* fmt, args */
365 char *fmt = va_arg(ap, char *);
366 _error(WARNING, FileName, LineNumber, fmt, ap);
373 crash(va_alist) /* fmt, args */
380 char *fmt = va_arg(ap, char *);
381 _error(CRASH, FileName, LineNumber, fmt, ap);
395 fatal(va_alist) /* fmt, args */
402 char *fmt = va_arg(ap, char *);
403 _error(FATAL, FileName, LineNumber, fmt, ap);
407 if (C_busy()) C_close();
414 _error(class, fn, ln, fmt, ap)
423 /* check visibility of message */
427 if (token_nmb < tk_nmb_at_last_syn_err + ERR_SHADOW)
428 /* warning or error message overshadowed */
433 /* Since name and number are gathered from different places
434 depending on the class, we first collect the relevant
435 values and then decide what to print.
457 remark = "(warning)";
468 remark = "CRASH\007";
472 remark = "fatal error --";
479 if ( /* there is a file name */
481 && /* the file name is global */
483 && /* it is not a .c file */
484 strcmp(&fn[strlen(fn)-2], ".c") != 0
486 /* we skip this message */
492 fprint(ERROUT, "\"%s\", line %u: ", fn, ln);
494 fprint(ERROUT, "%s ", remark);
495 doprnt(ERROUT, fmt, ap); /* contents of error */
496 fprint(ERROUT, "\n");