1 /* $NetBSD: error.c,v 1.14 2018/12/23 20:27:23 jakllsch Exp $ */ 2 3 #include "defs.h" 4 5 #include <sys/cdefs.h> 6 __RCSID("$NetBSD: error.c,v 1.14 2018/12/23 20:27:23 jakllsch Exp $"); 7 /* Id: error.c,v 1.14 2016/12/02 18:35:55 tom Exp */ 8 9 /* routines for printing error messages */ 10 11 __dead void 12 fatal(const char *msg) 13 { 14 fprintf(stderr, "%s: f - %s\n", myname, msg); 15 done(2); 16 } 17 18 __dead void 19 no_space(void) 20 { 21 fprintf(stderr, "%s: f - out of space\n", myname); 22 done(2); 23 } 24 25 __dead void 26 open_error(const char *filename) 27 { 28 fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename); 29 done(2); 30 } 31 32 void 33 missing_brace(void) 34 { 35 fprintf(stderr, "%s: e - line %d of \"%s\", missing '}'\n", 36 myname, lineno, input_file_name); 37 done(1); 38 } 39 40 void 41 unexpected_EOF(void) 42 { 43 fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n", 44 myname, lineno, input_file_name); 45 done(1); 46 } 47 48 static void 49 print_pos(const char *st_line, const char *st_cptr) 50 { 51 const char *s; 52 53 if (st_line == 0) 54 return; 55 for (s = st_line; *s != '\n'; ++s) 56 { 57 if (isprint(UCH(*s)) || *s == '\t') 58 putc(*s, stderr); 59 else 60 putc('?', stderr); 61 } 62 putc('\n', stderr); 63 for (s = st_line; s < st_cptr; ++s) 64 { 65 if (*s == '\t') 66 putc('\t', stderr); 67 else 68 putc(' ', stderr); 69 } 70 putc('^', stderr); 71 putc('\n', stderr); 72 } 73 74 __dead void 75 syntax_error(int st_lineno, char *st_line, char *st_cptr) 76 { 77 fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n", 78 myname, st_lineno, input_file_name); 79 print_pos(st_line, st_cptr); 80 done(1); 81 } 82 83 __dead void 84 unterminated_comment(const struct ainfo *a) 85 { 86 fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n", 87 myname, a->a_lineno, input_file_name); 88 print_pos(a->a_line, a->a_cptr); 89 done(1); 90 } 91 92 __dead void 93 unterminated_string(const struct ainfo *a) 94 { 95 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n", 96 myname, a->a_lineno, input_file_name); 97 print_pos(a->a_line, a->a_cptr); 98 done(1); 99 } 100 101 __dead void 102 unterminated_text(const struct ainfo *a) 103 { 104 fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n", 105 myname, a->a_lineno, input_file_name); 106 print_pos(a->a_line, a->a_cptr); 107 done(1); 108 } 109 110 __dead void 111 unterminated_union(const struct ainfo *a) 112 { 113 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \ 114 declaration\n", myname, a->a_lineno, input_file_name); 115 print_pos(a->a_line, a->a_cptr); 116 done(1); 117 } 118 119 __dead void 120 over_unionized(char *u_cptr) 121 { 122 fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \ 123 declarations\n", myname, lineno, input_file_name); 124 print_pos(line, u_cptr); 125 done(1); 126 } 127 128 __dead void 129 illegal_tag(int t_lineno, char *t_line, char *t_cptr) 130 { 131 fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n", 132 myname, t_lineno, input_file_name); 133 print_pos(t_line, t_cptr); 134 done(1); 135 } 136 137 __dead void 138 illegal_character(char *c_cptr) 139 { 140 fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n", 141 myname, lineno, input_file_name); 142 print_pos(line, c_cptr); 143 done(1); 144 } 145 146 __dead void 147 used_reserved(char *s) 148 { 149 fprintf(stderr, 150 "%s: e - line %d of \"%s\", illegal use of reserved symbol \ 151 %s\n", myname, lineno, input_file_name, s); 152 done(1); 153 } 154 155 __dead void 156 tokenized_start(char *s) 157 { 158 fprintf(stderr, 159 "%s: e - line %d of \"%s\", the start symbol %s cannot be \ 160 declared to be a token\n", myname, lineno, input_file_name, s); 161 done(1); 162 } 163 164 void 165 retyped_warning(char *s) 166 { 167 fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \ 168 redeclared\n", myname, lineno, input_file_name, s); 169 } 170 171 void 172 reprec_warning(char *s) 173 { 174 fprintf(stderr, 175 "%s: w - line %d of \"%s\", the precedence of %s has been \ 176 redeclared\n", myname, lineno, input_file_name, s); 177 } 178 179 void 180 revalued_warning(char *s) 181 { 182 fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \ 183 redeclared\n", myname, lineno, input_file_name, s); 184 } 185 186 void 187 terminal_start(char *s) 188 { 189 fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \ 190 token\n", myname, lineno, input_file_name, s); 191 done(1); 192 } 193 194 void 195 restarted_warning(void) 196 { 197 fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \ 198 redeclared\n", myname, lineno, input_file_name); 199 } 200 201 void 202 no_grammar(void) 203 { 204 fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \ 205 specified\n", myname, lineno, input_file_name); 206 done(1); 207 } 208 209 void 210 terminal_lhs(int s_lineno) 211 { 212 fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \ 213 of a production\n", myname, s_lineno, input_file_name); 214 done(1); 215 } 216 217 void 218 prec_redeclared(void) 219 { 220 fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \ 221 specifiers\n", myname, lineno, input_file_name); 222 } 223 224 void 225 unterminated_action(const struct ainfo *a) 226 { 227 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n", 228 myname, a->a_lineno, input_file_name); 229 print_pos(a->a_line, a->a_cptr); 230 done(1); 231 } 232 233 void 234 dollar_warning(int a_lineno, int i) 235 { 236 fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \ 237 end of the current rule\n", myname, a_lineno, input_file_name, i); 238 } 239 240 __dead void 241 dollar_error(int a_lineno, char *a_line, char *a_cptr) 242 { 243 fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n", 244 myname, a_lineno, input_file_name); 245 print_pos(a_line, a_cptr); 246 done(1); 247 } 248 249 __dead void 250 untyped_lhs(void) 251 { 252 fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n", 253 myname, lineno, input_file_name); 254 done(1); 255 } 256 257 __dead void 258 untyped_rhs(int i, char *s) 259 { 260 fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n", 261 myname, lineno, input_file_name, i, s); 262 done(1); 263 } 264 265 __dead void 266 unknown_rhs(int i) 267 { 268 fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n", 269 myname, lineno, input_file_name, i); 270 done(1); 271 } 272 273 void 274 default_action_warning(char *s) 275 { 276 fprintf(stderr, 277 "%s: w - line %d of \"%s\", the default action for %s assigns an \ 278 undefined value to $$\n", 279 myname, lineno, input_file_name, s); 280 } 281 282 void 283 undefined_goal(char *s) 284 { 285 fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s); 286 done(1); 287 } 288 289 void 290 undefined_symbol_warning(char *s) 291 { 292 fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s); 293 } 294 295 #if ! defined(YYBTYACC) 296 void 297 unsupported_flag_warning(const char *flag, const char *details) 298 { 299 fprintf(stderr, "%s: w - %s flag unsupported, %s\n", 300 myname, flag, details); 301 } 302 #endif 303 304 #if defined(YYBTYACC) 305 void 306 at_warning(int a_lineno, int i) 307 { 308 fprintf(stderr, "%s: w - line %d of \"%s\", @%d references beyond the \ 309 end of the current rule\n", myname, a_lineno, input_file_name, i); 310 } 311 312 void 313 at_error(int a_lineno, char *a_line, char *a_cptr) 314 { 315 fprintf(stderr, 316 "%s: e - line %d of \"%s\", illegal @$ or @N reference\n", 317 myname, a_lineno, input_file_name); 318 print_pos(a_line, a_cptr); 319 done(1); 320 } 321 322 void 323 unterminated_arglist(const struct ainfo *a) 324 { 325 fprintf(stderr, 326 "%s: e - line %d of \"%s\", unterminated argument list\n", 327 myname, a->a_lineno, input_file_name); 328 print_pos(a->a_line, a->a_cptr); 329 done(1); 330 } 331 332 void 333 arg_number_disagree_warning(int a_lineno, char *a_name) 334 { 335 fprintf(stderr, "%s: w - line %d of \"%s\", number of arguments of %s " 336 "doesn't agree with previous declaration\n", 337 myname, a_lineno, input_file_name, a_name); 338 } 339 340 void 341 bad_formals(void) 342 { 343 fprintf(stderr, "%s: e - line %d of \"%s\", bad formal argument list\n", 344 myname, lineno, input_file_name); 345 print_pos(line, cptr); 346 done(1); 347 } 348 349 void 350 arg_type_disagree_warning(int a_lineno, int i, char *a_name) 351 { 352 fprintf(stderr, "%s: w - line %d of \"%s\", type of argument %d " 353 "to %s doesn't agree with previous declaration\n", 354 myname, a_lineno, input_file_name, i, a_name); 355 } 356 357 void 358 unknown_arg_warning(int d_lineno, const char *dlr_opt, const char *d_arg, const char 359 *d_line, const char *d_cptr) 360 { 361 fprintf(stderr, "%s: w - line %d of \"%s\", unknown argument %s%s\n", 362 myname, d_lineno, input_file_name, dlr_opt, d_arg); 363 print_pos(d_line, d_cptr); 364 } 365 366 void 367 untyped_arg_warning(int a_lineno, const char *dlr_opt, const char *a_name) 368 { 369 fprintf(stderr, "%s: w - line %d of \"%s\", untyped argument %s%s\n", 370 myname, a_lineno, input_file_name, dlr_opt, a_name); 371 } 372 373 void 374 wrong_number_args_warning(const char *which, const char *a_name) 375 { 376 fprintf(stderr, 377 "%s: w - line %d of \"%s\", wrong number of %sarguments for %s\n", 378 myname, lineno, input_file_name, which, a_name); 379 print_pos(line, cptr); 380 } 381 382 void 383 wrong_type_for_arg_warning(int i, char *a_name) 384 { 385 fprintf(stderr, 386 "%s: w - line %d of \"%s\", wrong type for default argument %d to %s\n", 387 myname, lineno, input_file_name, i, a_name); 388 print_pos(line, cptr); 389 } 390 391 void 392 start_requires_args(char *a_name) 393 { 394 fprintf(stderr, 395 "%s: w - line %d of \"%s\", start symbol %s requires arguments\n", 396 myname, 0, input_file_name, a_name); 397 398 } 399 400 void 401 destructor_redeclared_warning(const struct ainfo *a) 402 { 403 fprintf(stderr, "%s: w - line %d of \"%s\", destructor redeclared\n", 404 myname, a->a_lineno, input_file_name); 405 print_pos(a->a_line, a->a_cptr); 406 } 407 #endif 408