1 # Process this -*- Autotest -*- file with autom4te.
3 # Macros for the GNU Bison Test suite.
5 # Copyright (C) 2003-2015, 2018-2019 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 <http://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 # AT_SETUP_STRIP(TITLE)
34 # ---------------------
35 # Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines
36 # that completely break AT_SETUP.
37 m4_define([AT_SETUP_STRIP],
39 [%\(language\|skeleton\) "?\([^\" ]*\)"?],
41 [%define "?\([-A-Za-z0-9_.]+\)"? \({[^\}]+}\|"[^\"]+"\|[-A-Za-z0-9_.]+\)],
43 [%define "?\([-A-Za-z0-9_.]+\)"?],
50 # AT_DATA_NO_FINAL_EOL(FILE, CONTENT)
51 # -----------------------------------
52 # Same as AT_DATA, except that CONTENT has no the final end of line.
54 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
55 # the final newline to be omitted. See the threads starting at
56 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
57 m4_define([AT_DATA_NO_FINAL_EOL],
61 set x `LC_ALL=C ls -l '$1'` &&
63 { test $size -eq 0 || dd obs=1 seek=`expr $size - 1` if=/dev/null of='$1'; }],
64 [], [ignore], [ignore])
74 # AT_PERL_CHECK(PERL-ARGS, ...)
75 # -----------------------------
76 # If Perl is available, run this test.
77 m4_define([AT_PERL_CHECK],
78 [if test x"$PERL" != x; then
79 AT_CHECK(["$PERL" $1], [$2], [$3], [$4])
84 # AT_REQUIRE(CMD, ...)
85 # --------------------
86 # Same as AT_CHECK(...) but skip this test if we failed.
87 m4_define([AT_REQUIRE],
88 [AT_CHECK([$1 || exit 77], [$2], [$3], [$4])])
91 # AT_PERL_REQUIRE(PERL-ARGS, ...)
92 # -------------------------------
93 # Run this Perl program, or skip the test if Perl is not available.
94 m4_define([AT_PERL_REQUIRE],
95 [AT_REQUIRE(["$PERL" $1], [$2], [$3], [$4])])
98 # AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT)
99 # ------------------------------------------
100 # Expect COUNT matches of the PERL-REGEXP in FILE. The file is
101 # taken in "slurp" mode, i.e., one can match end-of-lines.
102 m4_define([AT_MATCHES_CHECK],
103 [AT_PERL_CHECK([-0777 -ne '
105 s{$2}{ ++$count; "" }gem;
106 printf "$count\n";' $1], [0], [$3
110 # AT_SAVE_SPECIAL_FILES / AT_RESTORE_SPECIAL_FILES
111 # ------------------------------------------------
112 # Don't interfere with caller's files.
113 m4_divert_text([PREPARE_TESTS],
114 [at_save_special_files ()
116 for at_save_file in stderr experr expout
118 test ! -f at-bison-check-$at_save_file.bak ||
119 as_fn_error 1 "fatal error: back-up on top of a back-up"
120 test ! -f $at_save_file || mv $at_save_file at-bison-check-$at_save_file.bak
124 at_restore_special_files ()
126 for at_save_file in stderr experr expout
128 test ! -f at-bison-check-$at_save_file.bak ||
129 mv at-bison-check-$at_save_file.bak $at_save_file
134 m4_define([AT_SAVE_SPECIAL_FILES], [at_save_special_files])
135 m4_define([AT_RESTORE_SPECIAL_FILES], [at_restore_special_files])
139 ## ------------------------------- ##
140 ## Macros decoding Bison options. ##
141 ## ------------------------------- ##
143 # AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN)
144 # ----------------------------------------------------------------
145 # Pushdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN).
146 m4_define([AT_LOC_PUSHDEF],
147 [m4_pushdef([AT_FIRST_LINE], [$1])
148 m4_pushdef([AT_FIRST_COLUMN], [$2])
149 m4_pushdef([AT_LAST_LINE], [$3])
150 m4_pushdef([AT_LAST_COLUMN], [$4])
151 m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.AT_FIRST_LINE])
152 m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.AT_FIRST_COLUMN])
153 m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.AT_LAST_LINE])
154 m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.AT_LAST_COLUMN])])
158 # Popdef AT(_LOC)?_(FIRST|LAST)_(LINE|COLUMN).
159 m4_define([AT_LOC_POPDEF],
160 [m4_popdef([AT_LOC_FIRST_LINE])
161 m4_popdef([AT_LOC_FIRST_COLUMN])
162 m4_popdef([AT_LOC_LAST_LINE])
163 m4_popdef([AT_LOC_LAST_COLUMN])
164 m4_popdef([AT_FIRST_LINE])
165 m4_popdef([AT_FIRST_COLUMN])
166 m4_popdef([AT_LAST_LINE])
167 m4_popdef([AT_LAST_COLUMN])
172 # AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
173 # -----------------------------------------
174 m4_define([AT_BISON_OPTION_PUSHDEFS],
175 [m4_divert_text([KILL],
176 [_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])])
179 # _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
180 # --------------------------------------------------
181 # This macro works around the impossibility to define macros
182 # inside macros, because issuing '[$1]' is not possible in M4 :(.
183 # This sucks hard, GNU M4 should really provide M5-like $$1.
184 m4_define([_AT_BISON_OPTION_PUSHDEFS],
185 [m4_pushdef([AT_BISON_OPTIONS], [$3])
187 m4_if([$1$2], $[1]$[2], [],
188 [m4_fatal([$0: invalid arguments: $@])])dnl
189 m4_pushdef([AT_AUTOMOVE_IF],
190 [m4_bmatch([$3], [%define api\.value\.automove], [$1], [$2])])
191 m4_pushdef([AT_DEFINES_IF],
192 [m4_bmatch([$3], [%defines], [$1], [$2])])
193 m4_pushdef([AT_DEBUG_IF],
194 [m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])])
195 m4_pushdef([AT_CXX_IF],
196 [m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
197 m4_pushdef([AT_D_IF],
198 [m4_bmatch([$3], [%language "[Dd]"\|%skeleton "[a-z0-9]+\.d"], [$1], [$2])])
199 m4_pushdef([AT_JAVA_IF],
200 [m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
201 # The target language: "c", "c++", or "java".
202 m4_pushdef([AT_LANG],
207 m4_pushdef([AT_C_IF],
208 [m4_if(AT_LANG, [c], [$1], [$2])])
209 m4_pushdef([AT_GLR_IF],
210 [m4_bmatch([$3], [%glr-parser\|%skeleton "glr\..*"], [$1], [$2])])
211 m4_pushdef([AT_LALR1_CC_IF],
212 [AT_CXX_IF([AT_GLR_IF([$2], [$1])], [$2])])
213 m4_pushdef([AT_GLR_CC_IF],
214 [AT_CXX_IF([AT_GLR_IF([$1], [$2])], [$2])])
216 m4_pushdef([AT_YACC_IF],
217 [m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
218 m4_pushdef([AT_LEXPARAM_IF],
219 [m4_bmatch([$3], [%lex-param], [$1], [$2])])
220 m4_pushdef([AT_LOCATION_IF],
221 [m4_bmatch([$3], [%locations], [$1], [$2])])
222 # Whether we use the Span location type (see calc.at), whose members are
223 # not named like those of the default location type (on purpose, to make
224 # sure we can use a user type).
225 m4_pushdef([AT_LOCATION_TYPE_SPAN_IF],
226 [m4_bmatch([$3], [%define \(api\.location\.type\|location_type\) \{Span\}], [$1], [$2])])
227 m4_pushdef([AT_PARAM_IF],
228 [m4_bmatch([$3], [%parse-param], [$1], [$2])])
229 # Comma-terminated list of formals parse-parameters.
230 # E.g., %parse-param { int x } %parse-param {int y} -> "int x, int y, ".
231 # FIXME: Support grouped parse-param.
232 m4_pushdef([AT_PARSE_PARAMS])
233 m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}],
234 [m4_append([AT_PARSE_PARAMS], [\1, ])])
236 m4_pushdef([AT_PURE_IF],
237 [m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
238 [m4_bmatch([$3], [%define *api\.pure *false], [$2], [$1])],
240 m4_pushdef([AT_PUSH_IF],
241 [m4_bmatch([$3], [%define api.push-pull \(both\|pull\)], [$1], [$2])])
243 m4_pushdef([AT_NAME_PREFIX],
244 [m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) .*],
246 [\(%define api\.prefix\|%name-prefix\) [\{\"]\([^\"\}]*\)[\"\}]],
248 [AT_JAVA_IF([YY], [yy])])])
249 # AT_NAMESPACE: also consider api.prefix. FIXME: Stop that confusion.
250 m4_pushdef([AT_NAMESPACE],
251 [m4_bmatch([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) .*],
253 [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) [\{\"]\([^\"\}]*\)[\"\}]],
256 m4_pushdef([AT_TOKEN_CTOR_IF],
257 [m4_bmatch([$3], [%define api\.token\.constructor], [$1], [$2])])
258 m4_pushdef([AT_TOKEN_PREFIX],
259 [m4_bmatch([$3], [%define api\.token\.prefix {.*}],
260 [m4_bregexp([$3], [%define api\.token\.prefix {\(.*\)}], [\1])])])
261 m4_pushdef([AT_TOKEN_RAW_IF],
262 [m4_bmatch([$3], [%define api\.token\.raw], [$1], [$2])])
263 m4_pushdef([AT_VARIANT_IF],
264 [m4_bmatch([$3], [%define api\.value\.type variant], [$1], [$2])])
265 m4_pushdef([AT_API_prefix],
266 [m4_bmatch([$3], [%define api\.prefix {.*}],
267 [m4_bregexp([$3], [%define api\.prefix {\([^\}]*\)}], [\1])],
268 [AT_JAVA_IF([YY], [yy])])])
269 m4_pushdef([AT_API_PREFIX],
270 [m4_toupper(AT_API_prefix)])
271 # yyerror receives the location if %location, and if the parser is pure. For
272 # historical reasons, with the "yacc.c" skeleton, the location is not passed
273 # unless an additional "%parse-param" is present, or if the purity is defined
275 m4_pushdef([AT_YYERROR_ARG_LOC_IF],
276 [AT_LOCATION_IF([AT_PURE_IF([m4_bmatch([$3],
277 m4_quote(m4_join([\|],
278 [%define api\.pure full],
281 [%skeleton "?glr.c"?])),
286 # yyerror always sees the locations (when activated) if the parser is impure.
287 # When the parser is pure, yyerror sees the location if it is received as an
289 m4_pushdef([AT_YYERROR_SEES_LOC_IF],
290 [AT_LOCATION_IF([AT_YACC_IF([AT_PURE_IF([AT_YYERROR_ARG_LOC_IF([$1], [$2])],
295 # The interface is pure: either because %define api.pure, or because we
296 # are using the C++ parsers.
297 m4_pushdef([AT_PURE_LEX_IF],
299 [AT_CXX_IF([$1], [$2])])])
301 m4_pushdef([AT_YYSTYPE],
302 [AT_CXX_IF([AT_NAMESPACE[::parser::semantic_type]],
303 [AT_API_PREFIX[STYPE]])])
304 m4_pushdef([AT_YYLTYPE],
305 [AT_CXX_IF([AT_NAMESPACE[::parser::location_type]],
306 [AT_API_PREFIX[LTYPE]])])
309 [m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
310 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
311 m4_pushdef([AT_YYLEX_FORMALS], [])
312 m4_pushdef([AT_YYLEX_RETURN], [yy::parser::symbol_type])
313 m4_pushdef([AT_YYLEX_ARGS], [])
314 m4_pushdef([AT_USE_LEX_ARGS], [])
315 m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
316 m4_pushdef([AT_YYLEX_PRE_ARGS], [])],
318 [m4_pushdef([AT_LOC], [(*llocp)])
319 m4_pushdef([AT_VAL], [(*lvalp)])
320 m4_pushdef([AT_YYLEX_FORMALS],
321 [AT_YYSTYPE *lvalp[]AT_LOCATION_IF([, AT_YYLTYPE *llocp])])
322 m4_pushdef([AT_YYLEX_RETURN], [int])
323 m4_pushdef([AT_YYLEX_ARGS],
324 [lvalp[]AT_LOCATION_IF([, llocp])])
325 m4_pushdef([AT_USE_LEX_ARGS],
326 [(void) lvalp;AT_LOCATION_IF([(void) llocp;])])
327 m4_pushdef([AT_YYLEX_PRE_FORMALS],
328 [AT_YYLEX_FORMALS, ])
329 m4_pushdef([AT_YYLEX_PRE_ARGS],
332 [m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
333 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
334 m4_pushdef([AT_YYLEX_FORMALS], [void])
335 m4_pushdef([AT_YYLEX_RETURN], [int])
336 m4_pushdef([AT_YYLEX_ARGS], [])
337 m4_pushdef([AT_USE_LEX_ARGS], [])
338 m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
339 m4_pushdef([AT_YYLEX_PRE_ARGS], [])
343 # Handle the different types of location components.
344 AT_LOCATION_TYPE_SPAN_IF(
345 [AT_LOC_PUSHDEF([first.l], [first.c], [last.l], [last.c])],
346 [AT_CXX_IF([AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])],
347 [AT_LOC_PUSHDEF([first_line], [first_column], [last_line], [last_column])])])
350 AT_GLR_IF([AT_KEYWORDS([glr])])
351 ])# _AT_BISON_OPTION_PUSHDEFS
354 # AT_BISON_OPTION_POPDEFS
355 # -----------------------
356 m4_define([AT_BISON_OPTION_POPDEFS],
357 [m4_divert_text([KILL],
358 [m4_popdef([AT_BISON_OPTIONS])
360 m4_popdef([AT_YYLEX_PRE_ARGS])
361 m4_popdef([AT_YYLEX_PRE_FORMALS])
362 m4_popdef([AT_USE_LEX_ARGS])
363 m4_popdef([AT_YYLEX_ARGS])
364 m4_popdef([AT_YYLEX_FORMALS])
365 m4_popdef([AT_YYLTYPE])
366 m4_popdef([AT_YYSTYPE])
369 m4_popdef([AT_PURE_LEX_IF])
370 m4_popdef([AT_YYERROR_SEES_LOC_IF])
371 m4_popdef([AT_YYERROR_ARG_LOC_IF])
372 m4_popdef([AT_API_PREFIX])
373 m4_popdef([AT_API_prefix])
374 m4_popdef([AT_VARIANT_IF])
375 m4_popdef([AT_TOKEN_RAW_IF])
376 m4_popdef([AT_TOKEN_PREFIX])
377 m4_popdef([AT_TOKEN_CTOR_IF])
378 m4_popdef([AT_NAMESPACE])
379 m4_popdef([AT_NAME_PREFIX])
380 m4_popdef([AT_LOCATION_TYPE_SPAN_IF])
381 m4_popdef([AT_LOCATION_IF])
382 m4_popdef([AT_PARSE_PARAMS])
383 m4_popdef([AT_PUSH_IF])
384 m4_popdef([AT_PURE_IF])
385 m4_popdef([AT_PARAM_IF])
386 m4_popdef([AT_LEXPARAM_IF])
387 m4_popdef([AT_YACC_IF])
388 m4_popdef([AT_GLR_IF])
389 m4_popdef([AT_CXX_IF])
392 m4_popdef([AT_JAVA_IF])
393 m4_popdef([AT_GLR_CC_IF])
394 m4_popdef([AT_LALR1_CC_IF])
395 m4_popdef([AT_DEFINES_IF])
396 m4_popdef([AT_DEBUG_IF])
398 ])# AT_BISON_OPTION_POPDEFS
402 ## -------------------------- ##
403 ## Generating Grammar Files. ##
404 ## -------------------------- ##
406 # AT_LANG_CASE(LANG1, IF-LANG1, LANG2, IF-LANG2, ..., DEFAULT)
407 # ------------------------------------------------------------
408 m4_define([AT_LANG_CASE],
409 [m4_case(AT_LANG, $@)])
412 # _AT_LANG_DISPATCH(LANG, MACRO, ARGS)
413 # ------------------------------------
414 # Call the specialization of MACRO for LANG with ARGS. Complain if
416 m4_define([_AT_LANG_DISPATCH],
418 [m4_indir([$2($1)], m4_shift2($@))],
419 [m4_fatal([$2: unknown language: $1])])])
422 # AT_LANG_DISPATCH(MACRO, ARGS)
423 # -----------------------------
424 # Call the specialization of MACRO for AT_LANG with ARGS. Complain if
426 m4_define([AT_LANG_DISPATCH],
427 [_AT_LANG_DISPATCH(AT_LANG, $@)])
431 # AT_DATA_SOURCE_PROLOGUE
432 # -----------------------
433 # The prologue that should be included in any source code that is
434 # meant to be compiled. Keep atlocal.in sync (BISON_CXX_WORKS).
435 m4_define([AT_DATA_SOURCE_PROLOGUE],
436 [[/* Adjust to the compiler.
437 We used to do it here, but each time we add a new line,
438 we have to adjust all the line numbers in error messages.
439 It's simpler to use a constant include to a varying file. */
440 #include <testsuite.h>
443 # AT_DATA_GRAMMAR_PROLOGUE
444 # ------------------------
445 # The prologue that should be included in any grammar whose parser is
446 # meant to be compiled.
447 m4_define([AT_DATA_GRAMMAR_PROLOGUE],
449 ]AT_DATA_SOURCE_PROLOGUE[]dnl
453 # AT_DATA_SOURCE(NAME, CONTENT)
454 # -----------------------------
455 # Generate the file NAME, whose CONTENT is preceded by
456 # AT_DATA_SOURCE_PROLOGUE.
457 m4_define([AT_DATA_SOURCE],
459 [AT_DATA_SOURCE_PROLOGUE
464 # AT_DATA_GRAMMAR(NAME, CONTENT)
465 # ------------------------------
466 # Generate the file NAME, whose CONTENT is preceded by
467 # AT_DATA_GRAMMAR_PROLOGUE.
468 m4_define([AT_DATA_GRAMMAR], [AT_LANG_DISPATCH([$0], $@)])
472 # AT_YYLEX_DECLARE_EXTERN
474 # AT_YYLEX_DEFINE([INPUT], [ACTION])
475 # ----------------------------------
476 # INPUT can be empty, or in double quotes, or a list (in braces).
477 # ACTION may compute yylval for instance, using "res" as token type,
478 # and "toknum" as the number of calls to yylex (starting at 0).
479 m4_define([AT_YYLEX_PROTOTYPE],
480 [AT_YYLEX_RETURN AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
483 m4_define([AT_YYLEX_DECLARE_EXTERN],
484 [AT_YYLEX_PROTOTYPE;dnl
487 m4_define([AT_YYLEX_DECLARE],
488 [static AT_YYLEX_DECLARE_EXTERN[]dnl
492 # AT_YYLEX_DEFINE([INPUT], [ACTION])
493 m4_define([AT_YYLEX_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
497 # AT_YYERROR_PROTOTYPE
498 # AT_YYERROR_DECLARE_EXTERN
501 # -------------------------
502 # Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
503 m4_define([AT_YYERROR_FORMALS], [AT_LANG_DISPATCH([$0], $@)])
504 m4_define([AT_YYERROR_PROTOTYPE],[AT_LANG_DISPATCH([$0], $@)])
505 m4_define([AT_YYERROR_DECLARE_EXTERN], [AT_LANG_DISPATCH([$0], $@)])
506 m4_define([AT_YYERROR_DECLARE], [AT_LANG_DISPATCH([$0], $@)])
507 m4_define([AT_YYERROR_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
511 m4_define([AT_MAIN_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
519 # AT_DATA_GRAMMAR(c)(NAME, CONTENT)
520 # ---------------------------------
521 # Generate the file NAME, with CONTENT.
522 m4_define([AT_DATA_GRAMMAR(c)],
524 [AT_DATA_GRAMMAR_PROLOGUE
528 m4_define([AT_YYERROR_FORMALS(c)],
529 [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE const * const llocp, ])AT_PARSE_PARAMS[const char *msg]])
531 m4_define([AT_YYERROR_PROTOTYPE(c)],
532 [[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])
534 m4_define([AT_YYERROR_DECLARE_EXTERN(c)],
535 [AT_YYERROR_PROTOTYPE;])
537 m4_define([AT_YYERROR_DECLARE(c)],
540 #if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
541 static int location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
542 # ifndef LOCATION_PRINT
543 # define LOCATION_PRINT(File, Loc) location_print (File, &(Loc))
547 static AT_YYERROR_DECLARE_EXTERN])
550 m4_define([AT_YYERROR_DEFINE(c)],
553 # if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
554 /* Print *YYLOCP on YYO. */
555 __attribute__((__unused__))
557 location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp)
560 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
561 if (0 <= yylocp->first_line)
563 res += fprintf (yyo, "%d", yylocp->first_line);
564 if (0 <= yylocp->first_column)
565 res += fprintf (yyo, ".%d", yylocp->first_column);
567 if (0 <= yylocp->last_line)
569 if (yylocp->first_line < yylocp->last_line)
571 res += fprintf (yyo, "-%d", yylocp->last_line);
573 res += fprintf (yyo, ".%d", end_col);
575 else if (0 <= end_col && yylocp->first_column < end_col)
576 res += fprintf (yyo, "-%d", end_col);
582 /* A C error reporting function. */
584 ]AT_YYERROR_PROTOTYPE[
585 {]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
586 [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
588 AT_YYERROR_SEES_LOC_IF([[
589 LOCATION_PRINT (stderr, ]AT_LOC[);
590 fprintf (stderr, ": ");]])[
591 fprintf (stderr, "%s\n", msg);
595 m4_define([AT_YYLEX_DEFINE(c)],
596 [[#include <assert.h>
600 ]m4_bmatch([$1], [^\(".*"\)?$],
601 [[static char const input[] = ]m4_default([$1], [""])],
602 [[static int const input[] = ]$1])[;
603 static int toknum = 0;
606 enum { input_elts = sizeof input / sizeof input[0] };
608 assert (0 <= toknum && toknum < input_elts);
609 res = input[toknum++];
610 ]$2[;]AT_TOKEN_CTOR_IF([], [[
612 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
613 ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
618 m4_define([AT_MAIN_DEFINE(c)],
619 [[#include <stdlib.h> /* getenv. */
620 #include <string.h> /* strcmp. */
622 main (int argc, char const* argv[])
624 yydebug = !!getenv ("YYDEBUG");
625 for (int i = 1; i < argc; ++i)
626 if (!strcmp (argv[i], "-p")
627 || !strcmp (argv[i], "-d") || !strcmp (argv[i], "--debug"))
629 else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--stat"))
633 return ]AT_NAME_PREFIX[parse ();
636 m4_define([AT_LANG_FOR_EACH_STD(c)],
645 # AT_DATA_GRAMMAR(NAME, CONTENT)
646 # ------------------------------
647 m4_copy([AT_DATA_GRAMMAR(c)], [AT_DATA_GRAMMAR(c++)])
649 # No need to declare, it's part of the class interface.
650 m4_define([AT_YYERROR_DECLARE(c++)], [])
651 m4_define([AT_YYERROR_DECLARE_EXTERN(c++)], [])
653 m4_define([AT_YYERROR_DEFINE(c++)],
654 [[/* A C++ error reporting function. */
656 ]AT_NAMESPACE[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
658 std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << '\n';
662 # AT_YYERROR_DEFINE(c++)([INPUT], [ACTION])
663 # -----------------------------------------
665 m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])
668 m4_define([AT_MAIN_DEFINE(c++)],
669 [[#include <cstdlib> // getenv.
670 #include <cstring> // strcmp.
672 main (int argc, char const* argv[])
674 ]AT_NAMESPACE[::parser p;]AT_DEBUG_IF([[
675 int debug = !!getenv ("YYDEBUG");
676 for (int i = 1; i < argc; ++i)
677 if (!strcmp (argv[i], "-p")
678 || !strcmp (argv[i], "-d") || !strcmp (argv[i], "--debug"))
680 else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--stat"))
682 p.set_debug_level (debug);]], [[
688 m4_define([AT_LANG_FOR_EACH_STD(c++)],
689 [AT_FOR_EACH_CXX([$1])])
691 m4_define([AT_FOR_EACH_CXX],
692 [[at_for_each_std_CXXFLAGS_save=$CXXFLAGS
694 ${CXX98_CXXFLAGS:+"$CXX98_CXXFLAGS"} \
695 ${CXX03_CXXFLAGS:+"$CXX03_CXXFLAGS"} \
696 ${CXX11_CXXFLAGS:+"$CXX11_CXXFLAGS"} \
697 ${CXX14_CXXFLAGS:+"$CXX14_CXXFLAGS"} \
698 ${CXX17_CXXFLAGS:+"$CXX17_CXXFLAGS"} \
699 ${CXX2A_CXXFLAGS:+"$CXX2A_CXXFLAGS"}
701 ]AS_ECHO(["======== Testing with C++ standard flags: '$at_cxx_std'"])[
702 CXXFLAGS="$at_for_each_std_CXXFLAGS_save $at_std"
705 CXXFLAGS=$at_for_each_std_CXXFLAGS_save
714 # AT_DATA_GRAMMAR(NAME, CONTENT)
715 # ------------------------------
716 m4_copy([AT_DATA], [AT_DATA_GRAMMAR(d)])
719 # No need to declare, it's part of the class interface.
720 m4_define([AT_YYERROR_DECLARE(d)], [])
721 m4_define([AT_YYERROR_DECLARE_EXTERN(d)], [])
723 m4_define([AT_YYERROR_DEFINE(d)],
724 [[/* An error reporting function. */
725 public void yyerror (]AT_LOCATION_IF([[YYLocation l, ]])[string m)
727 stderr.writeln (]AT_LOCATION_IF([[l, ": ", ]])[m);
731 m4_define([AT_MAIN_DEFINE(d)],
734 auto l = new ]AT_API_prefix[Lexer ();
735 auto p = new ]AT_API_PREFIX[Parser (l);
746 # AT_DATA_GRAMMAR(NAME, CONTENT)
747 # ------------------------------
748 m4_copy([AT_DATA], [AT_DATA_GRAMMAR(java)])
751 # AT_JAVA_POSITION_DEFINE
752 # -----------------------
753 m4_define([AT_JAVA_POSITION_DEFINE],
764 public Position (int l, int t)
770 public boolean equals (Position l)
772 return l.line == line && l.token == token;
775 public String toString ()
777 return Integer.toString (line) + "." + Integer.toString(token);
792 m4_define([AT_YYERROR_DEFINE(java)],
793 [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String m)
796 System.err.println (m);
798 System.err.println (l + ": " + m);
801 public void yyerror (String m)
803 System.err.println (m);
808 m4_define([AT_YYLEX_DEFINE(java)],
814 public String input = "]$1[";
815 public int index = 0;
818 if (index < input.length ())
819 return input.charAt (index++);
823 public Object getLVal ()
829 m4_define([AT_MAIN_DEFINE(java)],
832 public static void main (String args[]) throws IOException
834 ]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser ();
835 System.exit (p.parse () ? 0 : 1);
839 m4_define([AT_LANG_FOR_EACH_STD(java)],
842 ## --------------- ##
844 ## --------------- ##
846 # AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
847 # -------------------------------------------------
848 # High-level routine that may call bison several times, under different
851 # Check Bison by invoking 'bison BISON_ARGS'. BISON_ARGS should not contain
852 # shell constructs (such as redirection or pipes) that would prevent
853 # appending additional command-line arguments for bison. OTHER_AT_CHECK_ARGS
854 # are the usual remaining arguments to AT_CHECK: STATUS, STDOUT, etc.
856 # This macro or AT_BISON_CHECK_NO_XML should always be used whenever invoking
857 # Bison in the test suite. For now it ensures that:
859 # 1. Valgrind doesn't report reachable memory when Bison is expected to have
860 # a non-zero exit status since Bison doesn't always try to free all memory
863 # 2. In the case of maintainer-xml-check, XML/XSLT output is compared with
864 # --graph and --report=all output for every working grammar.
866 # 3. If stderr contains a warning, -Werror and --warnings=error
867 # convert the warning to an error.
869 # 4. If stderr contains a warning, -Wnone and --warnings=none suppress it.
870 m4_define([AT_BISON_CHECK],
871 [m4_null_if([$2], [AT_BISON_CHECK_XML($@)])
872 AT_BISON_CHECK_NO_XML($@)])
874 # AT_BISON_CHECK_(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
875 # --------------------------------------------------
876 # Low-level macro to run bison once.
877 m4_define([AT_BISON_CHECK_],
878 [AT_CHECK(AT_SET_ENV[[ bison --color=no -fno-caret ]]$@)])
881 # AT_BISON_CHECK_WARNINGS(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
882 # ----------------------------------------------------------
883 # Check that warnings (if some are expected) are correctly
884 # turned into errors with -Werror, etc.
886 # When -Wno-error is used, the rules are really different, don't try.
887 m4_define([AT_BISON_CHECK_WARNINGS],
888 [m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
889 m4_bregexp([$1], [-Wno-error=]), [-1],
890 [m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
892 m4_define([AT_BISON_CHECK_WARNINGS_],
893 [[# Defining POSIXLY_CORRECT causes bison to complain if options are
894 # added after the grammar file name, so skip these checks in that
896 if test "$POSIXLY_CORRECT_IS_EXPORTED" = false; then
897 ]AT_SAVE_SPECIAL_FILES[
899 # To avoid expanding it repeatedly, store specified stdout.
900 ]AT_DATA([expout], [$3])[
903 ]AT_BISON_CHECK_([$1[ -Werror]], [[1]], [expout], [stderr])[
905 if test x"$PERL" != x; then
906 # Build expected stderr up to and including the "warnings being
907 # treated as errors" message.
908 ]AT_DATA([[experr]], [$4])[
909 "$PERL" -pi -e 's{(.*): warning:}{$][1: error:};' \
910 -e 's{\[-W(.*)\]$}{@<:@-Werror=$][1@:>@}' \
912 ]AT_CHECK([[sed 's,.*/$,,' stderr 1>&2]], [[0]], [[]], [experr])[
914 # Now check --warnings=error.
916 ]AT_BISON_CHECK_([$1[ --warnings=error]], [[1]], [expout], [experr])[
919 # Now check -Wnone and --warnings=none by making sure that
920 # -Werror doesn't change the exit status when -Wnone or
921 # --warnings=none is specified. With traces disabled, there should
922 # be no output on stderr.
923 ]AT_BISON_CHECK_([$1[ -Wnone,none -Werror --trace=none]], [[0]], [expout])[
924 ]AT_BISON_CHECK_([$1[ --warnings=none -Werror --trace=none]], [[0]], [expout])[
926 ]AT_RESTORE_SPECIAL_FILES[
930 # AT_BISON_CHECK_NO_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
931 # --------------------------------------------------------
932 # Same as AT_BISON_CHECK except don't perform XML/XSLT checks. This is useful
933 # when a tortured grammar's XML is known to be too large for xsltproc to
935 m4_define([AT_BISON_CHECK_NO_XML],
936 [AT_CHECK(AT_SET_ENV_IF([$2]) [[bison --color=no -fno-caret ]]$@)
937 AT_BISON_CHECK_WARNINGS($@)])
939 # AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
940 # -----------------------------------------------------
941 # Run AT_BISON_CHECK's XML/XSLT checks if $BISON_TEST_XML=1 and $XSLTPROC is
942 # defined. It doesn't make sense to invoke this macro if Bison is expected to
943 # have a non-zero exit status.
944 m4_define([AT_BISON_CHECK_XML],
945 [[if test x"$BISON_TEST_XML" = x1 && test x"$XSLTPROC" != x""; then]
946 AT_SAVE_SPECIAL_FILES
948 m4_pushdef([AT_BISON_ARGS],
949 [m4_bpatsubsts([[$1]],
950 [--report(-file)?=[^][ ]*], [],
951 [--graph=[^][ ]*], [],
952 [--xml=[^][ ]*], [])])dnl
953 # Don't combine these Bison invocations since we want to be sure that
954 # --report=all isn't required to get the full XML file.
955 AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \
956 --graph=xml-tests/test.gv ]]AT_BISON_ARGS,
957 [[0]], [ignore], [ignore])
958 AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
959 [[0]], [ignore], [ignore])
960 m4_popdef([AT_BISON_ARGS])dnl
961 [cp xml-tests/test.output expout]
962 AT_CHECK([[$XSLTPROC \
963 `]]AT_SET_ENV[[ bison --print-datadir`/xslt/xml2text.xsl \
964 xml-tests/test.xml]], [[0]], [expout])
965 [sort xml-tests/test.gv > expout]
966 AT_CHECK([[$XSLTPROC \
967 `]]AT_SET_ENV[[ bison --print-datadir`/xslt/xml2dot.xsl \
968 xml-tests/test.xml | sort]], [[0]], [expout])
969 [rm -rf xml-tests expout]
970 AT_RESTORE_SPECIAL_FILES
974 # AT_SET_ENV_IF(EXIT-STATUS)
975 # --------------------------
976 # Put this before a Bison invocation to set the environment to:
977 # - define COLUMNS to make the test suite independant of the user's
979 # - keep Valgrind from complaining about reachable memory (when
980 # EXIT-STATUS is not 0).
982 # Do not quote invocations of this macro within the first argument of AT_CHECK.
983 # The triple quoting below will cause test cases to fail if you do. If you do
984 # so anyway but also decrease the quoting below to avoid that problem, AT_CHECK
985 # will then fail to shell-escape its contents when attempting to print them.
986 # The testsuite verbose output, at least, will be incorrect, but nothing may
987 # fail to make sure you notice.
988 m4_define([AT_SET_ENV_IF],
989 [[[COLUMNS=1000; export COLUMNS;]] m4_null_if($1, [], [[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS; ]]])])
995 m4_define([AT_SET_ENV],
996 [AT_SET_ENV_IF([1])])
998 ## ------------------------ ##
999 ## Compiling C, C++ Files. ##
1000 ## ------------------------ ##
1003 # AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c], [EXTRA-COMPILER-FLAGS])
1004 # ----------------------------------------------------------------
1005 # Compile SOURCES into OUTPUT.
1007 # If OUTPUT does not contain '.', assume that we are linking too,
1008 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1009 # with trailing .o removed, and ".c" appended.
1010 m4_define([AT_COMPILE],
1011 [AT_SKIP_IF([[! $BISON_C_WORKS]])
1012 AT_CHECK(m4_join([ ],
1013 [$CC $CFLAGS $CPPFLAGS $3],
1014 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
1016 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).c])],
1017 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
1018 0, [ignore], [ignore])])
1021 # AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc], [EXTRA-COMPILER-FLAGS])
1022 # ---------------------------------------------------------------------
1023 # Compile SOURCES into OUTPUT. If the C++ compiler does not work,
1026 # If OUTPUT does not contain '.', assume that we are linking too,
1027 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1028 # with trailing ".o" removed, and ".cc" appended.
1029 m4_define([AT_COMPILE_CXX],
1031 AT_SKIP_IF([[! $BISON_CXX_WORKS]])
1032 AT_CHECK(m4_join([ ],
1033 [$CXX $CXXFLAGS $CPPFLAGS $3],
1034 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
1036 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).cc])],
1037 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
1038 0, [ignore], [ignore])])
1041 # AT_COMPILE_D(OUTPUT, [SOURCES = OUTPUT.d], [EXTRA-COMPILER-FLAGS])
1042 # -------------------------------------------------------------------
1043 # Compile SOURCES into OUTPUT. If the C++ compiler does not work,
1046 # If OUTPUT does not contain '.', assume that we are linking too,
1047 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1048 # with trailing ".o" removed, and ".cc" appended.
1049 m4_define([AT_COMPILE_D],
1051 AT_SKIP_IF([[! $BISON_DC_WORKS]])
1052 AT_CHECK(m4_join([ ],
1054 [m4_bmatch([$1], [[.]], [-c])],
1056 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).d])]),
1057 0, [ignore], [ignore])])
1060 # AT_JAVA_COMPILE(SOURCES)
1061 # ------------------------
1062 # Compile SOURCES into Java class files. Skip the test if java or javac
1064 m4_define([AT_JAVA_COMPILE],
1066 AT_SKIP_IF([[test -z "$CONF_JAVAC"]])
1067 AT_SKIP_IF([[test -z "$CONF_JAVA"]])
1068 AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
1069 [[0]], [ignore], [ignore])])
1072 # AT_LANG_FOR_EACH_STD(BODY)
1073 # --------------------------
1074 m4_define([AT_LANG_FOR_EACH_STD], [AT_LANG_DISPATCH([$0], $@)])
1077 # AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c], [EXTRA-COMPILER-FLAGS])
1078 # ---------------------------------------------------------------------
1079 # Compile SOURCES into OUTPUT. Skip if compiler does not work.
1081 # If OUTPUT does not contain '.', assume that we are linking too,
1082 # otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
1083 # with trailing .o removed, and ".c"/".cc" appended.
1084 m4_define([AT_LANG_COMPILE], [AT_LANG_DISPATCH([$0], $@)])
1085 m4_define([AT_LANG_COMPILE(c)], [AT_COMPILE([$1], [$2], [$3])])
1086 m4_define([AT_LANG_COMPILE(c++)], [AT_COMPILE_CXX([$1], [$2], [$3])])
1087 m4_define([AT_LANG_COMPILE(d)], [AT_COMPILE_D([$1], [$2], [$3])])
1088 m4_define([AT_LANG_COMPILE(java)], [AT_JAVA_COMPILE([$1.java], [$2], [$3])])
1093 # The file extension corresponding to the language: c, cc, or java.
1094 m4_define([AT_LANG_EXT], [AT_LANG_DISPATCH([$0], $@)])
1095 m4_define([AT_LANG_EXT(c)], [c])
1096 m4_define([AT_LANG_EXT(c++)], [cc])
1097 m4_define([AT_LANG_EXT(d)], [d])
1098 m4_define([AT_LANG_EXT(java)], [java])
1103 # The header file extension corresponding to the language: c, cc.
1104 m4_define([AT_LANG_HDR], [AT_LANG_DISPATCH([$0], $@)])
1105 m4_define([AT_LANG_HDR(c)], [h])
1106 m4_define([AT_LANG_HDR(c++)], [hh])
1109 # AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2],
1110 # [$4: EXTRA-COMPILER-FLAGS, [$5: EXTRA-BISON-FLAGS])
1111 # -------------------------------------------------------------------
1112 # Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then
1113 # compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile
1114 # OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
1115 # OUTPUT.java along with it. Relies on AT_CXX_IF and
1117 m4_define([AT_FULL_COMPILE],
1118 [AT_BISON_CHECK([$5 -o $1.AT_LANG_EXT $1.y])
1119 AT_LANG_COMPILE([$1],
1122 m4_ifval($2, [[$1-$2.]AT_LANG_EXT]),
1123 m4_ifval($3, [[$1-$3.]AT_LANG_EXT])),
1128 # AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
1129 # --------------------------------
1130 # Check that we can link together C and C++ objects.
1131 m4_define([AT_SKIP_IF_CANNOT_LINK_C_AND_CXX],
1132 [AT_DATA([c-and-cxx.h],
1133 [[#ifdef __cplusplus
1137 int fortytwo (void);
1143 [[#include "c-and-cxx.h"
1147 return fortytwo () == 42 ? 0 : 1;
1150 AT_DATA([cxx-only.cc],
1151 [[#include "c-and-cxx.h"
1157 AT_COMPILE([c-only.o], [c-only.c])
1158 AT_COMPILE_CXX([cxx-only.o], [cxx-only.cc])
1159 AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS $LDFLAGS c-only.o cxx-only.o -o c-and-cxx ||
1160 exit 77], [0], [ignore], [ignore])
1161 AT_C_PARSER_CHECK([c-and-cxx])
1165 # AT_REQUIRE_CXX_STD(STD, [IF-FAIL = SKIP])
1166 # -----------------------------------------
1167 # Skip unless this compiler supports at least C++ STD (e.g., "11",
1169 m4_define([AT_REQUIRE_CXX_STD],
1170 [AT_DATA([check.cc],
1173 #if !defined __cplusplus || __cplusplus < ]m4_case([$1],
1180 [m4_fatal([$0: invalid arguments: $@])])[
1187 AT_COMPILE_CXX([check])
1188 AT_CHECK([@&t@./check], [ignore])
1190 [if test $at_status != 0; then
1193 [AT_SKIP_IF([test $at_status != 0])])
1197 # AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR
1198 # ------------------------------------
1199 # Check that we can expect exceptions to be handled properly.
1200 # GCC 4.3 and 4.4 fail https://trac.macports.org/ticket/40853.
1201 m4_define([AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR],
1202 [AT_DATA_SOURCE([exception.cc],
1203 [[#include <iostream>
1204 #include <stdexcept>
1210 throw std::runtime_error ("foo");
1214 std::cerr << "Inner caught\n";
1227 std::cerr << "Outer caught\n";
1233 AT_COMPILE_CXX([exception])
1234 # The "empty" quadrigraph is to protect from cfg.mk's
1235 # sc_at_parser_check.
1236 AT_CHECK([@&t@./exception || exit 77], [0], [], [ignore])
1240 ## ---------------------------- ##
1241 ## Running a generated parser. ##
1242 ## ---------------------------- ##
1245 # AT_C_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
1246 # --------------------------------------------------------------
1247 # So that we can run './testsuite PREPARSER='valgrind -q' for instance.
1249 # Get rid of spurious messages when compiled with --coverage:
1250 # +profiling:/[...]/lib/fprintf.gcda:Merge mismatch for summaries
1251 m4_define([AT_C_PARSER_CHECK],
1252 [AT_CHECK([$5 $PREPARSER ./$1], [$2], [$3], [stderr])
1253 AT_CHECK([sed >&2 -e '/^profiling:.*:Merge mismatch for summaries/d' stderr],
1258 # AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
1259 # -----------------------------------------------------------------
1260 m4_define([AT_JAVA_PARSER_CHECK],
1261 [AT_CHECK([$5[ $SHELL ../../../javaexec.sh ]$1], [$2], [$3], [$4])])
1264 # AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
1265 # ------------------------------------------------------------
1266 # If we know we are in Java (via AT_BISON_OPTION_PUSHDEFS/POPDEFS),
1267 # run AT_JAVA_PARSER_CHECK, otherwise AT_C_PARSER_CHECK.
1268 m4_define([AT_PARSER_CHECK],
1269 [m4_ifdef([AT_JAVA_IF],
1270 [AT_JAVA_IF([AT_JAVA_PARSER_CHECK($@)],
1271 [AT_C_PARSER_CHECK($@)])],
1272 [AT_C_PARSER_CHECK($@)])])
1275 # AT_TEST_TABLES_AND_PARSE(TITLE, COND-VALUE, TEST-SPEC,
1276 # DECLS, GRAMMAR, INPUT,
1277 # BISON-STDERR, TABLES-OR-LAST-STATE,
1279 # [PARSER-EXIT-VALUE],
1280 # [PARSER-STDOUT], [PARSER-STDERR])
1281 # -------------------------------------------------------------
1282 # Using TITLE as the test group title, check the generated parser tables
1283 # and parser for a specified grammar file under a condition labeled by
1286 # TEST-SPEC is a comma-delimited list of attributes of this test. Each
1287 # recognized attribute is described below where it is relevant.
1289 # Insert DECLS and GRAMMAR into the declarations and grammar section of
1290 # the grammar file. Insert basic yyerror, yylex, and main function
1291 # definitions as well. Hardcode yylex to return the (possibly empty)
1292 # comma-delimited series of tokens in INPUT followed by token 0.
1294 # If TEST-SPEC contains the attribute no-xml, then invoke bison using
1295 # AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK.
1296 # On the bison command-line, specify `--report=all --defines'. Check
1297 # that Bison exits with value 0, has no stdout, and has stderr
1300 # If TEST-SPEC contains the attribute 'last-state', check that the value
1301 # of TABLES-OR-LAST-STATE is the index of the last state generated for
1302 # the grammar; in other words, check the number of states (minus one).
1303 # Otherwise, check that everything in the '.output' file starting with
1304 # the definition of state 0 is the same as the entire value of
1305 # TABLES-OR-LAST-STATE.
1307 # Expand the M4 in OTHER-CHECKS to perform additional checks of the
1308 # '.output' file, which is named 'input.output', and/or grammar file,
1309 # which is named 'input.y'.
1311 # Finally, compile the generated parser and then run it using
1312 # AT_PARSER_CHECK with PARSER-EXIT-VALUE, PARSER-STDOUT, and
1313 # PARSER-STDERR as the 2nd-4th arguments.
1315 # As a precondition, you must properly double-quote all arguments that
1316 # are to be interpreted as strings.
1318 # AT_COND_CASE (when appearing in single-quoted segments of arguments)
1319 # invokes m4_case with its own arguments but COND-VALUE inserted as the
1320 # first argument. This is useful, for example, when wrapping multiple
1321 # AT_TEST_TABLES_AND_PARSE invocations, each representing a different
1322 # condition, in another macro.
1326 # # AT_TEST_SYNTAX_ERROR(DESCRIPTION, DECLS, GRAMMAR, INPUT, LAST-STATE,
1327 # # PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR)
1328 # # ---------------------------------------------------------------------
1329 # m4_define([AT_TEST_SYNTAX_ERROR],
1331 # AT_TEST_TABLES_AND_PARSE([$1[ with %define parse.error verbose]], [[verbose]],
1333 # [[%define parse.error verbose ]$2], [$3], [$4],
1334 # [[]], [$5], [], [$6], [$7], [$8])
1335 # AT_TEST_TABLES_AND_PARSE([$1[ with no %define parse.error verbose]], [[no verbose]],
1338 # [[]], [$5], [], [$6], [$7], [$8])
1341 # AT_TEST_SYNTAX_ERROR([[Single Char Grammar]],
1342 # [[%token 'b']], [[start: 'a' ;]], [['a', 'b']],
1345 # [AT_COND_CASE([[no verbose]],
1348 # [[syntax error, unexpected 'b', expecting $end
1350 m4_define([AT_TEST_TABLES_AND_PARSE],
1351 [m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
1354 AT_BISON_OPTION_PUSHDEFS([$4])
1355 AT_DATA_GRAMMAR([[input.y]],
1357 ]AT_YYERROR_DECLARE[
1372 static int const input[] = {
1373 ]m4_if([$6], [], [], [$6], [[]], [], [$6[, ]])[0
1375 static int const *inputp = input;
1382 # In some versions of Autoconf, AT_CHECK invokes AS_ESCAPE before
1383 # expanding macros, so it corrupts some special characters in the
1384 # macros. To avoid this, expand now and pass it the result with proper
1385 # string quotation. Assume args 7 through 12 expand to properly quoted
1388 m4_if(m4_index(m4_quote($3), [no-xml]), -1,
1390 [AT_BISON_CHECK_NO_XML])([[-Wall --report=all --defines -o input.c input.y]],
1391 [0], [], m4_dquote($7))
1393 m4_if(m4_index(m4_quote($3), [last-state]), -1,
1394 [AT_CHECK([[sed -n '/^State 0$/,$p' input.output]], [[0]],
1396 [AT_CHECK([[sed -n 's/^State //p' input.output | tail -1]], [[0]],
1402 # Canonical LR generates very large tables, resulting in very long
1403 # files with #line directives that may overflow what the standards
1404 # (C90 and C++98) guarantee: 32767. In that case, GCC's -pedantic
1405 # will issue an error.
1407 # There is no "" around `wc` since some indent the result.
1408 m4_bmatch([$4], [%define lr.type canonical-lr],
1409 [if test 32767 -lt `wc -l < input.c`; then
1410 CFLAGS=`echo " $CFLAGS " | sed -e 's/ -pedantic / /'`
1411 CXXFLAGS=`echo " $CXXFLAGS " | sed -e 's/ -pedantic / /'`
1413 AT_COMPILE([[input]])
1415 AT_PARSER_CHECK([[input]],
1416 m4_ifval([$10], [m4_dquote($10)]),
1417 m4_ifval([$11], [m4_dquote($11)]),
1418 m4_ifval([$12], [m4_dquote($12)]))
1420 AT_BISON_OPTION_POPDEFS
1423 m4_popdef([AT_COND_CASE])])
1427 # AT_SETS_CHECK(INPUT, SETS, EXPECTED)
1428 # ------------------------------------
1429 # Extract the information about the grammar sets from a bison
1430 # trace output (INPUT), and compare to EXPECTED.
1432 # And remember, there is no alternation in portable sed.
1433 m4_define([AT_SETS_CHECK],
1434 [AT_DATA([extract.sed],
1436 ]m4_foreach([m4_Set], [$2], [[
1445 AT_CHECK([sed -f extract.sed $1], 0, [$3])
1451 ## ----------------------- ##
1452 ## Launch the test suite. ##
1453 ## ----------------------- ##
1459 # Redefine AT_SETUP to be more concise. Must be done after AT_INIT.
1460 m4_copy_force([AT_SETUP], [B4_SETUP])
1461 m4_define([AT_SETUP],
1462 [B4_SETUP(m4_expand([AT_SETUP_STRIP([[$1]])]))])
1464 # Cannot assign CC and CFLAGS here, since atlocal is loaded after
1465 # options are processed, so we don't know the value of CXX and
1468 # Note that it also means that command line values for CXX and
1469 # CXXFLAGS will not be propagated to CC and CFLAGS.
1470 AT_ARG_OPTION([compile-c-with-cxx],
1471 [compile C parsers with the C++ compiler])