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