[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
glr2.cc: fix destructor support
From: |
Akim Demaille |
Subject: |
glr2.cc: fix destructor support |
Date: |
Sun, 24 Jan 2021 09:53:33 +0100 |
commit 01957f6457cbfafdab3777e016543d90ff0d625a
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Sun Jan 24 09:46:56 2021 +0100
glr2.cc: fix destructor support
Currently glr2.cc does not use 'symbol's everywhere, in various places
it also uses yykind, yyval and yyloc "by hand". So we need two
different calls for user-defined constructors: once for ~symbol,
another for yy_destroy_. Both need to call the user destructors with
different calling conventions.
* data/skeletons/glr2.cc (b4_symbol_action): Rename as...
(b4_symbol_action_for_yyval): this.
(b4_symbol_action): New, taken from lalr1.cc.
(yy_destroy_, yy_symbol_value_print_): Use b4_symbol_action_for_yyval.
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 10956c9e8..9c3f09b0c 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -122,8 +122,34 @@ m4_define([b4_rhs_location],
# ----------------------------------
# Run the action KIND (destructor or printer) for SYMBOL-NUM.
# Same as in C, but using references instead of pointers.
+#
+# Currently we need two different b4_symbol_action: once for the
+# self-contained symbols, and another time for yy_destroy_ and
+# yy_symbol_value_print_, which don't use genuine symbols yet.
m4_define([b4_symbol_action],
[b4_symbol_if([$1], [has_$2],
+[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
+b4_dollar_pushdef([yysym.value],
+ [$1],
+ [],
+ [yysym.location])dnl
+ _b4_symbol_case([$1])[]dnl
+b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl
+ b4_symbol([$1], [$2])
+b4_syncline([@oline@], [@ofile@])dnl
+ break;
+
+m4_popdef([b4_symbol_value])[]dnl
+b4_dollar_popdef[]dnl
+])])
+
+
+# b4_symbol_action_for_yyval(SYMBOL-NUM, KIND)
+# --------------------------------------------
+# Run the action KIND (destructor or printer) for SYMBOL-NUM.
+# Same as in C, but using references instead of pointers.
+m4_define([b4_symbol_action_for_yyval],
+[b4_symbol_if([$1], [has_$2],
[b4_dollar_pushdef([yyval],
[$1],
[],
@@ -3378,7 +3404,9 @@ static void yypdumpstack (const glr_stack& yystack)
YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- ]b4_symbol_actions([destructor])[
+ ]m4_do([m4_pushdef([b4_symbol_action],
m4_defn([b4_symbol_action_for_yyval]))],
+ [b4_symbol_actions([destructor])],
+ [m4_popdef([b4_symbol_action])])[
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
@@ -3396,7 +3424,9 @@ static void yypdumpstack (const glr_stack& yystack)
YY_USE (yyval);
std::ostream& yyo = debug_stream ();
YY_USE (yyo);
- ]b4_symbol_actions([printer])[
+ ]m4_do([m4_pushdef([b4_symbol_action],
m4_defn([b4_symbol_action_for_yyval]))],
+ [b4_symbol_actions([printer])],
+ [m4_popdef([b4_symbol_action])])[
}
void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- glr2.cc: fix destructor support,
Akim Demaille <=