@@ -126,6 +126,26 @@ m4_define([b4_rhs_location],
126126[(b4_rhs_data([$1 ], [$2 ]).yyloc)])
127127
128128
129+ # b4_symbol_action(SYMBOL-NUM, KIND)
130+ # ----------------------------------
131+ # Run the action KIND (destructor or printer) for SYMBOL-NUM.
132+ # Same as in C, but using references instead of pointers.
133+ m4_define ([b4_symbol_action],
134+ [b4_symbol_if([$1 ], [has_$2 ],
135+ [b4_dollar_pushdef([yyval],
136+ [$1 ],
137+ [],
138+ [yyloc])dnl
139+ _b4_symbol_case([$1 ])[]dnl
140+ b4_syncline([b4_symbol([$1 ], [$2_line])], [b4_symbol([$1 ], [$2_file])])dnl
141+ b4_symbol([$1 ], [$2 ])
142+ b4_syncline([@oline@], [@ofile@])dnl
143+ break;
144+
145+ b4_dollar_popdef[]dnl
146+ ])])
147+
148+
129149# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
130150# ---------------------------------------------------
131151m4_define ([b4_call_merger],
@@ -315,19 +335,19 @@ const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
315335# if ]b4_api_PREFIX[DEBUG
316336 public:
317337 // / \brief Report a symbol value on the debug stream.
318- // / \param yykind The symbol kind.
319- // / \param yyvaluep Its semantic value.]b4_locations_if([[
320- // / \param yylocationp Its location.]])[
338+ // / \param yykind The symbol kind.
339+ // / \param yyval Its semantic value.]b4_locations_if([[
340+ // / \param yyloc Its location.]])[
321341 virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
322- const value_type* yyvaluep ]b4_locations_if ([[,
323- const location_type* yylocationp ]])[) const ;
342+ const value_type& yyval ]b4_locations_if ([[,
343+ const location_type& yyloc ]])[) const ;
324344 // / \brief Report a symbol on the debug stream.
325- // / \param yykind The symbol kind.
326- // / \param yyvaluep Its semantic value.]b4_locations_if([[
327- // / \param yylocationp Its location.]])[
345+ // / \param yykind The symbol kind.
346+ // / \param yyval Its semantic value.]b4_locations_if([[
347+ // / \param yyloc Its location.]])[
328348 virtual void yy_symbol_print_ (symbol_kind_type yykind,
329- const value_type* yyvaluep ]b4_locations_if ([[,
330- const location_type* yylocationp ]])[) const ;
349+ const value_type& yyval ]b4_locations_if ([[,
350+ const location_type& yyloc ]])[) const ;
331351 private:
332352 // / Debug stream.
333353 std::ostream* yycdebug_;
@@ -354,8 +374,8 @@ const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
354374 // / If null, print nothing.
355375 // / \param yykind The symbol kind.
356376 void yy_destroy_ (const char * yymsg, symbol_kind_type yykind,
357- const value_type* yyvaluep ]b4_locations_if ([[,
358- const location_type* yylocationp ]])[);
377+ value_type& yyval ]b4_locations_if ([[,
378+ location_type& yyloc ]])[);
359379
360380]b4_parse_param_vars[
361381 };
@@ -1555,12 +1575,18 @@ void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class
15551575 check_ ();]])[
15561576 if (yyresolved)
15571577 yyparser.yy_destroy_ (yymsg, yy_accessing_symbol (yylrState),
1558- & value ()]b4_locations_if ([, & yyloc])[);
1578+ value ()]b4_locations_if ([, yyloc])[);
15591579 else
15601580 {
1561- YY_SYMBOL_PRINT (yymsg << (firstVal () ? " unresolved" : " incomplete" ),
1562- yy_accessing_symbol (yylrState), YY_NULLPTR, &yyloc);
1563-
1581+ #if ]b4_api_PREFIX[DEBUG
1582+ YYCDEBUG << yymsg
1583+ << (firstVal () ? " unresolved " : " incomplete " )
1584+ << (yy_accessing_symbol (yylrState) < YYNTOKENS ? " token" : " nterm" )
1585+ << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState))
1586+ << " (" ]b4_locations_if ([[
1587+ << yyloc << " : " ]])[
1588+ << " )\n " ;
1589+ #endif
15641590 if (firstVal () != YY_NULLPTR)
15651591 {
15661592 semantic_option& yyoption = *firstVal ();
@@ -1882,8 +1908,8 @@ class state_stack
18821908 std::cerr << " $" << yyi + 1 << " = " ;
18831909 yyparser.yy_symbol_print_
18841910 (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1 ].getState ().yylrState ),
1885- & yyvsp[yyi - yynrhs + 1 ].getState ().value ()]b4_locations_if ([[,
1886- & ]b4_rhs_location (yynrhs, yyi + 1 )])[);
1911+ yyvsp[yyi - yynrhs + 1 ].getState ().value ()]b4_locations_if ([[,
1912+ ]b4_rhs_location (yynrhs, yyi + 1 )])[);
18871913 if (!yyvsp[yyi - yynrhs + 1 ].getState ().yyresolved )
18881914 std::cerr << " (unresolved)" ;
18891915 std::cerr << ' \n ' ;
@@ -2012,7 +2038,7 @@ class glr_stack
20122038 {
20132039 if (this ->yychar != ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol (empty, id)[)
20142040 yyparser.yy_destroy_ (" Cleanup: discarding lookahead" ,
2015- YYTRANSLATE (this ->yychar ), & this ->yylval ]b4_locations_if ([, & this ->yylloc ])[);
2041+ YYTRANSLATE (this ->yychar ), this ->yylval ]b4_locations_if ([, this ->yylloc ])[);
20162042 popall_ ();
20172043 }
20182044
@@ -2210,7 +2236,7 @@ class glr_stack
22102236 YYLLOC_DEFAULT ((yys->yyloc ), yyerror_range, 2 );]])[
22112237 yysymbol_kind_t yytoken = YYTRANSLATE (this ->yychar );
22122238 yyparser.yy_destroy_ (" Error: discarding" ,
2213- yytoken, & yylval]b4_locations_if ([, & yylloc])[);]b4_variant_if ([[
2239+ yytoken, yylval]b4_locations_if ([, yylloc])[);]b4_variant_if ([[
22142240 // Value type destructor.
22152241 ]b4_symbol_variant ([[YYTRANSLATE (this ->yychar )]], [[yylval]], [[template destroy]])])[
22162242 this ->yychar = ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol (empty, id)[;
@@ -2249,8 +2275,8 @@ class glr_stack
22492275 location_type yyerrloc;
22502276 yyerror_range[2 ].getState ().yyloc = this ->yylloc ;
22512277 YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2 );]])[
2252- YY_SYMBOL_PRINT (" Shifting" , yy_accessing_symbol (yytable[yyj]),
2253- & yylval, & yyerrloc);
2278+ YY_SYMBOL_PRINT (" Shifting" , yy_accessing_symbol (yytable[yyj]),
2279+ yylval, yyerrloc);
22542280 yyglrShift (create_state_set_index (0 ), yytable[yyj],
22552281 yys->yyposn , yylval]b4_locations_if ([, yyerrloc])[);
22562282 yys = firstTopState ();
@@ -2426,7 +2452,7 @@ class glr_stack
24262452 YYERROR;
24272453 }
24282454 #endif // YY_EXCEPTIONS
2429- YY_SYMBOL_PRINT (" -> $$ =" , yylhsNonterm (yyrule), yyvalp, yylocp);
2455+ YY_SYMBOL_PRINT (" -> $$ =" , yylhsNonterm (yyrule), * yyvalp, * yylocp);
24302456
24312457 return yyok;
24322458 # undef yyerrok
@@ -2751,7 +2777,7 @@ class glr_stack
27512777 {
27522778 yyparser.yy_destroy_ (" Cleanup: discarding incompletely merged value for" ,
27532779 yy_accessing_symbol (yys.yylrState ),
2754- & this ->yylval ]b4_locations_if ([, yylocp])[);
2780+ this ->yylval ]b4_locations_if ([, * yylocp])[);
27552781 break ;
27562782 }
27572783 yyuserMerge (yymerger[yyp->yyrule ], val, yyval_other);]b4_variant_if ([[
@@ -2921,7 +2947,7 @@ yygetToken (int& yycharp, ]b4_namespace_ref[::]b4_parser_class[& yyparser, glr_s
29212947 else
29222948 {
29232949 yytoken = YYTRANSLATE (yycharp);
2924- YY_SYMBOL_PRINT (" Next token is" , yytoken, & yystack.yylval , & yystack.yylloc );
2950+ YY_SYMBOL_PRINT (" Next token is" , yytoken, yystack.yylval , yystack.yylloc );
29252951 }
29262952 return yytoken;
29272953}
@@ -3127,7 +3153,7 @@ b4_dollar_popdef])[]dnl
31273153 break ;
31283154 if (yyisShiftAction (yyaction))
31293155 {
3130- YY_SYMBOL_PRINT (" Shifting" , yytoken, & yystack.yylval , & yystack.yylloc );
3156+ YY_SYMBOL_PRINT (" Shifting" , yytoken, yystack.yylval , yystack.yylloc );
31313157 yystack.yychar = token::]b4_symbol (empty, id)[;
31323158 yyposn += 1 ;
31333159 // FIXME: we should move yylval.
@@ -3207,7 +3233,7 @@ b4_dollar_popdef])[]dnl
32073233 = yygetLRActions (yystate, yytoken_to_shift, yyconflicts);
32083234 /* Note that yyconflicts were handled by yyprocessOneStack. */
32093235 YYCDEBUG << " On stack " << yys.get () << " , " ;
3210- YY_SYMBOL_PRINT (" shifting" , yytoken_to_shift, & yystack.yylval , & yystack.yylloc );
3236+ YY_SYMBOL_PRINT (" shifting" , yytoken_to_shift, yystack.yylval , yystack.yylloc );
32113237 yystack.yyglrShift (yys, yyaction, yyposn, yystack.yylval ]b4_locations_if ([, yystack.yylloc ])[);
32123238 YYCDEBUG << " Stack " << yys.get () << " now in state "
32133239 << yystack.topState (yys)->yylrState << ' \n ' ;
@@ -3343,16 +3369,16 @@ b4_dollar_popdef])[]dnl
33433369
33443370 void
33453371 ]b4_parser_class[::yy_destroy_ (const char * yymsg, symbol_kind_type yykind,
3346- const value_type* yyvaluep ]b4_locations_if ([[,
3347- const location_type* yylocationp ]])[)
3372+ value_type& yyval ]b4_locations_if ([[,
3373+ location_type& yyloc ]])[)
33483374 {
3349- YY_USE (yyvaluep );]b4_locations_if ([[
3350- YY_USE (yylocationp );]])[
3375+ YY_USE (yyval );]b4_locations_if ([[
3376+ YY_USE (yyloc );]])[
33513377 if (!yymsg)
33523378 yymsg = " Deleting" ;
33533379 ]b4_parser_class[& yyparser = *this ;
33543380 YY_USE (yyparser);
3355- YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp );
3381+ YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc );
33563382
33573383 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
33583384 ]b4_symbol_actions ([destructor])[
@@ -3366,26 +3392,25 @@ b4_dollar_popdef])[]dnl
33663392
33673393 void
33683394 ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
3369- const value_type* yyvaluep ]b4_locations_if ([[,
3370- const location_type* yylocationp ]])[) const
3395+ const value_type& yyval ]b4_locations_if ([[,
3396+ const location_type& yyloc ]])[) const
33713397 {]b4_locations_if ([[
3372- YY_USE (yylocationp );]])[
3373- YY_USE (yyvaluep );
3398+ YY_USE (yyloc );]])[
3399+ YY_USE (yyval );
33743400 std::ostream& yyo = debug_stream ();
3375- std::ostream& yyoutput = yyo;
3376- YY_USE (yyoutput);
3401+ YY_USE (yyo);
33773402 ]b4_symbol_actions ([printer])[
33783403 }
33793404
33803405 void
33813406 ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
3382- const value_type* yyvaluep ]b4_locations_if ([[,
3383- const location_type* yylocationp ]])[) const
3407+ const value_type& yyval ]b4_locations_if ([[,
3408+ const location_type& yyloc ]])[) const
33843409 {
33853410 *yycdebug_ << (yykind < YYNTOKENS ? " token" : " nterm" )
33863411 << ' ' << symbol_name (yykind) << " (" ]b4_locations_if ([[
3387- << *yylocationp << " : " ]])[;
3388- yy_symbol_value_print_ (yykind, yyvaluep ]b4_locations_if ([[, yylocationp ]])[);
3412+ << yyloc << " : " ]])[;
3413+ yy_symbol_value_print_ (yykind, yyval ]b4_locations_if ([[, yyloc ]])[);
33893414 *yycdebug_ << ' )' ;
33903415 }
33913416
0 commit comments