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