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