]> git.saurik.com Git - bison.git/blame - tests/c++.at
Test variants.
[bison.git] / tests / c++.at
CommitLineData
e019c247 1# Checking the output filenames. -*- Autotest -*-
76307410 2# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
e019c247 3
f16b0819 4# This program is free software: you can redistribute it and/or modify
e019c247 5# it under the terms of the GNU General Public License as published by
f16b0819
PE
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
e019c247
AD
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.
f16b0819 13#
e019c247 14# You should have received a copy of the GNU General Public License
f16b0819 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
e019c247
AD
16
17AT_BANNER([[C++ Features.]])
18
19
76307410
AD
20## ---------- ##
21## Variants. ##
22## ---------- ##
23
24# AT_CHECK_VARIANTS([DIRECTIVES])
25# -------------------------------
26# Check the support of variants in C++, with the additional DIRECTIVES.
27m4_define([AT_CHECK_VARIANTS],
28[AT_SETUP([Variants $1])
29
30# Store strings and integers in a list of strings.
31AT_DATA([list.yy],
32[[%debug
33%skeleton "lalr1.cc"
34%defines
35%define variant
36
37%code requires // code for the .hh file
38{
39#include <list>
40#include <string>
41typedef std::list<std::string> strings_type;
42}
43
44%code // code for the .cc file
45{
46#include <algorithm>
47#include <iostream>
48#include <iterator>
49#include <sstream>
50
51 // Prototype of the yylex function providing subsequent tokens.
52 static yy::parser::token_type yylex(yy::parser::semantic_type* yylval);
53
54 // Printing a list of strings.
55 // Koening look up will look into std, since that's an std::list.
56 namespace std
57 {
58 std::ostream&
59 operator<<(std::ostream& o, const strings_type& s)
60 {
61 std::copy(s.begin(), s.end(),
62 std::ostream_iterator<strings_type::value_type>(o, "\n"));
63 return o;
64 }
65 }
66
67 // Conversion to string.
68 template <typename T>
69 inline
70 std::string
71 string_cast (const T& t)
72 {
73 std::ostringstream o;
74 o << t;
75 return o.str();
76 }
77}
78
79%token <std::string> TEXT;
80%token <int> NUMBER;
81%printer { debug_stream() << $][$; } <int> <std::string> <strings_type>;
82%token END_OF_FILE 0;
83
84%type <std::string> item;
85%type <strings_type> list result;
86
87%%
88
89result:
90 list { std::cout << $][1; }
91;
92
93list:
94 /* nothing */ { /* Generates an empty string list */ }
95| list item { std::swap($][$,$][1); $$.push_back($][2); }
96;
97
98item:
99 TEXT { std::swap($][$,$][1); }
100| NUMBER { $][$ = string_cast($][1); }
101;
102%%
103
104static
105yy::parser::token_type
106yylex(yy::parser::semantic_type* yylval)
107{
108 static int stage = 0;
109 yy::parser::token_type result;
110
111 switch (stage)
112 {
113 case 0:
114 yylval->build<std::string>() = std::string("BEGIN");
115 result = yy::parser::token::TEXT;
116 break;
117 case 1:
118 case 2:
119 case 3:
120 yylval->build<int>() = stage;
121 result = yy::parser::token::NUMBER;
122 break;
123 case 4:
124 yylval->build<std::string>() = std::string("END");
125 result = yy::parser::token::TEXT;
126 break;
127 default:
128 result = yy::parser::token::END_OF_FILE;
129 break;
130 }
131
132 ++stage;
133 return result;
134}
135
136// Mandatory error function
137void
138yy::parser::error(const yy::parser::location_type& yylloc,
139 const std::string& message)
140{
141 std::cerr << yylloc << ": " << message << std::endl;
142}
143
144int main(int argc, char *argv[])
145{
146 yy::parser p;
147 p.set_debug_level(!!getenv("YYDEBUG"));
148 return p.parse();
149}
150]])
151
152AT_BISON_CHECK([-o list.cc list.yy], 0)
153AT_COMPILE_CXX([list])
154AT_CHECK([./list], 0,
155[BEGIN
1561
1572
1583
159END
160])
161
162AT_CLEANUP
163])
164
165AT_CHECK_VARIANTS([])
166AT_CHECK_VARIANTS([%define assert])
167
168
e019c247
AD
169## ----------------------- ##
170## Doxygen Documentation. ##
171## ----------------------- ##
172
173m4_define([AT_CHECK_DOXYGEN],
174[m4_case([$1],
175 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
176 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
177 [m4_fatal([invalid argument: $1])])
178AT_SETUP([Doxygen $1 Documentation])
179
180AT_DATA([input.yy],
181[[%skeleton "lalr1.cc"
182%locations
183%debug
184%defines
185%%
186exp:;
187%%
188yy::parser::error (const location& l, const std::string& m)
189{
190 std::cerr << l << s << std::endl;
191}
192]])
193
da730230 194AT_BISON_CHECK([-o input.cc input.yy], 0)
e019c247
AD
195
196AT_DATA([Doxyfile],
197[# The PROJECT_NAME tag is a single word (or a sequence of words
198# surrounded by quotes) that should identify the project.
199PROJECT_NAME = "Bison C++ Parser"
200
201# The QUIET tag can be used to turn on/off the messages that are
202# generated by doxygen. Possible values are YES and NO. If left blank
203# NO is used.
204QUIET = YES
205
206# The WARNINGS tag can be used to turn on/off the warning messages
207# that are generated by doxygen. Possible values are YES and NO. If
208# left blank NO is used.
209WARNINGS = YES
210# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
211# warnings for undocumented members. If EXTRACT_ALL is set to YES then
212# this flag will automatically be disabled.
213WARN_IF_UNDOCUMENTED = YES
214# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
215# for potential errors in the documentation, such as not documenting
216# some parameters in a documented function, or documenting parameters
217# that don't exist or using markup commands wrongly.
218WARN_IF_DOC_ERROR = YES
219# The WARN_FORMAT tag determines the format of the warning messages
220# that doxygen can produce. The string should contain the $file,
221# $line, and $text tags, which will be replaced by the file and line
222# number from which the warning originated and the warning text.
223WARN_FORMAT = "$file:$line: $text"
224
225# If the EXTRACT_ALL tag is set to YES doxygen will assume all
226# entities in documentation are documented, even if no documentation
227# was available. Private class members and static file members will
228# be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
229# to YES
230EXTRACT_ALL = YES
231
232# If the EXTRACT_PRIVATE tag is set to YES all private members of a
233# class will be included in the documentation.
234EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
235
236# If the EXTRACT_STATIC tag is set to YES all static members of a file
237# will be included in the documentation.
238EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
239])
240
241AT_CHECK([doxygen --version || exit 77], 0, ignore)
242AT_CHECK([doxygen], 0, [], [ignore])
243
244AT_CLEANUP
245
246m4_popdef([AT_DOXYGEN_PRIVATE])
247])# AT_CHECK_DOXYGEN
248
249AT_CHECK_DOXYGEN([Public])
250AT_CHECK_DOXYGEN([Private])
793fbca5 251
76307410
AD
252
253
254
793fbca5
JD
255## ------------ ##
256## Namespaces. ##
257## ------------ ##
258
259# AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
260# ---------------------------------------------------
261# See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
262# is specified, then Bison should accept the input, but compilation will fail,
263# so don't check compilation.
264m4_define([AT_CHECK_NAMESPACE],
265[
266
267AT_DATA_GRAMMAR([[input.y]],
268[[%language "C++"
269%defines
270%define namespace "]$1["
271%union { int i; }
272%define global_tokens_and_yystype
273
274%code {
275 // YYSTYPE contains a namespace reference.
276 int yylex (YYSTYPE *lval) {
277 lval->i = 3;
278 return 0;
279 }
280}
281
282%%
283
284start: ;
285
286%%
287
288void
289]$1[::parser::error (const ]$1[::parser::location_type &loc,
290 const std::string &msg)
291{
292 std::cerr << "At " << loc << ": " << msg << std::endl;
293}
294
295int
296main (void)
297{
298 ]$1[::parser p;
299 return p.parse ();
300}
301]])
302
da730230 303AT_BISON_CHECK([[-o input.cc input.y]])
793fbca5
JD
304
305m4_if([$#], [1],
306[AT_COMPILE_CXX([[input]], [[input.cc]])
307AT_PARSER_CHECK([[./input]])])
308
309])
310
311AT_SETUP([[Relative namespace references]])
312AT_CHECK_NAMESPACE([[foo]])
313AT_CHECK_NAMESPACE([[foo::bar]])
314AT_CHECK_NAMESPACE([[foo::bar::baz]])
315AT_CLEANUP
316
317AT_SETUP([[Absolute namespace references]])
318AT_CHECK_NAMESPACE([[::foo]])
319AT_CHECK_NAMESPACE([[::foo::bar]])
320AT_CHECK_NAMESPACE([[::foo::bar::baz]])
321AT_CHECK_NAMESPACE([[ ::foo]])
322AT_CHECK_NAMESPACE([[ ::foo::bar]])
323AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
324AT_CLEANUP
325
326AT_SETUP([[Syntactically invalid namespace references]])
327AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
328AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
329# This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
330# contains single occurrences of `:'.
331AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
332AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
333AT_CHECK_NAMESPACE([[foo::bar::(baz]], [[-]])
334AT_CLEANUP