Apply --prefix to C++ skeletons too: they change the namespace.

The test suite already exercize these cases.
* data/c++.m4 (b4_namespace): New.
* data/lalr1.cc, data/glr.cc, data/location.cc: Use it instead of `yy'.
* data/lalr1.cc (yytnameerr_): Move its definition into the namespace.
* data/yacc.c, data/glr.c: Remove a useless `[]'.
* doc/bison.texinfo: Document it.
(Option Cross Key): Use @multitable in all formats.  It looks
nicer, even in TeX outputs.
(Rules): Use the same code whatever the output type is.
* tests/local.at (_AT_BISON_OPTION_PUSHDEFS)
(_AT_BISON_OPTION_POPDEFS): Support AT_NAME_PREFIX.
* tests/calc.at: Use it, instead of hard coding `yy'.
This commit is contained in:
Akim Demaille
2006-03-12 14:45:27 +00:00
parent 455671735e
commit aa08666d72
11 changed files with 123 additions and 132 deletions

View File

@@ -29,7 +29,7 @@ m4_include(b4_pkgdatadir/[c.m4])
m4_define_default([b4_parser_class_name], [parser])
m4_define_default([b4_location_type], [location])
m4_define_default([b4_filename_type], [std::string])
m4_define_default([b4_namespace], m4_defn([b4_prefix]))
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)

View File

@@ -150,7 +150,7 @@ b4_copyright([Skeleton parser for GLR parsing with Bison],
]b4_identification
m4_if(b4_prefix[], [yy], [],
m4_if(b4_prefix, [yy], [],
[/* Substitute the variable and function names. */
#define yyparse b4_prefix[]parse
#define yylex b4_prefix[]lex

View File

@@ -73,9 +73,9 @@ m4_define([b4_yy_symbol_print_generate],
[static void],
[[FILE *], []],
[[int yytype], [yytype]],
[[const yy::b4_parser_class_name::semantic_type *yyvaluep],
[[const b4_namespace::b4_parser_class_name::semantic_type *yyvaluep],
[yyvaluep]],
[[const yy::b4_parser_class_name::location_type *yylocationp],
[[const b4_namespace::b4_parser_class_name::location_type *yylocationp],
[yylocationp]],
b4_parse_param)[
{
@@ -92,7 +92,7 @@ b4_syncline([@oline@], [@ofile@])
b4_c_ansi_function_decl([yyerror],
[static void],
[[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
[[b4_namespace::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
b4_parse_param,
[[const char* msg], [msg]])])
@@ -107,7 +107,7 @@ b4_syncline([@oline@], [@ofile@])[
]b4_c_ansi_function_def([yyerror],
[static void],
[[yy::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
[[b4_namespace::b4_parser_class_name::location_type *yylocationp], [yylocationp]],
b4_parse_param,
[[const char* msg], [msg]])[
{
@@ -116,7 +116,7 @@ b4_syncline([@oline@], [@ofile@])[
}
namespace yy
namespace ]b4_namespace[
{
]dnl In this section, the parse param are the original parse_params.
m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
@@ -195,7 +195,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
#endif /* ! YYDEBUG */
]m4_popdef([b4_parse_param])dnl
[} // namespace yy
[} // namespace ]b4_namespace[
]])
@@ -203,10 +203,10 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
# Let glr.c believe that the user arguments include the parser itself.
m4_ifset([b4_parse_param],
[m4_pushdef([b4_parse_param],
m4_dquote([[[yy::b4_parser_class_name& yyparser], [[yyparser]]],]
m4_dquote([[[b4_namespace::b4_parser_class_name& yyparser], [[yyparser]]],]
m4_defn([b4_parse_param])))],
[m4_pushdef([b4_parse_param],
[[[[yy::b4_parser_class_name& yyparser], [[yyparser]]]]])
[[[[b4_namespace::b4_parser_class_name& yyparser], [[yyparser]]]]])
])
m4_include(b4_pkgdatadir/[glr.c])
m4_popdef([b4_parse_param])
@@ -227,7 +227,7 @@ b4_copyright([C++ Skeleton parser for GLALR(1) parsing with Bison],
/* Using locations. */
#define YYLSP_NEEDED ]b4_locations_flag[
namespace yy
namespace ]b4_namespace[
{
class position;
class location;
@@ -287,7 +287,7 @@ b4_syncline([@oline@], [@ofile@])[
while (/*CONSTCOND*/ 0)
#endif
namespace yy
namespace ]b4_namespace[
{
/// A Bison parser.
class ]b4_parser_class_name[
@@ -384,10 +384,10 @@ m4_ifset([b4_global_tokens_and_yystype],
[b4_token_defines(b4_tokens)])
[
#ifndef YYSTYPE
# define YYSTYPE yy::]b4_parser_class_name[::semantic_type
# define YYSTYPE ]b4_namespace[::]b4_parser_class_name[::semantic_type
#endif
#ifndef YYLTYPE
# define YYLTYPE yy::]b4_parser_class_name[::location_type
# define YYLTYPE ]b4_namespace[::]b4_parser_class_name[::location_type
#endif
}

View File

@@ -42,7 +42,7 @@ dnl FIXME: This is wrong, we want computed header guards.
#include <iostream>
#include "stack.hh"
namespace yy
namespace ]b4_namespace[
{
class position;
class location;
@@ -94,7 +94,7 @@ do { \
} while (false)
#endif
namespace yy
namespace ]b4_namespace[
{
/// A Bison parser.
@@ -291,7 +291,7 @@ b4_error_verbose_if([, int tok])[);
#ifndef YYSTYPE
/* Redirection for backward compatibility. */
# define YYSTYPE yy::b4_parser_class_name::semantic_type
# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
#endif
])[
#endif /* ! defined PARSER_HEADER_H */]
@@ -299,7 +299,7 @@ b4_error_verbose_if([, int tok])[);
@output @output_parser_name@
b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
[2002, 2003, 2004, 2005, 2006])
m4_if(b4_prefix[], [yy], [],
m4_if(b4_prefix, [yy], [],
[
// Take the name prefix into account.
#define yylex b4_prefix[]lex])
@@ -370,49 +370,49 @@ do { \
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
namespace ]b4_namespace[
{
#if YYERROR_VERBOSE
/* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
std::string
yy::]b4_parser_class_name[::yytnamerr_ (const char *yystr)
{
if (*yystr == '"')
{
std::string yyr = "";
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
/* Fall through. */
default:
yyr += *yyp;
break;
case '"':
return yyr;
}
do_not_strip_quotes: ;
}
return yystr;
}
/* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
std::string
]b4_parser_class_name[::yytnamerr_ (const char *yystr)
{
if (*yystr == '"')
{
std::string yyr = "";
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
/* Fall through. */
default:
yyr += *yyp;
break;
case '"':
return yyr;
}
do_not_strip_quotes: ;
}
return yystr;
}
#endif
namespace yy
{
/// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)
: yydebug_ (false),
@@ -1047,7 +1047,7 @@ b4_error_verbose_if([, int tok])[)
const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
} // namespace yy
} // namespace ]b4_namespace[
]b4_epilogue
dnl
@@ -1060,7 +1060,7 @@ b4_copyright([stack handling for Bison C++ parsers],
#include <deque>
namespace yy
namespace ]b4_namespace[
{
template <class T, class S = std::deque<T> >
class stack

View File

@@ -28,7 +28,7 @@ b4_copyright([Position class for Bison C++ parsers],
/**
** \file position.hh
** Define the yy::position class.
** Define the ]b4_namespace[::position class.
*/
#ifndef BISON_POSITION_HH
@@ -37,7 +37,7 @@ b4_copyright([Position class for Bison C++ parsers],
# include <iostream>
# include <string>
namespace yy
namespace ]b4_namespace[
{
/// Abstract a position.
class position
@@ -140,7 +140,7 @@ b4_copyright([Location class for Bison C++ parsers],
/**
** \file location.hh
** Define the yy::location class.
** Define the ]b4_namespace[::location class.
*/
#ifndef BISON_LOCATION_HH
@@ -150,7 +150,7 @@ b4_copyright([Location class for Bison C++ parsers],
# include <string>
# include "position.hh"
namespace yy
namespace ]b4_namespace[
{
/// Abstract a location.

View File

@@ -154,7 +154,7 @@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
USER NAME SPACE" below. */
]b4_identification
m4_if(b4_prefix[], [yy], [],
m4_if(b4_prefix, [yy], [],
[/* Substitute the variable and function names. */
#define yyparse b4_prefix[]parse
#define yylex b4_prefix[]lex