summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-12-30 09:10:05 +0100
committerAkim Demaille <akim.demaille@gmail.com>2021-01-23 15:02:49 +0100
commit84b00b6bf0e1813f674e16ab3c349e9d7d71904c (patch)
treedd6bf1e24633657a720bc117acb23346bf7dc4f0
parenta26f7cf98fcfe9fa1a3077dafdbff0687c22c039 (diff)
downloadbison-84b00b6bf0e1813f674e16ab3c349e9d7d71904c.tar.gz
%merge: delegate the generation of calls to mergers to m4
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 (b4_call_merger): New.
-rw-r--r--data/skeletons/glr.c11
-rw-r--r--src/output.c8
2 files changed, 12 insertions, 7 deletions
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 5034b5ef..1ef948cd 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -1,4 +1,4 @@
- -*- C -*-
+# -*- C -*-
# GLR skeleton for Bison
@@ -145,6 +145,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/src/output.c b/src/output.c
index 19c89cb4..5c87d5b4 100644
--- a/src/output.c
+++ b/src/output.c
@@ -533,12 +533,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);
}