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