1 # Checking the output filenames. -*- Autotest -*-
3 # Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010 Free Software
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 AT_BANNER([[C++ Features.]])
26 # AT_CHECK_VARIANTS([DIRECTIVES])
27 # -------------------------------
28 # Check the support of variants in C++, with the additional DIRECTIVES.
29 m4_define([AT_CHECK_VARIANTS],
30 [AT_SETUP([Variants $1])
32 # Store strings and integers in a list of strings.
33 AT_DATA_GRAMMAR([list.yy],
39 ]m4_bpatsubst([$1], [\\n], [
42 %code requires // code for the .hh file
46 typedef std::list<std::string> strings_type;
49 %code // code for the .cc file
55 #if defined USE_LEX_SYMBOL
56 yy::parser::symbol_type yylex ();
58 yy::parser::token_type yylex (yy::parser::semantic_type* yylval,
59 yy::parser::location_type* yylloc);
62 // Printing a list of strings (for %printer).
63 // Koening look up will look into std, since that's an std::list.
67 operator<<(std::ostream& o, const strings_type& s)
70 for (strings_type::const_iterator i = s.begin(); i != s.end (); ++i)
80 // Conversion to string.
84 string_cast (const T& t)
92 %token <::std::string> TEXT;
96 %type <::std::string> item;
97 // Using the template type to exercize its parsing.
98 // Starting with :: to ensure we don't output "<::" which starts by the
99 // digraph for the left square bracket.
100 %type <::std::list<std::string>> list result;
102 %printer { debug_stream() << $][$; }
103 <int> <::std::string> <::std::list<::std::string>>;
107 list { std::cout << $][1 << std::endl; }
111 /* nothing */ { /* Generates an empty string list */ }
112 | list item { std::swap($][$,$][1); $$.push_back($][2); }
113 | list error { std::swap($][$,$][1); }
117 TEXT { std::swap($][$,$][1); }
118 | NUMBER { if ($][1 == 3) YYERROR; else $][$ = string_cast($][1); }
124 #if defined USE_LEX_SYMBOL
125 yy::parser::symbol_type yylex()
127 yy::parser::token_type yylex(yy::parser::semantic_type* yylval,
128 yy::parser::location_type* yylloc)
131 typedef yy::parser::token token;
132 typedef yy::parser::location_type location_type;
133 static int stage = -1;
135 if (stage == STAGE_MAX)
137 #if defined USE_LEX_SYMBOL
138 return yy::parser::make_END_OF_FILE (location_type ());
140 *yylloc = location_type ();
141 return token::END_OF_FILE;
146 #if defined USE_LEX_SYMBOL
147 return yy::parser::make_NUMBER (stage, location_type ());
149 # if defined ONE_STAGE_BUILD
150 yylval->build(stage);
152 yylval->build<int>() = stage;
154 *yylloc = location_type ();
155 return token::NUMBER;
160 #if defined USE_LEX_SYMBOL
161 return yy::parser::make_TEXT (string_cast (stage), location_type ());
163 # if defined ONE_STAGE_BUILD
164 yylval->build (string_cast (stage));
166 yylval->build<std::string>() = string_cast (stage);
168 *yylloc = location_type ();
176 yy::parser::error(const yy::parser::location_type&,
177 const std::string& message)
179 std::cerr << message << std::endl;
186 p.set_debug_level(!!getenv("YYDEBUG"));
191 AT_BISON_CHECK([-o list.cc list.yy])
192 AT_COMPILE_CXX([list])
193 AT_CHECK([./list], 0,
200 AT_CHECK_VARIANTS([])
201 AT_CHECK_VARIANTS([%define parse.assert])
202 AT_CHECK_VARIANTS([[%define parse.assert %code {\n#define ONE_STAGE_BUILD\n}]])
203 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n}]])
204 AT_CHECK_VARIANTS([[%define parse.assert %define lex_symbol %code {\n#define USE_LEX_SYMBOL\n} %define api.tokens.prefix "TOK_"]])
207 ## ----------------------- ##
208 ## Doxygen Documentation. ##
209 ## ----------------------- ##
211 m4_define([AT_CHECK_DOXYGEN],
213 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
214 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
215 [m4_fatal([invalid argument: $1])])
216 AT_SETUP([Doxygen $1 Documentation])
219 [[%skeleton "lalr1.cc"
226 yy::parser::error (const location& l, const std::string& m)
228 std::cerr << l << s << std::endl;
232 AT_BISON_CHECK([-o input.cc input.yy], 0)
235 [# The PROJECT_NAME tag is a single word (or a sequence of words
236 # surrounded by quotes) that should identify the project.
237 PROJECT_NAME = "Bison C++ Parser"
239 # The QUIET tag can be used to turn on/off the messages that are
240 # generated by doxygen. Possible values are YES and NO. If left blank
244 # The WARNINGS tag can be used to turn on/off the warning messages
245 # that are generated by doxygen. Possible values are YES and NO. If
246 # left blank NO is used.
248 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
249 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
250 # this flag will automatically be disabled.
251 WARN_IF_UNDOCUMENTED = YES
252 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
253 # for potential errors in the documentation, such as not documenting
254 # some parameters in a documented function, or documenting parameters
255 # that don't exist or using markup commands wrongly.
256 WARN_IF_DOC_ERROR = YES
257 # The WARN_FORMAT tag determines the format of the warning messages
258 # that doxygen can produce. The string should contain the $file,
259 # $line, and $text tags, which will be replaced by the file and line
260 # number from which the warning originated and the warning text.
261 WARN_FORMAT = "$file:$line: $text"
263 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
264 # entities in documentation are documented, even if no documentation
265 # was available. Private class members and static file members will
266 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
270 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
271 # class will be included in the documentation.
272 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
274 # If the EXTRACT_STATIC tag is set to YES all static members of a file
275 # will be included in the documentation.
276 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
279 AT_CHECK([doxygen --version || exit 77], 0, ignore)
280 AT_CHECK([doxygen], 0, [], [ignore])
284 m4_popdef([AT_DOXYGEN_PRIVATE])
287 AT_CHECK_DOXYGEN([Public])
288 AT_CHECK_DOXYGEN([Private])
295 # AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
296 # ---------------------------------------------------
297 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
298 # is specified, then Bison should accept the input, but compilation will fail,
299 # so don't check compilation.
300 m4_define([AT_CHECK_NAMESPACE],
303 AT_DATA_GRAMMAR([[input.y]],
306 %define api.namespace "]$1["
308 %define global_tokens_and_yystype
312 // YYSTYPE contains a namespace reference.
313 int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
326 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
327 const std::string &msg)
329 std::cerr << "At " << loc << ": " << msg << std::endl;
340 AT_BISON_CHECK([[-o input.cc input.y]])
343 [AT_COMPILE_CXX([[input]], [[input.cc]])
344 AT_PARSER_CHECK([[./input]])])
348 AT_SETUP([[Relative namespace references]])
349 AT_CHECK_NAMESPACE([[foo]])
350 AT_CHECK_NAMESPACE([[foo::bar]])
351 AT_CHECK_NAMESPACE([[foo::bar::baz]])
354 AT_SETUP([[Absolute namespace references]])
355 AT_CHECK_NAMESPACE([[::foo]])
356 AT_CHECK_NAMESPACE([[::foo::bar]])
357 AT_CHECK_NAMESPACE([[::foo::bar::baz]])
358 AT_CHECK_NAMESPACE([[ ::foo]])
359 AT_CHECK_NAMESPACE([[ ::foo::bar]])
360 AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
363 AT_SETUP([[Syntactically invalid namespace references]])
364 AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
365 AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
366 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
367 # contains single occurrences of `:'.
368 AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
369 AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
370 AT_CHECK_NAMESPACE([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
374 ## -------------------------------------- ##
375 ## Syntax error discarding no lookahead. ##
376 ## -------------------------------------- ##
378 # After a syntax error, lalr1.cc used to not check whether there
379 # actually is a lookahead before discarding the lookahead. As a result,
380 # it mistakenly invoked the destructor for the previous lookahead.
382 AT_SETUP([[Syntax error discarding no lookahead]])
384 AT_DATA_GRAMMAR([[input.yy]],
385 [[%skeleton "lalr1.cc"
389 int yylex (yy::parser::semantic_type *, yy::location *);
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 *, yy::location *)
426 static char const *input = "aa";
431 yy::parser::error (const location_type &, 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]], [[]],