1 # Process this -*- Autotest -*- file with autom4te.
3 # Macros for the GNU Bison Test suite.
5 # Copyright (C) 2003-2015, 2018-2021 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 m4_version_prereq([2.58])
23 # m4_null_if(VAL, IF-TRUE, IF-FALSE)
24 # ----------------------------------
25 # If VAL evaluates to empty or 0, run IF-TRUE, otherwise IF-FALSE.
26 m4_define([m4_null_if],
27 [m4_case(m4_quote($1),
33 # m4_rpatsubst(STRING, PATTERN, REPLACEMENT)
34 # ------------------------------------------
35 # As long as PATTERN matches STRING, replace occurrences of PATTERN by
38 # Contrary to m4_bpatsubst, matches PATTERN from previous replacements.
39 m4_define([m4_rpatsubst],
40 [m4_if(m4_bregexp([$1], [$2]),
42 [m4_rpatsubst(m4_quote(m4_bpatsubst([$1], [$2], [$3])), [$2], [$3])])])
45 # AT_SETUP_STRIP(TITLE)
46 # ---------------------
47 # Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines
48 # that completely break AT_SETUP.
49 m4_define([AT_SETUP_STRIP],
51 [%\(language\|skeleton\) "?\([^\" ]*\)"?],
53 [%define "?\([-A-Za-z0-9_.]+\)"? \({[^\}]+}\|"[^\"]+"\|[-A-Za-z0-9_.]+\)],
55 [%define "?\([-A-Za-z0-9_.]+\)"?],
62 # AT_DATA_NO_FINAL_EOL(FILE, CONTENT)
63 # -----------------------------------
64 # Same as AT_DATA, except that CONTENT has no the final end of line.
66 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
67 # the final newline to be omitted. See the threads starting at
68 # <https://lists.gnu.org/r/bison-patches/2009-07/msg00019.html>.
69 m4_define([AT_DATA_NO_FINAL_EOL],
73 set x `LC_ALL=C ls -l '$1'` &&
75 { test $size -eq 0 || dd obs=1 seek=`expr $size - 1` if=/dev/null of='$1'; }],
76 [], [ignore], [ignore])
86 # AT_DIFF_U_CHECK(DIFF-ARGS, EXPECTED-DIFF)
87 # -----------------------------------------
88 # If diff -u works as we expect, use it, with headers stripped.
89 m4_define([AT_DIFF_U_CHECK],
90 [if $DIFF_U_WORKS; then
91 AT_CHECK([diff -u $1 | sed -n '/^@@/,$p' | sed 's/^ $//'], [0], [$2])
96 # AT_PERL_CHECK(PERL-ARGS, ...)
97 # -----------------------------
98 # If Perl is available, run this test.
99 m4_define([AT_PERL_CHECK],
100 [if test x"$PERL" != x; then
101 AT_CHECK(["$PERL" $1], [$2], [$3], [$4])
106 # AT_REQUIRE(CMD, ...)
107 # --------------------
108 # Same as AT_CHECK(...) but skip this test if we failed.
109 m4_define([AT_REQUIRE],
110 [AT_CHECK([$1 || exit 77], [$2], [$3], [$4])])
113 # AT_PERL_REQUIRE(PERL-ARGS, ...)
114 # -------------------------------
115 # Run this Perl program, or skip the test if Perl is not available.
116 m4_define([AT_PERL_REQUIRE],
117 [AT_REQUIRE(["$PERL" $1], [$2], [$3], [$4])])
120 # AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT)
121 # ------------------------------------------
122 # Expect COUNT matches of the PERL-REGEXP in FILE. The file is
123 # taken in "slurp" mode, i.e., one can match end-of-lines.
124 m4_define([AT_MATCHES_CHECK],
125 [AT_PERL_CHECK([-0777 -ne '
127 s{$2}{ ++$count; "" }gem;
128 printf "$count\n";' $1], [0], [$3
132 # AT_SAVE_SPECIAL_FILES / AT_RESTORE_SPECIAL_FILES
133 # ------------------------------------------------
134 # Don't interfere with caller's files.
135 m4_divert_text([PREPARE_TESTS],
136 [at_save_special_files ()
138 for at_save_file in stderr experr expout
140 test ! -f at-bison-check-$at_save_file.bak ||
141 as_fn_error 1 "fatal error: back-up on top of a back-up"
142 test ! -f $at_save_file || mv $at_save_file at-bison-check-$at_save_file.bak
146 at_restore_special_files ()
148 for at_save_file in stderr experr expout
150 test ! -f at-bison-check-$at_save_file.bak ||
151 mv at-bison-check-$at_save_file.bak $at_save_file
156 m4_define([AT_SAVE_SPECIAL_FILES], [at_save_special_files])
157 m4_define([AT_RESTORE_SPECIAL_FILES], [at_restore_special_files])
160 # AT_FOR_EACH_SKEL(BODY)
161 # ----------------------
162 m4_define([AT_FOR_EACH_SKEL],
163 [m4_foreach([b4_skel],
164 [[yacc.c], [glr.c], [lalr1.cc], [glr.cc], [glr2.cc], [lalr1.d], [lalr1.java]],
170 ## ------------------------------- ##
171 ## Macros decoding Bison options. ##
172 ## ------------------------------- ##
174 # AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN)
175 # ----------------------------------------------------------------
176 # Pushdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN).
177 m4_define([AT_LOC_PUSHDEF],
178 [m4_pushdef([AT_FIRST_LINE], [$1])
179 m4_pushdef([AT_FIRST_COLUMN], [$2])
180 m4_pushdef([AT_LAST_LINE], [$3])
181 m4_pushdef([AT_LAST_COLUMN], [$4])
182 m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.AT_FIRST_LINE])
183 m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.AT_FIRST_COLUMN])
184 m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.AT_LAST_LINE])
185 m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.AT_LAST_COLUMN])])
189 # Popdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN).
190 m4_define([AT_LOC_POPDEF],
191 [m4_popdef([AT_LOC_FIRST_LINE])
192 m4_popdef([AT_LOC_FIRST_COLUMN])
193 m4_popdef([AT_LOC_LAST_LINE])
194 m4_popdef([AT_LOC_LAST_COLUMN])
195 m4_popdef([AT_FIRST_LINE])
196 m4_popdef([AT_FIRST_COLUMN])
197 m4_popdef([AT_LAST_LINE])
198 m4_popdef([AT_LAST_COLUMN])
203 # AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
204 # -----------------------------------------
205 m4_define([AT_BISON_OPTION_PUSHDEFS],
206 [m4_divert_text([KILL],
207 [_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])])
210 # _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
211 # --------------------------------------------------
212 # This macro works around the impossibility to define macros
213 # inside macros, because issuing '[$1]' is not possible in M4 :(.
214 # This sucks hard, GNU M4 should really provide M5-like $$1.
215 m4_define([_AT_BISON_OPTION_PUSHDEFS],
216 [m4_pushdef([AT_BISON_OPTIONS], [$3])
218 m4_if([$1$2], $[1]$[2], [],
219 [m4_fatal([$0: invalid arguments: $@])])dnl
220 m4_pushdef([AT_AUTOMOVE_IF],
221 [m4_bmatch([$3], [%define api\.value\.automove], [$1], [$2])])
222 m4_pushdef([AT_HEADER_IF],
223 [m4_bmatch([$3], [%defines\|%header], [$1], [$2])])
224 m4_pushdef([AT_DEBUG_IF],
225 [m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])])
226 m4_pushdef([AT_ERROR_CUSTOM_IF],
227 [m4_bmatch([$3], [%define parse\.error custom], [$1], [$2])])
228 m4_pushdef([AT_ERROR_DETAILED_IF],
229 [m4_bmatch([$3], [%define parse\.error detailed], [$1], [$2])])
230 m4_pushdef([AT_ERROR_VERBOSE_IF],
231 [m4_bmatch([$3], [%define parse\.error verbose], [$1], [$2])])
232 m4_pushdef([AT_ERROR_SIMPLE_IF],
233 [AT_ERROR_CUSTOM_IF([$2], [AT_ERROR_DETAILED_IF([$2], [AT_ERROR_VERBOSE_IF([$2], [$1])], [$1])], [$1])])
235 m4_pushdef([AT_CXX_IF],
236 [m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
237 m4_pushdef([AT_D_IF],
238 [m4_bmatch([$3], [%language "[Dd]"\|%skeleton "[a-z0-9]+\.d"], [$1], [$2])])
239 m4_pushdef([AT_JAVA_IF],
240 [m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
241 # The target language: "c", "c++", or "java".
242 m4_pushdef([AT_LANG],
247 m4_pushdef([AT_C_IF],
248 [m4_if(AT_LANG, [c], [$1], [$2])])
250 m4_pushdef([AT_GLR_IF],
251 [m4_bmatch([$3], [%glr-parser\|%skeleton "glr.*"], [$1], [$2])])
252 m4_pushdef([AT_LALR1_CC_IF],
253 [AT_CXX_IF([AT_GLR_IF([$2], [$1])], [$2])])
254 m4_pushdef([AT_GLR_CC_IF],
255 [AT_CXX_IF([AT_GLR_IF([$1], [$2])], [$2])])
256 m4_pushdef([AT_GLR2_CC_IF],
257 [m4_bmatch([$3], [%skeleton "glr2\.cc"], [$1], [$2])])
259 m4_pushdef([AT_YACC_C_IF],
260 [m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
263 m4_pushdef([AT_LAC_IF],
264 [m4_bmatch([$3], [%define parse.lac full], [$1], [$2])])
265 m4_pushdef([AT_LEXPARAM_IF],
266 [m4_bmatch([$3], [%lex-param], [$1], [$2])])
267 m4_pushdef([AT_LOCATION_IF],
268 [m4_bmatch([$3], [%locations], [$1], [$2])])
269 # Whether we use the Span location type (see calc.at), whose members are
270 # not named like those of the default location type (on purpose, to make
271 # sure we can use a user type).
272 m4_pushdef([AT_LOCATION_TYPE_SPAN_IF],
273 [m4_bmatch([$3], [%define \(api\.location\.type\|location_type\) \{Span\}], [$1], [$2])])
274 m4_pushdef([AT_MULTISTART_IF],
275 [m4_bmatch([$3], [%start [_a-zA-Z]+ [_a-zA-Z]+], [$1], [$2])])
276 m4_pushdef([AT_PARAM_IF],
277 [m4_bmatch([$3], [%parse-param], [$1], [$2])])
278 m4_pushdef([AT_YACC_IF],
279 [m4_bmatch([$3], [%yacc], [$1], [$2])])
281 # Comma-terminated list of formals parse-parameters.
282 # E.g., %parse-param { int x } %parse-param {int y} -> "int x, int y, ".
283 m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}{ *\([^{}]*[^{} ]\) *}{ *\([^{}]*[^{} ]\) *}],
284 [m4_append([AT_PARSE_PARAMS], [\1, \2, \3], [, ])])
285 m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}{ *\([^{}]*[^{} ]\) *}\([^{].*\)?$],
286 [m4_append([AT_PARSE_PARAMS], [\1, \2], [, ])])
287 m4_rpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}\([^{}].*\)?$],
288 [m4_append([AT_PARSE_PARAMS], [\1], [, ])\2])
289 m4_ifndef([AT_PARSE_PARAMS],
290 [m4_define([AT_PARSE_PARAMS])])
292 m4_pushdef([AT_PARSER_CLASS],
293 [m4_bmatch([$3], [%define *api\.parser\.class {\([^\}]*\)}],
294 [m4_bregexp([$3], [%define *api\.parser\.class {\([^\}]*\)}], [\1])],
295 [AT_JAVA_IF([AT_API_PREFIX[]Parser], [parser])])])
297 m4_pushdef([AT_PURE_IF],
298 [m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
299 [m4_bmatch([$3], [%define *api\.pure *false], [$2], [$1])],
301 m4_pushdef([AT_PUSH_IF],
302 [m4_bmatch([$3], [%define api.push-pull \(both\|pull\)], [$1], [$2])])
303 # Whether we use %define api.value.type union
304 m4_pushdef([AT_VALUE_UNION_IF],
305 [m4_bmatch([$3], [%define api\.value\.type union], [$1], [$2])])
309 m4_pushdef([AT_NAME_PREFIX],
310 [m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) .*],
312 [\(%define api\.prefix\|%name-prefix\) [\{\"]\([^\"\}]*\)[\"\}]],
314 [AT_JAVA_IF([YY], [yy])])])
315 # AT_NAMESPACE: also consider api.prefix. FIXME: Stop that confusion.
316 m4_pushdef([AT_NAMESPACE],
317 [m4_bmatch([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) .*],
319 [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) [\{\"]\([^\"\}]*\)[\"\}]],
322 m4_pushdef([AT_TOKEN_CTOR_IF],
323 [m4_bmatch([$3], [%define api\.token\.constructor], [$1], [$2])])
324 m4_pushdef([AT_TOKEN_PREFIX],
325 [m4_bmatch([$3], [%define api\.token\.prefix {.*}],
326 [m4_bregexp([$3], [%define api\.token\.prefix {\(.*\)}], [\1])])])
327 m4_pushdef([AT_TOKEN_RAW_IF],
328 [m4_bmatch([$3], [%define api\.token\.raw], [$1], [$2])])
329 m4_pushdef([AT_UNION_IF],
330 [m4_bmatch([$3], [%define api\.value\.type union], [$1], [$2])])
331 m4_pushdef([AT_VARIANT_IF],
332 [m4_bmatch([$3], [%define api\.value\.type variant], [$1], [$2])])
333 m4_pushdef([AT_UNION_IF],
334 [m4_bmatch([$3], [%define api\.value\.type union], [$1], [$2])])
335 m4_pushdef([AT_API_prefix],
336 [m4_bmatch([$3], [%define api\.prefix {.*}],
337 [m4_bregexp([$3], [%define api\.prefix {\([^\}]*\)}], [\1])],
338 [AT_JAVA_IF([YY], [yy])])])
339 m4_pushdef([AT_API_PREFIX],
340 [m4_toupper(AT_API_prefix)])
341 # yyerror receives the location if %location, and if the parser is pure. For
342 # historical reasons, with the "yacc.c" skeleton, the location is not passed
343 # unless an additional "%parse-param" is present, or if the purity is defined
345 m4_pushdef([AT_YYERROR_ARG_LOC_IF],
346 [AT_LOCATION_IF([AT_PURE_IF([m4_bmatch([$3],
347 m4_quote(m4_join([\|],
348 [%define api\.pure full],
351 [%skeleton "?glr.c"?])),
356 # yyerror always sees the locations (when activated) if the parser is impure.
357 # When the parser is pure, yyerror sees the location if it is received as an
359 m4_pushdef([AT_YYERROR_SEES_LOC_IF],
360 [AT_LOCATION_IF([AT_YACC_C_IF([AT_PURE_IF([AT_YYERROR_ARG_LOC_IF([$1], [$2])],
365 # The interface is pure: either because %define api.pure, or because we
366 # are using the C++ parsers.
367 m4_pushdef([AT_PURE_LEX_IF],
369 [AT_CXX_IF([$1], [$2])])])
371 # Whether token translation is supported.
372 m4_pushdef([AT_TOKEN_TRANSLATE_IF],
373 [AT_ERROR_CUSTOM_IF([$1], [AT_ERROR_DETAILED_IF([$1], [$2])])])
375 m4_pushdef([AT_TOKEN],
376 [AT_CXX_IF([AT_CXX_IF([AT_NAMESPACE::AT_PARSER_CLASS::token::])[]AT_TOKEN_PREFIX[$1]],
377 [AT_TOKEN_PREFIX[$1]])])
380 m4_pushdef([AT_YYSTYPE],
381 [AT_CXX_IF([AT_NAMESPACE[::]AT_PARSER_CLASS[::semantic_type]],
382 [AT_API_PREFIX[STYPE]])])
383 m4_pushdef([AT_YYLTYPE],
384 [AT_CXX_IF([AT_NAMESPACE[::]AT_PARSER_CLASS[::location_type]],
385 [AT_API_PREFIX[LTYPE]])])
388 [m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
389 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
390 m4_pushdef([AT_YYLEX_FORMALS], [])
391 m4_pushdef([AT_YYLEX_RETURN], [AT_NAMESPACE::AT_PARSER_CLASS::symbol_type])
392 m4_pushdef([AT_YYLEX_ARGS], [])
393 m4_pushdef([AT_USE_LEX_ARGS], [])
394 m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
395 m4_pushdef([AT_YYLEX_PRE_ARGS], [])],
397 [m4_pushdef([AT_LOC], [(*llocp)])
398 m4_pushdef([AT_VAL], [(*lvalp)])
399 m4_pushdef([AT_YYLEX_FORMALS],
400 [AT_YYSTYPE *lvalp[]AT_LOCATION_IF([, AT_YYLTYPE *llocp])])
401 m4_pushdef([AT_YYLEX_RETURN], [int])
402 m4_pushdef([AT_YYLEX_ARGS],
403 [lvalp[]AT_LOCATION_IF([, llocp])])
404 m4_pushdef([AT_USE_LEX_ARGS],
405 [(void) lvalp;AT_LOCATION_IF([(void) llocp;])])
406 m4_pushdef([AT_YYLEX_PRE_FORMALS],
407 [AT_YYLEX_FORMALS, ])
408 m4_pushdef([AT_YYLEX_PRE_ARGS],
411 [m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
412 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
413 m4_pushdef([AT_YYLEX_FORMALS], [void])
414 m4_pushdef([AT_YYLEX_RETURN], [int])
415 m4_pushdef([AT_YYLEX_ARGS], [])
416 m4_pushdef([AT_USE_LEX_ARGS], [])
417 m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
418 m4_pushdef([AT_YYLEX_PRE_ARGS], [])
422 # Handle the different types of location components.
423 AT_LOCATION_TYPE_SPAN_IF(
424 [AT_LOC_PUSHDEF([first.l], [first.c], [last.l], [last.c])],
425 [AT_CXX_IF([AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])],
426 [AT_LOC_PUSHDEF([first_line], [first_column], [last_line], [last_column])])])
429 AT_GLR_IF([AT_KEYWORDS([glr])])
430 AT_MULTISTART_IF([AT_KEYWORDS([multistart])])
431 AT_PUSH_IF([AT_KEYWORDS([push])])
432 AT_YACC_IF([AT_KEYWORDS([yacc])])
433 ])# _AT_BISON_OPTION_PUSHDEFS
436 # AT_BISON_OPTION_POPDEFS
437 # -----------------------
438 m4_define([AT_BISON_OPTION_POPDEFS],
439 [m4_divert_text([KILL],
440 [m4_popdef([AT_BISON_OPTIONS])
442 m4_popdef([AT_YYLEX_PRE_ARGS])
443 m4_popdef([AT_YYLEX_PRE_FORMALS])
444 m4_popdef([AT_USE_LEX_ARGS])
445 m4_popdef([AT_YYLEX_ARGS])
446 m4_popdef([AT_YYLEX_FORMALS])
447 m4_popdef([AT_YYLTYPE])
448 m4_popdef([AT_YYSTYPE])
451 m4_popdef([AT_TOKEN])
452 m4_popdef([AT_TOKEN_TRANSLATE_IF])
453 m4_popdef([AT_PURE_LEX_IF])
454 m4_popdef([AT_YYERROR_SEES_LOC_IF])
455 m4_popdef([AT_YYERROR_ARG_LOC_IF])
456 m4_popdef([AT_API_PREFIX])
457 m4_popdef([AT_API_prefix])
458 m4_popdef([AT_VARIANT_IF])
459 m4_popdef([AT_UNION_IF])
460 m4_popdef([AT_TOKEN_RAW_IF])
461 m4_popdef([AT_TOKEN_PREFIX])
462 m4_popdef([AT_TOKEN_CTOR_IF])
463 m4_popdef([AT_NAMESPACE])
464 m4_popdef([AT_NAME_PREFIX])
465 m4_popdef([AT_LOCATION_TYPE_SPAN_IF])
466 m4_popdef([AT_LOCATION_IF])
467 m4_undefine([AT_PARSE_PARAMS])
468 m4_popdef([AT_VALUE_UNION_IF])
469 m4_popdef([AT_PUSH_IF])
470 m4_popdef([AT_PURE_IF])
471 m4_popdef([AT_PARSER_CLASS])
472 m4_popdef([AT_YACC_IF])
473 m4_popdef([AT_PARAM_IF])
474 m4_popdef([AT_MULTISTART_IF])
475 m4_popdef([AT_LEXPARAM_IF])
476 m4_popdef([AT_LAC_IF])
477 m4_popdef([AT_YACC_C_IF])
478 m4_popdef([AT_GLR_IF])
479 m4_popdef([AT_CXX_IF])
482 m4_popdef([AT_JAVA_IF])
483 m4_popdef([AT_GLR2_CC_IF])
484 m4_popdef([AT_GLR_CC_IF])
485 m4_popdef([AT_LALR1_CC_IF])
486 m4_popdef([AT_ERROR_SIMPLE_IF])
487 m4_popdef([AT_ERROR_VERBOSE_IF])
488 m4_popdef([AT_ERROR_DETAILED_IF])
489 m4_popdef([AT_ERROR_CUSTOM_IF])
490 m4_popdef([AT_DEBUG_IF])
491 m4_popdef([AT_HEADER_IF])
492 m4_popdef([AT_AUTOMOVE_IF])
494 ])# AT_BISON_OPTION_POPDEFS
498 ## -------------------------- ##
499 ## Generating Grammar Files. ##
500 ## -------------------------- ##
502 # AT_LANG_CASE(LANG1, IF-LANG1, LANG2, IF-LANG2, ..., DEFAULT)
503 # ------------------------------------------------------------
504 m4_define([AT_LANG_CASE],
505 [m4_case(AT_LANG, $@)])
508 # AT_LANG_MATCH(LANG1, IF-LANG1, LANG2, IF-LANG2, ..., DEFAULT)
509 # ------------------------------------------------------------
510 m4_define([AT_LANG_MATCH],
511 [m4_bmatch(AT_LANG, $@)])
514 # _AT_LANG_DISPATCH(LANG, MACRO, ARGS)
515 # ------------------------------------
516 # Call the specialization of MACRO for LANG with ARGS. Complain if
518 m4_define([_AT_LANG_DISPATCH],
520 [m4_indir([$2($1)], m4_shift2($@))],
521 [m4_fatal([$2: unknown language: $1])])])
524 # AT_LANG_DISPATCH(MACRO, ARGS)
525 # -----------------------------
526 # Call the specialization of MACRO for AT_LANG with ARGS. Complain if
528 m4_define([AT_LANG_DISPATCH],
529 [_AT_LANG_DISPATCH(AT_LANG, $@)])
533 # AT_DATA_SOURCE_PROLOGUE
534 # -----------------------
535 # The prologue that should be included in any source code that is
536 # meant to be compiled. Keep atlocal.in sync (BISON_CXX_WORKS).
537 m4_define([AT_DATA_SOURCE_PROLOGUE],
538 [[/* Adjust to the compiler.
539 We used to do it here, but each time we add a new line,
540 we have to adjust all the line numbers in error messages.
541 It's simpler to use a constant include to a varying file. */
542 #include <testsuite.h>
545 # AT_DATA_GRAMMAR_PROLOGUE
546 # ------------------------
547 # The prologue that should be included in any grammar whose parser is
548 # meant to be compiled.
549 m4_define([AT_DATA_GRAMMAR_PROLOGUE],
550 [[%code top { /* -*- ]AT_LANG[ -*- */
551 ]AT_DATA_SOURCE_PROLOGUE[]dnl
555 # AT_DATA_SOURCE(NAME, CONTENT)
556 # -----------------------------
557 # Generate the file NAME, whose CONTENT is preceded by
558 # AT_DATA_SOURCE_PROLOGUE.
559 m4_define([AT_DATA_SOURCE],
561 [AT_DATA_SOURCE_PROLOGUE
566 # AT_DATA_GRAMMAR(NAME, CONTENT)
567 # ------------------------------
568 # Generate the file NAME, whose CONTENT is preceded by
569 # AT_DATA_GRAMMAR_PROLOGUE.
570 m4_define([AT_DATA_GRAMMAR], [AT_LANG_DISPATCH([$0], $@)])
574 # AT_YYLEX_DECLARE_EXTERN
576 # AT_YYLEX_DEFINE([INPUT], [ACTION])
577 # ----------------------------------
578 # INPUT can be empty, or in double quotes, or a list (in braces).
579 # ACTION may compute yylval for instance, using "res" as token kind,
580 # and "toknum" as the number of calls to yylex (starting at 0).
581 m4_define([AT_YYLEX_PROTOTYPE],
582 [AT_YYLEX_RETURN AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
585 m4_define([AT_YYLEX_DECLARE_EXTERN],
586 [AT_YYLEX_PROTOTYPE;dnl
589 m4_define([AT_YYLEX_DECLARE],
590 [static AT_YYLEX_DECLARE_EXTERN[]dnl
594 # AT_YYLEX_DEFINE([INPUT], [ACTION])
595 m4_define([AT_YYLEX_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
599 # AT_YYERROR_PROTOTYPE
600 # AT_YYERROR_DECLARE_EXTERN
603 # -------------------------
604 # Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
605 m4_define([AT_YYERROR_FORMALS], [AT_LANG_DISPATCH([$0], $@)])
606 m4_define([AT_YYERROR_PROTOTYPE], [AT_LANG_DISPATCH([$0], $@)])
607 m4_define([AT_YYERROR_DECLARE_EXTERN], [AT_LANG_DISPATCH([$0], $@)])
608 m4_define([AT_YYERROR_DECLARE], [AT_LANG_DISPATCH([$0], $@)])
609 m4_define([AT_YYERROR_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
613 m4_define([AT_MAIN_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
621 # AT_DATA_GRAMMAR(c)(NAME, CONTENT)
622 # ---------------------------------
623 # Generate the file NAME, with CONTENT.
624 m4_define([AT_DATA_GRAMMAR(c)],
626 [AT_DATA_GRAMMAR_PROLOGUE
630 # AT_LOCATION_PRINT_DECLARE
631 # -------------------------
632 m4_define([AT_LOCATION_PRINT_DECLARE],
634 #if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
635 static int location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
636 # ifndef LOCATION_PRINT
637 # define LOCATION_PRINT(File, Loc) location_print (File, &(Loc))
643 # AT_LOCATION_PRINT_DEFINE
644 # ------------------------
645 m4_define([AT_LOCATION_PRINT_DEFINE],
647 # if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
648 /* Print *YYLOCP on YYO. */
649 __attribute__((__unused__))
651 location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp)
654 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
655 if (0 <= yylocp->first_line)
657 res += fprintf (yyo, "%d", yylocp->first_line);
658 if (0 <= yylocp->first_column)
659 res += fprintf (yyo, ".%d", yylocp->first_column);
661 if (0 <= yylocp->last_line)
663 if (yylocp->first_line < yylocp->last_line)
665 res += fprintf (yyo, "-%d", yylocp->last_line);
667 res += fprintf (yyo, ".%d", end_col);
669 else if (0 <= end_col && yylocp->first_column < end_col)
670 res += fprintf (yyo, "-%d", end_col);
678 m4_define([AT_YYERROR_FORMALS(c)],
679 [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE const * const llocp, ])AT_PARAM_IF([AT_PARSE_PARAMS, ])[const char *msg]])
681 m4_define([AT_YYERROR_PROTOTYPE(c)],
682 [[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])
684 m4_define([AT_YYERROR_DECLARE_EXTERN(c)],
685 [AT_YYERROR_PROTOTYPE;])
687 m4_define([AT_YYERROR_DECLARE(c)],
689 ]AT_LOCATION_PRINT_DECLARE[
690 ]AT_YACC_IF([], [[static ]AT_YYERROR_DECLARE_EXTERN])])
693 # "%define parse.error custom" uses a different format, easy to check.
694 # The "verbose" one can be computed from it (see _AT_CHECK_CALC_ERROR).
695 m4_define([AT_YYERROR_DEFINE(c)],
696 [AT_LOCATION_PRINT_DEFINE[
698 ]AT_ERROR_CUSTOM_IF([[
700 yyreport_syntax_error (const yypcontext_t *ctx]AT_PARAM_IF([, AT_PARSE_PARAMS])[)
702 int res = 0;]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
703 [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
704 YY_USE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
706 ++*nerrs;]])[]AT_LOCATION_IF([[
707 LOCATION_PRINT (stderr, *yypcontext_location (ctx));
708 fprintf (stderr, ": ");]])[
709 fprintf (stderr, "syntax error");
711 yysymbol_kind_t la = yypcontext_token (ctx);
712 if (la != YYSYMBOL_YYEMPTY)
713 fprintf (stderr, " on token [%s]", yysymbol_name (la));
716 enum { TOKENMAX = 10 };
717 yysymbol_kind_t expected[TOKENMAX];
718 int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
719 /* Forward errors to yyparse. */
724 fprintf (stderr, " (expected:");
725 for (int i = 0; i < n; ++i)
726 fprintf (stderr, " [%s]", yysymbol_name (expected[i]));
727 fprintf (stderr, ")");
730 fprintf (stderr, "\n");
735 /* A C error reporting function. */
736 ]AT_YACC_IF([], [static])[
737 ]AT_YYERROR_PROTOTYPE[
738 {]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
739 [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
741 AT_YYERROR_SEES_LOC_IF([[
742 LOCATION_PRINT (stderr, ]AT_LOC[);
743 fprintf (stderr, ": ");]])[
744 fprintf (stderr, "%s\n", msg);]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
750 m4_define([AT_YYLEX_DEFINE(c)],
751 [[#include <assert.h>
755 ]m4_bmatch([$1], [^\(".*"\)?$],
756 [[static char const input[] = ]m4_default([$1], [""])],
757 [[static int const input[] = ]$1])[;
758 static int toknum = 0;
761 enum { input_elts = sizeof input / sizeof input[0] };
763 assert (0 <= toknum && toknum < input_elts);
764 res = input[toknum++];
765 ]$2[;]AT_TOKEN_CTOR_IF([], [[
767 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
768 ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
773 m4_define([AT_MAIN_DEFINE(c)],
774 [[#include <stdlib.h> /* getenv. */
775 #include <string.h> /* strcmp. */
777 main (int argc, char const* argv[])
779 yydebug = !!getenv ("YYDEBUG");
780 for (int i = 1; i < argc; ++i)
781 if (!strcmp (argv[i], "-p")
782 || !strcmp (argv[i], "-d") || !strcmp (argv[i], "--debug"))
784 else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--stat"))
788 return ]AT_NAME_PREFIX[parse ();
791 m4_define([AT_LANG_FOR_EACH_STD(c)],
800 # AT_DATA_GRAMMAR(NAME, CONTENT)
801 # ------------------------------
802 m4_copy([AT_DATA_GRAMMAR(c)], [AT_DATA_GRAMMAR(c++)])
804 # No need to declare, it's part of the class interface.
805 m4_define([AT_YYERROR_DECLARE(c++)], [])
806 m4_define([AT_YYERROR_DECLARE_EXTERN(c++)], [])
808 m4_define([AT_YYERROR_DEFINE(c++)],
809 [[/* A C++ error reporting function. */
811 ]AT_NAMESPACE[::]AT_PARSER_CLASS[::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
812 {]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
815 std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << '\n';
816 }]AT_ERROR_CUSTOM_IF([[
818 ]AT_NAMESPACE[::]AT_PARSER_CLASS[::report_syntax_error (const context& ctx) const
819 {]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
820 [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
821 YY_USE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
823 ++*nerrs;]])[]AT_LOCATION_IF([[
824 std::cerr << ctx.location () << ": ";]])[
825 std::cerr << "syntax error";
827 symbol_kind_type la = ctx.token ();
828 if (la != symbol_kind::S_YYEMPTY)
829 std::cerr << " on token [" << symbol_name (la) << ']';
832 enum { TOKENMAX = 10 };
833 symbol_kind_type expected[TOKENMAX];
834 int n = ctx.expected_tokens (expected, TOKENMAX);
837 std::cerr << " (expected:";
838 for (int i = 0; i < n; ++i)
839 std::cerr << " [" << symbol_name (expected[i]) << ']';
847 # AT_YYLEX_DEFINE(c++)([INPUT], [ACTION])
848 # ---------------------------------------
850 m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])
853 m4_define([AT_MAIN_DEFINE(c++)],
854 [[#include <cstdlib> // getenv.
855 #include <cstring> // strcmp.
857 main (int argc, char const* argv[])
859 ]AT_NAMESPACE[::]AT_PARSER_CLASS[ p;]AT_DEBUG_IF([[
860 int debug = !!getenv ("YYDEBUG");
861 for (int i = 1; i < argc; ++i)
862 if (!strcmp (argv[i], "-p")
863 || !strcmp (argv[i], "-d") || !strcmp (argv[i], "--debug"))
865 else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--stat"))
867 p.set_debug_level (debug);]], [[
873 m4_define([AT_LANG_FOR_EACH_STD(c++)],
874 [AT_FOR_EACH_CXX([$1])])
876 m4_define([AT_FOR_EACH_CXX],
877 [[at_for_each_std_CXXFLAGS_save=$CXXFLAGS
879 ${CXX98_CXXFLAGS:+"$CXX98_CXXFLAGS"} \
880 ${CXX03_CXXFLAGS:+"$CXX03_CXXFLAGS"} \
881 ${CXX11_CXXFLAGS:+"$CXX11_CXXFLAGS"} \
882 ${CXX14_CXXFLAGS:+"$CXX14_CXXFLAGS"} \
883 ${CXX17_CXXFLAGS:+"$CXX17_CXXFLAGS"} \
884 ${CXX20_CXXFLAGS:+"$CXX20_CXXFLAGS"} \
885 ${CXX2B_CXXFLAGS:+"$CXX2B_CXXFLAGS"}
887 ]AS_ECHO(["======== Testing with C++ standard flags: '$at_cxx_std'"])[
888 CXXFLAGS="$at_for_each_std_CXXFLAGS_save $at_std"
891 CXXFLAGS=$at_for_each_std_CXXFLAGS_save
900 # AT_DATA_GRAMMAR(NAME, CONTENT)
901 # ------------------------------
902 m4_copy([AT_DATA], [AT_DATA_GRAMMAR(d)])
905 # No need to declare, it's part of the class interface.
906 m4_define([AT_YYERROR_DECLARE(d)], [])
907 m4_define([AT_YYERROR_DECLARE_EXTERN(d)], [])
909 m4_define([AT_YYERROR_DEFINE(d)],
910 [[/* An error reporting function. */
911 public void yyerror (]AT_LOCATION_IF([[const YYLocation l, ]])[string m)
913 stderr.writeln (]AT_LOCATION_IF([[l, ": ", ]])[m);
915 ]AT_ERROR_CUSTOM_IF([[
916 // In the case of D, there are no single quotes around the symbols
917 // so they need to be added here
918 public string transformToken(]AT_API_PREFIX[Parser.SymbolKind token)
921 foreach (i; format("%s", token))
929 return '\'' ~ res ~ '\'';
934 public void reportSyntaxError(]AT_API_PREFIX[Parser.Context ctx)
936 // Buffer and print the message at the end, to avoid being intertwined
937 // with debug traces from getExpectedTokens.
939 msg ~=]AT_LOCATION_IF([[ ctx.getLocation().toString() ~ ": " ~]])[ "syntax error";
941 ]AT_API_PREFIX[Parser.SymbolKind token = ctx.getToken();
942 msg ~= " on token @<:@" ~ transformToken(token) ~ "@:>@";
945 immutable int argmax = 7;
946 ]AT_API_PREFIX[Parser.SymbolKind[] arg = new ]AT_API_PREFIX[Parser.SymbolKind[argmax];
947 int n = ctx.getExpectedTokens(arg, argmax);
950 msg ~= " (expected:";
951 for (int i = 0; i < n; ++i)
952 msg ~= " @<:@" ~ transformToken(arg[i]) ~ "@:>@";
961 # FIXME: this does not work. It is a stub copied blindly from Java.
962 m4_define([AT_YYLEX_DEFINE(d)],
968 public string input = ]$1[;
969 public int index = 0;
971 if (index < input.length())
972 return input.charAt(index++);
976 public Object getLVal() {
977 ]m4_ifval([$2], [$2], [return null])[;
981 m4_define([AT_MAIN_DEFINE(d)],
984 auto l = new ]AT_API_prefix[Lexer ();
985 auto p = new ]AT_API_PREFIX[Parser (l);
996 # AT_DATA_GRAMMAR(NAME, CONTENT)
997 # ------------------------------
998 m4_copy([AT_DATA], [AT_DATA_GRAMMAR(java)])
1000 # No need to declare, it's part of the class interface.
1001 m4_define([AT_YYERROR_DECLARE(java)], [])
1002 m4_define([AT_YYERROR_DECLARE_EXTERN(java)], [])
1004 # AT_JAVA_POSITION_DEFINE
1005 # -----------------------
1006 m4_define([AT_JAVA_POSITION_DEFINE],
1008 public int line = 1;
1009 public int column = 1;
1017 public Position (int l, int t)
1023 public Position (Position p)
1029 public void set (Position p)
1035 public boolean equals (Position l)
1037 return l.line == line && l.column == column;
1040 public String toString ()
1042 return Integer.toString (line) + "." + Integer.toString (column);
1050 public int column ()
1056 class PositionReader extends BufferedReader {
1058 private Position position = new Position ();
1059 private Position previousPosition = new Position ();
1061 public PositionReader (Reader reader) {
1065 public int read () throws IOException {
1066 int res = super.read ();
1067 previousPosition.set (position);
1070 if (c == '\r' || c == '\n') {
1072 position.column = 1;
1074 position.column += 1;
1080 public Position getPosition () {
1084 public Position getPreviousPosition () {
1085 return previousPosition;
1090 # AT_YYERROR_DEFINE(java)
1091 # -----------------------
1092 # FIXME: We should not hard-code "Calc".
1093 m4_define([AT_YYERROR_DEFINE(java)],
1094 [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String m)
1095 {]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
1099 System.err.println(m);
1101 System.err.println(l + ": " + m);
1104 public void yyerror (String m)
1105 {]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
1108 System.err.println (m);
1112 ]AT_ERROR_CUSTOM_IF([[
1113 public void reportSyntaxError(Calc.Context ctx) {
1114 // Buffer and print the message at the end, to avoid being intertwined
1115 // with debug traces from getExpectedTokens.
1116 String msg = ]AT_LOCATION_IF([[ctx.getLocation() + ": " + ]])["syntax error";
1118 Calc.SymbolKind token = ctx.getToken();
1120 msg += " on token @<:@" + token.getName() + "@:>@";
1123 Calc.SymbolKind[] arg = new Calc.SymbolKind[ctx.NTOKENS];
1124 int n = ctx.getExpectedTokens(arg, ctx.NTOKENS);
1126 msg += " (expected:";
1127 for (int i = 0; i < n; ++i)
1128 msg += " @<:@" + arg[i].getName() + "@:>@";
1132 System.err.println(msg);
1137 m4_define([AT_YYLEX_DEFINE(java)],
1143 public String input = ]$1[;
1144 public int index = 0;
1145 public int yylex() {
1146 if (index < input.length())
1147 return input.charAt(index++);
1151 public Object getLVal() {
1152 ]m4_ifval([$2], [$2], [return null])[;
1156 m4_define([AT_MAIN_DEFINE(java)],
1159 public static void main(String[] args) throws IOException {
1160 ]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser();
1161 boolean success = p.parse();
1167 m4_define([AT_LANG_FOR_EACH_STD(java)],
1172 ## --------------- ##
1173 ## Running Bison. ##
1174 ## --------------- ##
1176 # AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
1177 # -------------------------------------------------
1178 # High-level routine that may call bison several times, under different
1181 # Check Bison by invoking 'bison BISON_ARGS'. BISON_ARGS should not contain
1182 # shell constructs (such as redirection or pipes) that would prevent
1183 # appending additional command-line arguments for bison. OTHER_AT_CHECK_ARGS
1184 # are the usual remaining arguments to AT_CHECK: STATUS, STDOUT, etc.
1186 # This macro or AT_BISON_CHECK_NO_XML should always be used whenever invoking
1187 # Bison in the test suite. For now it ensures that:
1189 # 1. Valgrind doesn't report reachable memory when Bison is expected to have
1190 # a non-zero exit status since Bison doesn't always try to free all memory
1193 # 2. In the case of maintainer-xml-check, XML/XSLT output is compared with
1194 # --graph and --report=all output for every working grammar.
1196 # 3. If stderr contains a warning, -Werror and --warnings=error
1197 # convert the warning to an error.
1199 # 4. If stderr contains a warning, -Wnone and --warnings=none suppress it.
1200 m4_define([AT_BISON_CHECK],
1201 [m4_null_if([$2], [AT_BISON_CHECK_XML($@)])
1202 AT_BISON_CHECK_NO_XML($@)])
1204 # AT_BISON_CHECK_(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
1205 # --------------------------------------------------
1206 # Low-level macro to run bison once.
1207 m4_define([AT_BISON_CHECK_],
1208 [AT_CHECK(AT_SET_ENV[[ bison --color=no -fno-caret ]]$@)])
1211 # AT_BISON_CHECK_WARNINGS(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
1212 # ----------------------------------------------------------
1213 # Check that warnings (if some are expected) are correctly
1214 # turned into errors with -Werror, etc.
1216 # When -Wno-error is used, the rules are really different, don't try.
1217 m4_define([AT_BISON_CHECK_WARNINGS],
1218 [m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
1219 m4_bregexp([$1], [-Wno-error=]), [-1],
1220 [m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
1222 m4_define([AT_BISON_CHECK_WARNINGS_],
1223 [[# Defining POSIXLY_CORRECT causes bison to complain if options are
1224 # added after the grammar file name, so skip these checks in that
1226 if test "$POSIXLY_CORRECT_IS_EXPORTED" = false; then
1227 ]AT_SAVE_SPECIAL_FILES[
1229 # To avoid expanding it repeatedly, store specified stdout.
1230 ]AT_DATA([expout], [$3])[
1233 ]AT_BISON_CHECK_([$1[ -Werror]], [[1]], [expout], [stderr])[
1235 if test x"$PERL" != x; then
1236 # Build expected stderr up to and including the "warnings being
1237 # treated as errors" message.
1238 ]AT_DATA([[experr]], [$4])[
1239 "$PERL" -pi -e 's{(.*): warning:}{$][1: error:};' \
1240 -e 's{\[-W(.*)\]$}{@<:@-Werror=$][1@:>@}' \
1242 ]AT_CHECK([[sed 's,.*/$,,' stderr 1>&2]], [[0]], [[]], [experr])[
1244 # Now check --warnings=error.
1246 ]AT_BISON_CHECK_([$1[ --warnings=error]], [[1]], [expout], [experr])[
1249 # Now check -Wnone and --warnings=none by making sure that
1250 # -Werror doesn't change the exit status when -Wnone or
1251 # --warnings=none is specified. With traces disabled, there should
1252 # be no output on stderr.
1253 ]AT_BISON_CHECK_([$1[ -Wnone,none -Werror --trace=none]], [[0]], [expout])[
1254 ]AT_BISON_CHECK_([$1[ --warnings=none -Werror --trace=none]], [[0]], [expout])[
1256 ]AT_RESTORE_SPECIAL_FILES[
1260 # AT_BISON_CHECK_NO_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
1261 # --------------------------------------------------------
1262 # Same as AT_BISON_CHECK except don't perform XML/XSLT checks. This is useful
1263 # when a tortured grammar's XML is known to be too large for xsltproc to
1265 m4_define([AT_BISON_CHECK_NO_XML],
1266 [AT_CHECK(AT_SET_ENV_IF([$2]) [[bison --color=no -fno-caret ]]$@)
1267 AT_BISON_CHECK_WARNINGS($@)])
1269 # AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
1270 # -----------------------------------------------------
1271 # Run AT_BISON_CHECK's XML/XSLT checks if $BISON_TEST_XML=1 and $XSLTPROC is
1272 # defined. It doesn't make sense to invoke this macro if Bison is expected to
1273 # have a non-zero exit status.
1274 m4_define([AT_BISON_CHECK_XML],
1275 [[if test x"$BISON_TEST_XML" = x1 && test x"$XSLTPROC" != x""; then]
1276 AT_SAVE_SPECIAL_FILES
1278 m4_pushdef([AT_BISON_ARGS],
1279 [m4_bpatsubsts([[$1]],
1280 [--report(-file)?=[^][ ]*], [],
1281 [--graph=[^][ ]*], [],
1282 [--xml=[^][ ]*], [])])dnl
1283 # Don't combine these Bison invocations since we want to be sure that
1284 # --report=all isn't required to get the full XML file.
1285 AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \
1286 --graph=xml-tests/test.gv ]]AT_BISON_ARGS,
1287 [[0]], [ignore], [ignore])
1288 AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
1289 [[0]], [ignore], [ignore])
1290 m4_popdef([AT_BISON_ARGS])dnl
1291 [cp xml-tests/test.output expout]
1292 AT_CHECK([[$XSLTPROC \
1293 `]]AT_SET_ENV[[ bison --print-datadir`/xslt/xml2text.xsl \
1294 xml-tests/test.xml]], [[0]], [stdout])
1295 # xml2text and xml2dot always use '•', while --report uses '•' or '.'
1296 # depending on the locale, and the test suite is run with the plain
1298 AT_CHECK([[sed -e 's/•/./g' stdout]], [], [expout])
1299 [sort xml-tests/test.gv > expout]
1300 AT_CHECK([[$XSLTPROC \
1301 `]]AT_SET_ENV[[ bison --print-datadir`/xslt/xml2dot.xsl \
1302 xml-tests/test.xml | sort | sed -e 's/•/./g']],
1304 [rm -rf xml-tests expout]
1305 AT_RESTORE_SPECIAL_FILES
1309 # AT_SET_ENV_IF(EXIT-STATUS)
1310 # --------------------------
1311 # Put this before a Bison invocation to set the environment to:
1312 # - define COLUMNS to make the test suite independent of the user's
1314 # - keep Valgrind from complaining about reachable memory (when
1315 # EXIT-STATUS is not 0).
1317 # Do not quote invocations of this macro within the first argument of AT_CHECK.
1318 # The triple quoting below will cause test cases to fail if you do. If you do
1319 # so anyway but also decrease the quoting below to avoid that problem, AT_CHECK
1320 # will then fail to shell-escape its contents when attempting to print them.
1321 # The testsuite verbose output, at least, will be incorrect, but nothing may
1322 # fail to make sure you notice.
1323 m4_define([AT_SET_ENV_IF],
1324 [[[COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;]] m4_null_if($1, [], [[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS; ]]])])
1330 m4_define([AT_SET_ENV],
1331 [AT_SET_ENV_IF([1])])
1333 ## ------------------------ ##
1334 ## Compiling C, C++ Files. ##
1335 ## ------------------------ ##
1338 # AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c], [EXTRA-COMPILER-FLAGS])
1339 # ----------------------------------------------------------------
1340 # Compile SOURCES into OUTPUT.
1342 # If OUTPUT does not contain '.', assume that we are linking too,
1343 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1344 # with trailing .o removed, and ".c" appended.
1345 m4_define([AT_COMPILE],
1346 [AT_SKIP_IF([[! $BISON_C_WORKS]])
1347 AT_CHECK(m4_join([ ],
1348 [$CC $CFLAGS $CPPFLAGS $3],
1349 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
1351 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).c])],
1352 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
1353 0, [ignore], [ignore])])
1356 # AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc], [EXTRA-COMPILER-FLAGS])
1357 # ---------------------------------------------------------------------
1358 # Compile SOURCES into OUTPUT. If the C++ compiler does not work,
1361 # If OUTPUT does not contain '.', assume that we are linking too,
1362 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1363 # with trailing ".o" removed, and ".cc" appended.
1364 m4_define([AT_COMPILE_CXX],
1366 AT_SKIP_IF([[! $BISON_CXX_WORKS]])
1367 AT_CHECK(m4_join([ ],
1368 [$CXX $CXXFLAGS $CPPFLAGS $3],
1369 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
1371 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).cc])],
1372 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
1373 0, [ignore], [ignore])])
1376 # AT_COMPILE_D(OUTPUT, [SOURCES = OUTPUT.d], [EXTRA-COMPILER-FLAGS])
1377 # -------------------------------------------------------------------
1378 # Compile SOURCES into OUTPUT. If the C++ compiler does not work,
1381 # If OUTPUT does not contain '.', assume that we are linking too,
1382 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1383 # with trailing ".o" removed, and ".cc" appended.
1384 m4_define([AT_COMPILE_D],
1386 AT_SKIP_IF([[! $BISON_DC_WORKS]])
1387 AT_CHECK(m4_join([ ],
1389 [m4_bmatch([$1], [[.]], [-c])],
1391 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).d])]),
1392 0, [ignore], [ignore])])
1395 # AT_JAVA_COMPILE(SOURCES)
1396 # ------------------------
1397 # Compile SOURCES into Java class files. Skip the test if java or javac
1399 m4_define([AT_JAVA_COMPILE],
1401 AT_SKIP_IF([[test -z "$CONF_JAVAC"]])
1402 AT_SKIP_IF([[test -z "$CONF_JAVA"]])
1403 AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
1404 [[0]], [ignore], [ignore])])
1407 # AT_LANG_FOR_EACH_STD(BODY)
1408 # --------------------------
1409 m4_define([AT_LANG_FOR_EACH_STD], [AT_LANG_DISPATCH([$0], $@)])
1412 # AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c], [EXTRA-COMPILER-FLAGS])
1413 # ---------------------------------------------------------------------
1414 # Compile SOURCES into OUTPUT. Skip if compiler does not work.
1416 # If OUTPUT does not contain '.', assume that we are linking too,
1417 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1418 # with trailing .o removed, and ".c"/".cc" appended.
1419 m4_define([AT_LANG_COMPILE], [AT_LANG_DISPATCH([$0], $@)])
1420 m4_define([AT_LANG_COMPILE(c)], [AT_COMPILE([$1], [$2], [$3])])
1421 m4_define([AT_LANG_COMPILE(c++)], [AT_COMPILE_CXX([$1], [$2], [$3])])
1422 m4_define([AT_LANG_COMPILE(d)], [AT_COMPILE_D([$1], [$2], [$3])])
1423 m4_define([AT_LANG_COMPILE(java)], [AT_JAVA_COMPILE([$1.java], [$2], [$3])])
1428 # The file extension corresponding to the language: c, cc, or java.
1429 m4_define([AT_LANG_EXT], [AT_LANG_DISPATCH([$0], $@)])
1430 m4_define([AT_LANG_EXT(c)], [c])
1431 m4_define([AT_LANG_EXT(c++)], [cc])
1432 m4_define([AT_LANG_EXT(d)], [d])
1433 m4_define([AT_LANG_EXT(java)], [java])
1438 # The header file extension corresponding to the language: c, cc.
1439 m4_define([AT_LANG_HDR], [AT_LANG_DISPATCH([$0], $@)])
1440 m4_define([AT_LANG_HDR(c)], [h])
1441 m4_define([AT_LANG_HDR(c++)], [hh])
1444 # AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2],
1445 # [$4: EXTRA-COMPILER-FLAGS], [$5: EXTRA-BISON-FLAGS])
1446 # --------------------------------------------------------------------
1447 # Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then
1448 # compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile
1449 # OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
1450 # OUTPUT.java along with it. Relies on AT_CXX_IF and
1452 m4_define([AT_FULL_COMPILE],
1453 [AT_BISON_CHECK([$5 -o $1.AT_LANG_EXT $1.y])
1454 AT_LANG_COMPILE([$1],
1457 m4_ifval($2, [[$1-$2.]AT_LANG_EXT]),
1458 m4_ifval($3, [[$1-$3.]AT_LANG_EXT])),
1463 # AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
1464 # --------------------------------
1465 # Check that we can link together C and C++ objects.
1466 m4_define([AT_SKIP_IF_CANNOT_LINK_C_AND_CXX],
1467 [AT_DATA([c-and-cxx.h],
1468 [[#ifdef __cplusplus
1472 int fortytwo (void);
1478 [[#include "c-and-cxx.h"
1482 return fortytwo () == 42 ? 0 : 1;
1485 AT_DATA([cxx-only.cc],
1486 [[#include "c-and-cxx.h"
1492 AT_COMPILE([c-only.o], [c-only.c])
1493 AT_COMPILE_CXX([cxx-only.o], [cxx-only.cc])
1494 AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS $LDFLAGS c-only.o cxx-only.o -o c-and-cxx ||
1495 exit 77], [0], [ignore], [ignore])
1496 AT_C_PARSER_CHECK([c-and-cxx])
1500 # AT_REQUIRE_CXX_STD(STD, [IF-FAIL = SKIP])
1501 # -----------------------------------------
1502 # Skip unless this compiler supports at least C++ STD (e.g., "11",
1504 m4_define([AT_REQUIRE_CXX_STD],
1505 [AT_DATA([check.cc],
1508 #if !defined __cplusplus || __cplusplus < ]m4_case([$1],
1516 [m4_fatal([$0: invalid arguments: $@])])[
1523 AT_COMPILE_CXX([check])
1524 AT_CHECK([@&t@./check], [ignore])
1526 [if test $at_status != 0; then
1529 [AT_SKIP_IF([test $at_status != 0])])
1533 # AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR
1534 # ------------------------------------
1535 # Check that we can expect exceptions to be handled properly.
1536 # GCC 4.3 and 4.4 fail https://trac.macports.org/ticket/40853.
1537 m4_define([AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR],
1538 [AT_DATA_SOURCE([exceptions.cc],
1539 [[#include <iostream>
1540 #include <stdexcept>
1546 throw std::runtime_error ("foo");
1550 std::cerr << "Inner caught\n";
1563 std::cerr << "Outer caught\n";
1569 AT_COMPILE_CXX([exceptions])
1570 # The "empty" quadrigraph is to protect from cfg.mk's sc_at_parser_check.
1571 AT_CHECK([@&t@./exceptions || exit 77], [0], [], [ignore])
1575 ## ---------------------------- ##
1576 ## Running a generated parser. ##
1577 ## ---------------------------- ##
1580 # AT_C_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
1581 # --------------------------------------------------------------
1582 # So that we can run './testsuite PREPARSER='valgrind -q' for instance.
1584 # Get rid of spurious messages when compiled with --coverage:
1585 # +profiling:/[...]/lib/fprintf.gcda:Merge mismatch for summaries
1586 m4_define([AT_C_PARSER_CHECK],
1587 [AT_CHECK([$5 $PREPARSER ./$1], [$2], [$3], [stderr])
1588 AT_CHECK([sed >&2 -e '/^profiling:.*:Merge mismatch for summaries/d' stderr],
1593 # AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
1594 # -----------------------------------------------------------------
1595 m4_define([AT_JAVA_PARSER_CHECK],
1596 [AT_CHECK([$5[ $SHELL ../../../javaexec.sh ]$1], [$2], [$3], [$4])])
1599 # AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
1600 # ------------------------------------------------------------
1601 # If we know we are in Java (via AT_BISON_OPTION_PUSHDEFS/POPDEFS),
1602 # run AT_JAVA_PARSER_CHECK, otherwise AT_C_PARSER_CHECK.
1603 m4_define([AT_PARSER_CHECK],
1604 [m4_ifdef([AT_JAVA_IF],
1605 [AT_JAVA_IF([AT_JAVA_PARSER_CHECK($@)],
1606 [AT_C_PARSER_CHECK($@)])],
1607 [AT_C_PARSER_CHECK($@)])])
1610 # AT_TEST_TABLES_AND_PARSE(TITLE, COND-VALUE, TEST-SPEC,
1611 # DECLS, GRAMMAR, INPUT,
1612 # BISON-STDERR, TABLES-OR-LAST-STATE,
1614 # [PARSER-EXIT-VALUE],
1615 # [PARSER-STDOUT], [PARSER-STDERR])
1616 # -------------------------------------------------------------
1617 # Using TITLE as the test group title, check the generated parser tables
1618 # and parser for a specified grammar file under a condition labeled by
1621 # TEST-SPEC is a comma-delimited list of attributes of this test. Each
1622 # recognized attribute is described below where it is relevant.
1624 # Insert DECLS and GRAMMAR into the declarations and grammar section of
1625 # the grammar file. Insert basic yyerror, yylex, and main function
1626 # definitions as well. Hardcode yylex to return the (possibly empty)
1627 # comma-delimited series of tokens in INPUT followed by token 0.
1629 # If TEST-SPEC contains the attribute no-xml, then invoke bison using
1630 # AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK.
1631 # On the bison command-line, specify `--report=all --header'. Check
1632 # that Bison exits with value 0, has no stdout, and has stderr
1635 # If TEST-SPEC contains the attribute 'last-state', check that the value
1636 # of TABLES-OR-LAST-STATE is the index of the last state generated for
1637 # the grammar; in other words, check the number of states (minus one).
1638 # Otherwise, check that everything in the '.output' file starting with
1639 # the definition of state 0 is the same as the entire value of
1640 # TABLES-OR-LAST-STATE.
1642 # Expand the M4 in OTHER-CHECKS to perform additional checks of the
1643 # '.output' file, which is named 'input.output', and/or grammar file,
1644 # which is named 'input.y'.
1646 # Finally, compile the generated parser and then run it using
1647 # AT_PARSER_CHECK with PARSER-EXIT-VALUE, PARSER-STDOUT, and
1648 # PARSER-STDERR as the 2nd-4th arguments.
1650 # As a precondition, you must properly double-quote all arguments that
1651 # are to be interpreted as strings.
1653 # AT_COND_CASE (when appearing in single-quoted segments of arguments)
1654 # invokes m4_case with its own arguments but COND-VALUE inserted as the
1655 # first argument. This is useful, for example, when wrapping multiple
1656 # AT_TEST_TABLES_AND_PARSE invocations, each representing a different
1657 # condition, in another macro.
1661 # # AT_TEST_SYNTAX_ERROR(DESCRIPTION, DECLS, GRAMMAR, INPUT, LAST-STATE,
1662 # # PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR)
1663 # # ---------------------------------------------------------------------
1664 # m4_define([AT_TEST_SYNTAX_ERROR],
1666 # AT_TEST_TABLES_AND_PARSE([$1[ with %define parse.error verbose]], [[verbose]],
1668 # [[%define parse.error verbose ]$2], [$3], [$4],
1669 # [[]], [$5], [], [$6], [$7], [$8])
1670 # AT_TEST_TABLES_AND_PARSE([$1[ with no %define parse.error verbose]], [[no verbose]],
1673 # [[]], [$5], [], [$6], [$7], [$8])
1676 # AT_TEST_SYNTAX_ERROR([[Single Char Grammar]],
1677 # [[%token 'b']], [[start: 'a' ;]], [['a', 'b']],
1680 # [AT_COND_CASE([[no verbose]],
1683 # [[syntax error, unexpected 'b', expecting $end
1685 m4_define([AT_TEST_TABLES_AND_PARSE],
1686 [m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
1689 AT_BISON_OPTION_PUSHDEFS([$4])
1690 AT_DATA_GRAMMAR([[input.y]],
1692 ]AT_YYERROR_DECLARE[
1707 static int const input[] = {
1708 ]m4_if([$6], [], [], [$6], [[]], [], [$6[, ]])[0
1710 static int const *inputp = input;
1717 # In some versions of Autoconf, AT_CHECK invokes AS_ESCAPE before
1718 # expanding macros, so it corrupts some special characters in the
1719 # macros. To avoid this, expand now and pass it the result with proper
1720 # string quotation. Assume args 7 through 12 expand to properly quoted
1723 m4_if(m4_index(m4_quote($3), [no-xml]), -1,
1725 [AT_BISON_CHECK_NO_XML])([[-Wall --report=all,no-cex --header -o input.c input.y]],
1726 [0], [], m4_dquote($7))
1728 m4_if(m4_index(m4_quote($3), [last-state]), -1,
1729 [AT_CHECK([[sed -n '/^State 0$/,$p' input.output]], [[0]],
1731 [AT_CHECK([[sed -n 's/^State //p' input.output | tail -1]], [[0]],
1737 # Canonical LR generates very large tables, resulting in very long
1738 # files with #line directives that may overflow what the standards
1739 # (C90 and C++98) guarantee: 32767. In that case, GCC's -pedantic
1740 # will issue an error.
1742 # There is no "" around `wc` since some wc indent the result.
1743 m4_bmatch([$4], [%define lr.type canonical-lr],
1744 [if test 32767 -lt `wc -l < input.c`; then
1745 CFLAGS=`echo " $CFLAGS " | sed -e 's/ -pedantic / /'`
1746 CXXFLAGS=`echo " $CXXFLAGS " | sed -e 's/ -pedantic / /'`
1748 AT_COMPILE([[input]])
1750 AT_PARSER_CHECK([[input]],
1751 m4_ifval([$10], [m4_dquote($10)]),
1752 m4_ifval([$11], [m4_dquote($11)]),
1753 m4_ifval([$12], [m4_dquote($12)]))
1755 AT_BISON_OPTION_POPDEFS
1758 m4_popdef([AT_COND_CASE])])
1762 # AT_SETS_CHECK(INPUT, SETS, EXPECTED)
1763 # ------------------------------------
1764 # Extract the information about the grammar sets from a bison
1765 # trace output (INPUT), and compare to EXPECTED.
1767 # And remember, there is no alternation in portable sed.
1768 m4_define([AT_SETS_CHECK],
1769 [AT_DATA([extract.sed],
1771 ]m4_foreach([m4_Set], [$2], [[
1773 :]m4_substr(m4_Set, 0, 7)[
1776 /^ *$/ !b ]m4_substr(m4_Set, 0, 7)[
1780 AT_CHECK([sed -f extract.sed $1], 0, [$3])
1786 ## ----------------------- ##
1787 ## Launch the test suite. ##
1788 ## ----------------------- ##
1794 # Redefine AT_SETUP to be more concise. Must be done after AT_INIT.
1795 m4_copy_force([AT_SETUP], [B4_SETUP])
1796 m4_define([AT_SETUP],
1797 [B4_SETUP(m4_expand([AT_SETUP_STRIP([[$1]])]))])
1799 # Cannot assign CC and CFLAGS here, since atlocal is loaded after
1800 # options are processed, so we don't know the value of CXX and
1803 # Note that it also means that command line values for CXX and
1804 # CXXFLAGS will not be propagated to CC and CFLAGS.
1805 AT_ARG_OPTION([compile-c-with-cxx],
1806 [compile C parsers with the C++ compiler])