X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/faef34664a1e4cd7eeaa085e8daaee83d0a85875..3a2803df74bf43b384db752e87be94a1f64fa847:/data/lalr1-fusion.cc?ds=inline diff --git a/data/lalr1-fusion.cc b/data/lalr1-fusion.cc index bae0c49e..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])) @@ -186,14 +186,6 @@ dnl FIXME: This is wrong, we want computed header guards. return *new (buffer) T; } - /// Destroy the stored \a T. - template - inline void - destroy() - { - reinterpret_cast(buffer).~T(); - } - /// Accessor to a built \a T. template inline T& @@ -210,6 +202,32 @@ 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 + destroy() + { + as().~T(); + } + /// A buffer large enough to store any of the semantic values. char buffer[S]; }; @@ -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