From a0ee2a7543902a3f5445a85fb1455c7a5166ec0b Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 29 Mar 2020 17:19:01 +0200 Subject: [PATCH] c++: replace symbol_number_type with symbol_type_type * data/skeletons/c++.m4, data/skeletons/glr.cc, * data/skeletons/lalr1.cc: here. --- data/skeletons/c++.m4 | 19 ++++++++----------- data/skeletons/glr.cc | 12 ++++++------ data/skeletons/lalr1.cc | 38 +++++++++++++++++++------------------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4 index 625cb8c5..b27e762d 100644 --- a/data/skeletons/c++.m4 +++ b/data/skeletons/c++.m4 @@ -265,11 +265,8 @@ m4_define([b4_public_types_declare], /// (External) token type, as returned by yylex. typedef token::yytokentype token_type; - /// Symbol codes. + /// (Internal) symbol codes. ]b4_declare_symbol_enum[ - - /// Symbol type: an internal symbol number. - typedef symbol_type_type symbol_number_type; ]]) @@ -325,7 +322,7 @@ m4_define([b4_symbol_type_define], void clear () {]b4_variant_if([[ // User destructor. - symbol_number_type yytype = this->type_get (); + symbol_type_type yytype = this->type_get (); basic_symbol& yysym = *this; (void) yysym; switch (yytype) @@ -387,11 +384,11 @@ m4_define([b4_symbol_type_define], /// The (internal) type number (corresponding to \a type). /// \a empty when empty. - symbol_number_type type_get () const YY_NOEXCEPT; + symbol_type_type type_get () const YY_NOEXCEPT; /// The symbol type. /// \a YYSYMBOL_YYEMPTY when empty. - symbol_number_type type; + symbol_type_type type; }; /// "External" symbols: returned by the scanner. @@ -511,7 +508,7 @@ m4_define([b4_public_types_define], that.clear (); } - ]b4_inline([$1])[]b4_parser_class[::symbol_number_type + ]b4_inline([$1])[]b4_parser_class[::symbol_type_type ]b4_parser_class[::by_type::type_get () const YY_NOEXCEPT { return type; @@ -531,11 +528,11 @@ m4_define([b4_token_constructor_define], []) # Define yytranslate_. Sometimes used in the header file ($1=hh), # sometimes in the cc file. m4_define([b4_yytranslate_define], -[ b4_inline([$1])b4_parser_class[::symbol_number_type +[ b4_inline([$1])b4_parser_class[::symbol_type_type ]b4_parser_class[::yytranslate_ (int t) { ]b4_api_token_raw_if( -[[ return static_cast (t);]], +[[ return static_cast (t);]], [[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to // TOKEN-NUM as returned by yylex. static @@ -549,7 +546,7 @@ m4_define([b4_yytranslate_define], if (t <= 0) return YYSYMBOL_YYEOF; else if (t <= user_token_number_max_) - return YY_CAST (symbol_number_type, translate_table[t]); + return YY_CAST (symbol_type_type, translate_table[t]); else return YYSYMBOL_YYUNDEF;]])[ } diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc index 2432570f..9ba52db0 100644 --- a/data/skeletons/glr.cc +++ b/data/skeletons/glr.cc @@ -83,7 +83,7 @@ m4_define([b4_yy_symbol_print_define], `--------------------*/ static void -yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_number_type yytype, +yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_type_type yytype, const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[, const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[) { @@ -175,7 +175,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl `--------------------*/ void - ]b4_parser_class[::yy_symbol_value_print_ (symbol_number_type yytype, + ]b4_parser_class[::yy_symbol_value_print_ (symbol_type_type yytype, const semantic_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) {]b4_locations_if([[ @@ -189,7 +189,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl void - ]b4_parser_class[::yy_symbol_print_ (symbol_number_type yytype, + ]b4_parser_class[::yy_symbol_print_ (symbol_type_type yytype, const semantic_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) { @@ -325,14 +325,14 @@ b4_percent_code_get([[requires]])[ /// \param yytype The token type. /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ - virtual void yy_symbol_value_print_ (symbol_number_type yytype, + virtual void yy_symbol_value_print_ (symbol_type_type yytype, const semantic_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[); /// \brief Report a symbol on the debug stream. /// \param yytype The token type. /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ - virtual void yy_symbol_print_ (symbol_number_type yytype, + virtual void yy_symbol_print_ (symbol_type_type yytype, const semantic_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[); private: @@ -356,7 +356,7 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]], ]b4_namespace_close[ ]m4_define([b4_declare_symbol_enum], -[[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_number_type yysymbol_type_t; +[[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_type_type yysymbol_type_t; #define YYSYMBOL_YYEMPTY ]b4_namespace_ref[::]b4_parser_class[::YYSYMBOL_YYEMPTY #define YYSYMBOL_YYERROR ]b4_namespace_ref[::]b4_parser_class[::YYSYMBOL_YYERROR #define YYSYMBOL_YYEOF ]b4_namespace_ref[::]b4_parser_class[::YYSYMBOL_YYEOF diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index 0e489744..169df09b 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -241,13 +241,13 @@ m4_define([b4_shared_declarations], public: context (const ]b4_parser_class[& yyparser, const symbol_type& yyla); const symbol_type& lookahead () const { return yyla_; } - symbol_number_type token () const { return yyla_.type_get (); }]b4_locations_if([[ + symbol_type_type token () const { return yyla_.type_get (); }]b4_locations_if([[ const location_type& location () const { return yyla_.location; } ]])[ /// Put in YYARG at most YYARGN of the expected tokens, and return the /// number of tokens stored in YYARG. If YYARG is null, return the /// number of expected tokens (guaranteed to be less than YYNTOKENS). - int yyexpected_tokens (symbol_number_type yyarg[], int yyargn) const; + int yyexpected_tokens (symbol_type_type yyarg[], int yyargn) const; private: const ]b4_parser_class[& yyparser_; @@ -261,10 +261,10 @@ m4_define([b4_shared_declarations], /// Check the lookahead yytoken. /// \returns true iff the token will be eventually shifted. - bool yy_lac_check_ (symbol_number_type yytoken) const; + bool yy_lac_check_ (symbol_type_type yytoken) const; /// Establish the initial context if no initial context currently exists. /// \returns true iff the token will be eventually shifted. - bool yy_lac_establish_ (symbol_number_type yytoken); + bool yy_lac_establish_ (symbol_type_type yytoken); /// Discard any previous initial lookahead context because of event. /// \param event the event which caused the lookahead to be discarded. /// Only used for debbuging output. @@ -280,7 +280,7 @@ m4_define([b4_shared_declarations], [detailed\|verbose], [[ /// The arguments of the error message. int yysyntax_error_arguments_ (const context& yyctx, - symbol_number_type yyarg[], int yyargn) const; + symbol_type_type yyarg[], int yyargn) const; /// Generate an error message. /// \param yyctx the context in which the error occurred. @@ -304,11 +304,11 @@ m4_define([b4_shared_declarations], /// Convert a scanner token number \a t to a symbol number. /// In theory \a t should be a token_type, but character literals /// are valid, yet not members of the token_type enum. - static symbol_number_type yytranslate_ (int t); + static symbol_type_type yytranslate_ (int t); ]b4_parse_error_bmatch([custom\|detailed], [[ /// The user-facing name of the symbol whose (internal) number is /// YYSYMBOL. No bounds checking. - static const char *yysymbol_name (symbol_number_type yysymbol); + static const char *yysymbol_name (symbol_type_type yysymbol); ]])[ // Tables. @@ -378,7 +378,7 @@ m4_define([b4_shared_declarations], /// The (internal) type number (corresponding to \a state). /// \a YYSYMBOL_YYEMPTY when empty. - symbol_number_type type_get () const YY_NOEXCEPT; + symbol_type_type type_get () const YY_NOEXCEPT; /// The state number used to denote an empty symbol. /// We use the initial state, as it does not have a value. @@ -586,7 +586,7 @@ m4_if(b4_prefix, [yy], [], /* The user-facing name of the symbol whose (internal) number is YYSYMBOL. No bounds checking. */ const char * - ]b4_parser_class[::yysymbol_name (symbol_number_type yysymbol) + ]b4_parser_class[::yysymbol_name (symbol_type_type yysymbol) { static const char *const yy_sname[] = { @@ -696,13 +696,13 @@ b4_parse_error_case([verbose], [[ : state (s) {} - ]b4_parser_class[::symbol_number_type + ]b4_parser_class[::symbol_type_type ]b4_parser_class[::by_state::type_get () const YY_NOEXCEPT { if (state == empty_state) return YYSYMBOL_YYEMPTY; else - return YY_CAST (symbol_number_type, yystos_[+state]); + return YY_CAST (symbol_type_type, yystos_[+state]); } ]b4_parser_class[::stack_symbol_type::stack_symbol_type () @@ -773,7 +773,7 @@ b4_parse_error_case([verbose], [[ { std::ostream& yyoutput = yyo; YYUSE (yyoutput); - symbol_number_type yytype = yysym.type_get (); + symbol_type_type yytype = yysym.type_get (); #if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ * 100 + __GNUC_MINOR__ <= 408 // Avoid a (spurious) G++ 4.8 warning about "array subscript is // below array bounds". @@ -1229,7 +1229,7 @@ b4_dollar_popdef])[]dnl {} int - ]b4_parser_class[::context::yyexpected_tokens (symbol_number_type yyarg[], int yyargn) const + ]b4_parser_class[::context::yyexpected_tokens (symbol_type_type yyarg[], int yyargn) const { // Actual number of expected tokens int yycount = 0; @@ -1243,7 +1243,7 @@ b4_dollar_popdef])[]dnl for (int yyx = 0; yyx < YYNTOKENS; ++yyx) { - symbol_number_type yysym = YY_CAST (symbol_number_type, yyx); + symbol_type_type yysym = YY_CAST (symbol_type_type, yyx); if (yysym != YYSYMBOL_YYERROR && yysym != YYSYMBOL_YYUNDEF && yyparser_.yy_lac_check_ (yysym)) { @@ -1274,7 +1274,7 @@ b4_dollar_popdef])[]dnl else if (yycount == yyargn) return 0; else - yyarg[yycount++] = YY_CAST (symbol_number_type, yyx); + yyarg[yycount++] = YY_CAST (symbol_type_type, yyx); } } ]])[ @@ -1283,7 +1283,7 @@ b4_dollar_popdef])[]dnl ]])b4_lac_if([[ bool - ]b4_parser_class[::yy_lac_check_ (symbol_number_type yytoken) const + ]b4_parser_class[::yy_lac_check_ (symbol_type_type yytoken) const { // Logically, the yylac_stack's lifetime is confined to this function. // Clear it, to get rid of potential left-overs from previous call. @@ -1361,7 +1361,7 @@ b4_dollar_popdef])[]dnl // Establish the initial context if no initial context currently exists. bool - ]b4_parser_class[::yy_lac_establish_ (symbol_number_type yytoken) + ]b4_parser_class[::yy_lac_establish_ (symbol_type_type yytoken) { /* Establish the initial context for the current lookahead if no initial context is currently established. @@ -1423,7 +1423,7 @@ b4_dollar_popdef])[]dnl int ]b4_parser_class[::yysyntax_error_arguments_ (const context& yyctx, - symbol_number_type yyarg[], int yyargn) const + symbol_type_type yyarg[], int yyargn) const { /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then @@ -1472,7 +1472,7 @@ b4_dollar_popdef])[]dnl // Its maximum. enum { YYARGS_MAX = 5 }; // Arguments of yyformat. - symbol_number_type yyarg[YYARGS_MAX]; + symbol_type_type yyarg[YYARGS_MAX]; int yycount = yysyntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); char const* yyformat = YY_NULLPTR;