1 # Checking the output filenames. -*- Autotest -*-
3 # Copyright (C) 2004-2005, 2007-2011 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[C++ Features.]])
25 # AT_CHECK_VARIANTS([DIRECTIVES])
26 # -------------------------------
27 # Check the support of variants in C++, with the additional DIRECTIVES.
28 m4_define([AT_CHECK_VARIANTS],
29 [AT_SETUP([Variants $1])
31 # Store strings and integers in a list of strings.
32 AT_DATA_GRAMMAR([list.yy],
38 ]m4_bpatsubst([$1], [\\n], [
41 %code requires // code for the .hh file
45 typedef std::list<std::string> strings_type;
48 %code // code for the .cc file
54 #if defined USE_LEX_SYMBOL
55 yy::parser::symbol_type yylex ();
57 yy::parser::token_type yylex (yy::parser::semantic_type* yylval,
58 yy::parser::location_type* yylloc);
61 // Printing a list of strings (for %printer).
62 // Koening look up will look into std, since that's an std::list.
66 operator<<(std::ostream& o, const strings_type& s)
69 for (strings_type::const_iterator i = s.begin(); i != s.end (); ++i)
79 // Conversion to string.
83 string_cast (const T& t)
91 %token <::std::string> TEXT;
95 %type <::std::string> item;
96 // Using the template type to exercize its parsing.
97 // Starting with :: to ensure we don't output "<::" which starts by the
98 // digraph for the left square bracket.
99 %type <::std::list<std::string>> list result;
101 %printer { debug_stream() << $][$; }
102 <int> <::std::string> <::std::list<::std::string>>;
106 list { std::cout << $][1 << std::endl; }
110 /* nothing */ { /* Generates an empty string list */ }
111 | list item { std::swap($][$,$][1); $$.push_back($][2); }
112 | list error { std::swap($][$,$][1); }
116 TEXT { std::swap($][$,$][1); }
117 | NUMBER { if ($][1 == 3) YYERROR; else $][$ = string_cast($][1); }
123 #if defined USE_LEX_SYMBOL
124 yy::parser::symbol_type yylex()
126 yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
127 yy::parser::location_type* yylloc)
130 typedef yy::parser::token token;
131 typedef yy::parser::location_type location_type;
132 static int stage = -1;
134 if (stage == STAGE_MAX)
136 #if defined USE_LEX_SYMBOL
137 return yy::parser::make_END_OF_FILE (location_type ());
139 *yylloc = location_type ();
140 return token::END_OF_FILE;
145 #if defined USE_LEX_SYMBOL
146 return yy::parser::make_NUMBER (stage, location_type ());
148 # if defined ONE_STAGE_BUILD
149 yylval->build(stage);
151 yylval->build<int>() = stage;
153 *yylloc = location_type ();
154 return token::NUMBER;
159 #if defined USE_LEX_SYMBOL
160 return yy::parser::make_TEXT (string_cast (stage), location_type ());
162 # if defined ONE_STAGE_BUILD
163 yylval->build (string_cast (stage));
165 yylval->build<std::string>() = string_cast (stage);
167 *yylloc = location_type ();
175 yy::parser::error(const yy::parser::location_type&,
176 const std::string& message)
178 std::cerr << message << std::endl;
185 p.set_debug_level(!!getenv("YYDEBUG"));
190 AT_BISON_CHECK([-o list.cc list.yy])
191 AT_COMPILE_CXX([list])
192 AT_CHECK([./list], 0,
199 AT_CHECK_VARIANTS([])
200 AT_CHECK_VARIANTS([%define parse.assert])
201 AT_CHECK_VARIANTS([[%define parse.assert %code {\n#define ONE_STAGE_BUILD\n}]])
202 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n}]])
203 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n} %define api.tokens.prefix "TOK_"]])
206 ## ----------------------- ##
207 ## Doxygen Documentation. ##
208 ## ----------------------- ##
210 m4_define([AT_CHECK_DOXYGEN],
212 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
213 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
214 [m4_fatal([invalid argument: $1])])
215 AT_SETUP([Doxygen $1 Documentation])
218 [[%skeleton "lalr1.cc"
225 yy::parser::error (const location& l, const std::string& m)
227 std::cerr << l << s << std::endl;
231 AT_BISON_CHECK([-o input.cc input.yy], 0)
234 [# The PROJECT_NAME tag is a single word (or a sequence of words
235 # surrounded by quotes) that should identify the project.
236 PROJECT_NAME = "Bison C++ Parser"
238 # The QUIET tag can be used to turn on/off the messages that are
239 # generated by doxygen. Possible values are YES and NO. If left blank
243 # The WARNINGS tag can be used to turn on/off the warning messages
244 # that are generated by doxygen. Possible values are YES and NO. If
245 # left blank NO is used.
247 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
248 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
249 # this flag will automatically be disabled.
250 WARN_IF_UNDOCUMENTED = YES
251 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
252 # for potential errors in the documentation, such as not documenting
253 # some parameters in a documented function, or documenting parameters
254 # that don't exist or using markup commands wrongly.
255 WARN_IF_DOC_ERROR = YES
256 # The WARN_FORMAT tag determines the format of the warning messages
257 # that doxygen can produce. The string should contain the $file,
258 # $line, and $text tags, which will be replaced by the file and line
259 # number from which the warning originated and the warning text.
260 WARN_FORMAT = "$file:$line: $text"
262 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
263 # entities in documentation are documented, even if no documentation
264 # was available. Private class members and static file members will
265 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
269 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
270 # class will be included in the documentation.
271 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
273 # If the EXTRACT_STATIC tag is set to YES all static members of a file
274 # will be included in the documentation.
275 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
278 AT_CHECK([doxygen --version || exit 77], 0, ignore)
279 AT_CHECK([doxygen], 0, [], [ignore])
283 m4_popdef([AT_DOXYGEN_PRIVATE])
286 AT_CHECK_DOXYGEN([Public])
287 AT_CHECK_DOXYGEN([Private])
294 # AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
295 # ---------------------------------------------------
296 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
297 # is specified, then Bison should accept the input, but compilation will fail,
298 # so don't check compilation.
299 m4_define([AT_CHECK_NAMESPACE],
302 AT_DATA_GRAMMAR([[input.y]],
305 %define api.namespace "]$1["
307 %define global_tokens_and_yystype
311 // YYSTYPE contains a namespace reference.
312 int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
325 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
326 const std::string &msg)
328 std::cerr << "At " << loc << ": " << msg << std::endl;
339 AT_BISON_CHECK([[-o input.cc input.y]])
342 [AT_COMPILE_CXX([[input]], [[input.cc]])
343 AT_PARSER_CHECK([[./input]])])
347 AT_SETUP([[Relative namespace references]])
348 AT_CHECK_NAMESPACE([[foo]])
349 AT_CHECK_NAMESPACE([[foo::bar]])
350 AT_CHECK_NAMESPACE([[foo::bar::baz]])
353 AT_SETUP([[Absolute namespace references]])
354 AT_CHECK_NAMESPACE([[::foo]])
355 AT_CHECK_NAMESPACE([[::foo::bar]])
356 AT_CHECK_NAMESPACE([[::foo::bar::baz]])
357 AT_CHECK_NAMESPACE([[ ::foo]])
358 AT_CHECK_NAMESPACE([[ ::foo::bar]])
359 AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
362 AT_SETUP([[Syntactically invalid namespace references]])
363 AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
364 AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
365 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
366 # contains single occurrences of `:'.
367 AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
368 AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
369 AT_CHECK_NAMESPACE([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
373 ## -------------------------------------- ##
374 ## Syntax error discarding no lookahead. ##
375 ## -------------------------------------- ##
377 # After a syntax error, lalr1.cc used to not check whether there
378 # actually is a lookahead before discarding the lookahead. As a result,
379 # it mistakenly invoked the destructor for the previous lookahead.
381 AT_SETUP([[Syntax error discarding no lookahead]])
383 AT_DATA_GRAMMAR([[input.yy]],
384 [[%skeleton "lalr1.cc"
388 int yylex (yy::parser::semantic_type *, yy::location *);
394 %define parse.error verbose
399 std::cerr << "Discarding 'a'." << std::endl;
404 start: error-reduce consistent-error 'a' { USE ($3); };
407 'a' 'a' consistent-error 'a' { USE (($1, $2, $4)); }
408 | 'a' error { std::cerr << "Reducing 'a'." << std::endl; USE ($1); }
413 | /*empty*/ %prec 'a'
416 // Provide another context in which all rules are useful so that this
417 // test case looks a little more realistic.
418 start: 'b' consistent-error ;
423 yylex (yy::parser::semantic_type *, yy::location *)
425 static char const *input = "aa";
430 yy::parser::error (const location_type &, const std::string &m)
432 std::cerr << m << std::endl;
439 return parser.parse ();
442 AT_BISON_CHECK([[-o input.cc input.yy]])
443 AT_COMPILE_CXX([[input]])
444 # This used to print "Discarding 'a'." again at the end.
445 AT_PARSER_CHECK([[./input]], [[1]], [[]],