1 # Checking the output filenames. -*- Autotest -*-
2 # Copyright (C) 2004-2005, 2007-2010 Free Software Foundation, Inc.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 AT_BANNER([[C++ Features.]])
24 # AT_CHECK_VARIANTS([DIRECTIVES])
25 # -------------------------------
26 # Check the support of variants in C++, with the additional DIRECTIVES.
27 m4_define([AT_CHECK_VARIANTS],
28 [AT_SETUP([Variants $1])
30 # Store strings and integers in a list of strings.
31 AT_DATA_GRAMMAR([list.yy],
37 ]m4_bpatsubst([$1], [\\n], [
40 %code requires // code for the .hh file
44 typedef std::list<std::string> strings_type;
47 %code // code for the .cc file
53 #if defined USE_LEX_SYMBOL
54 yy::parser::symbol_type yylex ();
56 yy::parser::token_type yylex (yy::parser::semantic_type* yylval,
57 yy::parser::location_type* yylloc);
60 // Printing a list of strings (for %printer).
61 // Koening look up will look into std, since that's an std::list.
65 operator<<(std::ostream& o, const strings_type& s)
68 for (strings_type::const_iterator i = s.begin(); i != s.end (); ++i)
78 // Conversion to string.
82 string_cast (const T& t)
90 %token <::std::string> TEXT;
94 %type <::std::string> item;
95 // Using the template type to exercize its parsing.
96 // Starting with :: to ensure we don't output "<::" which starts by the
97 // digraph for the left square bracket.
98 %type <::std::list<std::string>> list result;
100 %printer { debug_stream() << $][$; }
101 <int> <::std::string> <::std::list<::std::string>>;
105 list { std::cout << $][1 << std::endl; }
109 /* nothing */ { /* Generates an empty string list */ }
110 | list item { std::swap($][$,$][1); $$.push_back($][2); }
111 | list error { std::swap($][$,$][1); }
115 TEXT { std::swap($][$,$][1); }
116 | NUMBER { if ($][1 == 3) YYERROR; else $][$ = string_cast($][1); }
122 #if defined USE_LEX_SYMBOL
123 yy::parser::symbol_type yylex()
125 yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
126 yy::parser::location_type* yylloc)
129 typedef yy::parser::token token;
130 typedef yy::parser::location_type location_type;
131 static int stage = -1;
133 if (stage == STAGE_MAX)
135 #if defined USE_LEX_SYMBOL
136 return yy::parser::make_END_OF_FILE (location_type ());
138 *yylloc = location_type ();
139 return token::END_OF_FILE;
144 #if defined USE_LEX_SYMBOL
145 return yy::parser::make_NUMBER (stage, location_type ());
147 # if defined ONE_STAGE_BUILD
148 yylval->build(stage);
150 yylval->build<int>() = stage;
152 *yylloc = location_type ();
153 return token::NUMBER;
158 #if defined USE_LEX_SYMBOL
159 return yy::parser::make_TEXT (string_cast (stage), location_type ());
161 # if defined ONE_STAGE_BUILD
162 yylval->build (string_cast (stage));
164 yylval->build<std::string>() = string_cast (stage);
166 *yylloc = location_type ();
174 yy::parser::error(const yy::parser::location_type&,
175 const std::string& message)
177 std::cerr << message << std::endl;
184 p.set_debug_level(!!getenv("YYDEBUG"));
189 AT_BISON_CHECK([-o list.cc list.yy])
190 AT_COMPILE_CXX([list])
191 AT_CHECK([./list], 0,
198 AT_CHECK_VARIANTS([])
199 AT_CHECK_VARIANTS([%define parse.assert])
200 AT_CHECK_VARIANTS([[%define parse.assert %code {\n#define ONE_STAGE_BUILD\n}]])
201 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n}]])
202 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n} %define api.tokens.prefix "TOK_"]])
205 ## ----------------------- ##
206 ## Doxygen Documentation. ##
207 ## ----------------------- ##
209 m4_define([AT_CHECK_DOXYGEN],
211 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
212 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
213 [m4_fatal([invalid argument: $1])])
214 AT_SETUP([Doxygen $1 Documentation])
217 [[%skeleton "lalr1.cc"
224 yy::parser::error (const location& l, const std::string& m)
226 std::cerr << l << s << std::endl;
230 AT_BISON_CHECK([-o input.cc input.yy], 0)
233 [# The PROJECT_NAME tag is a single word (or a sequence of words
234 # surrounded by quotes) that should identify the project.
235 PROJECT_NAME = "Bison C++ Parser"
237 # The QUIET tag can be used to turn on/off the messages that are
238 # generated by doxygen. Possible values are YES and NO. If left blank
242 # The WARNINGS tag can be used to turn on/off the warning messages
243 # that are generated by doxygen. Possible values are YES and NO. If
244 # left blank NO is used.
246 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
247 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
248 # this flag will automatically be disabled.
249 WARN_IF_UNDOCUMENTED = YES
250 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
251 # for potential errors in the documentation, such as not documenting
252 # some parameters in a documented function, or documenting parameters
253 # that don't exist or using markup commands wrongly.
254 WARN_IF_DOC_ERROR = YES
255 # The WARN_FORMAT tag determines the format of the warning messages
256 # that doxygen can produce. The string should contain the $file,
257 # $line, and $text tags, which will be replaced by the file and line
258 # number from which the warning originated and the warning text.
259 WARN_FORMAT = "$file:$line: $text"
261 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
262 # entities in documentation are documented, even if no documentation
263 # was available. Private class members and static file members will
264 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
268 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
269 # class will be included in the documentation.
270 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
272 # If the EXTRACT_STATIC tag is set to YES all static members of a file
273 # will be included in the documentation.
274 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
277 AT_CHECK([doxygen --version || exit 77], 0, ignore)
278 AT_CHECK([doxygen], 0, [], [ignore])
282 m4_popdef([AT_DOXYGEN_PRIVATE])
285 AT_CHECK_DOXYGEN([Public])
286 AT_CHECK_DOXYGEN([Private])
293 # AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
294 # ---------------------------------------------------
295 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
296 # is specified, then Bison should accept the input, but compilation will fail,
297 # so don't check compilation.
298 m4_define([AT_CHECK_NAMESPACE],
301 AT_DATA_GRAMMAR([[input.y]],
304 %define api.namespace "]$1["
306 %define global_tokens_and_yystype
310 // YYSTYPE contains a namespace reference.
311 int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
324 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
325 const std::string &msg)
327 std::cerr << "At " << loc << ": " << msg << std::endl;
338 AT_BISON_CHECK([[-o input.cc input.y]])
341 [AT_COMPILE_CXX([[input]], [[input.cc]])
342 AT_PARSER_CHECK([[./input]])])
346 AT_SETUP([[Relative namespace references]])
347 AT_CHECK_NAMESPACE([[foo]])
348 AT_CHECK_NAMESPACE([[foo::bar]])
349 AT_CHECK_NAMESPACE([[foo::bar::baz]])
352 AT_SETUP([[Absolute namespace references]])
353 AT_CHECK_NAMESPACE([[::foo]])
354 AT_CHECK_NAMESPACE([[::foo::bar]])
355 AT_CHECK_NAMESPACE([[::foo::bar::baz]])
356 AT_CHECK_NAMESPACE([[ ::foo]])
357 AT_CHECK_NAMESPACE([[ ::foo::bar]])
358 AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
361 AT_SETUP([[Syntactically invalid namespace references]])
362 AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
363 AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
364 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
365 # contains single occurrences of `:'.
366 AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
367 AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
368 AT_CHECK_NAMESPACE([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
372 ## -------------------------------------- ##
373 ## Syntax error discarding no lookahead. ##
374 ## -------------------------------------- ##
376 # After a syntax error, lalr1.cc used to not check whether there
377 # actually is a lookahead before discarding the lookahead. As a result,
378 # it mistakenly invoked the destructor for the previous lookahead.
380 AT_SETUP([[Syntax error discarding no lookahead]])
382 AT_DATA_GRAMMAR([[input.yy]],
383 [[%skeleton "lalr1.cc"
387 int yylex (yy::parser::semantic_type *, yy::location *);
393 %define parse.error verbose
398 std::cerr << "Discarding 'a'." << std::endl;
403 start: error-reduce consistent-error 'a' { USE ($3); };
406 'a' 'a' consistent-error 'a' { USE (($1, $2, $4)); }
407 | 'a' error { std::cerr << "Reducing 'a'." << std::endl; USE ($1); }
412 | /*empty*/ %prec 'a'
415 // Provide another context in which all rules are useful so that this
416 // test case looks a little more realistic.
417 start: 'b' consistent-error ;
422 yylex (yy::parser::semantic_type *, yy::location *)
424 static char const *input = "aa";
429 yy::parser::error (const location_type &, const std::string &m)
431 std::cerr << m << std::endl;
438 return parser.parse ();
441 AT_BISON_CHECK([[-o input.cc input.yy]])
442 AT_COMPILE_CXX([[input]])
443 # This used to print "Discarding 'a'." again at the end.
444 AT_PARSER_CHECK([[./input]], [[1]], [[]],