1 # Checking the output filenames. -*- Autotest -*-
3 # Copyright (C) 2004-2005, 2007-2012 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 { yyo << $][$; }
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 #ifndef USE_LEX_SYMBOL
131 typedef yy::parser::token token;
133 typedef yy::parser::location_type location_type;
134 static int stage = -1;
136 if (stage == STAGE_MAX)
138 #if defined USE_LEX_SYMBOL
139 return yy::parser::make_END_OF_FILE (location_type ());
141 *yylloc = location_type ();
142 return token::END_OF_FILE;
147 #if defined USE_LEX_SYMBOL
148 return yy::parser::make_NUMBER (stage, location_type ());
150 # if defined ONE_STAGE_BUILD
151 yylval->build (stage);
153 yylval->build<int>() = stage;
155 *yylloc = location_type ();
156 return token::NUMBER;
161 #if defined USE_LEX_SYMBOL
162 return yy::parser::make_TEXT (string_cast (stage), location_type ());
164 # if defined ONE_STAGE_BUILD
165 yylval->build (string_cast (stage));
167 yylval->build<std::string>() = string_cast (stage);
169 *yylloc = location_type ();
177 yy::parser::error (const yy::parser::location_type&,
178 const std::string& message)
180 std::cerr << message << std::endl;
187 p.set_debug_level (!!getenv ("YYDEBUG"));
192 AT_BISON_CHECK([-o list.cc list.yy])
193 AT_COMPILE_CXX([list])
194 AT_CHECK([./list], 0,
201 AT_CHECK_VARIANTS([])
202 AT_CHECK_VARIANTS([%define parse.assert])
203 AT_CHECK_VARIANTS([[%define parse.assert %code {\n#define ONE_STAGE_BUILD\n}]])
204 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n}]])
205 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n} %define api.tokens.prefix "TOK_"]])
208 ## ----------------------- ##
209 ## Doxygen Documentation. ##
210 ## ----------------------- ##
212 m4_define([AT_CHECK_DOXYGEN],
214 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
215 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
216 [m4_fatal([invalid argument: $1])])
217 AT_SETUP([Doxygen $1 Documentation])
220 [[%skeleton "lalr1.cc"
227 yy::parser::error (const location& l, const std::string& m)
229 std::cerr << l << s << std::endl;
233 AT_BISON_CHECK([-o input.cc input.yy], 0)
236 [# The PROJECT_NAME tag is a single word (or a sequence of words
237 # surrounded by quotes) that should identify the project.
238 PROJECT_NAME = "Bison C++ Parser"
240 # The QUIET tag can be used to turn on/off the messages that are
241 # generated by doxygen. Possible values are YES and NO. If left blank
245 # The WARNINGS tag can be used to turn on/off the warning messages
246 # that are generated by doxygen. Possible values are YES and NO. If
247 # left blank NO is used.
249 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
250 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
251 # this flag will automatically be disabled.
252 WARN_IF_UNDOCUMENTED = YES
253 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
254 # for potential errors in the documentation, such as not documenting
255 # some parameters in a documented function, or documenting parameters
256 # that don't exist or using markup commands wrongly.
257 WARN_IF_DOC_ERROR = YES
258 # The WARN_FORMAT tag determines the format of the warning messages
259 # that doxygen can produce. The string should contain the $file,
260 # $line, and $text tags, which will be replaced by the file and line
261 # number from which the warning originated and the warning text.
262 WARN_FORMAT = "$file:$line: $text"
264 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
265 # entities in documentation are documented, even if no documentation
266 # was available. Private class members and static file members will
267 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
271 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
272 # class will be included in the documentation.
273 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
275 # If the EXTRACT_STATIC tag is set to YES all static members of a file
276 # will be included in the documentation.
277 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
280 AT_CHECK([doxygen --version || exit 77], 0, ignore)
281 AT_CHECK([doxygen], 0, [], [ignore])
285 m4_popdef([AT_DOXYGEN_PRIVATE])
288 AT_CHECK_DOXYGEN([Public])
289 AT_CHECK_DOXYGEN([Private])
296 # AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
297 # ---------------------------------------------------
298 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
299 # is specified, then Bison should accept the input, but compilation will fail,
300 # so don't check compilation.
301 m4_define([AT_CHECK_NAMESPACE],
304 AT_DATA_GRAMMAR([[input.y]],
307 %define api.namespace "]$1["
309 %define global_tokens_and_yystype
313 // YYSTYPE contains a namespace reference.
314 int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
327 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
328 const std::string &msg)
330 std::cerr << "At " << loc << ": " << msg << std::endl;
341 AT_BISON_CHECK([[-o input.cc input.y]])
344 [AT_COMPILE_CXX([[input]], [[input.cc]])
345 AT_PARSER_CHECK([[./input]])])
349 AT_SETUP([[Relative namespace references]])
350 AT_CHECK_NAMESPACE([[foo]])
351 AT_CHECK_NAMESPACE([[foo::bar]])
352 AT_CHECK_NAMESPACE([[foo::bar::baz]])
355 AT_SETUP([[Absolute namespace references]])
356 AT_CHECK_NAMESPACE([[::foo]])
357 AT_CHECK_NAMESPACE([[::foo::bar]])
358 AT_CHECK_NAMESPACE([[::foo::bar::baz]])
359 AT_CHECK_NAMESPACE([[ ::foo]])
360 AT_CHECK_NAMESPACE([[ ::foo::bar]])
361 AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
364 AT_SETUP([[Syntactically invalid namespace references]])
365 AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
366 AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
367 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
368 # contains single occurrences of `:'.
369 AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
370 AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
371 AT_CHECK_NAMESPACE([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
375 ## -------------------------------------- ##
376 ## Syntax error discarding no lookahead. ##
377 ## -------------------------------------- ##
379 # After a syntax error, lalr1.cc used to not check whether there
380 # actually is a lookahead before discarding the lookahead. As a result,
381 # it mistakenly invoked the destructor for the previous lookahead.
383 AT_SETUP([[Syntax error discarding no lookahead]])
385 AT_DATA_GRAMMAR([[input.yy]],
386 [[%skeleton "lalr1.cc"
390 int yylex (yy::parser::semantic_type *);
395 %define parse.error verbose
400 std::cerr << "Discarding 'a'." << std::endl;
405 start: error-reduce consistent-error 'a' { USE ($3); };
408 'a' 'a' consistent-error 'a' { USE (($1, $2, $4)); }
409 | 'a' error { std::cerr << "Reducing 'a'." << std::endl; USE ($1); }
414 | /*empty*/ %prec 'a'
417 // Provide another context in which all rules are useful so that this
418 // test case looks a little more realistic.
419 start: 'b' consistent-error ;
424 yylex (yy::parser::semantic_type *)
426 static char const *input = "aa";
431 yy::parser::error (const std::string &m)
433 std::cerr << m << std::endl;
440 return parser.parse ();
443 AT_BISON_CHECK([[-o input.cc input.yy]])
444 AT_COMPILE_CXX([[input]])
445 # This used to print "Discarding 'a'." again at the end.
446 AT_PARSER_CHECK([[./input]], [[1]], [[]],
455 ## --------------------------- ##
456 ## Syntax error as exception. ##
457 ## --------------------------- ##
459 AT_SETUP([[Syntax error as exception]])
461 AT_DATA_GRAMMAR([[input.yy]],
462 [[%skeleton "lalr1.cc"
467 int yylex (yy::parser::semantic_type *);
472 %define parse.error verbose
482 error { std::cerr << "caught error" << std::endl; }
490 throw yy::parser::syntax_error ("invalid expression");
496 yylex (yy::parser::semantic_type *)
498 // 's': syntax error, 'l': lexical error.
499 static char const *input = "asal";
500 switch (int res = *input++)
503 throw yy::parser::syntax_error ("invalid character");
510 yy::parser::error (const std::string &m)
512 std::cerr << "error: " << m << std::endl;
519 parser.set_debug_level (!!getenv ("YYDEBUG"));
520 return parser.parse ();
523 AT_BISON_CHECK([[-o input.cc input.yy]])
524 AT_COMPILE_CXX([[input]])
526 AT_PARSER_CHECK([[./input]], [[0]], [[]],
527 [[error: invalid expression
529 error: invalid character