X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/be6fa942acae21a4a025bac5e339451be6ad136d..361444e4197b4b70790ebce25ef509d1eda963b0:/data/variant.hh diff --git a/data/variant.hh b/data/variant.hh index e2a537ad..968d6496 100644 --- a/data/variant.hh +++ b/data/variant.hh @@ -26,7 +26,7 @@ # YYTYPE. m4_define([b4_symbol_variant], [m4_pushdef([b4_dollar_dollar], - [$2.$3< $][3 >(m4_shift3($@))])dnl + [$2.$3< $][3 > (m4_shift3($@))])dnl switch ($1) { b4_type_foreach([b4_type_action_])[]dnl @@ -104,7 +104,7 @@ m4_define([b4_variant_define], : tname (typeid (T).name ())])[ { YYASSERT (sizeof (T) <= S); - new (buffer.raw) T (t); + new (as_ ()) T (t); } /// Destruction, allowed only if empty. @@ -121,7 +121,7 @@ m4_define([b4_variant_define], YYASSERT (!tname); YYASSERT (sizeof (T) <= S); tname = typeid (T).name ();])[ - return *new (buffer.raw) T; + return *new (as_ ()) T; } /// Instantiate a \a T in here from \a t. @@ -132,7 +132,7 @@ m4_define([b4_variant_define], YYASSERT (!tname); YYASSERT (sizeof (T) <= S); tname = typeid (T).name ();])[ - return *new (buffer.raw) T (t); + return *new (as_ ()) T (t); } /// Accessor to a built \a T. @@ -142,10 +142,7 @@ m4_define([b4_variant_define], {]b4_parse_assert_if([ YYASSERT (tname == typeid (T).name ()); YYASSERT (sizeof (T) <= S);])[ - { - void *dummy = buffer.raw; - return *static_cast (dummy); - } + return *as_ (); } /// Const accessor to a built \a T (for %printer). @@ -155,10 +152,7 @@ m4_define([b4_variant_define], {]b4_parse_assert_if([ YYASSERT (tname == typeid (T).name ()); YYASSERT (sizeof (T) <= S);])[ - { - const void *dummy = buffer.raw; - return *static_cast (dummy); - } + return *as_ (); } /// Swap the content with \a other, of same type. @@ -175,7 +169,7 @@ m4_define([b4_variant_define], {]b4_parse_assert_if([ YYASSERT (tname); YYASSERT (tname == other.tname);])[ - std::swap (as(), other.as()); + std::swap (as (), other.as ()); } /// Move the content of \a other to this. @@ -186,9 +180,9 @@ m4_define([b4_variant_define], move (self_type& other) {]b4_parse_assert_if([ YYASSERT (!tname);])[ - build(); - swap(other); - other.destroy(); + build (); + swap (other); + other.destroy (); } /// Copy the content of \a other to this. @@ -213,6 +207,24 @@ m4_define([b4_variant_define], self_type& operator=(const self_type&); variant (const self_type&); + /// Accessor to raw memory as \a T. + template + T* + as_ () + { + void *yyp = buffer.raw; + return static_cast (yyp); + } + + /// Const accessor to raw memory as \a T. + template + const T* + as_ () const + { + const void *yyp = buffer.raw; + return static_cast (yyp); + } + /// A buffer large enough to store any of the semantic values. /// Long double is chosen as it has the strongest alignment /// constraints. @@ -223,7 +235,7 @@ m4_define([b4_variant_define], } buffer;]b4_parse_assert_if([ /// Whether the content is built: if defined, the name of the stored type. - const char* tname;])[ + const char *tname;])[ }; ]]) @@ -252,7 +264,7 @@ m4_define([b4_semantic_type_declare], # ---------------------------- m4_define([b4_symbol_value], [m4_ifval([$2], - [$1.as< $2 >()], + [$1.as< $2 > ()], [$1])]) # b4_symbol_value_template(VAL, [TYPE]) @@ -260,7 +272,7 @@ m4_define([b4_symbol_value], # Same as b4_symbol_value, but used in a template method. m4_define([b4_symbol_value_template], [m4_ifval([$2], - [$1.template as< $2 >()], + [$1.template as< $2 > ()], [$1])])