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 1.11 1995/08/17 16:51:09 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 */
26 #include "tokenname.h"
27 #include <flt_arith.h>
34 /* This file contains the error-message and diagnostic
35 functions. Beware, they are called with a variable number of
49 extern char options[];
51 extern char loptions[];
54 /* There are three general error-message functions:
55 lexerror() lexical and pre-processor error messages
56 error() syntactic and semantic error messages
57 expr_error() errors in expressions
58 The difference lies in the place where the file name and line
60 Lexical errors report from the global variables LineNumber and
61 FileName, expression errors get their information from the
62 expression, whereas other errors use the information in the token.
75 _error(ERROR, dot.tk_file, dot.tk_line, fmt, ap);
81 expr_error(struct expr *expr, char *fmt, ...)
87 if (!(expr->ex_flags & EX_ERROR)) {
88 /* to prevent proliferation */
89 _error(ERROR, expr->ex_file, expr->ex_line, fmt, ap);
90 expr->ex_flags |= EX_ERROR;
97 lexstrict(char *fmt, ...)
103 _error(STRICT, FileName, LineNumber, fmt, ap);
109 strict(char *fmt, ...)
115 _error(STRICT, dot.tk_file, dot.tk_line, fmt, ap);
121 expr_strict(struct expr *expr, char *fmt, ...)
127 if (!(expr->ex_flags & EX_ERROR)) {
128 /* to prevent proliferation */
129 _error(STRICT, expr->ex_file, expr->ex_line, fmt, ap);
137 debug(char *fmt, ...)
143 _error(DO_DEBUG, dot.tk_file, dot.tk_line, fmt, ap);
150 warning(char *fmt, ...)
156 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
162 expr_warning(struct expr *expr, char *fmt, ...)
168 if (!(expr->ex_flags & EX_ERROR)) {
169 /* to prevent proliferation */
170 _error(WARNING, expr->ex_file, expr->ex_line, fmt, ap);
179 def_warning(struct def *def, char *fmt, ...)
185 _error(WARNING, def->df_file, def->df_line, fmt, ap);
192 hwarning(char *fmt, ...)
199 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
205 awarning(char *fmt, ...)
212 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
220 lexerror(char *fmt, ...)
226 _error(ERROR, FileName, LineNumber, fmt, ap);
232 lexwarning(char *fmt, ...)
238 _error(WARNING, FileName, LineNumber, fmt, ap);
244 crash(char *fmt, ...)
250 _error(CRASH, FileName, LineNumber, fmt, ap);
264 fatal(char *fmt, ...)
270 _error(FATAL, FileName, LineNumber, fmt, ap);
274 if (C_busy()) C_close();
280 error(va_alist) /* fmt, args */
287 char *fmt = va_arg(ap, char *);
288 _error(ERROR, dot.tk_file, dot.tk_line, fmt, ap);
294 expr_error(va_alist) /* expr, fmt, args */
301 register struct expr *expr = va_arg(ap, struct expr *);
302 char *fmt = va_arg(ap, char *);
304 if (!(expr->ex_flags & EX_ERROR)) {
305 /* to prevent proliferation */
306 _error(ERROR, expr->ex_file, expr->ex_line, fmt, ap);
307 expr->ex_flags |= EX_ERROR;
321 char *fmt = va_arg(ap, char *);
322 _error(STRICT, FileName, LineNumber, fmt, ap);
335 char *fmt = va_arg(ap, char *);
336 _error(STRICT, dot.tk_file, dot.tk_line, fmt, ap);
342 expr_strict(va_alist) /* expr, fmt, args */
349 struct expr *expr = va_arg(ap, struct expr *);
350 char *fmt = va_arg(ap, char *);
352 if (!(expr->ex_flags & EX_ERROR)) {
353 /* to prevent proliferation */
354 _error(STRICT, expr->ex_file, expr->ex_line, fmt, ap);
369 char *fmt = va_arg(ap, char *);
370 _error(DO_DEBUG, dot.tk_file, dot.tk_line, fmt, ap);
384 char *fmt = va_arg(ap, char *);
385 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
391 expr_warning(va_alist) /* expr, fmt, args */
398 struct expr *expr = va_arg(ap, struct expr *);
399 char *fmt = va_arg(ap, char *);
401 if (!(expr->ex_flags & EX_ERROR)) {
402 /* to prevent proliferation */
403 _error(WARNING, expr->ex_file, expr->ex_line, fmt, ap);
412 def_warning(va_alist) /* def, fmt, args */
419 register struct def *def = va_arg(ap, struct def *);
420 char *fmt = va_arg(ap, char *);
422 _error(WARNING, def->df_file, def->df_line, fmt, ap);
429 hwarning(va_alist) /* fmt, args */
436 char *fmt = va_arg(ap, char *);
438 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
444 awarning(va_alist) /* fmt, args */
451 char *fmt = va_arg(ap, char *);
453 _error(WARNING, dot.tk_file, dot.tk_line, fmt, ap);
461 lexerror(va_alist) /* fmt, args */
468 char *fmt = va_arg(ap, char *);
469 _error(ERROR, FileName, LineNumber, fmt, ap);
475 lexwarning(va_alist) /* fmt, args */
482 char *fmt = va_arg(ap, char *);
483 _error(WARNING, FileName, LineNumber, fmt, ap);
489 crash(va_alist) /* fmt, args */
496 char *fmt = va_arg(ap, char *);
497 _error(CRASH, FileName, LineNumber, fmt, ap);
511 fatal(va_alist) /* fmt, args */
518 char *fmt = va_arg(ap, char *);
519 _error(FATAL, FileName, LineNumber, fmt, ap);
523 if (C_busy()) C_close();
530 _error(class, fn, ln, fmt, ap)
539 /* check visibility of message */
544 if (token_nmb < tk_nmb_at_last_syn_err + ERR_SHADOW)
545 /* warning or error message overshadowed */
550 /* Since name and number are gathered from different places
551 depending on the class, we first collect the relevant
552 values and then decide what to print.
582 remark = "(warning)";
593 remark = "CRASH\007";
597 remark = "fatal error --";
609 if ( /* there is a file name */
611 && /* the file name is global */
613 && /* it is not a .c file */
614 strcmp(&fn[strlen(fn)-2], ".c") != 0
616 /* we skip this message */
622 fprint(ERROUT, "\"%s\", line %u: ", fn, ln);
624 fprint(ERROUT, "%s ", remark);
625 doprnt(ERROUT, fmt, ap); /* contents of error */
626 fprint(ERROUT, "\n");