]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
muscle: let -D/-F support the three kinds of %define variable values
[bison.git] / data / lalr1.cc
index 473dd29bd571f3c4ea300b004cdfef030e68d16d..3294f591106d6cbe53c80c32241e1632990861b9 100644 (file)
@@ -17,6 +17,8 @@
 
 m4_include(b4_pkgdatadir/[c++.m4])
 
+# api.value.type=variant is valid.
+m4_define([b4_value_type_setup_variant])
 
 # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
 # --------------------------------------------------------------
@@ -38,13 +40,14 @@ m4_define([b4_integral_parser_table_define],
   };dnl
 ])
 
-
 # b4_symbol_value_template(VAL, [TYPE])
 # -------------------------------------
 # Same as b4_symbol_value, but used in a template method.  It makes
-# a difference when using variants.
+# a difference when using variants.  Note that b4_value_type_setup_union
+# overrides b4_symbol_value, so we must override it again.
 m4_copy([b4_symbol_value], [b4_symbol_value_template])
-
+m4_append([b4_value_type_setup_union],
+          [m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])])
 
 # b4_lhs_value([TYPE])
 # --------------------
@@ -201,6 +204,10 @@ b4_location_define])])[
     void error (const syntax_error& err);
 
   private:
+    /// This class is not copyable.
+    ]b4_parser_class_name[ (const ]b4_parser_class_name[&);
+    ]b4_parser_class_name[& operator= (const ]b4_parser_class_name[&);
+
     /// State numbers.
     typedef int state_type;
 
@@ -284,9 +291,11 @@ b4_location_define])])[
       void move (by_state& that);
 
       /// The (internal) type number (corresponding to \a state).
-      /// -1 when empty.
+      /// "empty" when empty.
       symbol_number_type type_get () const;
 
+      enum { empty = 0 };
+
       /// The state.
       state_type state;
     };
@@ -523,7 +532,7 @@ m4_if(b4_prefix, [yy], [],
   // by_state.
   inline
   ]b4_parser_class_name[::by_state::by_state ()
-    : state (-1)
+    : state (empty)
   {}
 
   inline
@@ -536,7 +545,7 @@ m4_if(b4_prefix, [yy], [],
   ]b4_parser_class_name[::by_state::move (by_state& that)
   {
     state = that.state;
-    that.state = -1;
+    that.state = empty;
   }
 
   inline
@@ -548,7 +557,7 @@ m4_if(b4_prefix, [yy], [],
   ]b4_parser_class_name[::symbol_number_type
   ]b4_parser_class_name[::by_state::type_get () const
   {
-    return state == -1 ? -1 : yystos_[state];
+    return state == empty ? 0 : yystos_[state];
   }
 
   inline
@@ -564,7 +573,7 @@ m4_if(b4_prefix, [yy], [],
                                       [value], [move], [that.value])],
                    [[value = that.value;]])[
     // that is emptied.
-    that.type = -1;
+    that.type = empty;
   }
 
   inline
@@ -589,13 +598,7 @@ m4_if(b4_prefix, [yy], [],
       YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
 
     // User destructor.
-    symbol_number_type yytype = yysym.type_get ();
-    switch (yytype)
-      {
-]b4_symbol_foreach([b4_symbol_destructor])dnl
-[       default:
-          break;
-      }])[
+    b4_symbol_actions([destructor], [yysym.type_get ()])])[
   }
 
 #if ]b4_api_PREFIX[DEBUG
@@ -610,12 +613,7 @@ m4_if(b4_prefix, [yy], [],
     yyo << (yytype < yyntokens_ ? "token" : "nterm")
         << ' ' << yytname_[yytype] << " ("]b4_locations_if([
         << yysym.location << ": "])[;
-    switch (yytype)
-      {
-]b4_symbol_foreach([b4_symbol_printer])dnl
-[       default:
-          break;
-      }
+    ]b4_symbol_actions([printer])[
     yyo << ')';
   }
 #endif
@@ -735,7 +733,7 @@ b4_dollar_popdef])[]dnl
        yynewstate, since the latter expects the semantical and the
        location values to have been already stored, initialize these
        stacks with a primary value.  */
-    yystack_ = stack_type (0);
+    yystack_.clear ();
     yypush_ (YY_NULL, 0, yyla);
 
     // A new symbol was pushed on the stack.
@@ -822,7 +820,7 @@ b4_dollar_popdef])[]dnl
        variants.  */
     b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])],[
     /* If YYLEN is nonzero, implement the default value of the action:
-       `$$ = $1'.  Otherwise, use the top of the stack.
+       '$$ = $1'.  Otherwise, use the top of the stack.
 
        Otherwise, the following line sets YYLHS.VALUE to garbage.
        This behavior is undocumented and Bison