GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/yacc/error.c Lines: 0 107 0.0 %
Date: 2017-11-07 Branches: 0 26 0.0 %

Line Branch Exec Source
1
/*		$OpenBSD: error.c,v 1.14 2014/03/08 01:05:39 tedu Exp $		*/
2
/*		$NetBSD: error.c,v 1.4 1996/03/19 03:21:32 jtc Exp $		*/
3
4
/*
5
 * Copyright (c) 1989 The Regents of the University of California.
6
 * All rights reserved.
7
 *
8
 * This code is derived from software contributed to Berkeley by
9
 * Robert Paul Corbett.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in the
18
 *    documentation and/or other materials provided with the distribution.
19
 * 3. Neither the name of the University nor the names of its contributors
20
 *    may be used to endorse or promote products derived from this software
21
 *    without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
 * SUCH DAMAGE.
34
 */
35
36
/* routines for printing error messages  */
37
38
#include "defs.h"
39
40
41
void
42
fatal(char *msg)
43
{
44
	fprintf(stderr, "%s: %s\n", input_file_name, msg);
45
	done(2);
46
}
47
48
49
void
50
no_space(void)
51
{
52
	fprintf(stderr, "%s: yacc is out of space\n", input_file_name);
53
	done(2);
54
}
55
56
57
void
58
open_error(char *filename)
59
{
60
	fprintf(stderr, "%s: cannot open source file %s\n",
61
	    input_file_name, filename);
62
	done(2);
63
}
64
65
void
66
open_write_error(char *filename)
67
{
68
	fprintf(stderr, "%s: cannot open target file %s for writing\n",
69
	    input_file_name, filename);
70
	done(2);
71
}
72
73
void
74
unexpected_EOF(void)
75
{
76
	fprintf(stderr, "%s:%d: unexpected end-of-file\n",
77
	    input_file_name, lineno);
78
	done(1);
79
}
80
81
82
void
83
print_pos(char *st_line, char *st_cptr)
84
{
85
	char *s;
86
87
	if (st_line == 0)
88
		return;
89
	for (s = st_line; *s != '\n'; ++s) {
90
		if (isprint((unsigned char)*s) || *s == '\t')
91
			putc(*s, stderr);
92
		else
93
			putc('?', stderr);
94
	}
95
	putc('\n', stderr);
96
	for (s = st_line; s < st_cptr; ++s) {
97
		if (*s == '\t')
98
			putc('\t', stderr);
99
		else
100
			putc(' ', stderr);
101
	}
102
	putc('^', stderr);
103
	putc('\n', stderr);
104
}
105
106
void
107
syntax_error(int st_lineno, char *st_line, char *st_cptr)
108
{
109
	fprintf(stderr, "%s:%d: syntax error\n",
110
	    input_file_name, st_lineno);
111
	print_pos(st_line, st_cptr);
112
	done(1);
113
}
114
115
void
116
unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
117
{
118
	fprintf(stderr, "%s:%d: unmatched /*\n",
119
	    input_file_name, c_lineno);
120
	print_pos(c_line, c_cptr);
121
	done(1);
122
}
123
124
void
125
unterminated_string(int s_lineno, char *s_line, char *s_cptr)
126
{
127
	fprintf(stderr, "%s:%d:, unterminated string\n",
128
	    input_file_name, s_lineno);
129
	print_pos(s_line, s_cptr);
130
	done(1);
131
}
132
133
void
134
unterminated_text(int t_lineno, char *t_line, char *t_cptr)
135
{
136
	fprintf(stderr, "%s:%d: unmatched %%{\n",
137
	    input_file_name, t_lineno);
138
	print_pos(t_line, t_cptr);
139
	done(1);
140
}
141
142
void
143
unterminated_union(int u_lineno, char *u_line, char *u_cptr)
144
{
145
	fprintf(stderr, "%s:%d: unterminated %%union declaration\n",
146
	    input_file_name, u_lineno);
147
	print_pos(u_line, u_cptr);
148
	done(1);
149
}
150
151
void
152
over_unionized(char *u_cptr)
153
{
154
	fprintf(stderr, "%s:%d: too many %%union declarations\n",
155
	    input_file_name, lineno);
156
	print_pos(line, u_cptr);
157
	done(1);
158
}
159
160
void
161
illegal_tag(int t_lineno, char *t_line, char *t_cptr)
162
{
163
	fprintf(stderr, "%s:%d: illegal tag\n",
164
	    input_file_name, t_lineno);
165
	print_pos(t_line, t_cptr);
166
	done(1);
167
}
168
169
170
void
171
illegal_character(char *c_cptr)
172
{
173
	fprintf(stderr, "%s:%d: illegal character\n",
174
	    input_file_name, lineno);
175
	print_pos(line, c_cptr);
176
	done(1);
177
}
178
179
180
void
181
used_reserved(char *s)
182
{
183
	fprintf(stderr, "%s:%d: illegal use of reserved symbol %s\n",
184
	    input_file_name, lineno, s);
185
	done(1);
186
}
187
188
void
189
tokenized_start(char *s)
190
{
191
	fprintf(stderr, "%s:%d: the start symbol %s cannot be declared to be a token\n",
192
	    input_file_name, lineno, s);
193
	done(1);
194
}
195
196
void
197
retyped_warning(char *s)
198
{
199
	fprintf(stderr, "%s:%d: the type of %s has been redeclared\n",
200
	    input_file_name, lineno, s);
201
}
202
203
void
204
reprec_warning(char *s)
205
{
206
	fprintf(stderr, "%s:%d: the precedence of %s has been redeclared\n",
207
	    input_file_name, lineno, s);
208
}
209
210
void
211
revalued_warning(char *s)
212
{
213
	fprintf(stderr, "%s:%d: the value of %s has been redeclared\n",
214
	    input_file_name, lineno, s);
215
}
216
217
void
218
terminal_start(char *s)
219
{
220
	fprintf(stderr, "%s:%d: the start symbol %s is a token\n",
221
	    input_file_name, lineno, s);
222
	done(1);
223
}
224
225
void
226
restarted_warning(void)
227
{
228
	fprintf(stderr, "%s:%d: the start symbol has been redeclared\n",
229
	     input_file_name, lineno);
230
}
231
232
void
233
no_grammar(void)
234
{
235
	fprintf(stderr, "%s:%d: no grammar has been specified\n",
236
	    input_file_name, lineno);
237
	done(1);
238
}
239
240
void
241
terminal_lhs(int s_lineno)
242
{
243
	fprintf(stderr, "%s:%d: a token appears on the lhs of a production\n",
244
	    input_file_name, s_lineno);
245
	done(1);
246
}
247
248
void
249
prec_redeclared(void)
250
{
251
	fprintf(stderr, "%s:%d: conflicting %%prec specifiers\n",
252
	    input_file_name, lineno);
253
}
254
255
void
256
unterminated_action(int a_lineno, char *a_line, char *a_cptr)
257
{
258
	fprintf(stderr, "%s:%d: unterminated action\n",
259
	    input_file_name, a_lineno);
260
	print_pos(a_line, a_cptr);
261
	done(1);
262
}
263
264
void
265
dollar_warning(int a_lineno, int i)
266
{
267
	fprintf(stderr, "%s:%d: $%d references beyond the end of the current rule\n",
268
	    input_file_name, a_lineno, i);
269
}
270
271
void
272
dollar_error(int a_lineno, char *a_line, char *a_cptr)
273
{
274
	fprintf(stderr, "%s:%d: illegal $-name\n",
275
	    input_file_name, a_lineno);
276
	print_pos(a_line, a_cptr);
277
	done(1);
278
}
279
280
281
void
282
untyped_lhs(void)
283
{
284
	fprintf(stderr, "%s:%d: $$ is untyped\n",
285
	    input_file_name, lineno);
286
	done(1);
287
}
288
289
void
290
untyped_rhs(int i, char *s)
291
{
292
	fprintf(stderr, "%s:%d: $%d (%s) is untyped\n",
293
	    input_file_name, lineno, i, s);
294
	done(1);
295
}
296
297
void
298
unknown_rhs(int i)
299
{
300
	fprintf(stderr, "%s:%d: $%d is untyped\n",
301
	    input_file_name, lineno, i);
302
	done(1);
303
}
304
305
void
306
default_action_warning(void)
307
{
308
	fprintf(stderr, "%s:%d: the default action assigns an undefined value to $$\n",
309
	    input_file_name, lineno);
310
}
311
312
void
313
undefined_goal(char *s)
314
{
315
	fprintf(stderr, "%s: the start symbol %s is undefined\n", input_file_name, s);
316
	done(1);
317
}
318
319
void
320
undefined_symbol_warning(char *s)
321
{
322
	fprintf(stderr, "%s: the symbol %s is undefined\n", input_file_name, s);
323
}