From: Akim Demaille Date: Mon, 21 Jul 2008 20:02:36 +0000 (+0200) Subject: Don't memcpy C++ structures. X-Git-Tag: v2.7.90~1152 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/4af4348a3f5f6b5c4e537edd09f5fe9cf30e9eb6 Don't memcpy C++ structures. * data/lalr1-fusion.cc (b4_symbol_variant): Adjust additional arguments. (variant::build): New overload for copy-construction-that-destroys. (variant::swap): New. (parser::yypush_): Use it in variant mode. --- diff --git a/ChangeLog b/ChangeLog index ea2c3d66..ba6b25f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-11-04 Akim Demaille + + Don't memcpy C++ structures. + * data/lalr1-fusion.cc (b4_symbol_variant): Adjust additional + arguments. + (variant::build): New overload for + copy-construction-that-destroys. + (variant::swap): New. + (parser::yypush_): Use it in variant mode. + 2008-11-04 Akim Demaille Better defaults for bench.pl. diff --git a/data/lalr1-fusion.cc b/data/lalr1-fusion.cc index e3cafff8..f2659fb9 100644 --- a/data/lalr1-fusion.cc +++ b/data/lalr1-fusion.cc @@ -85,13 +85,13 @@ m4_define([b4_symbol_action_], ])]) -# b4_symbol_variant(YYTYPE, YYVAL, ACTION) -# ---------------------------------------- +# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) +# ------------------------------------------------ # Run some ACTION ("build", or "destroy") on YYVAL of symbol type # YYTYPE. m4_define([b4_symbol_variant], [m4_pushdef([b4_dollar_dollar], - [$2.$3<$][3>()])dnl + [$2.$3<$][3>(m4_shift3($@))])dnl switch ($1) { m4_map([b4_symbol_action_], m4_defn([b4_type_names])) @@ -202,6 +202,24 @@ dnl FIXME: This is wrong, we want computed header guards. return reinterpret_cast(buffer); } + /// Swap the content with \a other. + template + inline void + swap(variant& other) + { + std::swap(as(), other.as()); + } + + /// Assign the content of \a other to this. + /// Destroys \a other. + template + inline void + build(variant& other) + { + build(); + swap(other); + } + /// Destroy the stored \a T. template inline void @@ -683,7 +701,10 @@ do { \ ]b4_parser_class_name[::yypush_ (state_type s, semantic_type& v, const location_type& l) { - yystack_.push (data_type (s, v, l)); +]b4_variant_if( +[[ yystack_.push (data_type (s, semantic_type(), l)); + ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]], [build], [v])], +[ yystack_.push (data_type (s, v, l));])[ } void