summaryrefslogtreecommitdiffstats
path: root/src/output.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-11 00:09:33 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-11 00:09:33 +0200
commit0f3c53fb630b810e3927e7184273d424ff8b165a (patch)
treea69d2b3ccd6df55d7119f07b7470824d9cbb3147 /src/output.cpp
parent1f2a900e4068810b862929f8e326f4329156176e (diff)
downloadsolar-0f3c53fb630b810e3927e7184273d424ff8b165a.tar
solar-0f3c53fb630b810e3927e7184273d424ff8b165a.zip
output: de-duplicate token value pushing
Diffstat (limited to 'src/output.cpp')
-rw-r--r--src/output.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/output.cpp b/src/output.cpp
index cfefbbb..1503c38 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -302,7 +302,7 @@ void output_t::emit_source() {
emit_reductions();
- std::fprintf(source_file, "int %spush(%scontext_t *parser, int token, const %stoken_value_t *value", prefix(), prefix(), prefix());
+ std::fprintf(source_file, "static int %sdo_push(%scontext_t *parser, int token", prefix(), prefix());
for (const auto &arg : get_generator()->get_grammar().extra_args)
std::fprintf(source_file, ", %s %s", arg.first.c_str(), arg.second.c_str());
std::fprintf(source_file, ") {\n");
@@ -314,6 +314,23 @@ void output_t::emit_source() {
std::fprintf(source_file, "\t\t}\n");
std::fprintf(source_file, "\t}\n");
+ std::fprintf(source_file, "}\n\n");
+
+ std::fprintf(source_file, "int %spush(%scontext_t *parser, int token, const %stoken_value_t *value", prefix(), prefix(), prefix());
+ for (const auto &arg : get_generator()->get_grammar().extra_args)
+ std::fprintf(source_file, ", %s %s", arg.first.c_str(), arg.second.c_str());
+ std::fprintf(source_file, ") {\n");
+
+ std::fprintf(source_file, "\tint ret = %sdo_push(parser, token", prefix());
+ for (const auto &arg : get_generator()->get_grammar().extra_args)
+ std::fprintf(source_file, ", %s", arg.second.c_str());
+ std::fprintf(source_file, ");\n\n");
+
+ std::fprintf(source_file, "\tif (ret > 0)\n");
+ std::fprintf(source_file, "\t\tparser->stack[parser->top-1].value.token = *value;\n\n");
+
+ std::fprintf(source_file, "\treturn ret;\n");
+
std::fprintf(source_file, "}\n");
}