]> git.saurik.com Git - bison.git/blame - tests/local.at
tests: add token declaration order test
[bison.git] / tests / local.at
CommitLineData
67a25fed
AD
1# Process this -*- Autotest -*- file with autom4te.
2
3# Macros for the GNU Bison Test suite.
7d424de1 4
7d6bad19 5# Copyright (C) 2003-2013 Free Software Foundation, Inc.
67a25fed 6
f16b0819 7# This program is free software: you can redistribute it and/or modify
67a25fed 8# it under the terms of the GNU General Public License as published by
f16b0819
PE
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
67a25fed
AD
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
f16b0819 16#
67a25fed 17# You should have received a copy of the GNU General Public License
f16b0819 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
67a25fed 19
ce05140d 20m4_version_prereq([2.58])
1f7a61ff 21
67a25fed 22
a122efad
AD
23# m4_null_if(VAL, IF-TRUE, IF-FALSE)
24# ----------------------------------
25# If VAL evaluates to empty or 0, run IF-TRUE, otherwise IF-FALSE.
26m4_define([m4_null_if],
27[m4_case(m4_quote($1),
28 [0], [$2],
29 [], [$2],
30 [$3])])
31
781eaf90
AD
32# AT_SETUP_STRIP(TITLE)
33# ---------------------
9b3bb258
AD
34# Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines
35# that completely break AT_SETUP.
781eaf90
AD
36m4_define([AT_SETUP_STRIP],
37[m4_bpatsubsts([$1],
38 [%\(language\|skeleton\) "?\([^\" ]*\)"?],
39 [\2],
9b3bb258
AD
40 [%define "?\([-A-Za-z0-9_.]+\)"? \("[^\"]+"\|[-A-Za-z0-9_.]+\)],
41 [\1=\2],
781eaf90 42 [%define "?\([-A-Za-z0-9_.]+\)"?],
9b3bb258
AD
43 [\1],
44 [ *
45+ *], [ ])dnl
781eaf90
AD
46])
47
48
6617622c
AD
49## ------------- ##
50## Basic tests. ##
51## ------------- ##
52
53# AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT)
54# ------------------------------------------
55# Expect COUNT matches of the PERL-REGEXP in FILE. The file is
56# taken in "slurp" mode, i.e., one can match end-of-lines.
57m4_define([AT_MATCHES_CHECK],
ff020c30 58[AT_CHECK([$PERL -0777 -ne '
6617622c
AD
59my $count = 0;
60s{$2}{ ++$count; "" }gem;
61printf "$count\n";' $1], [0], [$3
62])])
63
64
5192fd5d
AD
65# AT_SAVE_SPECIAL_FILES / AT_RESTORE_SPECIAL_FILES
66# ------------------------------------------------
67# Don't interfere with caller's files.
68m4_divert_text([PREPARE_TESTS],
69[at_save_special_files ()
70{
71 for at_save_file in stderr experr expout
72 do
1aa9fa82
AD
73 test ! -f at-bison-check-$at_save_file.bak ||
74 as_fn_error 1 "fatal error: back-up on top of a back-up"
5192fd5d
AD
75 test ! -f $at_save_file || mv $at_save_file at-bison-check-$at_save_file.bak
76 done
77}
78
79at_restore_special_files ()
80{
81 for at_save_file in stderr experr expout
82 do
83 test ! -f at-bison-check-$at_save_file.bak ||
84 mv at-bison-check-$at_save_file.bak $at_save_file
85 done
86}
87])
88
89m4_define([AT_SAVE_SPECIAL_FILES], [at_save_special_files])
90m4_define([AT_RESTORE_SPECIAL_FILES], [at_restore_special_files])
91
92
93
67a25fed
AD
94## ------------------------------- ##
95## Macros decoding Bison options. ##
96## ------------------------------- ##
97
4f756f88
AD
98# AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN)
99# ----------------------------------------------------------------
aedcb6c0 100# Pushdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN).
4f756f88 101m4_define([AT_LOC_PUSHDEF],
aedcb6c0
AD
102[m4_pushdef([AT_FIRST_LINE], [$1])
103m4_pushdef([AT_FIRST_COLUMN], [$2])
104m4_pushdef([AT_LAST_LINE], [$3])
105m4_pushdef([AT_LAST_COLUMN], [$4])
106m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.AT_FIRST_LINE])
107m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.AT_FIRST_COLUMN])
108m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.AT_LAST_LINE])
109m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.AT_LAST_COLUMN])])
4f756f88
AD
110
111# AT_LOC_POPDEF
112# -------------
aedcb6c0 113# Popdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN).
4f756f88
AD
114m4_define([AT_LOC_POPDEF],
115[m4_popdef([AT_LOC_FIRST_LINE])
116m4_popdef([AT_LOC_FIRST_COLUMN])
117m4_popdef([AT_LOC_LAST_LINE])
aedcb6c0
AD
118m4_popdef([AT_LOC_LAST_COLUMN])
119m4_popdef([AT_FIRST_LINE])
120m4_popdef([AT_FIRST_COLUMN])
121m4_popdef([AT_LAST_LINE])
122m4_popdef([AT_LAST_COLUMN])
123])
4f756f88
AD
124
125
67a25fed
AD
126
127# AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
128# -----------------------------------------
129m4_define([AT_BISON_OPTION_PUSHDEFS],
a32a2d57
AD
130[m4_divert_text([KILL],
131 [_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])])
67a25fed
AD
132
133
134# _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
135# --------------------------------------------------
136# This macro works around the impossibility to define macros
137# inside macros, because issuing `[$1]' is not possible in M4 :(.
417e31d2 138# This sucks hard, GNU M4 should really provide M5-like $$1.
67a25fed
AD
139m4_define([_AT_BISON_OPTION_PUSHDEFS],
140[m4_if([$1$2], $[1]$[2], [],
141 [m4_fatal([$0: Invalid arguments: $@])])dnl
6c88b51e
JD
142m4_pushdef([AT_DEFINES_IF],
143[m4_bmatch([$3], [%defines], [$1], [$2])])
3ef9fa8f
AD
144m4_pushdef([AT_DEBUG_IF],
145[m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])])
8f7e3cf9 146m4_pushdef([AT_SKEL_CC_IF],
0e021770 147[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
d2060f06
JD
148m4_pushdef([AT_SKEL_JAVA_IF],
149[m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
3472de82 150# The target language: "c", "c++", or "java".
2d40532b
AD
151m4_pushdef([AT_LANG],
152[AT_SKEL_JAVA_IF([java],
05a7b6ec 153 [AT_SKEL_CC_IF([c++],
2d40532b 154 [c])])])
67a25fed 155m4_pushdef([AT_GLR_IF],
5f7f1e21 156[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\..*"], [$1], [$2])])
0e021770
PE
157m4_pushdef([AT_LALR1_CC_IF],
158[AT_SKEL_CC_IF([AT_GLR_IF([$2], [$1])], [$2])])
159m4_pushdef([AT_GLR_CC_IF],
160[AT_SKEL_CC_IF([AT_GLR_IF([$1], [$2])], [$2])])
67a25fed
AD
161# Using yacc.c?
162m4_pushdef([AT_YACC_IF],
0e021770 163[m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
01b477c6
PB
164m4_pushdef([AT_LEXPARAM_IF],
165[m4_bmatch([$3], [%lex-param], [$1], [$2])])
67a25fed
AD
166m4_pushdef([AT_LOCATION_IF],
167[m4_bmatch([$3], [%locations], [$1], [$2])])
24bb8c8c 168m4_pushdef([AT_LOCATION_TYPE_IF],
db8ab2be 169[m4_bmatch([$3], [%define \(api\.location\.type\|location_type\)], [$1], [$2])])
24bb8c8c
AD
170m4_pushdef([AT_PARAM_IF],
171[m4_bmatch([$3], [%parse-param], [$1], [$2])])
3472de82 172# Comma-terminated list of formals parse-parameters.
e42906f7
AD
173# E.g., %parse-param { int x } %parse-param {int y} -> "int x, int y, ".
174# FIXME: Support grouped parse-param.
3472de82
AD
175m4_pushdef([AT_PARSE_PARAMS])
176m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}],
177 [m4_append([AT_PARSE_PARAMS], [\1, ])])
178
67a25fed 179m4_pushdef([AT_PURE_IF],
d9df47b6 180[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
cf499cff 181 [m4_bmatch([$3], [%define *api\.pure *"?false"?], [$2], [$1])],
d9df47b6 182 [$2])])
56b91ae0 183# AT_NAME_PREFIX: also consider api.namespace.
aa08666d 184m4_pushdef([AT_NAME_PREFIX],
56b91ae0
AD
185[m4_bmatch([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) ".*"],
186 [m4_bregexp([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) "\([^""]*\)"], [\3])],
5cf61e93 187 [yy])])
e36ec1f4
AD
188m4_pushdef([AT_TOKEN_CTOR_IF],
189[m4_bmatch([$3], [%define api.token.constructor], [$1], [$2])])
417e31d2 190m4_pushdef([AT_TOKEN_PREFIX],
2a6b66c5
AD
191[m4_bmatch([$3], [%define api.token.prefix ".*"],
192 [m4_bregexp([$3], [%define api.token.prefix "\(.*\)"], [\1])])])
837b7696
AD
193m4_pushdef([AT_API_prefix],
194[m4_bmatch([$3], [%define api\.prefix ".*"],
195 [m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])],
196 [yy])])
4b3847c3
AD
197m4_pushdef([AT_API_PREFIX],
198[m4_toupper(AT_API_prefix)])
dbb99836
TR
199# yyerror receives the location if %location, and if the parser is pure. For
200# historical reasons, with the "yacc.c" skeleton, the location is not passed
201# unless an additional "%parse-param" is present, or if the purity is defined
202# as "full".
67a25fed 203m4_pushdef([AT_YYERROR_ARG_LOC_IF],
dbb99836
TR
204[AT_LOCATION_IF([AT_PURE_IF([m4_bmatch([$3],
205 m4_quote(m4_join([\|],
6428a8a4 206 [%define api.pure "?full"?],
dbb99836
TR
207 [%glr-parser],
208 [%parse-param],
209 [%skeleton "?glr.c"?])),
210 [$1], [$2])],
211 [$2])],
e9690142 212 [$2])])
dbb99836
TR
213
214# yyerror always sees the locations (when activated) if the parser is impure.
215# When the parser is pure, yyerror sees the location if it is received as an
216# argument.
67a25fed 217m4_pushdef([AT_YYERROR_SEES_LOC_IF],
dbb99836 218[AT_LOCATION_IF([AT_YACC_IF([AT_PURE_IF([AT_YYERROR_ARG_LOC_IF([$1], [$2])],
e9690142
JD
219 [$1])],
220 [$1])],
221 [$2])])
67a25fed 222
d9df47b6 223# The interface is pure: either because %define api.pure, or because we
67a25fed
AD
224# are using the C++ parsers.
225m4_pushdef([AT_PURE_LEX_IF],
94ebeba5 226[AT_PURE_IF([$1],
e9690142 227 [AT_SKEL_CC_IF([$1], [$2])])])
67a25fed 228
0e16927b
AD
229m4_pushdef([AT_YYSTYPE],
230[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::semantic_type]],
4b3847c3 231 [AT_API_PREFIX[STYPE]])])
0e16927b
AD
232m4_pushdef([AT_YYLTYPE],
233[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::location_type]],
4b3847c3 234 [AT_API_PREFIX[LTYPE]])])
0e16927b
AD
235
236
67a25fed 237AT_PURE_LEX_IF(
ebc3737e
PE
238[m4_pushdef([AT_LOC], [(*llocp)])
239 m4_pushdef([AT_VAL], [(*lvalp)])
230a3db4 240 m4_pushdef([AT_YYLEX_FORMALS],
297e263a 241 [AT_YYSTYPE *lvalp[]AT_LOCATION_IF([, AT_YYLTYPE *llocp])])
230a3db4 242 m4_pushdef([AT_YYLEX_ARGS],
e9690142 243 [lvalp[]AT_LOCATION_IF([, llocp])])
67a25fed 244 m4_pushdef([AT_USE_LEX_ARGS],
e9690142 245 [(void) lvalp;AT_LOCATION_IF([(void) llocp])])
230a3db4 246 m4_pushdef([AT_YYLEX_PRE_FORMALS],
297e263a 247 [AT_YYLEX_FORMALS, ])
230a3db4 248 m4_pushdef([AT_YYLEX_PRE_ARGS],
297e263a 249 [AT_YYLEX_ARGS, ])
67a25fed 250],
6c88b51e
JD
251[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
252 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
230a3db4
AD
253 m4_pushdef([AT_YYLEX_FORMALS], [void])
254 m4_pushdef([AT_YYLEX_ARGS], [])
67a25fed 255 m4_pushdef([AT_USE_LEX_ARGS], [])
230a3db4
AD
256 m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
257 m4_pushdef([AT_YYLEX_PRE_ARGS], [])
67a25fed 258])
4f756f88
AD
259
260# Handle the different types of location components.
261
262AT_SKEL_CC_IF(
263 [AT_LOCATION_TYPE_IF(
49976d5c 264 [AT_LOC_PUSHDEF([first.l], [first.c], [last.l], [last.c])],
4f756f88
AD
265 [AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])])],
266 [AT_LOC_PUSHDEF([first_line], [first_column], [last_line], [last_column])])
267
268
6130b755 269AT_GLR_IF([AT_KEYWORDS([glr])])
67a25fed
AD
270])# _AT_BISON_OPTION_PUSHDEFS
271
272
273# AT_BISON_OPTION_POPDEFS
274# -----------------------
275m4_define([AT_BISON_OPTION_POPDEFS],
a32a2d57 276[m4_divert_text([KILL],
230a3db4
AD
277[m4_popdef([AT_YYLEX_PRE_ARGS])
278m4_popdef([AT_YYLEX_PRE_FORMALS])
67a25fed 279m4_popdef([AT_USE_LEX_ARGS])
230a3db4
AD
280m4_popdef([AT_YYLEX_ARGS])
281m4_popdef([AT_YYLEX_FORMALS])
0e16927b
AD
282m4_popdef([AT_YYLTYPE])
283m4_popdef([AT_YYSTYPE])
67a25fed
AD
284m4_popdef([AT_VAL])
285m4_popdef([AT_LOC])
286m4_popdef([AT_PURE_LEX_IF])
287m4_popdef([AT_YYERROR_SEES_LOC_IF])
288m4_popdef([AT_YYERROR_ARG_LOC_IF])
4b3847c3 289m4_popdef([AT_API_PREFIX])
837b7696 290m4_popdef([AT_API_prefix])
e36ec1f4
AD
291m4_popdef([AT_TOKEN_PREFIX])
292m4_popdef([AT_TOKEN_CTOR_IF])
aa08666d 293m4_popdef([AT_NAME_PREFIX])
24bb8c8c 294m4_popdef([AT_LOCATION_TYPE_IF])
67a25fed 295m4_popdef([AT_LOCATION_IF])
3472de82 296m4_popdef([AT_PARSE_PARAMS])
67a25fed 297m4_popdef([AT_PARAM_IF])
01b477c6 298m4_popdef([AT_LEXPARAM_IF])
67a25fed
AD
299m4_popdef([AT_YACC_IF])
300m4_popdef([AT_GLR_IF])
8f7e3cf9 301m4_popdef([AT_SKEL_CC_IF])
2d40532b 302m4_popdef([AT_LANG])
d2060f06 303m4_popdef([AT_SKEL_JAVA_IF])
8f7e3cf9 304m4_popdef([AT_GLR_CC_IF])
67a25fed 305m4_popdef([AT_LALR1_CC_IF])
6c88b51e 306m4_popdef([AT_DEFINES_IF])
3ef9fa8f 307m4_popdef([AT_DEBUG_IF])
a32a2d57 308AT_LOC_POPDEF])dnl
67a25fed
AD
309])# AT_BISON_OPTION_POPDEFS
310
311
312
313## -------------------------- ##
314## Generating Grammar Files. ##
315## -------------------------- ##
316
6c88b51e 317# AT_DATA_SOURCE_PROLOGUE
67a25fed 318# ------------------------
6c88b51e 319# The prologue that should be included in any source code that is
67a25fed 320# meant to be compiled.
6c88b51e
JD
321m4_define([AT_DATA_SOURCE_PROLOGUE],
322[[#include <config.h>
231ed89a
PE
323/* We don't need perfect functions for these tests. */
324#undef malloc
325#undef memcmp
326#undef realloc
6c88b51e
JD
327]])
328
329# AT_DATA_GRAMMAR_PROLOGUE
330# ------------------------
331# The prologue that should be included in any grammar which parser is
332# meant to be compiled.
333m4_define([AT_DATA_GRAMMAR_PROLOGUE],
334[[%code top {
335]AT_DATA_SOURCE_PROLOGUE[]dnl
336[}
337]])
67a25fed 338
6c88b51e
JD
339# AT_DATA_SOURCE(NAME, CONTENT)
340# -----------------------------
341# Generate the file NAME, which CONTENT is preceded by
342# AT_DATA_SOURCE_PROLOGUE.
343m4_define([AT_DATA_SOURCE],
344[AT_DATA([$1],
345[AT_DATA_SOURCE_PROLOGUE
346$2])
347])
67a25fed
AD
348
349# AT_DATA_GRAMMAR(NAME, CONTENT)
350# ------------------------------
351# Generate the file NAME, which CONTENT is preceded by
352# AT_DATA_GRAMMAR_PROLOGUE.
353m4_define([AT_DATA_GRAMMAR],
354[AT_DATA([$1],
355[AT_DATA_GRAMMAR_PROLOGUE
356$2])
357])
358
230a3db4 359# AT_YYLEX_PROTOTYPE
55f48c48
AD
360# AT_YYLEX_DECLARE_EXTERN
361# AT_YYLEX_DECLARE
95361618
AD
362# AT_YYLEX_DEFINE([INPUT], [ACTION])
363# ----------------------------------
364# INPUT can be empty, or in double quotes, or a list (in braces).
365# ACTION may compute yylval for instance, using "res" as token type,
366# and "toknum" as the number of calls to yylex (starting at 0).
230a3db4 367m4_define([AT_YYLEX_PROTOTYPE],
837b7696 368[int AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
230a3db4
AD
369])
370
55f48c48 371m4_define([AT_YYLEX_DECLARE_EXTERN],
230a3db4 372[AT_YYLEX_PROTOTYPE;dnl
55f48c48
AD
373])
374
375m4_define([AT_YYLEX_DECLARE],
376[static AT_YYLEX_DECLARE_EXTERN[]dnl
377])
378
379m4_define([AT_YYLEX_DEFINE],
77519a7d 380[[#include <assert.h>
230a3db4
AD
381static
382]AT_YYLEX_PROTOTYPE[
55f48c48 383{
95361618
AD
384 ]m4_bmatch([$1], [^\(".*"\)?$],
385 [[static char const input[] = ]m4_default([$1], [""])],
386 [[static int const input[] = ]$1])[;
55f48c48
AD
387 static size_t toknum = 0;
388 int res;
0e16927b 389 ]AT_USE_LEX_ARGS[;
55e075f2 390 assert (toknum < sizeof input / sizeof input[0]);
55f48c48 391 res = input[toknum++];
0e16927b
AD
392 ]$2[;]AT_LOCATION_IF([[
393 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
394 ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
55f48c48
AD
395 return res;
396}]dnl
397])
398
6428a8a4 399# AT_YYERROR_FORMALS
6d559547 400# AT_YYERROR_PROTOTYPE
55f48c48
AD
401# AT_YYERROR_DECLARE_EXTERN
402# AT_YYERROR_DECLARE
403# AT_YYERROR_DEFINE
404# -------------------------
6d559547 405# Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
230a3db4
AD
406m4_define([AT_YYERROR_FORMALS],
407[m4_case(AT_LANG,
dbb99836 408[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE const * const llocp, ])AT_PARSE_PARAMS [const char *msg]])[]dnl
230a3db4
AD
409])
410
6d559547
AD
411m4_define([AT_YYERROR_PROTOTYPE],
412[m4_case(AT_LANG,
837b7696 413[c], [[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])[]dnl
6d559547
AD
414])
415
55f48c48 416m4_define([AT_YYERROR_DECLARE_EXTERN],
05a7b6ec 417[m4_case(AT_LANG,
6d559547 418[c], [AT_YYERROR_PROTOTYPE;])[]dnl
55f48c48
AD
419])
420
421m4_define([AT_YYERROR_DECLARE],
05a7b6ec 422[m4_case(AT_LANG,
f0f95a50
AD
423[c], [#include <stdio.h>
424]AT_LOCATION_IF([[
425#if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
426static unsigned location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
427# ifndef LOCATION_PRINT
428# define LOCATION_PRINT(File, Loc) location_print (File, &(Loc))
429# endif
430#endif
431]])[
432static AT_YYERROR_DECLARE_EXTERN])[]dnl
55f48c48
AD
433])
434
435m4_define([AT_YYERROR_DEFINE],
05a7b6ec 436[m4_case(AT_LANG,
f0f95a50
AD
437[c], [[
438]AT_LOCATION_IF([[
439# if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
440/* Print *YYLOCP on YYO. */
441__attribute__((__unused__))
442static unsigned
443location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp)
444{
445 unsigned res = 0;
446 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
447 if (0 <= yylocp->first_line)
448 {
449 res += fprintf (yyo, "%d", yylocp->first_line);
450 if (0 <= yylocp->first_column)
451 res += fprintf (yyo, ".%d", yylocp->first_column);
452 }
453 if (0 <= yylocp->last_line)
454 {
455 if (yylocp->first_line < yylocp->last_line)
456 {
457 res += fprintf (yyo, "-%d", yylocp->last_line);
458 if (0 <= end_col)
459 res += fprintf (yyo, ".%d", end_col);
460 }
461 else if (0 <= end_col && yylocp->first_column < end_col)
462 res += fprintf (yyo, "-%d", end_col);
463 }
464 return res;
465}
466#endif
467]])[
74909941 468/* A C error reporting function. */
6d559547
AD
469static
470]AT_YYERROR_PROTOTYPE[
3472de82
AD
471{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
472 [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
473 YYUSE(\1);])dnl
474AT_YYERROR_SEES_LOC_IF([[
f0f95a50 475 LOCATION_PRINT (stderr, ]AT_LOC[);
74909941 476 fprintf (stderr, ": ");]])[
55f48c48 477 fprintf (stderr, "%s\n", msg);
05a7b6ec 478}]],
74909941
AD
479[c++], [[/* A C++ error reporting function. */
480void
6cf3716c 481]AT_NAME_PREFIX[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
3ef9fa8f
AD
482{
483 std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl;
05a7b6ec 484}]],
6d559547 485[java], [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String s)
6cf3716c 486{
6d559547
AD
487 if (l == null)
488 System.err.println (s);
489 else
490 System.err.println (l + ": " + s);
491 }
492]], [[
493 public void yyerror (String s)
494 {
495 System.err.println (s);
535ee0cb
AD
496 }]])],
497[m4_fatal([$0: invalid language: ]AT_LANG)])dnl
55f48c48
AD
498])
499
55f48c48 500
3ef9fa8f
AD
501# AT_MAIN_DEFINE
502# --------------
503m4_define([AT_MAIN_DEFINE],
504[m4_case(AT_LANG,
505[c],
506[[#include <stdlib.h> /* getenv. */
f42c012f 507#include <string.h> /* strcmp. */
3ef9fa8f 508int
f42c012f
AD
509main (int argc, char const* argv[])
510{]AT_DEBUG_IF([[
511 if (getenv("YYDEBUG")
512 || (argc == 2
513 && (!strcmp (argv[1], "-d") || !strcmp (argv[1], "--debug"))))
514 yydebug |= 1;]], [[
515 (void) argc;
516 (void) argv;]])[
56b91ae0 517 return ]AT_NAME_PREFIX[parse ();
3ef9fa8f
AD
518}]],
519[c++],
520[[#include <cstdlib> // getenv.
f42c012f 521#include <cstring> // strcmp.
3ef9fa8f 522int
f42c012f 523main (int argc, char const* argv[])
3ef9fa8f 524{
56b91ae0 525 ]AT_NAME_PREFIX[::parser p;]AT_DEBUG_IF([[
f42c012f
AD
526 if (getenv("YYDEBUG")
527 || (argc == 2
528 && (!strcmp (argv[1], "-d") || !strcmp (argv[1], "--debug"))))
529 p.set_debug_level (true);]], [[
530 (void) argc;
531 (void) argv;]])[
532 return p.parse ();
3ef9fa8f
AD
533}]],
534[java],
535[[class input
536{
537 public static void main (String args[]) throws IOException
538 {
539 YYParser p = new YYParser ();
540 p.parse ();
541 }
542}]])])
543
544
55f48c48
AD
545## --------------- ##
546## Running Bison. ##
547## --------------- ##
548
da730230
JD
549# AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
550# -------------------------------------------------
a122efad
AD
551# High-level routine that may call bison several times, under different
552# conditions.
553#
c39014ae
JD
554# Check Bison by invoking `bison BISON_ARGS'. BISON_ARGS should not contain
555# shell constructs (such as redirection or pipes) that would prevent
556# appending additional command-line arguments for bison. OTHER_AT_CHECK_ARGS
557# are the usual remaining arguments to AT_CHECK: STATUS, STDOUT, etc.
da730230
JD
558#
559# This macro or AT_BISON_CHECK_NO_XML should always be used whenever invoking
560# Bison in the test suite. For now it ensures that:
561#
562# 1. Valgrind doesn't report reachable memory when Bison is expected to have
563# a non-zero exit status since Bison doesn't always try to free all memory
564# in that case.
565#
566# 2. In the case of maintainer-xml-check, XML/XSLT output is compared with
567# --graph and --report=all output for every working grammar.
2bfcac9a
JD
568#
569# 3. If stderr contains a warning, -Werror and --warnings=error
570# convert the warning to an error.
c39014ae
JD
571#
572# 4. If stderr contains a warning, -Wnone and --warnings=none suppress it.
da730230 573m4_define([AT_BISON_CHECK],
a122efad 574[m4_null_if([$2], [AT_BISON_CHECK_XML($@)])
da730230
JD
575AT_BISON_CHECK_NO_XML($@)])
576
a122efad
AD
577# AT_BISON_CHECK_(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
578# --------------------------------------------------
579# Low-level macro to run bison once.
580m4_define([AT_BISON_CHECK_],
9c4788b7 581[AT_CHECK(AT_QUELL_VALGRIND[[ bison -fno-caret ]]$@)])
a122efad
AD
582
583
e4828e23
AD
584# AT_BISON_CHECK_WARNINGS(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
585# ----------------------------------------------------------
586# Check that warnings (if some are expected) are correctly
587# turned into errors with -Werror, etc.
588m4_define([AT_BISON_CHECK_WARNINGS],
589[m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
590 [m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
591
592m4_define([AT_BISON_CHECK_WARNINGS_],
94843f0a
AD
593[[# Defining POSIXLY_CORRECT causes bison to complain if options are
594# added after the grammar file name, so skip these checks in that
595# case.
0a36880a 596if test "$POSIXLY_CORRECT_IS_EXPORTED" = false; then
5192fd5d 597 ]AT_SAVE_SPECIAL_FILES[
e4a14879 598
8f6bbe0c
TR
599 # To avoid expanding it repeatedly, store specified stdout.
600 ]AT_DATA([expout], [$3])[
e4a14879 601
8f6bbe0c 602 # Run with -Werror.
e4828e23 603 ]AT_BISON_CHECK_([$1[ -Werror]], [[1]], [expout], [stderr])[
e4a14879 604
8f6bbe0c
TR
605 # Build expected stderr up to and including the "warnings being
606 # treated as errors" message.
e89d8806
TR
607 ]AT_DATA([[experr]], [$4])[
608 $PERL -pi -e 's{(.*): warning: (.*)\[-W(.*)\]$}
609 {$][1: error: $][2\@<:@-Werror=$][3@:>@}' experr
610 ]AT_CHECK([[sed 's,.*/$,,' stderr 1>&2]], [[0]], [[]], [experr])[
8f6bbe0c
TR
611
612 # Now check --warnings=error.
613 cp stderr experr
e4828e23 614 ]AT_BISON_CHECK_([$1[ --warnings=error]], [[1]], [expout], [experr])[
e4a14879 615
8f6bbe0c
TR
616 # Now check -Wnone and --warnings=none by making sure that
617 # -Werror doesn't change the exit status when -Wnone or
618 # --warnings=none is specified.
e4828e23
AD
619 ]AT_BISON_CHECK_([$1[ -Wnone -Werror]], [[0]], [expout])[
620 ]AT_BISON_CHECK_([$1[ --warnings=none -Werror]], [[0]], [expout])[
e4a14879 621
8f6bbe0c 622 ]AT_RESTORE_SPECIAL_FILES[
e4828e23 623fi]dnl
2bfcac9a 624])
da730230 625
da730230
JD
626# AT_BISON_CHECK_NO_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
627# --------------------------------------------------------
628# Same as AT_BISON_CHECK except don't perform XML/XSLT checks. This is useful
629# when a tortured grammar's XML is known to be too large for xsltproc to
630# handle.
631m4_define([AT_BISON_CHECK_NO_XML],
9c4788b7 632[AT_CHECK(m4_null_if([$2], [], [AT_QUELL_VALGRIND ])[[bison -fno-caret ]]$@)
e4828e23 633AT_BISON_CHECK_WARNINGS($@)])
da730230
JD
634
635# AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
636# -----------------------------------------------------
637# Run AT_BISON_CHECK's XML/XSLT checks if $BISON_TEST_XML=1 and $XSLTPROC is
638# defined. It doesn't make sense to invoke this macro if Bison is expected to
639# have a non-zero exit status.
640m4_define([AT_BISON_CHECK_XML],
035810ed
AD
641[[if test x"$BISON_TEST_XML" = x1 && test x"$XSLTPROC" != x""; then]
642 AT_SAVE_SPECIAL_FILES
643 [mkdir xml-tests]
da730230
JD
644 m4_pushdef([AT_BISON_ARGS],
645 [m4_bpatsubsts([[$1]],
646 [--report(-file)?=[^][ ]*], [],
647 [--graph=[^][ ]*], [],
648 [--xml=[^][ ]*], [])])dnl
649 # Don't combine these Bison invocations since we want to be sure that
650 # --report=all isn't required to get the full XML file.
a122efad 651 AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \
da730230
JD
652 --graph=xml-tests/test.dot ]]AT_BISON_ARGS,
653 [[0]], [ignore], [ignore])
a122efad 654 AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
da730230
JD
655 [[0]], [ignore], [ignore])
656 m4_popdef([AT_BISON_ARGS])dnl
247b8c21 657 [cp xml-tests/test.output expout]
da730230
JD
658 AT_CHECK([[$XSLTPROC \
659 `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2text.xsl \
660 xml-tests/test.xml]], [[0]], [expout])
be3517b0 661 [sort xml-tests/test.dot > expout]
da730230
JD
662 AT_CHECK([[$XSLTPROC \
663 `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2dot.xsl \
be3517b0 664 xml-tests/test.xml | sort]], [[0]], [expout])
035810ed
AD
665 [rm -rf xml-tests expout]
666 AT_RESTORE_SPECIAL_FILES
667[fi]])
da730230
JD
668
669# AT_QUELL_VALGRIND
670# -----------------
671# Put this before a Bison invocation to keep Valgrind from complaining about
672# reachable memory.
673#
674# Do not quote invocations of this macro within the first argument of AT_CHECK.
675# The triple quoting below will cause test cases to fail if you do. If you do
676# so anyway but also decrease the quoting below to avoid that problem, AT_CHECK
677# will then fail to shell-escape its contents when attempting to print them.
678# The testsuite verbose output, at least, will be incorrect, but nothing may
679# fail to make sure you notice.
680m4_define([AT_QUELL_VALGRIND],
681[[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS;]]])
67a25fed 682
e4828e23
AD
683
684
67a25fed
AD
685## ------------------------ ##
686## Compiling C, C++ Files. ##
687## ------------------------ ##
688
689
690# AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c])
691# ----------------------------------------
91ce0b3a
AD
692# Compile SOURCES into OUTPUT.
693#
694# If OUTPUT does not contain '.', assume that we are linking too,
695# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
696# with trailing .o removed, and ".c" appended.
67a25fed 697m4_define([AT_COMPILE],
d4728d92 698[AT_CHECK([$BISON_C_WORKS], 0, ignore, ignore)
0a36880a 699AT_CHECK(m4_join([ ],
91ce0b3a
AD
700 [$CC $CFLAGS $CPPFLAGS],
701 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
702 [-o $1],
703 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).c])],
704 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
e9690142 705 0, [ignore], [ignore])])
67a25fed 706
07971983 707# AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc])
91ce0b3a
AD
708# ---------------------------------------------
709# Compile SOURCES into OUTPUT. If the C++ compiler does not work,
710# ignore the test.
711#
712# If OUTPUT does not contain '.', assume that we are linking too,
713# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
714# with trailing .o removed, and ".cc" appended.
67a25fed
AD
715m4_define([AT_COMPILE_CXX],
716[AT_KEYWORDS(c++)
209ea708 717AT_CHECK([$BISON_CXX_WORKS], 0, ignore, ignore)
91ce0b3a
AD
718AT_CHECK(m4_join([ ],
719 [$CXX $CXXFLAGS $CPPFLAGS],
720 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
721 [-o $1],
722 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).cc])],
723 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
e9690142 724 0, [ignore], [ignore])])
67a25fed 725
d2060f06
JD
726# AT_JAVA_COMPILE(SOURCES)
727# ------------------------
728# Compile SOURCES into Java class files. Skip the test if java or javac
729# is not installed.
730m4_define([AT_JAVA_COMPILE],
731[AT_KEYWORDS(java)
916f26b6
AD
732AT_SKIP_IF([[test -z "$CONF_JAVAC"]])
733AT_SKIP_IF([[test -z "$CONF_JAVA"]])
d2060f06
JD
734AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
735 [[0]], [ignore], [ignore])])
67a25fed 736
2d40532b
AD
737# AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c]
738# --------------------------------------------
91ce0b3a
AD
739# Compile SOURCES into OUTPUT. Skip if compiler does not work.
740#
741# If OUTPUT does not contain '.', assume that we are linking too,
742# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
743# with trailing .o removed, and ".c"/".cc" appended.
2d40532b
AD
744m4_define([AT_LANG_COMPILE],
745[m4_case(AT_LANG,
746[c], [AT_COMPILE([$1], [$2])],
05a7b6ec 747[c++], [AT_COMPILE_CXX([$1], [$2])],
2d40532b
AD
748[java], [AT_JAVA_COMPILE([$1.java], [$2])],
749 [m4_fatal([unknown language: ]m4_defn([AT_LANG]))])[]dnl
750])
751
6aef2e01
AD
752# AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2])
753# -------------------------------------------
d2060f06
JD
754# Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then
755# compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile
756# OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
757# OUTPUT.java along with it. Relies on AT_SKEL_CC_IF and
758# AT_SKEL_JAVA_IF.
2d40532b
AD
759m4_define([AT_FULL_COMPILE],
760[m4_case(AT_LANG,
761[java],
762 [AT_BISON_CHECK([-o $1.java $1.y])
763 AT_LANG_COMPILE([$1],
6aef2e01
AD
764 m4_join([ ],
765 [$1.java],
766 m4_ifval($2, [[$1-$2.java]]),
2d40532b 767 m4_ifval($3, [[$1-$3.java]])))],
05a7b6ec 768[c++],
2d40532b
AD
769 [AT_BISON_CHECK([-o $1.cc $1.y])
770 AT_LANG_COMPILE([$1],
6aef2e01
AD
771 m4_join([ ],
772 [$1.cc],
773 m4_ifval($2, [[$1-$2.cc]]),
2d40532b
AD
774 m4_ifval($3, [[$1-$3.cc]])))],
775[c],
776 [AT_BISON_CHECK([-o $1.c $1.y])
777 AT_LANG_COMPILE([$1],
6aef2e01 778 m4_join([ ],
e436fa67 779 [$1.c],
6aef2e01 780 m4_ifval($2, [[$1-$2.c]]),
2d40532b 781 m4_ifval($3, [[$1-$3.c]])))])
7ca2266a
AD
782])
783
67a25fed 784
8aaa0c2f
AD
785
786# AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
787# --------------------------------
788# Check that we can link together C and C++ objects.
789m4_define([AT_SKIP_IF_CANNOT_LINK_C_AND_CXX],
790[AT_DATA([c-and-cxx.h],
791[[#ifdef __cplusplus
792extern "C"
793{
794#endif
795 int fortytwo (void);
796#ifdef __cplusplus
797}
798#endif
799]])
800AT_DATA([c-only.c],
801[[#include "c-and-cxx.h"
802int
803main (void)
804{
805 return fortytwo () == 42 ? 0 : 1;
806}
807]])
808AT_DATA([cxx-only.cc],
809[[#include "c-and-cxx.h"
810int fortytwo ()
811{
812 return 42;
813}
814]])
815AT_COMPILE([c-only.o], [c-only.c])
816AT_COMPILE_CXX([cxx-only.o], [cxx-only.cc])
817AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS $LDFLAGS c-only.o cxx-only.o -o c-and-cxx ||
818 exit 77], [ignore], [ignore])
2bb8f621 819AT_PARSER_CHECK([./c-and-cxx])
8aaa0c2f
AD
820])
821
822
67a25fed
AD
823## ---------------------------- ##
824## Running a generated parser. ##
825## ---------------------------- ##
826
95e343fe 827
e0ac9b4b
JD
828# AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
829# ------------------------------------------------------------
67a25fed 830# So that we can run `./testsuite PREPARSER='valgrind -q' for instance.
95e343fe
AD
831#
832# Get rid of spurious messages when compiled with --coverage:
833# +profiling:/[...]/lib/fprintf.gcda:Merge mismatch for summaries
67a25fed 834m4_define([AT_PARSER_CHECK],
95e343fe
AD
835[AT_CHECK([$5 $PREPARSER $1], [$2], [$3], [stderr])
836AT_CHECK([sed >&2 -e '/^profiling:.*:Merge mismatch for summaries/d' stderr],
837 [0], [], [$4])
838])
839
1f7a61ff 840
d2060f06
JD
841# AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
842# -----------------------------------------------------------------
843m4_define([AT_JAVA_PARSER_CHECK],
844[AT_CHECK([$5[ $SHELL ../../../javaexec.sh ]$1], [$2], [$3], [$4])])
845
95e343fe 846
7254f6a8
JD
847# AT_TEST_TABLES_AND_PARSE(TITLE, COND-VALUE, TEST-SPEC,
848# DECLS, GRAMMAR, INPUT,
849# BISON-STDERR, TABLES-OR-LAST-STATE,
850# [OTHER-CHECKS],
851# [PARSER-EXIT-VALUE],
852# [PARSER-STDOUT], [PARSER-STDERR])
853# -------------------------------------------------------------
854# Using TITLE as the test group title, check the generated parser tables
855# and parser for a specified grammar file under a condition labeled by
856# COND-VALUE.
857#
858# TEST-SPEC is a comma-delimited list of attributes of this test. Each
859# recognized attribute is described below where it is relevant.
860#
861# Insert DECLS and GRAMMAR into the declarations and grammar section of
862# the grammar file. Insert basic yyerror, yylex, and main function
863# definitions as well. Hardcode yylex to return the (possibly empty)
864# comma-delimited series of tokens in INPUT followed by token 0.
865#
866# If TEST-SPEC contains the attribute no-xml, then invoke bison using
867# AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK.
868# On the bison command-line, specify `--report=all --defines'. Check
869# that Bison exits with value 0, has no stdout, and has stderr
870# BISON-STDERR.
871#
872# If TEST-SPEC contains the attribute `last-state', check that the value
873# of TABLES-OR-LAST-STATE is the index of the last state generated for
874# the grammar; in other words, check the number of states (minus one).
875# Otherwise, check that everything in the `.output' file starting with
876# the definition of state 0 is the same as the entire value of
877# TABLES-OR-LAST-STATE.
878#
879# Expand the M4 in OTHER-CHECKS to perform additional checks of the
880# `.output' file, which is named `input.output', and/or grammar file,
881# which is named `input.y'.
882#
883# Finally, compile the generated parser and then run it using
884# AT_PARSER_CHECK with PARSER-EXIT-VALUE, PARSER-STDOUT, and
885# PARSER-STDERR as the 2nd-4th arguments.
886#
887# As a precondition, you must properly double-quote all arguments that
888# are to be interpreted as strings.
889#
890# AT_COND_CASE (when appearing in single-quoted segments of arguments)
891# invokes m4_case with its own arguments but COND-VALUE inserted as the
892# first argument. This is useful, for example, when wrapping multiple
893# AT_TEST_TABLES_AND_PARSE invocations, each representing a different
894# condition, in another macro.
895#
896# For example:
897#
898# # AT_TEST_SYNTAX_ERROR(DESCRIPTION, DECLS, GRAMMAR, INPUT, LAST-STATE,
899# # PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR)
900# # ---------------------------------------------------------------------
901# m4_define([AT_TEST_SYNTAX_ERROR],
902# [
903# AT_TEST_TABLES_AND_PARSE([$1[ with %error-verbose]], [[verbose]],
904# [[last-state]],
905# [[%error-verbose ]$2], [$3], [$4],
906# [[]], [$5], [], [$6], [$7], [$8])
907# AT_TEST_TABLES_AND_PARSE([$1[ with no %error-verbose]], [[no verbose]],
908# [[last-state]],
909# [$2], [$3], [$4],
910# [[]], [$5], [], [$6], [$7], [$8])
911# ])
912#
913# AT_TEST_SYNTAX_ERROR([[Single Char Grammar]],
914# [[%token 'b']], [[start: 'a' ;]], [['a', 'b']],
915# [[3]],
916# [[1]], [[]],
917# [AT_COND_CASE([[no verbose]],
918# [[syntax error
919# ]],
920# [[syntax error, unexpected 'b', expecting $end
921# ]])])
922m4_define([AT_TEST_TABLES_AND_PARSE],
c4be5517 923[m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
7254f6a8 924
c4be5517 925AT_SETUP([$1])
55f48c48 926AT_BISON_OPTION_PUSHDEFS([$4])
7254f6a8
JD
927AT_DATA_GRAMMAR([[input.y]],
928[[%code {
55f48c48
AD
929 ]AT_YYERROR_DECLARE[
930 ]AT_YYLEX_DECLARE[
7254f6a8
JD
931}
932
c4be5517 933]$4[
7254f6a8
JD
934
935%%
936
c4be5517 937]$5[
7254f6a8
JD
938
939%%
55f48c48 940]AT_YYERROR_DEFINE[
7254f6a8
JD
941static int
942yylex (void)
943{
944 static int const input[] = {
c4be5517 945 ]m4_if([$6], [], [], [$6], [[]], [], [$6[, ]])[0
7254f6a8
JD
946 };
947 static int const *inputp = input;
948 return *inputp++;
949}
950
f0f95a50 951]AT_MAIN_DEFINE[
7254f6a8
JD
952]])
953
c4be5517
JD
954# In some versions of Autoconf, AT_CHECK invokes AS_ESCAPE before
955# expanding macros, so it corrupts some special characters in the
956# macros. To avoid this, expand now and pass it the result with proper
cbdb6d91 957# string quotation. Assume args 7 through 12 expand to properly quoted
c4be5517 958# strings.
7254f6a8 959
c4be5517 960m4_if(m4_index(m4_quote($3), [no-xml]), -1,
7254f6a8
JD
961 [AT_BISON_CHECK],
962 [AT_BISON_CHECK_NO_XML])([[--report=all --defines -o input.c input.y]],
c4be5517 963 [0], [], m4_dquote($7))
7254f6a8 964
c4be5517 965m4_if(m4_index(m4_quote($3), [last-state]), -1,
d42fe46e 966 [AT_CHECK([[sed -n '/^State 0$/,$p' input.output]], [[0]],
c4be5517 967 m4_dquote($8))],
d42fe46e 968 [AT_CHECK([[sed -n 's/^State //p' input.output | tail -1]], [[0]],
c4be5517 969 m4_dquote($8)[[
7254f6a8 970]])])
7254f6a8 971
c4be5517 972$9
7254f6a8 973
8ec3110a
AD
974# Canonical LR generates very large tables, resulting in very long
975# files with #line directives that may overflow what the standards
976# (C90 and C++98) guarantee: 32767. In that case, GCC's -pedantic
977# will issue an error.
978#
979# There is no "" around `wc` since some indent the result.
980m4_bmatch([$4], [%define lr.type canonical-lr],
981[if test 32767 -lt `wc -l < input.c`; then
982 CFLAGS=`echo " $CFLAGS " | sed -e 's/ -pedantic //'`
983 CXXFLAGS=`echo " $CXXFLAGS " | sed -e 's/ -pedantic //'`
984fi])
7254f6a8
JD
985AT_COMPILE([[input]])
986
c4be5517
JD
987AT_PARSER_CHECK([[./input]],
988 m4_ifval([$10], [m4_dquote($10)]),
989 m4_ifval([$11], [m4_dquote($11)]),
990 m4_ifval([$12], [m4_dquote($12)]))
7254f6a8 991
55f48c48 992AT_BISON_OPTION_POPDEFS
7254f6a8
JD
993AT_CLEANUP
994
995m4_popdef([AT_COND_CASE])])
1f7a61ff
AD
996
997
998
781eaf90 999
1f7a61ff
AD
1000## ----------------------- ##
1001## Launch the test suite. ##
1002## ----------------------- ##
1003
1004AT_INIT
1005
781eaf90
AD
1006# AT_SETUP([TITLE])
1007# -----------------
1008# Redefine AT_SETUP to be more concise. Must be done after AT_INIT.
1009m4_copy_force([AT_SETUP], [B4_SETUP])
1010m4_define([AT_SETUP],
1011[B4_SETUP(m4_expand([AT_SETUP_STRIP([[$1]])]))])
1012
ac3f2e33
AD
1013# Cannot assign CC and CFLAGS here, since atlocal is loaded after
1014# options are processed, so we don't know the value of CXX and
1015# CXXFLAGS yet.
1016#
1017# Note that it also means that command line values for CXX and
1018# CXXFLAGS will not be propagated to CC and CFLAGS.
1019AT_ARG_OPTION([compile-c-with-cxx],
1020 [compile C parsers with the C++ compiler])
1021
1022AT_COLOR_TESTS
1023
1f7a61ff 1024AT_TESTED([bison])