[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/6] %merge: delegate the generation of calls to mergers to m4
From: |
Akim Demaille |
Subject: |
[PATCH 3/6] %merge: delegate the generation of calls to mergers to m4 |
Date: |
Thu, 31 Dec 2020 08:14:35 +0100 |
Don't generate C code from bison, leave that to the skeletons.
* src/output.c (merger_output): Emit invocations to b4_call_merger.
* data/skeletons/glr.c, data/skeletons/glr2.cc (b4_call_merger): New.
---
data/skeletons/glr.c | 11 ++++++++++-
data/skeletons/glr2.cc | 8 ++++++++
src/output.c | 8 ++------
3 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 78e255e1..08dd7817 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -1,4 +1,4 @@
- -*- C -*-
+# -*- C -*-
# GLR skeleton for Bison
@@ -147,6 +147,15 @@ m4_define([b4_rhs_location],
[(b4_rhs_data([$1], [$2]).yyloc)])
+# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
+# ---------------------------------------------------
+m4_define([b4_call_merger],
+[b4_case([$1],
+ [ b4_symbol_if([$3], [has_type],
+ [yy0->b4_symbol($3, type) = $2 (*yy0, *yy1);],
+ [*yy0 = $2 (*yy0, *yy1);])])])
+
+
## -------------- ##
## Declarations. ##
## -------------- ##
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 4f476124..8210c628 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -122,6 +122,14 @@ m4_define([b4_rhs_location],
[(b4_rhs_data([$1], [$2]).yyloc)])
+# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM)
+# ---------------------------------------------------
+m4_define([b4_call_merger],
+[b4_case([$1],
+ [ b4_symbol_if([$3], [has_type],
+ [yy0->b4_symbol($3, type) = $2 (*yy0, *yy1);],
+ [*yy0 = $2 (*yy0, *yy1);])])])
+
# b4_lex
# ------
# Call yylex.
diff --git a/src/output.c b/src/output.c
index e58d8b75..1d63c043 100644
--- a/src/output.c
+++ b/src/output.c
@@ -554,12 +554,8 @@ merger_output (FILE *out)
int n;
merger_list* p;
for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next)
- if (p->sym && p->sym->content->type_name)
- fprintf (out, " case %d: yy0->%s = %s (*yy0, *yy1); break;\n",
- n, p->sym->content->type_name, p->name);
- else
- fprintf (out, " case %d: *yy0 = %s (*yy0, *yy1); break;\n",
- n, p->name);
+ fprintf (out, "]b4_call_merger([%d], [%s], [%d])[\n",
+ n, p->name, p->sym->content->number);
fputs ("]])\n\n", out);
}
--
2.29.2
- [PATCH 0/6] glr: fix compatibility bw %merge and api.value.type=union, Akim Demaille, 2020/12/31
- [PATCH 1/6] %merge: clearer tests on diagnostics, Akim Demaille, 2020/12/31
- [PATCH 2/6] %merge: let mergers record a typing-symbol, rather than a type, Akim Demaille, 2020/12/31
- [PATCH 3/6] %merge: delegate the generation of calls to mergers to m4,
Akim Demaille <=
- [PATCH 5/6] %merge: test support for api.value.type=union, Akim Demaille, 2020/12/31
- [PATCH 4/6] %merge: fix compatibility with api.value.type=union, Akim Demaille, 2020/12/31
- [PATCH 6/6] %merge: associate it to its first definition, not the latest, Akim Demaille, 2020/12/31