]>
Commit | Line | Data |
---|---|---|
1 | # Checking the Bison scanner. -*- Autotest -*- | |
2 | ||
3 | # Copyright (C) 2002-2013 Free Software Foundation, Inc. | |
4 | ||
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation, either version 3 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | AT_BANNER([[Input Processing.]]) | |
19 | ||
20 | # Mostly test that we are robust to mistakes. | |
21 | ||
22 | ||
23 | ## ---------------- ## | |
24 | ## Invalid inputs. ## | |
25 | ## ---------------- ## | |
26 | ||
27 | AT_SETUP([Invalid inputs]) | |
28 | ||
29 | AT_DATA([input.y], | |
30 | [[\000\001\002\377? | |
31 | %% | |
32 | ? | |
33 | default: 'a' } | |
34 | %& | |
35 | %a-does-not-exist | |
36 | %- | |
37 | %{ | |
38 | ]]) | |
39 | AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]]) | |
40 | ||
41 | AT_BISON_CHECK([input.y], [1], [], | |
42 | [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?' | |
43 | input.y:3.1: error: invalid character: '?' | |
44 | input.y:4.14: error: invalid character: '}' | |
45 | input.y:5.1: error: invalid character: '%' | |
46 | input.y:5.2: error: invalid character: '&' | |
47 | input.y:6.1-17: error: invalid directive: '%a-does-not-exist' | |
48 | input.y:7.1: error: invalid character: '%' | |
49 | input.y:7.2: error: invalid character: '-' | |
50 | input.y:8.1-9.0: error: missing '%}' at end of file | |
51 | input.y:8.1-9.0: error: syntax error, unexpected %{...%} | |
52 | ]]) | |
53 | ||
54 | AT_CLEANUP | |
55 | ||
56 | ||
57 | AT_SETUP([Invalid inputs with {}]) | |
58 | ||
59 | # We used to SEGV here. See | |
60 | # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html | |
61 | ||
62 | AT_DATA([input.y], | |
63 | [[ | |
64 | %destructor | |
65 | %initial-action | |
66 | %lex-param | |
67 | %parse-param | |
68 | %printer | |
69 | %union | |
70 | ]]) | |
71 | ||
72 | AT_BISON_CHECK([input.y], [1], [], | |
73 | [[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...} | |
74 | ]]) | |
75 | ||
76 | AT_CLEANUP | |
77 | ||
78 | ||
79 | ||
80 | ## ------------ ## | |
81 | ## Invalid $n. ## | |
82 | ## ------------ ## | |
83 | ||
84 | AT_SETUP([Invalid $n and @n]) | |
85 | ||
86 | AT_DATA([input.y], | |
87 | [[%% | |
88 | exp: { $$ = $1 ; }; | |
89 | exp: { @$ = @1 ; }; | |
90 | ]]) | |
91 | ||
92 | AT_BISON_CHECK([-fcaret input.y], [1], [], | |
93 | [[input.y:2.13-14: error: integer out of range: '$1' | |
94 | exp: { $$ = $1 ; }; | |
95 | ^^ | |
96 | input.y:3.13-14: error: integer out of range: '@1' | |
97 | exp: { @$ = @1 ; }; | |
98 | ^^ | |
99 | ]]) | |
100 | ||
101 | AT_CLEANUP | |
102 | ||
103 | ||
104 | ## -------------- ## | |
105 | ## Type Clashes. ## | |
106 | ## -------------- ## | |
107 | ||
108 | AT_SETUP([Type Clashes]) | |
109 | ||
110 | AT_DATA([input.y], | |
111 | [[%union { int bar; } | |
112 | %token foo | |
113 | %type <bar> exp | |
114 | %% | |
115 | exp: foo { $$; } foo { $2; } foo | |
116 | | foo | |
117 | | /* empty. */ | |
118 | ; | |
119 | ]]) | |
120 | ||
121 | AT_BISON_CHECK([-fcaret input.y], [1], [], | |
122 | [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type | |
123 | exp: foo { $$; } foo { $2; } foo | |
124 | ^^ | |
125 | input.y:5.24-25: error: $2 of 'exp' has no declared type | |
126 | exp: foo { $$; } foo { $2; } foo | |
127 | ^^ | |
128 | input.y:5.6-32: warning: type clash on default action: <bar> != <> [-Wother] | |
129 | exp: foo { $$; } foo { $2; } foo | |
130 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
131 | input.y:6.6-8: warning: type clash on default action: <bar> != <> [-Wother] | |
132 | | foo | |
133 | ^^^ | |
134 | input.y:7.5: warning: empty rule for typed nonterminal, and no action [-Wother] | |
135 | | /* empty. */ | |
136 | ^ | |
137 | ]]) | |
138 | ||
139 | AT_CLEANUP | |
140 | ||
141 | ||
142 | # _AT_UNUSED_VALUES_DECLARATIONS() | |
143 | # -------------------------------- | |
144 | # Generate the token, type, and destructor | |
145 | # declarations for the unused values tests. | |
146 | m4_define([_AT_UNUSED_VALUES_DECLARATIONS], | |
147 | [[[%token <integer> INT; | |
148 | %type <integer> a b c d e f g h i j k l; | |
149 | %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]]) | |
150 | ||
151 | ||
152 | # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES) | |
153 | # ---------------------------------------------------------------- | |
154 | # Generate a grammar to test unused values, compile it, run it. If | |
155 | # DECLARATIONS_AFTER is set, then the token, type, and destructor | |
156 | # declarations are generated after the rules rather than before. If | |
157 | # CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set. | |
158 | m4_define([AT_CHECK_UNUSED_VALUES], | |
159 | [AT_DATA([input.y], | |
160 | m4_ifval($1, [ | |
161 | ||
162 | ||
163 | ], [_AT_UNUSED_VALUES_DECLARATIONS | |
164 | ])[[%% | |
165 | start: | |
166 | 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; } | |
167 | | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; } | |
168 | | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; } | |
169 | ; | |
170 | ||
171 | a: INT | INT { } INT { } INT { }; | |
172 | b: INT | /* empty */; | |
173 | c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; }; | |
174 | d: INT | INT { } INT { $]1[; } INT { $<integer>2; }; | |
175 | e: INT | INT { } INT { } INT { $]1[; }; | |
176 | f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; }; | |
177 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
178 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
179 | i: INT | INT INT { } { $]$[ = $]1[ + $]2[; }; | |
180 | j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; }; | |
181 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; | |
182 | l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [ | |
183 | _AT_UNUSED_VALUES_DECLARATIONS]) | |
184 | ) | |
185 | ||
186 | AT_BISON_CHECK(m4_ifval($2, [--warnings=midrule-values ])[-fcaret input.y], | |
187 | [0], [], | |
188 | [[input.y:11.10-32: warning: unset value: $][$ [-Wother] | |
189 | a: INT | INT { } INT { } INT { }; | |
190 | ^^^^^^^^^^^^^^^^^^^^^^^ | |
191 | input.y:11.10-12: warning: unused value: $][1 [-Wother] | |
192 | a: INT | INT { } INT { } INT { }; | |
193 | ^^^ | |
194 | input.y:11.18-20: warning: unused value: $][3 [-Wother] | |
195 | a: INT | INT { } INT { } INT { }; | |
196 | ^^^ | |
197 | input.y:11.26-28: warning: unused value: $][5 [-Wother] | |
198 | a: INT | INT { } INT { } INT { }; | |
199 | ^^^ | |
200 | input.y:12.9: warning: empty rule for typed nonterminal, and no action [-Wother] | |
201 | b: INT | /* empty */; | |
202 | ^ | |
203 | ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $][$ [-Wmidrule-values] | |
204 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; | |
205 | ^^^^^^^ | |
206 | input.y:13.26-41: warning: unset value: $][$ [-Wmidrule-values] | |
207 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; | |
208 | ^^^^^^^^^^^^^^^^ | |
209 | ]]])[[input.y:13.10-62: warning: unset value: $][$ [-Wother] | |
210 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; | |
211 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
212 | input.y:13.22-24: warning: unused value: $][3 [-Wother] | |
213 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; | |
214 | ^^^ | |
215 | input.y:13.43-45: warning: unused value: $][5 [-Wother] | |
216 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; }; | |
217 | ^^^ | |
218 | ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $][$ [-Wmidrule-values] | |
219 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; | |
220 | ^^^ | |
221 | ]]])[[input.y:14.10-49: warning: unset value: $][$ [-Wother] | |
222 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; | |
223 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
224 | input.y:14.18-20: warning: unused value: $][3 [-Wother] | |
225 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; | |
226 | ^^^ | |
227 | input.y:14.30-32: warning: unused value: $][5 [-Wother] | |
228 | d: INT | INT { } INT { $][1; } INT { $<integer>2; }; | |
229 | ^^^ | |
230 | input.y:15.10-37: warning: unset value: $][$ [-Wother] | |
231 | e: INT | INT { } INT { } INT { $][1; }; | |
232 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
233 | input.y:15.18-20: warning: unused value: $][3 [-Wother] | |
234 | e: INT | INT { } INT { } INT { $][1; }; | |
235 | ^^^ | |
236 | input.y:15.27-29: warning: unused value: $][5 [-Wother] | |
237 | e: INT | INT { } INT { } INT { $][1; }; | |
238 | ^^^ | |
239 | input.y:17.10-58: warning: unset value: $][$ [-Wother] | |
240 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
241 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
242 | input.y:17.10-12: warning: unused value: $][1 [-Wother] | |
243 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
244 | ^^^ | |
245 | ]]m4_ifval($2, [[[input.y:17.14-29: warning: unused value: $][2 [-Wmidrule-values] | |
246 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
247 | ^^^^^^^^^^^^^^^^ | |
248 | ]]])[[input.y:17.31-33: warning: unused value: $][3 [-Wother] | |
249 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
250 | ^^^ | |
251 | ]]m4_ifval($2, [[[input.y:17.35-50: warning: unused value: $][4 [-Wmidrule-values] | |
252 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
253 | ^^^^^^^^^^^^^^^^ | |
254 | ]]])[[input.y:17.52-54: warning: unused value: $][5 [-Wother] | |
255 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; | |
256 | ^^^ | |
257 | input.y:18.10-72: warning: unset value: $][$ [-Wother] | |
258 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
259 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
260 | input.y:18.10-12: warning: unused value: $][1 [-Wother] | |
261 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
262 | ^^^ | |
263 | input.y:18.31-33: warning: unused value: $][3 [-Wother] | |
264 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
265 | ^^^ | |
266 | ]]m4_ifval($2, [[[input.y:18.35-64: warning: unused value: $][4 [-Wmidrule-values] | |
267 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
268 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
269 | ]]])[[input.y:18.66-68: warning: unused value: $][5 [-Wother] | |
270 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
271 | ^^^ | |
272 | ]]m4_ifval($2, [[[input.y:20.18-37: warning: unused value: $][3 [-Wmidrule-values] | |
273 | j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; }; | |
274 | ^^^^^^^^^^^^^^^^^^^^ | |
275 | ]]])[[input.y:21.10-68: warning: unset value: $][$ [-Wother] | |
276 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; | |
277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
278 | input.y:21.10-12: warning: unused value: $][1 [-Wother] | |
279 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; | |
280 | ^^^ | |
281 | input.y:21.14-16: warning: unused value: $][2 [-Wother] | |
282 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; | |
283 | ^^^ | |
284 | ]]m4_ifval($2, [[[input.y:21.35-64: warning: unused value: $][4 [-Wmidrule-values] | |
285 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; | |
286 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
287 | ]]])) | |
288 | ]) | |
289 | ||
290 | ## --------------- ## | |
291 | ## Unused values. ## | |
292 | ## --------------- ## | |
293 | ||
294 | AT_SETUP([Unused values]) | |
295 | AT_CHECK_UNUSED_VALUES | |
296 | AT_CHECK_UNUSED_VALUES(, [1]) | |
297 | AT_CLEANUP | |
298 | ||
299 | ||
300 | ## ------------------------------------------ ## | |
301 | ## Unused values before symbol declarations. ## | |
302 | ## ------------------------------------------ ## | |
303 | ||
304 | AT_SETUP([Unused values before symbol declarations]) | |
305 | AT_CHECK_UNUSED_VALUES([1]) | |
306 | AT_CHECK_UNUSED_VALUES([1], [1]) | |
307 | AT_CLEANUP | |
308 | ||
309 | ||
310 | ## --------------------------------------------- ## | |
311 | ## Default %printer and %destructor redeclared. ## | |
312 | ## --------------------------------------------- ## | |
313 | ||
314 | AT_SETUP([Default %printer and %destructor redeclared]) | |
315 | ||
316 | AT_DATA([[input.y]], | |
317 | [[%destructor { destroy ($$); } <*> <*> | |
318 | %printer { print ($$); } <*> <*> | |
319 | ||
320 | %destructor { destroy ($$); } <*> | |
321 | %printer { print ($$); } <*> | |
322 | ||
323 | %destructor { destroy ($$); } <> <> | |
324 | %printer { print ($$); } <> <> | |
325 | ||
326 | %destructor { destroy ($$); } <> | |
327 | %printer { print ($$); } <> | |
328 | ||
329 | %% | |
330 | ||
331 | start: ; | |
332 | ||
333 | %destructor { destroy ($$); } <*>; | |
334 | %printer { print ($$); } <*>; | |
335 | ||
336 | %destructor { destroy ($$); } <>; | |
337 | %printer { print ($$); } <>; | |
338 | ]]) | |
339 | ||
340 | AT_BISON_CHECK([-fcaret input.y], [1], [], | |
341 | [[input.y:1.13-29: error: %destructor redeclaration for <*> | |
342 | %destructor { destroy ($$); } <*> <*> | |
343 | ^^^^^^^^^^^^^^^^^ | |
344 | input.y:1.13-29: previous declaration | |
345 | %destructor { destroy ($$); } <*> <*> | |
346 | ^^^^^^^^^^^^^^^^^ | |
347 | input.y:2.10-24: error: %printer redeclaration for <*> | |
348 | %printer { print ($$); } <*> <*> | |
349 | ^^^^^^^^^^^^^^^ | |
350 | input.y:2.10-24: previous declaration | |
351 | %printer { print ($$); } <*> <*> | |
352 | ^^^^^^^^^^^^^^^ | |
353 | input.y:4.13-29: error: %destructor redeclaration for <*> | |
354 | %destructor { destroy ($$); } <*> | |
355 | ^^^^^^^^^^^^^^^^^ | |
356 | input.y:1.13-29: previous declaration | |
357 | %destructor { destroy ($$); } <*> <*> | |
358 | ^^^^^^^^^^^^^^^^^ | |
359 | input.y:5.10-24: error: %printer redeclaration for <*> | |
360 | %printer { print ($$); } <*> | |
361 | ^^^^^^^^^^^^^^^ | |
362 | input.y:2.10-24: previous declaration | |
363 | %printer { print ($$); } <*> <*> | |
364 | ^^^^^^^^^^^^^^^ | |
365 | input.y:7.13-29: error: %destructor redeclaration for <> | |
366 | %destructor { destroy ($$); } <> <> | |
367 | ^^^^^^^^^^^^^^^^^ | |
368 | input.y:7.13-29: previous declaration | |
369 | %destructor { destroy ($$); } <> <> | |
370 | ^^^^^^^^^^^^^^^^^ | |
371 | input.y:8.10-24: error: %printer redeclaration for <> | |
372 | %printer { print ($$); } <> <> | |
373 | ^^^^^^^^^^^^^^^ | |
374 | input.y:8.10-24: previous declaration | |
375 | %printer { print ($$); } <> <> | |
376 | ^^^^^^^^^^^^^^^ | |
377 | input.y:10.13-29: error: %destructor redeclaration for <> | |
378 | %destructor { destroy ($$); } <> | |
379 | ^^^^^^^^^^^^^^^^^ | |
380 | input.y:7.13-29: previous declaration | |
381 | %destructor { destroy ($$); } <> <> | |
382 | ^^^^^^^^^^^^^^^^^ | |
383 | input.y:11.10-24: error: %printer redeclaration for <> | |
384 | %printer { print ($$); } <> | |
385 | ^^^^^^^^^^^^^^^ | |
386 | input.y:8.10-24: previous declaration | |
387 | %printer { print ($$); } <> <> | |
388 | ^^^^^^^^^^^^^^^ | |
389 | input.y:17.13-29: error: %destructor redeclaration for <*> | |
390 | %destructor { destroy ($$); } <*>; | |
391 | ^^^^^^^^^^^^^^^^^ | |
392 | input.y:4.13-29: previous declaration | |
393 | %destructor { destroy ($$); } <*> | |
394 | ^^^^^^^^^^^^^^^^^ | |
395 | input.y:18.10-24: error: %printer redeclaration for <*> | |
396 | %printer { print ($$); } <*>; | |
397 | ^^^^^^^^^^^^^^^ | |
398 | input.y:5.10-24: previous declaration | |
399 | %printer { print ($$); } <*> | |
400 | ^^^^^^^^^^^^^^^ | |
401 | input.y:20.13-29: error: %destructor redeclaration for <> | |
402 | %destructor { destroy ($$); } <>; | |
403 | ^^^^^^^^^^^^^^^^^ | |
404 | input.y:10.13-29: previous declaration | |
405 | %destructor { destroy ($$); } <> | |
406 | ^^^^^^^^^^^^^^^^^ | |
407 | input.y:21.10-24: error: %printer redeclaration for <> | |
408 | %printer { print ($$); } <>; | |
409 | ^^^^^^^^^^^^^^^ | |
410 | input.y:11.10-24: previous declaration | |
411 | %printer { print ($$); } <> | |
412 | ^^^^^^^^^^^^^^^ | |
413 | ]]) | |
414 | ||
415 | AT_CLEANUP | |
416 | ||
417 | ||
418 | ## ---------------------------------------------- ## | |
419 | ## Per-type %printer and %destructor redeclared. ## | |
420 | ## ---------------------------------------------- ## | |
421 | ||
422 | AT_SETUP([Per-type %printer and %destructor redeclared]) | |
423 | ||
424 | AT_DATA([[input.y]], | |
425 | [[%destructor { destroy ($$); } <field1> <field2> | |
426 | %printer { print ($$); } <field1> <field2> | |
427 | ||
428 | %destructor { destroy ($$); } <field1> <field1> | |
429 | %printer { print ($$); } <field2> <field2> | |
430 | ||
431 | %% | |
432 | ||
433 | start: ; | |
434 | ||
435 | %destructor { destroy ($$); } <field2> <field1>; | |
436 | %printer { print ($$); } <field2> <field1>; | |
437 | ]]) | |
438 | ||
439 | AT_BISON_CHECK([input.y], [1], [], | |
440 | [[input.y:4.13-29: error: %destructor redeclaration for <field1> | |
441 | input.y:1.13-29: previous declaration | |
442 | input.y:4.13-29: error: %destructor redeclaration for <field1> | |
443 | input.y:4.13-29: previous declaration | |
444 | input.y:5.10-24: error: %printer redeclaration for <field2> | |
445 | input.y:2.10-24: previous declaration | |
446 | input.y:5.10-24: error: %printer redeclaration for <field2> | |
447 | input.y:5.10-24: previous declaration | |
448 | input.y:11.13-29: error: %destructor redeclaration for <field2> | |
449 | input.y:1.13-29: previous declaration | |
450 | input.y:11.13-29: error: %destructor redeclaration for <field1> | |
451 | input.y:4.13-29: previous declaration | |
452 | input.y:12.10-24: error: %printer redeclaration for <field2> | |
453 | input.y:5.10-24: previous declaration | |
454 | input.y:12.10-24: error: %printer redeclaration for <field1> | |
455 | input.y:2.10-24: previous declaration | |
456 | ]]) | |
457 | ||
458 | AT_CLEANUP | |
459 | ||
460 | ## ------------------- ## | |
461 | ## Undefined symbols. ## | |
462 | ## ------------------- ## | |
463 | ||
464 | AT_SETUP([Undefined symbols]) | |
465 | ||
466 | AT_DATA([[input.y]], | |
467 | [[%printer {} foo baz | |
468 | %destructor {} bar | |
469 | %type <foo> qux | |
470 | %% | |
471 | exp: bar; | |
472 | ]]) | |
473 | ||
474 | AT_BISON_CHECK([-fcaret input.y], [1], [], | |
475 | [[input.y:2.16-18: error: symbol bar is used, but is not defined as a token and has no rules | |
476 | %destructor {} bar | |
477 | ^^^ | |
478 | input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother] | |
479 | %printer {} foo baz | |
480 | ^^^ | |
481 | input.y:1.13-15: warning: symbol foo is used, but is not defined as a token and has no rules [-Wother] | |
482 | %printer {} foo baz | |
483 | ^^^ | |
484 | input.y:3.13-15: warning: symbol qux is used, but is not defined as a token and has no rules [-Wother] | |
485 | %type <foo> qux | |
486 | ^^^ | |
487 | ]]) | |
488 | ||
489 | AT_CLEANUP | |
490 | ||
491 | ||
492 | ## ----------------------------------------------------- ## | |
493 | ## Unassociated types used for a printer or destructor. ## | |
494 | ## ----------------------------------------------------- ## | |
495 | ||
496 | AT_SETUP([Unassociated types used for a printer or destructor]) | |
497 | ||
498 | AT_DATA([[input.y]], | |
499 | [[%token <type1> tag1 | |
500 | %type <type2> tag2 | |
501 | ||
502 | %printer { } <type1> <type3> | |
503 | %destructor { } <type2> <type4> | |
504 | ||
505 | %% | |
506 | ||
507 | exp: tag1 { $1; } | |
508 | | tag2 { $1; } | |
509 | ||
510 | tag2: "a" { $$; } | |
511 | ]]) | |
512 | ||
513 | AT_BISON_CHECK([input.y], [0], [], | |
514 | [[input.y:4.22-28: warning: type <type3> is used, but is not associated to any symbol [-Wother] | |
515 | input.y:5.25-31: warning: type <type4> is used, but is not associated to any symbol [-Wother] | |
516 | ]]) | |
517 | ||
518 | AT_CLEANUP | |
519 | ||
520 | ||
521 | ## --------------------------------- ## | |
522 | ## Useless printers or destructors. ## | |
523 | ## --------------------------------- ## | |
524 | ||
525 | AT_SETUP([Useless printers or destructors]) | |
526 | ||
527 | # AT_TEST([INPUT], [STDERR]) | |
528 | # -------------------------- | |
529 | m4_pushdef([AT_TEST], | |
530 | [AT_DATA([[input.y]], | |
531 | [$1 | |
532 | ]) | |
533 | AT_BISON_CHECK([input.y], [0], [], [$2 | |
534 | ])]) | |
535 | ||
536 | AT_TEST([[%token <type1> token1 | |
537 | %token <type2> token2 | |
538 | %token <type3> token3 | |
539 | %token <type4> token4 | |
540 | %token <type5> token51 token52 | |
541 | %token <type6> token61 token62 | |
542 | %token <type7> token7 | |
543 | ||
544 | %printer {} token1 | |
545 | %destructor {} token2 | |
546 | %printer {} token51 | |
547 | %destructor {} token61 | |
548 | ||
549 | %printer {} token7 | |
550 | ||
551 | %printer {} <type1> | |
552 | %destructor {} <type2> | |
553 | %printer {} <type3> | |
554 | %destructor {} <type4> | |
555 | ||
556 | %printer {} <type5> | |
557 | %destructor {} <type6> | |
558 | ||
559 | %destructor {} <type7> | |
560 | ||
561 | %% | |
562 | exp: "a";]], | |
563 | [[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother] | |
564 | input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]]) | |
565 | ||
566 | # If everybody is typed, <> is useless. | |
567 | AT_TEST([[%type <type> exp | |
568 | %token <type> a | |
569 | %printer {} <> <*> | |
570 | %% | |
571 | exp: a;]], | |
572 | [[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]]) | |
573 | ||
574 | # If nobody is typed, <*> is useless. | |
575 | AT_TEST([[%token a | |
576 | %printer {} <> <*> | |
577 | %% | |
578 | exp: a;]], | |
579 | [[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]]) | |
580 | ||
581 | m4_popdef([AT_TEST]) | |
582 | ||
583 | AT_CLEANUP | |
584 | ||
585 | ||
586 | ## ---------------------------------------- ## | |
587 | ## Unused values with default %destructor. ## | |
588 | ## ---------------------------------------- ## | |
589 | ||
590 | AT_SETUP([Unused values with default %destructor]) | |
591 | ||
592 | AT_DATA([[input.y]], | |
593 | [[%destructor { destroy ($$); } <> | |
594 | %type <tag> tagged | |
595 | ||
596 | %% | |
597 | ||
598 | start: end end tagged tagged { $<tag>1; $3; } ; | |
599 | end: { } ; | |
600 | tagged: { } ; | |
601 | ]]) | |
602 | ||
603 | AT_BISON_CHECK([-fcaret input.y], [0], [], | |
604 | [[input.y:6.8-45: warning: unset value: $$ [-Wother] | |
605 | start: end end tagged tagged { $<tag>1; $3; } ; | |
606 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
607 | input.y:6.12-14: warning: unused value: $2 [-Wother] | |
608 | start: end end tagged tagged { $<tag>1; $3; } ; | |
609 | ^^^ | |
610 | input.y:7.6-8: warning: unset value: $$ [-Wother] | |
611 | end: { } ; | |
612 | ^^^ | |
613 | ]]) | |
614 | ||
615 | AT_DATA([[input.y]], | |
616 | [[%destructor { destroy ($$); } <*> | |
617 | %type <tag> tagged | |
618 | ||
619 | %% | |
620 | ||
621 | start: end end tagged tagged { $<tag>1; $3; } ; | |
622 | end: { } ; | |
623 | tagged: { } ; | |
624 | ]]) | |
625 | ||
626 | AT_BISON_CHECK([input.y], [0], [], | |
627 | [[input.y:6.23-28: warning: unused value: $4 [-Wother] | |
628 | input.y:8.9-11: warning: unset value: $$ [-Wother] | |
629 | ]]) | |
630 | ||
631 | AT_CLEANUP | |
632 | ||
633 | ||
634 | ## ----------------------------------------- ## | |
635 | ## Unused values with per-type %destructor. ## | |
636 | ## ----------------------------------------- ## | |
637 | ||
638 | AT_SETUP([Unused values with per-type %destructor]) | |
639 | ||
640 | AT_DATA([[input.y]], | |
641 | [[%destructor { destroy ($$); } <field1> | |
642 | %type <field1> start end | |
643 | ||
644 | %% | |
645 | ||
646 | start: end end { $1; } ; | |
647 | end: { } ; | |
648 | ]]) | |
649 | ||
650 | AT_BISON_CHECK([-fcaret input.y], [0], [], | |
651 | [[input.y:6.8-22: warning: unset value: $$ [-Wother] | |
652 | start: end end { $1; } ; | |
653 | ^^^^^^^^^^^^^^^ | |
654 | input.y:6.12-14: warning: unused value: $2 [-Wother] | |
655 | start: end end { $1; } ; | |
656 | ^^^ | |
657 | input.y:7.6-8: warning: unset value: $$ [-Wother] | |
658 | end: { } ; | |
659 | ^^^ | |
660 | ]]) | |
661 | ||
662 | AT_CLEANUP | |
663 | ||
664 | ||
665 | ## ---------------------- ## | |
666 | ## Incompatible Aliases. ## | |
667 | ## ---------------------- ## | |
668 | ||
669 | AT_SETUP([Incompatible Aliases]) | |
670 | ||
671 | AT_DATA([input.y], | |
672 | [[%token foo "foo" | |
673 | ||
674 | %type <bar> foo | |
675 | %printer {bar} foo | |
676 | %destructor {bar} foo | |
677 | %left foo | |
678 | ||
679 | %type <baz> "foo" | |
680 | %printer {baz} "foo" | |
681 | %destructor {baz} "foo" | |
682 | %left "foo" | |
683 | ||
684 | %% | |
685 | exp: foo; | |
686 | ]]) | |
687 | ||
688 | AT_BISON_CHECK([-fcaret input.y], [1], [], | |
689 | [[input.y:8.7-11: error: %type redeclaration for foo | |
690 | %type <baz> "foo" | |
691 | ^^^^^ | |
692 | input.y:3.7-11: previous declaration | |
693 | %type <bar> foo | |
694 | ^^^^^ | |
695 | input.y:10.13-17: error: %destructor redeclaration for foo | |
696 | %destructor {baz} "foo" | |
697 | ^^^^^ | |
698 | input.y:5.13-17: previous declaration | |
699 | %destructor {bar} foo | |
700 | ^^^^^ | |
701 | input.y:9.10-14: error: %printer redeclaration for foo | |
702 | %printer {baz} "foo" | |
703 | ^^^^^ | |
704 | input.y:4.10-14: previous declaration | |
705 | %printer {bar} foo | |
706 | ^^^^^ | |
707 | input.y:11.1-5: error: %left redeclaration for foo | |
708 | %left "foo" | |
709 | ^^^^^ | |
710 | input.y:6.1-5: previous declaration | |
711 | %left foo | |
712 | ^^^^^ | |
713 | ]]) | |
714 | ||
715 | AT_CLEANUP | |
716 | ||
717 | ||
718 | ||
719 | ## ----------------------- ## | |
720 | ## Torturing the Scanner. ## | |
721 | ## ----------------------- ## | |
722 | ||
723 | # Be sure to compile and run, so that the C compiler checks what | |
724 | # we do. | |
725 | ||
726 | AT_SETUP([Torturing the Scanner]) | |
727 | ||
728 | AT_BISON_OPTION_PUSHDEFS | |
729 | AT_DATA([input.y], []) | |
730 | AT_BISON_CHECK([input.y], [1], [], | |
731 | [[input.y:1.1: error: syntax error, unexpected end of file | |
732 | ]]) | |
733 | ||
734 | ||
735 | AT_DATA([input.y], | |
736 | [{} | |
737 | ]) | |
738 | AT_BISON_CHECK([-fcaret input.y], [1], [], | |
739 | [[input.y:1.1-2: error: syntax error, unexpected {...} | |
740 | {} | |
741 | ^^ | |
742 | ]]) | |
743 | ||
744 | ||
745 | AT_DATA_GRAMMAR([input.y], | |
746 | [[%{ | |
747 | /* This is seen in GCC: a %{ and %} in middle of a comment. */ | |
748 | const char *foo = "So %{ and %} can be here too."; | |
749 | ||
750 | #if 0 | |
751 | /* These examples test Bison while not stressing C compilers too much. | |
752 | Many C compilers mishandle backslash-newlines, so this part of the | |
753 | test is inside "#if 0". The comment and string are written so that | |
754 | the "#endif" will be seen regardless of the C compiler bugs that we | |
755 | know about, namely: | |
756 | ||
757 | HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a | |
758 | comment. | |
759 | ||
760 | The Apple Darwin compiler (as of late 2002) mishandles | |
761 | \\[newline]' within a character constant. | |
762 | ||
763 | */ | |
764 | ||
765 | /\ | |
766 | * A comment with backslash-newlines in it. %} *\ | |
767 | \ | |
768 | / | |
769 | /* { Close the above comment, if the C compiler mishandled it. */ | |
770 | ||
771 | char str[] = "\\ | |
772 | " A string with backslash-newlines in it %{ %} \\ | |
773 | \ | |
774 | ""; | |
775 | ||
776 | char apostrophe = '\''; | |
777 | #endif | |
778 | ||
779 | #include <stdio.h> | |
780 | #include <stdlib.h> | |
781 | #include <assert.h> | |
782 | %} | |
783 | /* %{ and %} can be here too. */ | |
784 | ||
785 | %{ | |
786 | /* Exercise pre-prologue dependency to %union. */ | |
787 | typedef int value; | |
788 | %} | |
789 | ||
790 | /* Exercise M4 quoting: '@:>@@:>@', 0. */ | |
791 | ||
792 | /* Also exercise %union. */ | |
793 | %union | |
794 | { | |
795 | value ival; /* A comment to exercise an old bug. */ | |
796 | }; | |
797 | ||
798 | ||
799 | /* Exercise post-prologue dependency to %union. */ | |
800 | %{ | |
801 | static YYSTYPE value_as_yystype (value val); | |
802 | ||
803 | /* Exercise quotes in declarations. */ | |
804 | char quote[] = "@:>@@:>@,"; | |
805 | %} | |
806 | ||
807 | %{ | |
808 | ]AT_YYERROR_DECLARE[ | |
809 | ]AT_YYLEX_DECLARE[ | |
810 | %} | |
811 | ||
812 | %type <ival> '@<:@' | |
813 | ||
814 | /* Exercise quotes in strings. */ | |
815 | %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1" | |
816 | ||
817 | %% | |
818 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */ | |
819 | exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt | |
820 | { | |
821 | /* Exercise quotes in braces. */ | |
822 | char tmp[] = "@<:@%c@:>@,\n"; | |
823 | printf (tmp, $1); | |
824 | } | |
825 | ; | |
826 | ||
827 | two: '\x000000000000000000000000000000000000000000000000000000000000000000002'; | |
828 | oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_'; | |
829 | output.or.oline.opt: ;|oline;;|output;;; | |
830 | output: '#' 'o' 'u' 't' 'p' 'u' 't' ' '; | |
831 | %% | |
832 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */ | |
833 | ||
834 | static YYSTYPE | |
835 | value_as_yystype (value val) | |
836 | { | |
837 | YYSTYPE res; | |
838 | res.ival = val; | |
839 | return res; | |
840 | } | |
841 | ]AT_YYERROR_DEFINE[ | |
842 | static int | |
843 | yylex (void) | |
844 | { | |
845 | static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\ | |
846 | #output "; /* " | |
847 | */ | |
848 | static size_t toknum; | |
849 | assert (toknum < sizeof input); | |
850 | yylval = value_as_yystype (input[toknum]); | |
851 | return input[toknum++]; | |
852 | } | |
853 | ]]) | |
854 | ||
855 | # Pacify Emacs'font-lock-mode: " | |
856 | ||
857 | AT_DATA([main.c], | |
858 | [[typedef int value; | |
859 | #include "input.h" | |
860 | ||
861 | int yyparse (void); | |
862 | ]AT_MAIN_DEFINE[ | |
863 | ]]) | |
864 | AT_BISON_OPTION_POPDEFS | |
865 | ||
866 | AT_BISON_CHECK([-d -v -o input.c input.y]) | |
867 | AT_COMPILE([input.o]) | |
868 | AT_COMPILE([main.o]) | |
869 | AT_COMPILE([input], [input.o main.o]) | |
870 | AT_PARSER_CHECK([./input], 0, | |
871 | [[[@<:@], | |
872 | ]]) | |
873 | ||
874 | AT_CLEANUP | |
875 | ||
876 | ||
877 | ## ---------------------- ## | |
878 | ## Typed symbol aliases. ## | |
879 | ## ---------------------- ## | |
880 | ||
881 | AT_SETUP([Typed symbol aliases]) | |
882 | ||
883 | # Bison 2.0 broke typed symbol aliases - ensure they work. | |
884 | ||
885 | AT_DATA_GRAMMAR([input.y], | |
886 | [[%union | |
887 | { | |
888 | int val; | |
889 | }; | |
890 | %token <val> MY_TOKEN "MY TOKEN" | |
891 | %type <val> exp | |
892 | %% | |
893 | exp: "MY TOKEN"; | |
894 | %% | |
895 | ]]) | |
896 | ||
897 | AT_BISON_CHECK([-o input.c input.y]) | |
898 | ||
899 | AT_CLEANUP | |
900 | ||
901 | ||
902 | ## --------- ## | |
903 | ## Require. ## | |
904 | ## --------- ## | |
905 | ||
906 | m4_define([AT_CHECK_REQUIRE], | |
907 | [AT_SETUP([Require $1]) | |
908 | AT_DATA_GRAMMAR([input.y], | |
909 | [[%require "$1"; | |
910 | %% | |
911 | empty_file: /* empty */; | |
912 | ]]) | |
913 | AT_BISON_CHECK([-o input.c input.y], $2, [], ignore) | |
914 | AT_CLEANUP | |
915 | ]) | |
916 | ||
917 | AT_CHECK_REQUIRE(1.0, 0) | |
918 | AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0) | |
919 | ## FIXME: Some day augment this version number. | |
920 | AT_CHECK_REQUIRE(100.0, 63) | |
921 | ||
922 | ||
923 | ## ------------------------------------- ## | |
924 | ## String aliases for character tokens. ## | |
925 | ## ------------------------------------- ## | |
926 | ||
927 | AT_SETUP([String aliases for character tokens]) | |
928 | ||
929 | # Bison once thought a character token and its alias were different | |
930 | # symbols with the same user token number. | |
931 | ||
932 | AT_DATA_GRAMMAR([input.y], | |
933 | [[%token 'a' "a" | |
934 | %% | |
935 | start: 'a'; | |
936 | %% | |
937 | ]]) | |
938 | ||
939 | AT_BISON_CHECK([-o input.c input.y]) | |
940 | ||
941 | AT_CLEANUP | |
942 | ||
943 | ||
944 | ## -------------- ## | |
945 | ## Symbol names. ## | |
946 | ## -------------- ## | |
947 | ||
948 | AT_SETUP([Symbols]) | |
949 | ||
950 | AT_BISON_OPTION_PUSHDEFS | |
951 | AT_DATA_GRAMMAR([input.y], | |
952 | [[%token WITH-DASH | |
953 | %token WITHOUT_DASH "WITHOUT-DASH" | |
954 | %token WITH.PERIOD | |
955 | %token WITHOUT_PERIOD "WITHOUT.PERIOD" | |
956 | %code { | |
957 | ]AT_YYERROR_DECLARE[ | |
958 | ]AT_YYLEX_DECLARE[ | |
959 | } | |
960 | %% | |
961 | start: with-dash without_dash with.period without_period; | |
962 | with-dash: WITH-DASH; | |
963 | without_dash: "WITHOUT-DASH"; | |
964 | with.period: WITH.PERIOD; | |
965 | without_period: "WITHOUT.PERIOD"; | |
966 | %% | |
967 | ]AT_YYERROR_DEFINE[ | |
968 | ]AT_YYLEX_DEFINE[ | |
969 | ]]) | |
970 | AT_BISON_OPTION_POPDEFS | |
971 | ||
972 | # POSIX Yacc accept periods, but not dashes. | |
973 | AT_BISON_CHECK([--yacc -Wno-error input.y], [], [], | |
974 | [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc] | |
975 | input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc] | |
976 | ]]) | |
977 | ||
978 | # So warn about them. | |
979 | AT_BISON_CHECK([-Wyacc input.y], [], [], | |
980 | [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc] | |
981 | input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc] | |
982 | ]]) | |
983 | ||
984 | # Dashes are fine for GNU Bison. | |
985 | AT_BISON_CHECK([-o input.c input.y]) | |
986 | ||
987 | # Make sure we don't export silly token identifiers with periods or dashes. | |
988 | AT_COMPILE([input.o]) | |
989 | ||
990 | ||
991 | # Periods are genuine letters, they can start identifiers. | |
992 | # Digits and dashes cannot. | |
993 | AT_DATA_GRAMMAR([input.y], | |
994 | [[%token .GOOD | |
995 | -GOOD | |
996 | 1NV4L1D | |
997 | -123 | |
998 | %% | |
999 | start: .GOOD GOOD | |
1000 | ]]) | |
1001 | AT_BISON_CHECK([-o input.c input.y], [1], [], | |
1002 | [[input.y:10.10: error: invalid character: '-' | |
1003 | input.y:11.10-16: error: invalid identifier: '1NV4L1D' | |
1004 | input.y:12.10: error: invalid character: '-' | |
1005 | ]]) | |
1006 | ||
1007 | AT_CLEANUP | |
1008 | ||
1009 | ||
1010 | ## ----------------- ## | |
1011 | ## Numbered tokens. ## | |
1012 | ## ----------------- ## | |
1013 | ||
1014 | AT_SETUP([Numbered tokens]) | |
1015 | ||
1016 | AT_DATA_GRAMMAR([redecl.y], | |
1017 | [[%token DECIMAL_1 11259375 | |
1018 | HEXADECIMAL_1 0xabcdef | |
1019 | HEXADECIMAL_2 0xFEDCBA | |
1020 | DECIMAL_2 16702650 | |
1021 | %% | |
1022 | start: DECIMAL_1 HEXADECIMAL_2; | |
1023 | ]]) | |
1024 | ||
1025 | AT_BISON_CHECK([redecl.y], [1], [], | |
1026 | [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1 | |
1027 | redecl.y:9.8-16: previous declaration for DECIMAL_1 | |
1028 | redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2 | |
1029 | redecl.y:11.10-22: previous declaration for HEXADECIMAL_2 | |
1030 | ]]) | |
1031 | ||
1032 | AT_DATA_GRAMMAR([too-large.y], | |
1033 | [[%token TOO_LARGE_DEC 999999999999999999999 | |
1034 | TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF | |
1035 | %% | |
1036 | start: TOO_LARGE_DEC TOO_LARGE_HEX | |
1037 | %% | |
1038 | ]]) | |
1039 | ||
1040 | AT_BISON_CHECK([too-large.y], [1], [], | |
1041 | [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999' | |
1042 | too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF' | |
1043 | ]]) | |
1044 | ||
1045 | AT_CLEANUP | |
1046 | ||
1047 | ||
1048 | ## --------------------- ## | |
1049 | ## Unclosed constructs. ## | |
1050 | ## --------------------- ## | |
1051 | ||
1052 | AT_SETUP([Unclosed constructs]) | |
1053 | ||
1054 | # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed | |
1055 | # constructs, so they were prepended to whatever it STRING_GROW'ed | |
1056 | # next. It also threw them away rather than returning them to the | |
1057 | # parser. The effect was confusing subsequent error messages. | |
1058 | ||
1059 | AT_DATA([input.y], | |
1060 | [[%token A "a | |
1061 | %token B "b" | |
1062 | %token AB "ab" // Used to complain that "ab" was already used. | |
1063 | %token C '1 | |
1064 | %token TWO "2" | |
1065 | %token TICK_TWELVE "'12" // Used to complain that "'12" was already used. | |
1066 | ||
1067 | %% | |
1068 | ||
1069 | start: ; | |
1070 | ||
1071 | // Used to report a syntax error because it didn't see any kind of symbol | |
1072 | // identifier. | |
1073 | %type <f> 'a | |
1074 | ; | |
1075 | %type <f> "a | |
1076 | ; | |
1077 | // Used to report a syntax error because it didn't see braced code. | |
1078 | %destructor { free ($$) | |
1079 | ]]) | |
1080 | ||
1081 | AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [], | |
1082 | [[input.y:1.10-2.0: error: missing '"' at end of line | |
1083 | %token A "a | |
1084 | ^^ | |
1085 | input.y:4.10-5.0: error: missing "'" at end of line | |
1086 | %token C '1 | |
1087 | ^^ | |
1088 | input.y:14.11-15.0: error: missing "'" at end of line | |
1089 | %type <f> 'a | |
1090 | ^^ | |
1091 | input.y:16.11-17.0: error: missing '"' at end of line | |
1092 | %type <f> "a | |
1093 | ^^ | |
1094 | input.y:19.13-20.0: error: missing '}' at end of file | |
1095 | %destructor { free ($$) | |
1096 | ^^^^^^^^^^^ | |
1097 | input.y:20.1: error: syntax error, unexpected end of file | |
1098 | ]]) | |
1099 | ||
1100 | AT_CLEANUP | |
1101 | ||
1102 | ||
1103 | ## ------------------------- ## | |
1104 | ## %start after first rule. ## | |
1105 | ## ------------------------- ## | |
1106 | ||
1107 | AT_SETUP([%start after first rule]) | |
1108 | ||
1109 | # Bison once complained that a %start after the first rule was a | |
1110 | # redeclaration of the start symbol. | |
1111 | ||
1112 | AT_DATA([input.y], | |
1113 | [[%% | |
1114 | false_start: ; | |
1115 | start: false_start ; | |
1116 | %start start; | |
1117 | ]]) | |
1118 | ||
1119 | AT_BISON_CHECK([-o input.c input.y]) | |
1120 | ||
1121 | AT_CLEANUP | |
1122 | ||
1123 | ||
1124 | ## --------------------- ## | |
1125 | ## %prec takes a token. ## | |
1126 | ## --------------------- ## | |
1127 | ||
1128 | AT_SETUP([%prec takes a token]) | |
1129 | ||
1130 | # Bison once allowed %prec sym where sym was a nonterminal. | |
1131 | ||
1132 | AT_DATA([input.y], | |
1133 | [[%% | |
1134 | start: PREC %prec PREC ; | |
1135 | PREC: ; | |
1136 | ]]) | |
1137 | ||
1138 | AT_BISON_CHECK([input.y], [1], [], | |
1139 | [[input.y:3.1-4: error: rule given for PREC, which is a token | |
1140 | ]]) | |
1141 | ||
1142 | AT_CLEANUP | |
1143 | ||
1144 | ||
1145 | ## ------------------------------- ## | |
1146 | ## %prec's token must be defined. ## | |
1147 | ## ------------------------------- ## | |
1148 | ||
1149 | AT_SETUP([[%prec's token must be defined]]) | |
1150 | ||
1151 | # According to POSIX, a %prec token must be defined separately. | |
1152 | ||
1153 | AT_DATA([[input.y]], | |
1154 | [[%% | |
1155 | start: %prec PREC ; | |
1156 | ]]) | |
1157 | ||
1158 | AT_BISON_CHECK([[input.y]], [[0]], [], | |
1159 | [[input.y:2.8-17: warning: token for %prec is not defined: PREC [-Wother] | |
1160 | ]]) | |
1161 | ||
1162 | AT_CLEANUP | |
1163 | ||
1164 | ||
1165 | ## -------------------------------- ## | |
1166 | ## Reject unused %code qualifiers. ## | |
1167 | ## -------------------------------- ## | |
1168 | ||
1169 | AT_SETUP([Reject unused %code qualifiers]) | |
1170 | ||
1171 | AT_DATA([input-c.y], | |
1172 | [[%code q {} | |
1173 | %code bad {} | |
1174 | %code bad {} | |
1175 | %code format {} | |
1176 | %% | |
1177 | start: ; | |
1178 | ]]) | |
1179 | AT_BISON_CHECK([[input-c.y]], [[1]], [], | |
1180 | [[input-c.y:1.7: error: %code qualifier 'q' is not used | |
1181 | input-c.y:2.7-9: error: %code qualifier 'bad' is not used | |
1182 | input-c.y:3.7-9: error: %code qualifier 'bad' is not used | |
1183 | input-c.y:4.7-12: error: %code qualifier 'format' is not used | |
1184 | ]]) | |
1185 | ||
1186 | AT_DATA([input-c-glr.y], | |
1187 | [[%code q {} | |
1188 | %code bad {} | |
1189 | %code bad {} | |
1190 | %% | |
1191 | start: ; | |
1192 | ]]) | |
1193 | AT_BISON_CHECK([[input-c-glr.y]], [[1]], [], | |
1194 | [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used | |
1195 | input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used | |
1196 | input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used | |
1197 | ]]) | |
1198 | ||
1199 | AT_DATA([input-c++.y], | |
1200 | [[%code q {} | |
1201 | %code bad {} | |
1202 | %code q {} | |
1203 | %% | |
1204 | start: ; | |
1205 | ]]) | |
1206 | AT_BISON_CHECK([[input-c++.y]], [[1]], [], | |
1207 | [[input-c++.y:1.7: error: %code qualifier 'q' is not used | |
1208 | input-c++.y:2.7-9: error: %code qualifier 'bad' is not used | |
1209 | input-c++.y:3.8: error: %code qualifier 'q' is not used | |
1210 | ]]) | |
1211 | ||
1212 | AT_DATA([input-c++-glr.y], | |
1213 | [[%code bad {} | |
1214 | %code q {} | |
1215 | %code q {} | |
1216 | %% | |
1217 | start: ; | |
1218 | ]]) | |
1219 | AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [], | |
1220 | [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used | |
1221 | input-c++-glr.y:2.7: error: %code qualifier 'q' is not used | |
1222 | input-c++-glr.y:3.7: error: %code qualifier 'q' is not used | |
1223 | ]]) | |
1224 | ||
1225 | AT_DATA([special-char-@@.y], | |
1226 | [[%code bad {} | |
1227 | %code q {} | |
1228 | %code q {} | |
1229 | %% | |
1230 | start: ; | |
1231 | ]]) | |
1232 | AT_BISON_CHECK([[special-char-@@.y]], [[1]], [], | |
1233 | [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used | |
1234 | special-char-@@.y:2.7: error: %code qualifier 'q' is not used | |
1235 | special-char-@@.y:3.7: error: %code qualifier 'q' is not used | |
1236 | ]]) | |
1237 | ||
1238 | AT_DATA([special-char-@:>@.y], | |
1239 | [[%code bad {} | |
1240 | %code q {} | |
1241 | %code q {} | |
1242 | %% | |
1243 | start: ; | |
1244 | ]]) | |
1245 | AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [], | |
1246 | [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used | |
1247 | special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used | |
1248 | special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used | |
1249 | ]]) | |
1250 | ||
1251 | AT_CLEANUP | |
1252 | ||
1253 | ||
1254 | ## ---------------- ## | |
1255 | ## %define errors. ## | |
1256 | ## ---------------- ## | |
1257 | ||
1258 | AT_SETUP([%define errors]) | |
1259 | ||
1260 | AT_DATA([input-redefined.y], | |
1261 | [[%define var "value1" | |
1262 | %define var "value1" | |
1263 | %define var "value2" | |
1264 | %define special1 "@:>@" | |
1265 | %define special2 "@<:@" | |
1266 | %% | |
1267 | start: ; | |
1268 | ]]) | |
1269 | ||
1270 | AT_BISON_CHECK([[input-redefined.y]], [[1]], [], | |
1271 | [[input-redefined.y:2.9-11: error: %define variable 'var' redefined | |
1272 | input-redefined.y:1.9-11: previous definition | |
1273 | input-redefined.y:3.10-12: error: %define variable 'var' redefined | |
1274 | input-redefined.y:2.9-11: previous definition | |
1275 | ]]) | |
1276 | ||
1277 | AT_DATA([input-unused.y], | |
1278 | [[%define var "value" | |
1279 | %% | |
1280 | start: ; | |
1281 | ]]) | |
1282 | ||
1283 | AT_BISON_CHECK([[input-unused.y]], [[1]], [], | |
1284 | [[input-unused.y:1.9-11: error: %define variable 'var' is not used | |
1285 | ]]) | |
1286 | ||
1287 | AT_CLEANUP | |
1288 | ||
1289 | ||
1290 | ## ----------------------------------- ## | |
1291 | ## %define, --define, --force-define. ## | |
1292 | ## ----------------------------------- ## | |
1293 | ||
1294 | AT_SETUP([[%define, --define, --force-define]]) | |
1295 | ||
1296 | AT_DATA([[skel.c]], | |
1297 | [[m4@&t@_divert_push(0)@ | |
1298 | @output(b4_parser_file_name@)@ | |
1299 | [var-dd: ]b4_percent_define_get([[var-dd]])[ | |
1300 | var-ff: ]b4_percent_define_get([[var-ff]])[ | |
1301 | var-dfg: ]b4_percent_define_get([[var-dfg]])[ | |
1302 | var-fd: ]b4_percent_define_get([[var-fd]]) | |
1303 | m4@&t@_divert_pop(0) | |
1304 | ]]) | |
1305 | AT_DATA([[input.y]], | |
1306 | [[%define var-dfg "gram" | |
1307 | %% | |
1308 | start: ; | |
1309 | ]]) | |
1310 | AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \ | |
1311 | -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \ | |
1312 | -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \ | |
1313 | -Fvar-fd=cmd-f -Dvar-fd=cmd-d \ | |
1314 | --skeleton ./skel.c input.y]]) | |
1315 | AT_CHECK([[cat input.tab.c]], [[0]], | |
1316 | [[var-dd: cmd-d2 | |
1317 | var-ff: cmd-f2 | |
1318 | var-dfg: cmd-f | |
1319 | var-fd: cmd-d | |
1320 | ]]) | |
1321 | ||
1322 | AT_DATA([[input-dg.y]], | |
1323 | [[%define var "gram" | |
1324 | %% | |
1325 | start: ; | |
1326 | ]]) | |
1327 | AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [], | |
1328 | [[input-dg.y:1.9-11: error: %define variable 'var' redefined | |
1329 | <command line>:2: previous definition | |
1330 | ]]) | |
1331 | ||
1332 | AT_DATA([[input-dg.y]], | |
1333 | [[%define var "gram" | |
1334 | %% | |
1335 | start: ; | |
1336 | ]]) | |
1337 | AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [], | |
1338 | [[input-dg.y:1.9-11: error: %define variable 'var' redefined | |
1339 | %define var "gram" | |
1340 | ^^^ | |
1341 | <command line>:3: previous definition | |
1342 | ]]) | |
1343 | ||
1344 | AT_DATA([[input-unused.y]], | |
1345 | [[%% | |
1346 | start: ; | |
1347 | ]]) | |
1348 | AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [], | |
1349 | [[<command line>:2: error: %define variable 'unused-d' is not used | |
1350 | <command line>:3: error: %define variable 'unused-f' is not used | |
1351 | ]]) | |
1352 | ||
1353 | AT_CLEANUP | |
1354 | ||
1355 | ## --------------------------- ## | |
1356 | ## %define Boolean variables. ## | |
1357 | ## --------------------------- ## | |
1358 | ||
1359 | AT_SETUP([["%define" Boolean variables]]) | |
1360 | ||
1361 | AT_DATA([Input.y], | |
1362 | [[%language "Java" | |
1363 | %define public "maybe" | |
1364 | %define parser_class_name "Input" | |
1365 | %% | |
1366 | start: ; | |
1367 | ]]) | |
1368 | ||
1369 | AT_BISON_CHECK([[Input.y]], [1], [], | |
1370 | [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public' | |
1371 | ]]) | |
1372 | ||
1373 | AT_CLEANUP | |
1374 | ||
1375 | ## ------------------------ ## | |
1376 | ## %define enum variables. ## | |
1377 | ## ------------------------ ## | |
1378 | ||
1379 | AT_SETUP([["%define" enum variables]]) | |
1380 | ||
1381 | # Check errors from the front-end, and the back-end. Since the | |
1382 | # front-end quits before calling the back-end, these tests cannot be | |
1383 | # fused. | |
1384 | ||
1385 | # Front-end. | |
1386 | AT_DATA([[input.y]], | |
1387 | [[%define lr.default-reduction bogus | |
1388 | %% | |
1389 | start: ; | |
1390 | ]]) | |
1391 | AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]], | |
1392 | [[input.y:1.9-28: error: invalid value for %define variable 'lr.default-reduction': 'bogus' | |
1393 | %define lr.default-reduction bogus | |
1394 | ^^^^^^^^^^^^^^^^^^^^ | |
1395 | input.y:1.9-28: accepted value: 'most' | |
1396 | input.y:1.9-28: accepted value: 'consistent' | |
1397 | input.y:1.9-28: accepted value: 'accepting' | |
1398 | ]]) | |
1399 | ||
1400 | # Back-end. | |
1401 | AT_DATA([[input.y]], | |
1402 | [[%define api.push-pull neither | |
1403 | %% | |
1404 | start: ; | |
1405 | ]]) | |
1406 | AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]], | |
1407 | [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither' | |
1408 | %define api.push-pull neither | |
1409 | ^^^^^^^^^^^^^ | |
1410 | input.y:1.9-21: accepted value: 'pull' | |
1411 | input.y:1.9-21: accepted value: 'push' | |
1412 | input.y:1.9-21: accepted value: 'both' | |
1413 | ]]) | |
1414 | ||
1415 | AT_CLEANUP | |
1416 | ||
1417 | ## -------------------------------- ## | |
1418 | ## %define backward compatibility. ## | |
1419 | ## -------------------------------- ## | |
1420 | ||
1421 | AT_SETUP([["%define" backward compatibility]]) | |
1422 | ||
1423 | # The error messages tell us whether the variables are properly updated. | |
1424 | AT_DATA([[input.y]], | |
1425 | [[%define api.push_pull both | |
1426 | %define lr.keep_unreachable_states maybe | |
1427 | %define namespace "foo" | |
1428 | %define api.namespace "foo" | |
1429 | %define variant | |
1430 | %% | |
1431 | start: ; | |
1432 | ]]) | |
1433 | AT_BISON_CHECK([[-fcaret input.y]], [1], [], | |
1434 | [[input.y:1.9-21: warning: deprecated directive, use '%define api.push-pull both' [-Wdeprecated] | |
1435 | %define api.push_pull both | |
1436 | ^^^^^^^^^^^^^ | |
1437 | input.y:2.9-34: warning: deprecated directive, use '%define lr.keep-unreachable-state maybe' [-Wdeprecated] | |
1438 | %define lr.keep_unreachable_states maybe | |
1439 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
1440 | input.y:3.9-17: warning: deprecated directive, use '%define api.namespace foo' [-Wdeprecated] | |
1441 | %define namespace "foo" | |
1442 | ^^^^^^^^^ | |
1443 | input.y:4.9-21: error: %define variable 'api.namespace' redefined | |
1444 | %define api.namespace "foo" | |
1445 | ^^^^^^^^^^^^^ | |
1446 | input.y:3.9-17: previous definition | |
1447 | %define namespace "foo" | |
1448 | ^^^^^^^^^ | |
1449 | input.y:5.9-15: warning: deprecated directive, use '%define api.value.type variant' [-Wdeprecated] | |
1450 | %define variant | |
1451 | ^^^^^^^ | |
1452 | ]]) | |
1453 | ||
1454 | AT_CLEANUP | |
1455 | ||
1456 | ## ------------------------- ## | |
1457 | ## Unused %define api.pure. ## | |
1458 | ## ------------------------- ## | |
1459 | ||
1460 | AT_SETUP([[Unused %define api.pure]]) | |
1461 | ||
1462 | # AT_CHECK_API_PURE(DECLS, VALUE) | |
1463 | # ------------------------------- | |
1464 | # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS | |
1465 | # are specified. | |
1466 | m4_define([AT_CHECK_API_PURE], | |
1467 | [ | |
1468 | AT_DATA([[input.y]], | |
1469 | [[%define api.pure ]$2[ | |
1470 | ]$1[ | |
1471 | %% | |
1472 | start: ; | |
1473 | ]]) | |
1474 | ||
1475 | AT_BISON_CHECK([[input.y]], [[1]], [], | |
1476 | [[input.y:1.9-16: error: %define variable 'api.pure' is not used | |
1477 | ]]) | |
1478 | ]) | |
1479 | ||
1480 | AT_CHECK_API_PURE([[%language "c++"]], [[]]) | |
1481 | AT_CHECK_API_PURE([[%language "c++"]], [[false]]) | |
1482 | AT_CHECK_API_PURE([[%language "c++" %glr-parser]], [[""]]) | |
1483 | AT_CHECK_API_PURE([[%language "c++" %glr-parser]], [[false]]) | |
1484 | AT_CHECK_API_PURE([[%language "java"]], [[true]]) | |
1485 | AT_CHECK_API_PURE([[%language "java"]], [[false]]) | |
1486 | ||
1487 | AT_CLEANUP | |
1488 | ||
1489 | ## -------------------------------- ## | |
1490 | ## C++ namespace reference errors. ## | |
1491 | ## -------------------------------- ## | |
1492 | ||
1493 | AT_SETUP([[C++ namespace reference errors]]) | |
1494 | ||
1495 | # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...) | |
1496 | # ------------------------------------------------------------- | |
1497 | # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL". | |
1498 | m4_define([AT_CHECK_NAMESPACE_ERROR], | |
1499 | [ | |
1500 | AT_DATA([[input.y]], | |
1501 | [[%language "C++" | |
1502 | %defines | |
1503 | %define api.namespace "]$1[" | |
1504 | %% | |
1505 | start: ; | |
1506 | ]]) | |
1507 | ||
1508 | AT_BISON_CHECK([[input.y]], [1], [], | |
1509 | [m4_foreach([b4_arg], m4_dquote(m4_shift($@)), | |
1510 | [[input.y:3.9-21: error: ]b4_arg[ | |
1511 | ]])]) | |
1512 | ]) | |
1513 | ||
1514 | AT_CHECK_NAMESPACE_ERROR([[]], | |
1515 | [[namespace reference is empty]]) | |
1516 | AT_CHECK_NAMESPACE_ERROR([[ ]], | |
1517 | [[namespace reference is empty]]) | |
1518 | AT_CHECK_NAMESPACE_ERROR([[foo::::bar]], | |
1519 | [[namespace reference has consecutive "::"]]) | |
1520 | AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]], | |
1521 | [[namespace reference has consecutive "::"]]) | |
1522 | AT_CHECK_NAMESPACE_ERROR([[::::bar]], | |
1523 | [[namespace reference has consecutive "::"]]) | |
1524 | AT_CHECK_NAMESPACE_ERROR([[:: ::bar]], | |
1525 | [[namespace reference has consecutive "::"]]) | |
1526 | AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]], | |
1527 | [[namespace reference has consecutive "::"]], | |
1528 | [[namespace reference has a trailing "::"]]) | |
1529 | AT_CHECK_NAMESPACE_ERROR([[foo::bar::]], | |
1530 | [[namespace reference has a trailing "::"]]) | |
1531 | AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]], | |
1532 | [[namespace reference has a trailing "::"]]) | |
1533 | AT_CHECK_NAMESPACE_ERROR([[::]], | |
1534 | [[namespace reference has a trailing "::"]]) | |
1535 | ||
1536 | AT_CLEANUP | |
1537 | ||
1538 | ## ------------------------ ## | |
1539 | ## Bad character literals. ## | |
1540 | ## ------------------------ ## | |
1541 | ||
1542 | # Bison used to accept character literals that were empty or contained | |
1543 | # too many characters. | |
1544 | ||
1545 | # FIXME: AT_DATA or some variant of AT_DATA may eventually permit | |
1546 | # the final newline to be omitted. See the threads starting at | |
1547 | # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>. | |
1548 | ||
1549 | AT_SETUP([[Bad character literals]]) | |
1550 | ||
1551 | AT_DATA([empty.y], | |
1552 | [[%% | |
1553 | start: ''; | |
1554 | start: ' | |
1555 | ]]) | |
1556 | AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]]) | |
1557 | ||
1558 | AT_BISON_CHECK([-fcaret empty.y], [1], [], | |
1559 | [[empty.y:2.8-9: warning: empty character literal [-Wother] | |
1560 | start: ''; | |
1561 | ^^ | |
1562 | empty.y:3.8-4.0: error: missing "'" at end of line | |
1563 | start: ' | |
1564 | ^ | |
1565 | empty.y:3.8-4.0: warning: empty character literal [-Wother] | |
1566 | start: ' | |
1567 | ^ | |
1568 | empty.y:4.8: error: missing "'" at end of file | |
1569 | start: ' | |
1570 | ^ | |
1571 | empty.y:4.8: warning: empty character literal [-Wother] | |
1572 | start: ' | |
1573 | ^ | |
1574 | ]]) | |
1575 | ||
1576 | AT_DATA([two.y], | |
1577 | [[%% | |
1578 | start: 'ab'; | |
1579 | start: 'ab | |
1580 | ]]) | |
1581 | AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]]) | |
1582 | ||
1583 | AT_BISON_CHECK([two.y], [1], [], | |
1584 | [[two.y:2.8-11: warning: extra characters in character literal [-Wother] | |
1585 | two.y:3.8-4.0: error: missing "'" at end of line | |
1586 | two.y:3.8-4.0: warning: extra characters in character literal [-Wother] | |
1587 | two.y:4.8-10: error: missing "'" at end of file | |
1588 | two.y:4.8-10: warning: extra characters in character literal [-Wother] | |
1589 | ]]) | |
1590 | ||
1591 | AT_DATA([three.y], | |
1592 | [[%% | |
1593 | start: 'abc'; | |
1594 | start: 'abc | |
1595 | ]]) | |
1596 | AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]]) | |
1597 | ||
1598 | AT_BISON_CHECK([three.y], [1], [], | |
1599 | [[three.y:2.8-12: warning: extra characters in character literal [-Wother] | |
1600 | three.y:3.8-4.0: error: missing "'" at end of line | |
1601 | three.y:3.8-4.0: warning: extra characters in character literal [-Wother] | |
1602 | three.y:4.8-11: error: missing "'" at end of file | |
1603 | three.y:4.8-11: warning: extra characters in character literal [-Wother] | |
1604 | ]]) | |
1605 | ||
1606 | AT_CLEANUP | |
1607 | ||
1608 | ## ------------------------- ## | |
1609 | ## Bad escapes in literals. ## | |
1610 | ## ------------------------- ## | |
1611 | ||
1612 | AT_SETUP([[Bad escapes in literals]]) | |
1613 | ||
1614 | AT_DATA([input.y], | |
1615 | [[%% | |
1616 | start: '\777' '\0' '\xfff' '\x0' | |
1617 | '\uffff' '\u0000' '\Uffffffff' '\U00000000' | |
1618 | '\ ' '\A'; | |
1619 | ]]) | |
1620 | ||
1621 | # It is not easy to create special characters, we cannot even trust tr. | |
1622 | # Beside we cannot even expect "echo '\0'" to output two characters | |
1623 | # (well three with \n): at least Bash 3.2 converts the two-character | |
1624 | # sequence "\0" into a single NUL character. | |
1625 | AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \ | |
1626 | || exit 77]]) | |
1627 | ||
1628 | AT_BISON_CHECK([input.y], [1], [], | |
1629 | [[input.y:2.9-12: error: invalid number after \-escape: 777 | |
1630 | input.y:2.8-13: warning: empty character literal [-Wother] | |
1631 | input.y:2.16-17: error: invalid number after \-escape: 0 | |
1632 | input.y:2.15-18: warning: empty character literal [-Wother] | |
1633 | input.y:2.21-25: error: invalid number after \-escape: xfff | |
1634 | input.y:2.20-26: warning: empty character literal [-Wother] | |
1635 | input.y:2.29-31: error: invalid number after \-escape: x0 | |
1636 | input.y:2.28-32: warning: empty character literal [-Wother] | |
1637 | input.y:3.9-14: error: invalid number after \-escape: uffff | |
1638 | input.y:3.8-15: warning: empty character literal [-Wother] | |
1639 | input.y:3.18-23: error: invalid number after \-escape: u0000 | |
1640 | input.y:3.17-24: warning: empty character literal [-Wother] | |
1641 | input.y:3.27-36: error: invalid number after \-escape: Uffffffff | |
1642 | input.y:3.26-37: warning: empty character literal [-Wother] | |
1643 | input.y:3.40-49: error: invalid number after \-escape: U00000000 | |
1644 | input.y:3.39-50: warning: empty character literal [-Wother] | |
1645 | input.y:4.9-10: error: invalid character after \-escape: ' ' | |
1646 | input.y:4.8-11: warning: empty character literal [-Wother] | |
1647 | input.y:4.14-15: error: invalid character after \-escape: A | |
1648 | input.y:4.13-16: warning: empty character literal [-Wother] | |
1649 | input.y:5.9-16: error: invalid character after \-escape: \t | |
1650 | input.y:5.17: error: invalid character after \-escape: \f | |
1651 | input.y:5.18: error: invalid character after \-escape: \0 | |
1652 | input.y:5.19: error: invalid character after \-escape: \001 | |
1653 | ]]) | |
1654 | ||
1655 | AT_CLEANUP | |
1656 | ||
1657 | ## ------------------------- ## | |
1658 | ## LAC: Errors for %define. ## | |
1659 | ## ------------------------- ## | |
1660 | ||
1661 | AT_SETUP([[LAC: Errors for %define]]) | |
1662 | ||
1663 | AT_DATA([[input.y]], | |
1664 | [[%% | |
1665 | start: ; | |
1666 | ]]) | |
1667 | ||
1668 | # parse.lac.* options are useless if LAC isn't actually activated. | |
1669 | AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]], | |
1670 | [[1]], [], | |
1671 | [[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used | |
1672 | ]]) | |
1673 | AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]], | |
1674 | [[1]], [], | |
1675 | [[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used | |
1676 | ]]) | |
1677 | ||
1678 | AT_CLEANUP | |
1679 | ||
1680 | ## --------------------------------------------- ## | |
1681 | ## -Werror is not affected by -Wnone and -Wall. ## | |
1682 | ## --------------------------------------------- ## | |
1683 | ||
1684 | AT_SETUP([[-Werror is not affected by -Wnone and -Wall]]) | |
1685 | ||
1686 | AT_DATA([[input.y]], | |
1687 | [[%% | |
1688 | foo-bar: ; | |
1689 | ]]) | |
1690 | ||
1691 | # -Werror is not enabled by -Wall or equivalent. | |
1692 | AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]], | |
1693 | [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc] | |
1694 | ]]) | |
1695 | AT_BISON_CHECK([[-W input.y]], [[0]], [[]], | |
1696 | [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc] | |
1697 | ]]) | |
1698 | AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]], | |
1699 | [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc] | |
1700 | ]]) | |
1701 | ||
1702 | # -Werror is not disabled by -Wnone or equivalent. | |
1703 | AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]]) | |
1704 | AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]], | |
1705 | [[input.y:2.1-7: error: POSIX Yacc forbids dashes in symbol names: foo-bar [-Werror=yacc] | |
1706 | ]]) | |
1707 | [mv stderr experr] | |
1708 | AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]]) | |
1709 | ||
1710 | AT_CLEANUP | |
1711 | ||
1712 | ||
1713 | ## ------------------------------------------------------ ## | |
1714 | ## %name-prefix and %define api.prefix are incompatible. ## | |
1715 | ## ------------------------------------------------------ ## | |
1716 | ||
1717 | AT_SETUP([[%name-prefix and api.prefix are incompatible]]) | |
1718 | ||
1719 | # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION) | |
1720 | # -------------------------------------------- | |
1721 | m4_pushdef([AT_TEST], | |
1722 | [AT_DATA([[input.y]], | |
1723 | [[$1 | |
1724 | %% | |
1725 | exp: /* empty */; | |
1726 | ]]) | |
1727 | AT_BISON_CHECK([[$2 input.y]], [[1]], [[]], | |
1728 | [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together | |
1729 | ]]) | |
1730 | ]) | |
1731 | ||
1732 | AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18]) | |
1733 | AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2]) | |
1734 | AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2]) | |
1735 | AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18]) | |
1736 | ||
1737 | m4_popdef([AT_TEST]) | |
1738 | ||
1739 | AT_CLEANUP | |
1740 | ||
1741 | ||
1742 | ## -------------- ## | |
1743 | ## Stray $ or @. ## | |
1744 | ## -------------- ## | |
1745 | ||
1746 | AT_SETUP([[Stray $ or @]]) | |
1747 | ||
1748 | # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to | |
1749 | # check that the warnings are reported once, not three times. | |
1750 | ||
1751 | AT_DATA_GRAMMAR([[input.y]], | |
1752 | [[%type <TYPE> exp | |
1753 | %token <TYPE> TOK TOK2 | |
1754 | %destructor { $%; @%; } <*> exp TOK; | |
1755 | %initial-action { $%; @%; }; | |
1756 | %printer { $%; @%; } <*> exp TOK; | |
1757 | %{ $ @ %} // Should not warn. | |
1758 | %% | |
1759 | exp: TOK { $%; @%; $$ = $1; }; | |
1760 | %% | |
1761 | $ @ // Should not warn. | |
1762 | ]]) | |
1763 | ||
1764 | AT_BISON_CHECK([[-Wall input.y]], 0, [], | |
1765 | [[input.y:11.19: warning: stray '$' [-Wother] | |
1766 | input.y:11.23: warning: stray '@' [-Wother] | |
1767 | input.y:12.19: warning: stray '$' [-Wother] | |
1768 | input.y:12.23: warning: stray '@' [-Wother] | |
1769 | input.y:13.19: warning: stray '$' [-Wother] | |
1770 | input.y:13.23: warning: stray '@' [-Wother] | |
1771 | input.y:16.19: warning: stray '$' [-Wother] | |
1772 | input.y:16.23: warning: stray '@' [-Wother] | |
1773 | ]]) | |
1774 | ||
1775 | AT_CLEANUP | |
1776 | ||
1777 | ||
1778 | ||
1779 | ## ---------------- ## | |
1780 | ## Code injection. ## | |
1781 | ## ---------------- ## | |
1782 | ||
1783 | ||
1784 | AT_SETUP([[Code injection]]) | |
1785 | ||
1786 | m4_pattern_allow([^m4_errprintn$]) | |
1787 | ||
1788 | # AT_TEST([MACRO]) | |
1789 | # ---------------- | |
1790 | # Try to have MACRO be run by bison. | |
1791 | m4_pushdef([AT_TEST], | |
1792 | [AT_DATA([[input.y]], | |
1793 | [[%type <$1(DEAD %type)> exp | |
1794 | %token <$1(DEAD %token)> a | |
1795 | %token b | |
1796 | %initial-action | |
1797 | { | |
1798 | $$; | |
1799 | $<$1(DEAD %initial-action)>$ | |
1800 | }; | |
1801 | %printer | |
1802 | { | |
1803 | $$ | |
1804 | $<$1(DEAD %printer)>$ | |
1805 | } <> <*>; | |
1806 | %lex-param | |
1807 | { | |
1808 | $1(DEAD %lex-param) | |
1809 | }; | |
1810 | %parse-param | |
1811 | { | |
1812 | $1(DEAD %parse-param) | |
1813 | }; | |
1814 | %% | |
1815 | exp: | |
1816 | a a[name] b | |
1817 | { | |
1818 | $$; | |
1819 | $][1; | |
1820 | $<$1(DEAD action 1)>$ | |
1821 | $<$1(DEAD action 2)>1 | |
1822 | $<$1(DEAD action 3)>name | |
1823 | $<$1(DEAD action 4)>0 | |
1824 | ; | |
1825 | }; | |
1826 | ]]) | |
1827 | ||
1828 | # FIXME: Provide a means to iterate over all the skeletons. | |
1829 | AT_BISON_CHECK([[-d input.y]]) | |
1830 | AT_BISON_CHECK([[-d -S glr.c input.y]]) | |
1831 | AT_BISON_CHECK([[-d -S lalr1.cc input.y]]) | |
1832 | AT_BISON_CHECK([[-d -S glr.cc input.y]]) | |
1833 | AT_BISON_CHECK([[ -S lalr1.java input.y]]) | |
1834 | ]) | |
1835 | ||
1836 | AT_TEST([m4_errprintn]) | |
1837 | AT_TEST([@:>@m4_errprintn]) | |
1838 | ||
1839 | m4_popdef([AT_TEST]) | |
1840 | ||
1841 | AT_CLEANUP | |
1842 | ||
1843 | ##----------------------- ## | |
1844 | ## Deprecated directives. ## | |
1845 | ## ---------------------- ## | |
1846 | ||
1847 | AT_SETUP([[Deprecated directives]]) | |
1848 | ||
1849 | AT_KEYWORDS([[deprec]]) | |
1850 | ||
1851 | AT_DATA_GRAMMAR([[input.y]], | |
1852 | [[ | |
1853 | %default_prec | |
1854 | %error_verbose | |
1855 | %expect_rr 0 | |
1856 | %file-prefix = "foo" | |
1857 | %file-prefix | |
1858 | = | |
1859 | "bar" | |
1860 | %fixed-output_files | |
1861 | %fixed_output-files | |
1862 | %fixed-output-files | |
1863 | %name-prefix= "foo" | |
1864 | %no-default_prec | |
1865 | %no_default-prec | |
1866 | %no_lines | |
1867 | %output = "foo" | |
1868 | %pure_parser | |
1869 | %token_table | |
1870 | %glr-parser | |
1871 | %% exp : '0' | |
1872 | ]]) | |
1873 | ||
1874 | AT_BISON_CHECK([[input.y]], [[0]], [[]], | |
1875 | [[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated] | |
1876 | input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1877 | input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1878 | input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated] | |
1879 | input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated] | |
1880 | input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated] | |
1881 | input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated] | |
1882 | input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%name-prefix' [-Wdeprecated] | |
1883 | input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated] | |
1884 | input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated] | |
1885 | input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated] | |
1886 | input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated] | |
1887 | input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%pure-parser' [-Wdeprecated] | |
1888 | input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated] | |
1889 | ]]) | |
1890 | ||
1891 | AT_CLEANUP | |
1892 | ||
1893 | ## ---------------------------- ## | |
1894 | ## Unput's effect on locations. ## | |
1895 | ## ---------------------------- ## | |
1896 | dnl When the scanner detects a deprecated construct, it unputs the correct | |
1897 | dnl version, but it should *not* have any impact on the scanner cursor. If it | |
1898 | dnl does, the locations of directives on the same line become erroneous. | |
1899 | ||
1900 | AT_SETUP([[Unput's effect on locations]]) | |
1901 | ||
1902 | AT_KEYWORDS([[deprec]]) | |
1903 | ||
1904 | AT_DATA_GRAMMAR([[input.y]], | |
1905 | [[ | |
1906 | %glr-parser | |
1907 | %expect_rr 42 %expect_rr 42 | |
1908 | %expect_rr 42 | |
1909 | %error_verbose %error_verbose | |
1910 | %error_verbose | |
1911 | %% exp: '0' | |
1912 | ]]) | |
1913 | ||
1914 | AT_BISON_CHECK([[input.y]], [[1]], [[]], | |
1915 | [[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1916 | input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1917 | input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] | |
1918 | input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1919 | input.y:13.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1920 | input.y:13.11-21: error: %define variable 'parse.error' redefined | |
1921 | input.y:13-6: previous definition | |
1922 | input.y:14.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] | |
1923 | input.y:14.11-21: error: %define variable 'parse.error' redefined | |
1924 | input.y:13.11-21: previous definition | |
1925 | ]]) | |
1926 | ||
1927 | AT_CLEANUP | |
1928 | ||
1929 | ##--------------------------- ## | |
1930 | ## Non-deprecated directives. ## | |
1931 | ## -------------------------- ## | |
1932 | ||
1933 | AT_SETUP([[Non-deprecated directives]]) | |
1934 | ||
1935 | AT_KEYWORDS([[deprec]]) | |
1936 | ||
1937 | AT_DATA_GRAMMAR([[input.y]], | |
1938 | [[ | |
1939 | %default-prec | |
1940 | %error-verbose | |
1941 | %expect-rr 42 | |
1942 | %file-prefix "foo" | |
1943 | %file-prefix | |
1944 | "bar" | |
1945 | %fixed-output-files | |
1946 | %name-prefix "foo" | |
1947 | %no-default-prec | |
1948 | %no-lines | |
1949 | %output "foo" | |
1950 | %pure-parser | |
1951 | %token-table | |
1952 | %% exp : '0' | |
1953 | ]]) | |
1954 | ||
1955 | AT_BISON_CHECK([[input.y]], [[0]], [[]], | |
1956 | [[input.y: warning: %expect-rr applies only to GLR parsers [-Wother] | |
1957 | ]]) | |
1958 | ||
1959 | AT_CLEANUP |