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