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