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