]> git.saurik.com Git - bison.git/blob - tests/c++.at
d351d41b6bbf658a25e84d7990e382c88401db74
[bison.git] / tests / c++.at
1 # Checking the output filenames. -*- Autotest -*-
2 # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_BANNER([[C++ Features.]])
18
19
20 ## ---------- ##
21 ## Variants. ##
22 ## ---------- ##
23
24 # AT_CHECK_VARIANTS([DIRECTIVES])
25 # -------------------------------
26 # Check the support of variants in C++, with the additional DIRECTIVES.
27 m4_define([AT_CHECK_VARIANTS],
28 [AT_SETUP([Variants $1])
29
30 # Store strings and integers in a list of strings.
31 AT_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>
41 typedef 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
89 result:
90 list { std::cout << $][1; }
91 ;
92
93 list:
94 /* nothing */ { /* Generates an empty string list */ }
95 | list item { std::swap($][$,$][1); $$.push_back($][2); }
96 ;
97
98 item:
99 TEXT { std::swap($][$,$][1); }
100 | NUMBER { $][$ = string_cast($][1); }
101 ;
102 %%
103
104 static
105 yy::parser::token_type
106 yylex(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
137 void
138 yy::parser::error(const yy::parser::location_type& yylloc,
139 const std::string& message)
140 {
141 std::cerr << yylloc << ": " << message << std::endl;
142 }
143
144 int main(int argc, char *argv[])
145 {
146 yy::parser p;
147 p.set_debug_level(!!getenv("YYDEBUG"));
148 return p.parse();
149 }
150 ]])
151
152 AT_BISON_CHECK([-o list.cc list.yy], 0)
153 AT_COMPILE_CXX([list])
154 AT_CHECK([./list], 0,
155 [BEGIN
156 1
157 2
158 3
159 END
160 ])
161
162 AT_CLEANUP
163 ])
164
165 AT_CHECK_VARIANTS([])
166 AT_CHECK_VARIANTS([%define assert])
167
168
169 ## ----------------------- ##
170 ## Doxygen Documentation. ##
171 ## ----------------------- ##
172
173 m4_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])])
178 AT_SETUP([Doxygen $1 Documentation])
179
180 AT_DATA([input.yy],
181 [[%skeleton "lalr1.cc"
182 %locations
183 %debug
184 %defines
185 %%
186 exp:;
187 %%
188 yy::parser::error (const location& l, const std::string& m)
189 {
190 std::cerr << l << s << std::endl;
191 }
192 ]])
193
194 AT_BISON_CHECK([-o input.cc input.yy], 0)
195
196 AT_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.
199 PROJECT_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.
204 QUIET = 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.
209 WARNINGS = 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.
213 WARN_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.
218 WARN_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.
223 WARN_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
230 EXTRACT_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.
234 EXTRACT_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.
238 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
239 ])
240
241 AT_CHECK([doxygen --version || exit 77], 0, ignore)
242 AT_CHECK([doxygen], 0, [], [ignore])
243
244 AT_CLEANUP
245
246 m4_popdef([AT_DOXYGEN_PRIVATE])
247 ])# AT_CHECK_DOXYGEN
248
249 AT_CHECK_DOXYGEN([Public])
250 AT_CHECK_DOXYGEN([Private])
251
252
253
254
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.
264 m4_define([AT_CHECK_NAMESPACE],
265 [
266
267 AT_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
284 start: ;
285
286 %%
287
288 void
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
295 int
296 main (void)
297 {
298 ]$1[::parser p;
299 return p.parse ();
300 }
301 ]])
302
303 AT_BISON_CHECK([[-o input.cc input.y]])
304
305 m4_if([$#], [1],
306 [AT_COMPILE_CXX([[input]], [[input.cc]])
307 AT_PARSER_CHECK([[./input]])])
308
309 ])
310
311 AT_SETUP([[Relative namespace references]])
312 AT_CHECK_NAMESPACE([[foo]])
313 AT_CHECK_NAMESPACE([[foo::bar]])
314 AT_CHECK_NAMESPACE([[foo::bar::baz]])
315 AT_CLEANUP
316
317 AT_SETUP([[Absolute namespace references]])
318 AT_CHECK_NAMESPACE([[::foo]])
319 AT_CHECK_NAMESPACE([[::foo::bar]])
320 AT_CHECK_NAMESPACE([[::foo::bar::baz]])
321 AT_CHECK_NAMESPACE([[ ::foo]])
322 AT_CHECK_NAMESPACE([[ ::foo::bar]])
323 AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
324 AT_CLEANUP
325
326 AT_SETUP([[Syntactically invalid namespace references]])
327 AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
328 AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
329 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
330 # contains single occurrences of `:'.
331 AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
332 AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
333 AT_CHECK_NAMESPACE([[foo::bar::(baz]], [[-]])
334 AT_CLEANUP