]> git.saurik.com Git - bison.git/blobdiff - data/lalr1-fusion.cc
Use strict on bench.pl.
[bison.git] / data / lalr1-fusion.cc
index 66edbf9b54f1ab19b394731cb50bdad15056de48..f2659fb9bfd24eb6c3f74aa6d6a76aaca0f81233 100644 (file)
@@ -52,7 +52,7 @@ m4_define([b4_rhs_value],
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[(yystack_@{($1) - ($2)@}.location)])
+[yystack_@{($1) - ($2)@}.location])
 
 
 # b4_symbol_actions(FILENAME, LINENO,
@@ -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 <typename T>
-    inline void
-    destroy()
-    {
-      reinterpret_cast<T&>(buffer).~T();
-    }
-
     /// Accessor to a built \a T.
     template <typename T>
     inline T&
@@ -210,6 +202,32 @@ dnl FIXME: This is wrong, we want computed header guards.
       return reinterpret_cast<const T&>(buffer);
     }
 
+    /// Swap the content with \a other.
+    template <typename T>
+    inline void
+    swap(variant<S>& other)
+    {
+      std::swap(as<T>(), other.as<T>());
+    }
+
+    /// Assign the content of \a other to this.
+    /// Destroys \a other.
+    template <typename T>
+    inline void
+    build(variant<S>& other)
+    {
+      build<T>();
+      swap<T>(other);
+    }
+
+    /// Destroy the stored \a T.
+    template <typename T>
+    inline void
+    destroy()
+    {
+      as<T>().~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