X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/7d6bad195977b0204fc8406cac57cf5a4f1c769b..ddb9db151b1620a2bffceeddf7790dd586129d92:/data/c%20%20.m4/bison.git/blobdiff_plain/7d6bad195977b0204fc8406cac57cf5a4f1c769b..ddb9db151b1620a2bffceeddf7790dd586129d92:/data/c++.m4 diff --git a/data/c++.m4 b/data/c++.m4 index d3b78f13..87bc5e0d 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -154,9 +154,15 @@ m4_define([b4_public_types_declare], ]b4_token_enums[ }; - /// Token type. + /// (External) token type, as returned by yylex. 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. /// /// Expects its Base type to provide access to the symbol type @@ -166,61 +172,71 @@ m4_define([b4_public_types_declare], template struct basic_symbol : Base { + /// Alias to Base. + typedef Base super_type; + /// Default constructor. - inline basic_symbol (); -]b4_locations_if([ - /// Constructor. - inline basic_symbol (const location_type& l);])[ + basic_symbol (); /// Copy constructor. - inline basic_symbol (const basic_symbol& other); + basic_symbol (const basic_symbol& other); /// Constructor for valueless symbols. - inline basic_symbol (]b4_join( - [typename Base::value_type t], - b4_locations_if([const location_type& l]))[); + basic_symbol (typename Base::kind_type t]b4_locations_if([, + const location_type& l])[); /// Constructor for symbols with semantic value. - inline basic_symbol (]b4_join( - [typename Base::value_type t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[); + basic_symbol (typename Base::kind_type t, + const semantic_type& v]b4_locations_if([, + const location_type& l])[); - /// Assignment operator. - inline basic_symbol& operator= (const basic_symbol& other); + ~basic_symbol (); - /// Destructive move, \a s is emptied. - inline void move (basic_symbol& s); + /// Destructive move, \a s is emptied into this. + void move (basic_symbol& s); /// The semantic value. semantic_type value;]b4_locations_if([ /// The location. location_type location;])[ + + private: + /// Assignment operator. + basic_symbol& operator= (const basic_symbol& other); }; /// Type access provider for token (enum) based symbols. struct by_type { /// Default constructor. - inline by_type (); + by_type (); /// Copy constructor. - inline by_type (const by_type& other); + by_type (const by_type& other); - /// Constructor. - inline by_type (token_type t); + /// The symbol type as needed by the constructor. + typedef token_type kind_type; - /// The symbol type. - int type; + /// Constructor from (external) token numbers. + by_type (kind_type t); + + /// Steal the symbol type from \a that. + void move (by_type& that); - /// The type (corresponding to \a type). - inline int type_get () const; + /// The (internal) type number (corresponding to \a type). + /// -1 when this symbol is empty. + symbol_number_type type_get () const; /// The token. - inline token_type token () const; + token_type token () const; - typedef token_type value_type; + enum { empty = 0 }; + + /// The symbol type. + /// + /// -1 when this symbol is empty. + token_number_type type; }; /// "External" symbols: returned by the scanner. @@ -233,7 +249,7 @@ m4_define([b4_public_types_declare], # ---------------------- # Provide the implementation needed by the public types. m4_define([b4_public_types_define], -[[inline +[[ inline ]b4_parser_class_name[::syntax_error::syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m) : std::runtime_error (m)]b4_locations_if([ , location (l)])[ @@ -245,21 +261,6 @@ m4_define([b4_public_types_define], ]b4_parser_class_name[::basic_symbol::basic_symbol () : value () {} -]b4_locations_if([ - template - inline - ]b4_parser_class_name[::basic_symbol::basic_symbol (const location_type& l) - : value () - , location (l) - {}])[ - - template - inline - ]b4_parser_class_name[::basic_symbol& - ]b4_parser_class_name[::basic_symbol::operator= (const basic_symbol& other) - { - abort (); - } template inline @@ -277,44 +278,59 @@ m4_define([b4_public_types_define], template inline ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( - [typename Base::value_type t], + [typename Base::kind_type t], [const semantic_type& v], b4_locations_if([const location_type& l]))[) : Base (t) - , value ()]b4_locations_if([ + , value (]b4_variant_if([], [v])[)]b4_locations_if([ , location (l)])[ - { - (void) v; /* FIXME: */ - ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [copy], - [v])], - [value = v;])[ - } + {]b4_variant_if([[ + (void) v; + ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[} template inline ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( - [typename Base::value_type t], + [typename Base::kind_type t], b4_locations_if([const location_type& l]))[) - : Base (t)]b4_locations_if([ + : Base (t) + , value ()]b4_locations_if([ , location (l)])[ {} + template + inline + ]b4_parser_class_name[::basic_symbol::~basic_symbol () + {]b4_variant_if([[ + // User destructor. + symbol_number_type yytype = this->type_get (); + switch (yytype) + { +]b4_symbol_foreach([b4_symbol_destructor])dnl +[ default: + break; + } + + // Type destructor. + ]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[ + } + template inline void ]b4_parser_class_name[::basic_symbol::move (basic_symbol& s) { - this->type = s.type_get ();]b4_locations_if([ - location = s.location;])[ - ]b4_variant_if([b4_symbol_variant([s.type_get ()], [value], [move], + super_type::move(s); + ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], [s.value])], - [value = s.value;])[ + [value = s.value;])[]b4_locations_if([ + location = s.location;])[ } // by_type. inline ]b4_parser_class_name[::by_type::by_type () - : type () + : type (empty) {} inline @@ -327,6 +343,14 @@ m4_define([b4_public_types_define], : type (yytranslate_ (t)) {} + inline + void + ]b4_parser_class_name[::by_type::move (by_type& that) + { + type = that.type; + that.type = empty; + } + inline int ]b4_parser_class_name[::by_type::type_get () const @@ -367,6 +391,7 @@ m4_define([b4_symbol_constructor_define], []) # sometimes in the cc file. m4_define([b4_yytranslate_define], [[ // Symbol number corresponding to token number t. + inline ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yytranslate_ (]b4_token_ctor_if([token_type], [int])[ t)