--- bison/data/c++.m4.orig 2006-03-12 15:45:27.000000000 +0100 +++ bison/data/c++.m4 2007-06-14 14:12:56.287740000 +0200 @@ -54,7 +54,7 @@ # -------------------- # Expansion of $$. m4_define([b4_lhs_value], -[(yyval[]m4_ifval([$1], [.$1]))]) +m4_ifdef([b4_variant],[(m4_ifval([$1], [boost::get<$1>(])yyval[]m4_ifval([$1], [)]))],[(yyval[]m4_ifval([$1], [.$1]))])) # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) @@ -62,8 +62,8 @@ # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[(address@hidden($1) - ($2)@}m4_ifval([$3], [.$3]))]) +m4_ifdef([b4_variant],[(m4_ifval([$3], [boost::get<$3>(])address@hidden($1) - ($2)@}m4_ifval([$3], [)]))],[(address@hidden($1) - ($2)@}m4_ifval([$3], [.$3]))])) # b4_lhs_location() # ----------------- --- bison/data/c.m4.orig 2006-05-21 06:48:47.000000000 +0200 +++ bison/data/c.m4 2007-06-14 14:09:20.068589000 +0200 @@ -417,8 +417,8 @@ # ------------------------------------------------- m4_define([b4_symbol_actions], [m4_pushdef([b4_dollar_dollar], - [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl + [m4_ifval([$6], m4_ifdef([b4_variant],[(boost::get<$6>(*yyvaluep))],[(yyvaluep->$6)]), [(*yyvaluep)])])dnl m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl case $4: /* $3 */ b4_syncline([$2], [$1]) --- bison/data/lalr1.cc.orig 2006-05-15 08:13:53.000000000 +0200 +++ bison/data/lalr1.cc 2007-06-14 14:37:20.720670000 +0200 @@ -44,7 +44,8 @@ # define PARSER_HEADER_H #include -#include +#include ]m4_ifdef([b4_variant],[ +#include ])[ #include "stack.hh" namespace ]b4_namespace[ @@ -108,13 +109,14 @@ public: /// Symbol semantic values. #ifndef YYSTYPE -]m4_ifdef([b4_stype], +]m4_ifdef([b4_variant], +[ typedef boost::variant semantic_type;],m4_ifdef([b4_stype], [ union semantic_type b4_stype /* Line __line__ of lalr1.cc. */ b4_syncline(address@hidden@], address@hidden@]) ;], -[ typedef int semantic_type;])[ +[ typedef int semantic_type;]))[ #else typedef YYSTYPE semantic_type; #endif @@ -560,8 +562,11 @@ stacks with a primary value. */ yystate_stack_ = state_stack_type (0); yysemantic_stack_ = semantic_stack_type (0); - yylocation_stack_ = location_stack_type (0); - yysemantic_stack_.push (yylval); + yylocation_stack_ = location_stack_type (0);]m4_ifdef([b4_variant],[ + /* we use swapping to avoid copying large amounts of data */ + yysemantic_stack_.push (semantic_type()); + address@hidden@}.swap(yylval);],[ + yysemantic_stack_.push (yylval);])[ yylocation_stack_.push (yylloc); /* New state. */ @@ -627,8 +632,11 @@ /* Discard the token being shifted unless it is eof. */ if (yychar != yyeof_) yychar = yyempty_; - - yysemantic_stack_.push (yylval); +]m4_ifdef([b4_variant],[ + /* we use swapping to avoid copying large amounts of data */ + yysemantic_stack_.push (semantic_type()); + address@hidden@}.swap(yylval);],[ + yysemantic_stack_.push (yylval);])[ yylocation_stack_.push (yylloc); /* Count tokens shifted since error; after three, turn off error @@ -652,7 +660,15 @@ | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: - yylen = yyr2_[yyn]; + yylen = yyr2_[yyn];]m4_ifdef([b4_variant],[ + /* Variants are always initialized to an empty instance of the correct type */ + /* The default $$=$1 rule is NOT applied when using variants */ + switch (yyn) + { +]b4_variant_initializations[ default: + yyval = semantic_type(); + break; + }],[ /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, use the top of the stack. @@ -660,9 +676,9 @@ This behavior is undocumented and Bison users should not rely upon it. */ if (yylen) - yyval = yysemantic_stack_[yylen - 1]; + yyval = address@hidden - address@hidden; else - yyval = yysemantic_stack_[0]; + yyval = address@hidden@};])[ { slice slice (yylocation_stack_, yylen); @@ -681,8 +697,11 @@ yypop_ (yylen); yylen = 0; YY_STACK_PRINT (); - - yysemantic_stack_.push (yyval); +]m4_ifdef([b4_variant],[ + /* we use swapping to avoid copying large amounts of data */ + yysemantic_stack_.push (semantic_type()); + address@hidden@}.swap(yyval);],[ + yysemantic_stack_.push (yyval);])[ yylocation_stack_.push (yyloc); /* Shift the result of the reduction. */ @@ -789,9 +808,12 @@ yyerror_range[1] = yylloc; // Using YYLLOC is tempting, but would change the location of // the look-ahead. YYLOC is available though. - YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); - yysemantic_stack_.push (yylval); + YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);]m4_ifdef([b4_variant],[ + /* we use swapping to avoid copying large amounts of data */ + yysemantic_stack_.push (semantic_type()); + address@hidden@}.swap(yylval);],[ + yysemantic_stack_.push (yylval);])[ yylocation_stack_.push (yyloc); /* Shift the error token. */ --- bison/src/output.c.orig 2006-05-14 22:40:35.000000000 +0200 +++ bison/src/output.c 2007-06-14 14:16:52.296829000 +0200 @@ -280,6 +280,26 @@ +/*------------- ---------------------------------------. +| Output the code for variant initializations to OUT. | +`-----------------------------------------------------*/ + +static void +variant_initializations_output (FILE *out) +{ + rule_number r; + + fputs ("m4_define([b4_variant_initializations], \n[[", out); + for (r = 0; r < nrules; ++r) + if (rules[r].lhs->type_name) + { + fprintf (out, " case %d:\n", r + 1); + fprintf (out, " yyval = %s();\n break;\n\n", + rules[r].lhs->type_name); + } + fputs ("]])\n\n", out); +} + /*---------------------------------. | Output the user actions to OUT. | `---------------------------------*/ @@ -554,6 +574,7 @@ /* Output the definitions of all the muscles. */ fputs ("m4_init()\n", out); + variant_initializations_output (out); user_actions_output (out); merger_output (out); token_definitions_output (out);