1 # Checking the C++ Features. -*- Autotest -*-
3 # Copyright (C) 2004-2005, 2007, 2009-2012 Free Software Foundation,
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.]])
22 ## ----------------------- ##
23 ## Doxygen Documentation. ##
24 ## ----------------------- ##
26 m4_define([AT_CHECK_DOXYGEN],
28 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
29 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
30 [m4_fatal([invalid argument: $1])])
31 AT_SETUP([Doxygen $1 Documentation])
33 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
35 [[%skeleton "lalr1.cc"
45 AT_BISON_CHECK([-o input.cc input.yy], 0)
48 [# The PROJECT_NAME tag is a single word (or a sequence of words
49 # surrounded by quotes) that should identify the project.
50 PROJECT_NAME = "Bison C++ Parser"
52 # The QUIET tag can be used to turn on/off the messages that are
53 # generated by doxygen. Possible values are YES and NO. If left blank
57 # The WARNINGS tag can be used to turn on/off the warning messages
58 # that are generated by doxygen. Possible values are YES and NO. If
59 # left blank NO is used.
61 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
62 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
63 # this flag will automatically be disabled.
64 WARN_IF_UNDOCUMENTED = YES
65 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
66 # for potential errors in the documentation, such as not documenting
67 # some parameters in a documented function, or documenting parameters
68 # that don't exist or using markup commands wrongly.
69 WARN_IF_DOC_ERROR = YES
70 # The WARN_FORMAT tag determines the format of the warning messages
71 # that doxygen can produce. The string should contain the $file,
72 # $line, and $text tags, which will be replaced by the file and line
73 # number from which the warning originated and the warning text.
74 WARN_FORMAT = "$file:$line: $text"
76 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
77 # entities in documentation are documented, even if no documentation
78 # was available. Private class members and static file members will
79 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
83 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
84 # class will be included in the documentation.
85 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
87 # If the EXTRACT_STATIC tag is set to YES all static members of a file
88 # will be included in the documentation.
89 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
92 AT_CHECK([doxygen --version || exit 77], 0, ignore)
93 AT_CHECK([doxygen], 0, [], [ignore])
95 AT_BISON_OPTION_POPDEFS
98 m4_popdef([AT_DOXYGEN_PRIVATE])
101 AT_CHECK_DOXYGEN([Public])
102 AT_CHECK_DOXYGEN([Private])
108 # AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
109 # ---------------------------------------------------
110 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
111 # is specified, then Bison should accept the input, but compilation will fail,
112 # so don't check compilation.
113 m4_define([AT_CHECK_NAMESPACE],
116 AT_DATA_GRAMMAR([[input.y]],
119 %define namespace "]$1["
121 %define global_tokens_and_yystype
124 // YYSTYPE contains a namespace reference.
125 int yylex (YYSTYPE *lval) {
138 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
139 const std::string &msg)
141 std::cerr << "At " << loc << ": " << msg << std::endl;
152 AT_BISON_CHECK([[-o input.cc input.y]])
155 [AT_COMPILE_CXX([[input]], [[input.cc]])
156 AT_PARSER_CHECK([[./input]])])
160 AT_SETUP([[Relative namespace references]])
161 AT_CHECK_NAMESPACE([[foo]])
162 AT_CHECK_NAMESPACE([[foo::bar]])
163 AT_CHECK_NAMESPACE([[foo::bar::baz]])
166 AT_SETUP([[Absolute namespace references]])
167 AT_CHECK_NAMESPACE([[::foo]])
168 AT_CHECK_NAMESPACE([[::foo::bar]])
169 AT_CHECK_NAMESPACE([[::foo::bar::baz]])
170 AT_CHECK_NAMESPACE([[ ::foo]])
171 AT_CHECK_NAMESPACE([[ ::foo::bar]])
172 AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
175 AT_SETUP([[Syntactically invalid namespace references]])
176 AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
177 AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
178 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
179 # contains single occurrences of `:'.
180 AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
181 AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
182 AT_CHECK_NAMESPACE([[foo::bar::(baz]], [[-]])
186 ## ------------------ ##
187 ## Exception safety. ##
188 ## ------------------ ##
190 AT_SETUP([[Exception safety]])
192 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
194 AT_DATA_GRAMMAR([[input.yy]],
195 [[%skeleton "lalr1.cc"
196 %defines // FIXME: Mandated in 2.6.
203 #include <cstdlib> // size_t and getenv.
209 /// A class that counts its number of instances.
212 typedef std::list<const Object*> objects;
213 static objects instances;
219 return instances.empty();
223 log (Object const *o, const std::string& msg)
228 std::cerr << o << "->";
229 std::cerr << msg << " {";
230 const char* sep = " ";
231 for (objects::const_iterator i = instances.begin(),
232 i_end = instances.end();
236 std::cerr << sep << *i;
239 std::cerr << " }" << std::endl;
246 instances.push_back(this);
247 log (this, "Object::Object");
252 instances.remove(this);
253 log (this, "Object::~Object");
261 #include <cstring> // strchr
263 int yylex (yy::parser::semantic_type *);
264 Object::objects Object::instances;
265 static char const *input;
275 if (strchr (input, 'i'))
276 throw std::runtime_error ("initial-action");
279 %destructor { delete $$; } <obj>;
282 yyo << $$ << " '" << $$->val << '\'';
284 throw std::runtime_error ("printer");
287 %token <obj> 'a' 'E' 'e' 'p' 'R' 's' 'T'
288 %type <obj> list item
292 start: list { delete $1; };
296 | item list { $$ = $1; delete $2; } // Right recursion to load the stack.
301 | 'e' { YYUSE ($$); YYUSE($1); error (location_type(), "syntax error"); }
302 // Not just 'E', otherwise we reduce when 'E' is the lookahead, and
303 // then the stack is emptied, defeating the point of the test.
304 | 'E' 'a' { YYUSE($1); $$ = $2; }
305 | 'R' { $$ = YY_NULL; delete $1; YYERROR; }
307 | 's' { $$ = $1; throw std::runtime_error ("reduction"); }
308 | 'T' { $$ = YY_NULL; delete $1; YYABORT; }
309 | error { $$ = YY_NULL; yyerrok; }
314 yylex (yy::parser::semantic_type *lvalp)
317 // 'e': user action calls error.
318 // 'E': syntax error, with yyerror that throws.
319 // 'i': initial action throws.
320 // 'l': yylex throws.
321 // 'R': call YYERROR in the action
322 // 's': reduction throws.
323 // 'T': call YYABORT in the action
324 switch (int res = *input++)
327 throw std::runtime_error ("yylex");
329 lvalp->obj = new Object (res);
336 /* A C++ error reporting function. */
338 yy::parser::error (const location_type& l, const std::string& m)
341 throw std::runtime_error (m);
345 main (int argc, const char *argv[])
353 assert (!strcmp (argv[1], "--debug"));
362 debug |= !!getenv ("YYDEBUG");
363 parser.set_debug_level (debug);
367 res = parser.parse ();
369 catch (const std::exception& e)
371 std::cerr << "exception caught: " << e.what () << std::endl;
375 std::cerr << "unknown exception caught" << std::endl;
377 Object::log (YY_NULL, "end");
378 assert (Object::empty());
382 AT_BISON_CHECK([[-o input.cc --report=all input.yy]])
383 AT_COMPILE_CXX([[input]])
385 AT_PARSER_CHECK([[./input aaaas]], [[2]], [[]],
386 [[exception caught: reduction
389 AT_PARSER_CHECK([[./input aaaal]], [[2]], [[]],
390 [[exception caught: yylex
393 AT_PARSER_CHECK([[./input i]], [[2]], [[]],
394 [[exception caught: initial-action
397 AT_PARSER_CHECK([[./input aaaap]])
399 AT_PARSER_CHECK([[./input --debug aaaap]], [[2]], [[]], [[stderr]])
400 AT_PARSER_CHECK([[grep '^exception caught: printer$' stderr]], [], [ignore])
402 AT_PARSER_CHECK([[./input aaaae]], [[2]], [[]],
403 [[exception caught: syntax error
406 AT_PARSER_CHECK([[./input aaaaE]], [[2]], [[]],
407 [[exception caught: syntax error, unexpected $end, expecting 'a'
410 AT_PARSER_CHECK([[./input aaaaT]], [[1]])
412 # There is error-recovery, so exit success.
413 AT_PARSER_CHECK([[./input aaaaR]], [[0]])
415 AT_BISON_OPTION_POPDEFS