mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
c++: use more explicit types than int
* data/c++.m4 (b4_public_types_declare): Declare token_number_type soon. Introduce symbol_number_type (wider than token_number_type). Clarify the requirement that kind_type from by_state and by_type denote the _input_ type (required by the constructor), not the stored type. Use symbol_number_type and token_number_type where appropriate, instead of int. * data/lalr1.cc: Adjust to these changes. Propagate "symbol_number_type". Invoke "type_get ()" instead of read "type" directly.
This commit is contained in:
35
data/c++.m4
35
data/c++.m4
@@ -154,9 +154,15 @@ m4_define([b4_public_types_declare],
|
|||||||
]b4_token_enums[
|
]b4_token_enums[
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Token type.
|
/// (External) token type, as returned by yylex.
|
||||||
typedef token::yytokentype token_type;
|
typedef token::yytokentype token_type;
|
||||||
|
|
||||||
|
/// Internal symbol number.
|
||||||
|
typedef int symbol_number_type;
|
||||||
|
|
||||||
|
/// Internal symbol number for tokens (subsumed by symbol_number_type).
|
||||||
|
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
|
||||||
|
|
||||||
/// A complete symbol.
|
/// A complete symbol.
|
||||||
///
|
///
|
||||||
/// Expects its Base type to provide access to the symbol type
|
/// Expects its Base type to provide access to the symbol type
|
||||||
@@ -209,27 +215,26 @@ m4_define([b4_public_types_declare],
|
|||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
by_type (const by_type& other);
|
by_type (const by_type& other);
|
||||||
|
|
||||||
/// Constructor.
|
/// The symbol type as needed by the constructor.
|
||||||
///
|
typedef token_type kind_type;
|
||||||
by_type (token_type t);
|
|
||||||
|
|
||||||
/// Steal the type of \a that.
|
/// Constructor from (external) token numbers.
|
||||||
|
by_type (kind_type t);
|
||||||
|
|
||||||
|
/// Steal the symbol type from \a that.
|
||||||
void move (by_type& that);
|
void move (by_type& that);
|
||||||
|
|
||||||
/// The symbol type.
|
/// The (internal) type number (corresponding to \a type).
|
||||||
///
|
|
||||||
/// -1 when this symbol is empty.
|
/// -1 when this symbol is empty.
|
||||||
int type;
|
symbol_number_type type_get () const;
|
||||||
|
|
||||||
/// The type (corresponding to \a type).
|
|
||||||
/// -1 when this symbol is empty.
|
|
||||||
int type_get () const;
|
|
||||||
|
|
||||||
/// The token.
|
/// The token.
|
||||||
token_type token () const;
|
token_type token () const;
|
||||||
|
|
||||||
/// The type used to store the symbol type.
|
/// The symbol type.
|
||||||
typedef token_type kind_type;
|
///
|
||||||
|
/// -1 when this symbol is empty.
|
||||||
|
token_number_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// "External" symbols: returned by the scanner.
|
/// "External" symbols: returned by the scanner.
|
||||||
@@ -296,7 +301,7 @@ m4_define([b4_public_types_define],
|
|||||||
]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol ()
|
]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol ()
|
||||||
{]b4_variant_if([[
|
{]b4_variant_if([[
|
||||||
// User destructor.
|
// User destructor.
|
||||||
int yytype = this->type_get ();
|
symbol_number_type yytype = this->type_get ();
|
||||||
switch (yytype)
|
switch (yytype)
|
||||||
{
|
{
|
||||||
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
||||||
|
|||||||
@@ -223,8 +223,6 @@ b4_location_define])])[
|
|||||||
/// \param yyvalue the value to check
|
/// \param yyvalue the value to check
|
||||||
static bool yy_table_value_is_error_ (int yyvalue);
|
static bool yy_table_value_is_error_ (int yyvalue);
|
||||||
|
|
||||||
/// Internal symbol numbers.
|
|
||||||
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
|
|
||||||
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
|
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
|
||||||
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
|
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
|
||||||
|
|
||||||
@@ -273,23 +271,24 @@ b4_location_define])])[
|
|||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
by_state ();
|
by_state ();
|
||||||
|
|
||||||
|
/// The symbol type as needed by the constructor.
|
||||||
|
typedef state_type kind_type;
|
||||||
|
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
by_state (state_type s);
|
by_state (kind_type s);
|
||||||
|
|
||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
by_state (const by_state& other);
|
by_state (const by_state& other);
|
||||||
|
|
||||||
|
/// Steal the symbol type from \a that.
|
||||||
void move (by_state& that);
|
void move (by_state& that);
|
||||||
|
|
||||||
|
/// The (internal) type number (corresponding to \a state).
|
||||||
|
/// -1 when empty.
|
||||||
|
symbol_number_type type_get () const;
|
||||||
|
|
||||||
/// The state.
|
/// The state.
|
||||||
state_type state;
|
state_type state;
|
||||||
|
|
||||||
/// The type (corresponding to \a state).
|
|
||||||
/// -1 when empty.
|
|
||||||
int type_get () const;
|
|
||||||
|
|
||||||
/// The type used to store the symbol type.
|
|
||||||
typedef state_type kind_type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// "Internal" symbol: element of the stack.
|
/// "Internal" symbol: element of the stack.
|
||||||
@@ -546,7 +545,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
int
|
]b4_parser_class_name[::symbol_number_type
|
||||||
]b4_parser_class_name[::by_state::type_get () const
|
]b4_parser_class_name[::by_state::type_get () const
|
||||||
{
|
{
|
||||||
return state == -1 ? -1 : yystos_[state];
|
return state == -1 ? -1 : yystos_[state];
|
||||||
@@ -590,7 +589,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
|
YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
|
||||||
|
|
||||||
// User destructor.
|
// User destructor.
|
||||||
int yytype = yysym.type_get ();
|
symbol_number_type yytype = yysym.type_get ();
|
||||||
switch (yytype)
|
switch (yytype)
|
||||||
{
|
{
|
||||||
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
||||||
@@ -607,7 +606,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
{
|
{
|
||||||
std::ostream& yyoutput = yyo;
|
std::ostream& yyoutput = yyo;
|
||||||
YYUSE (yyoutput);
|
YYUSE (yyoutput);
|
||||||
int yytype = yysym.type_get ();
|
symbol_number_type yytype = yysym.type_get ();
|
||||||
yyo << (yytype < yyntokens_ ? "token" : "nterm")
|
yyo << (yytype < yyntokens_ ? "token" : "nterm")
|
||||||
<< ' ' << yytname_[yytype] << " ("]b4_locations_if([
|
<< ' ' << yytname_[yytype] << " ("]b4_locations_if([
|
||||||
<< yysym.location << ": "])[;
|
<< yysym.location << ": "])[;
|
||||||
@@ -778,8 +777,8 @@ b4_dollar_popdef])[]dnl
|
|||||||
|
|
||||||
/* If the proper action on seeing token YYLA.TYPE is to reduce or
|
/* If the proper action on seeing token YYLA.TYPE is to reduce or
|
||||||
to detect an error, take that action. */
|
to detect an error, take that action. */
|
||||||
yyn += yyla.type;
|
yyn += yyla.type_get ();
|
||||||
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
|
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
|
||||||
goto yydefault;
|
goto yydefault;
|
||||||
|
|
||||||
// Reduce or error.
|
// Reduce or error.
|
||||||
@@ -875,7 +874,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
++yynerrs_;
|
++yynerrs_;
|
||||||
error (]b4_join(b4_locations_if([yyla.location]),
|
error (]b4_join(b4_locations_if([yyla.location]),
|
||||||
[[yysyntax_error_ (yystack_[0].state,
|
[[yysyntax_error_ (yystack_[0].state,
|
||||||
yyempty ? yyempty_ : yyla.type)]])[);
|
yyempty ? yyempty_ : yyla.type_get ())]])[);
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
@@ -886,7 +885,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
// Return failure if at end of input.
|
// Return failure if at end of input.
|
||||||
if (yyla.type == yyeof_)
|
if (yyla.type_get () == yyeof_)
|
||||||
YYABORT;
|
YYABORT;
|
||||||
else if (!yyempty)
|
else if (!yyempty)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user