X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/5807bb9156930091850a52b5bb9ab9f89082b04e..ddb9db151b1620a2bffceeddf7790dd586129d92:/data/c%20%20.m4/bison.git/blobdiff_plain/5807bb9156930091850a52b5bb9ab9f89082b04e..ddb9db151b1620a2bffceeddf7790dd586129d92:/data/c++.m4 diff --git a/data/c++.m4 b/data/c++.m4 index 10855df9..87bc5e0d 100644 --- a/data/c++.m4 +++ b/data/c++.m4 @@ -2,7 +2,7 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2012 Free Software Foundation, Inc. +# Copyright (C) 2002-2013 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,13 @@ m4_include(b4_pkgdatadir/[c.m4]) +# b4_comment(TEXT, [PREFIX]) +# -------------------------- +# Put TEXT in comment. Prefix all the output lines with PREFIX. +m4_define([b4_comment], +[b4_comment_([$1], [$2// ], [$2// ])]) + + ## ---------------- ## ## Default values. ## ## ---------------- ## @@ -112,7 +119,8 @@ m4_define([b4_semantic_type_declare], [ /// Symbol semantic values. m4_ifdef([b4_stype], [ union semantic_type - {b4_user_stype + { +b4_user_stype };], [m4_if(b4_tag_seen_flag, 0, [[ typedef int semantic_type;]], @@ -146,63 +154,94 @@ m4_define([b4_public_types_declare], ]b4_token_enums[ }; - /// Token type. + /// (External) token type, as returned by yylex. typedef token::yytokentype token_type; - /// A complete symbol, with its type. - template - struct symbol_base_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 + /// via type_get(). + /// + /// Provide access to semantic value]b4_locations_if([ and location])[. + template + struct basic_symbol : Base { + /// Alias to Base. + typedef Base super_type; + /// Default constructor. - inline symbol_base_type (); + basic_symbol (); - /// Constructor.]b4_locations_if([ - inline symbol_base_type (const location_type& l);])[ - inline symbol_base_type (]b4_join( - [const semantic_type& v], - b4_locations_if([const location_type& l]))[); + /// Copy constructor. + basic_symbol (const basic_symbol& other); - /// Return this with its exact type. - const Exact& self () const; - Exact& self (); + /// Constructor for valueless symbols. + basic_symbol (typename Base::kind_type t]b4_locations_if([, + const location_type& l])[); - /// Return the type of this symbol. - int type_get () const; + /// Constructor for symbols with semantic value. + basic_symbol (typename Base::kind_type t, + const semantic_type& v]b4_locations_if([, + const location_type& l])[); + + ~basic_symbol (); + + /// 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); }; - /// External form of a symbol: its type and attributes. - struct symbol_type : symbol_base_type + /// Type access provider for token (enum) based symbols. + struct by_type { - /// The parent class. - typedef symbol_base_type super_type; - /// Default constructor. - inline symbol_type (); + by_type (); - /// Constructor for tokens with semantic value. - inline symbol_type (]b4_join([token_type t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[); + /// Copy constructor. + by_type (const by_type& other); - /// Constructor for valueless tokens. - inline symbol_type (]b4_join([token_type t], - b4_locations_if([const location_type& l]))[); + /// 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); - /// The symbol type. - inline int type_get_ () const; + /// Steal the symbol type from \a that. + void move (by_type& that); + + /// 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; + + enum { empty = 0 }; + + /// The symbol type. + /// + /// -1 when this symbol is empty. + token_number_type type; }; + + /// "External" symbols: returned by the scanner. + typedef basic_symbol symbol_type; + ]b4_symbol_constructor_declare]) @@ -216,94 +255,112 @@ m4_define([b4_public_types_define], , location (l)])[ {} - // symbol_base_type. - template + // basic_symbol. + template inline - ]b4_parser_class_name[::symbol_base_type::symbol_base_type () - : value()]b4_locations_if([ - , location()])[ - { - }]b4_locations_if([[ + ]b4_parser_class_name[::basic_symbol::basic_symbol () + : value () + {} - template + template inline - ]b4_parser_class_name[::symbol_base_type::symbol_base_type (const location_type& l) - : value() - , location(l) + ]b4_parser_class_name[::basic_symbol::basic_symbol (const basic_symbol& other) + : Base (other) + , value ()]b4_locations_if([ + , location (other.location)])[ { - }]])[ + ]b4_variant_if([b4_symbol_variant([other.type_get ()], [value], [copy], + [other.value])], + [value = other.value;])[ + } + - template + template inline - ]b4_parser_class_name[::symbol_base_type::symbol_base_type (]b4_join( + ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], [const semantic_type& v], b4_locations_if([const location_type& l]))[) - : value(v)]b4_locations_if([ - , location(l)])[ - { - } + : Base (t) + , value (]b4_variant_if([], [v])[)]b4_locations_if([ + , location (l)])[ + {]b4_variant_if([[ + (void) v; + ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[} - template + template inline - const Exact& - ]b4_parser_class_name[::symbol_base_type::self () const - { - return static_cast(*this); - } + ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_locations_if([const location_type& l]))[) + : Base (t) + , value ()]b4_locations_if([ + , location (l)])[ + {} - template + template inline - Exact& - ]b4_parser_class_name[::symbol_base_type::self () - { - return static_cast(*this); + ]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 + template inline - int - ]b4_parser_class_name[::symbol_base_type::type_get () const + void + ]b4_parser_class_name[::basic_symbol::move (basic_symbol& s) { - return self ().type_get_ (); + super_type::move(s); + ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], + [s.value])], + [value = s.value;])[]b4_locations_if([ + location = s.location;])[ } - // symbol_type. + // by_type. inline - ]b4_parser_class_name[::symbol_type::symbol_type () - : super_type () - , type () - { - } + ]b4_parser_class_name[::by_type::by_type () + : type (empty) + {} inline - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_join( - [token_type t], - b4_locations_if([const location_type& l]))[) - : super_type (]b4_locations_if([l])[) - , type (yytranslate_ (t)) - { - } + ]b4_parser_class_name[::by_type::by_type (const by_type& other) + : type (other.type) + {} inline - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_join( - [token_type t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : super_type (v]b4_locations_if([, l])[) - , type (yytranslate_ (t)) + ]b4_parser_class_name[::by_type::by_type (token_type t) + : 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[::symbol_type::type_get_ () const + ]b4_parser_class_name[::by_type::type_get () const { return type; } ]b4_token_ctor_if([[ inline ]b4_parser_class_name[::token_type - ]b4_parser_class_name[::symbol_type::token () const + ]b4_parser_class_name[::by_type::token () const { // YYTOKNUM[NUM] -- (External) token number corresponding to the // (internal) symbol number NUM (which must be that of a token). */ @@ -334,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) @@ -421,7 +479,7 @@ m4_define([b4_cc_constructor_call], m4_define([b4_parse_param_vars], [m4_ifset([b4_parse_param], [ - /* User arguments. */ + // User arguments. b4_cc_var_decls(b4_parse_param)])]) m4_define([b4_cc_var_decls], [m4_map_sep([b4_cc_var_decl], [