]> ocean-lang.org Git - ocean/commitdiff
parsergen: do not create empty goto arrays
authorNeilBrown <neil@brown.name>
Wed, 24 Feb 2021 08:57:08 +0000 (19:57 +1100)
committerNeilBrown <neil@brown.name>
Wed, 10 Mar 2021 01:00:31 +0000 (12:00 +1100)
These empty arrays are a waste of space ...  assuming they take up
any(?).

Using NULL is more ideomatic.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/parsergen.mdc

index a6486df26025ab252fd4fc446aea2c3dda02e9aa..5d2e164221fb38488948210128bf007390f0e561 100644 (file)
@@ -2065,10 +2065,13 @@ The go to table is stored in a simple array of `sym` and corresponding
                int i;
                fprintf(f, "#line 0 \"gen_goto\"\n");
                for (i = 0; i < g->states; i++) {
                int i;
                fprintf(f, "#line 0 \"gen_goto\"\n");
                for (i = 0; i < g->states; i++) {
+                       struct symset gt = g->statetab[i]->go_to;
                        int j;
                        int j;
+
+                       if (gt.cnt == 0)
+                               continue;
                        fprintf(f, "static const struct lookup goto_%d[] = {\n",
                                i);
                        fprintf(f, "static const struct lookup goto_%d[] = {\n",
                                i);
-                       struct symset gt = g->statetab[i]->go_to;
                        for (j = 0; j < gt.cnt; j++)
                                fprintf(f, "\t{ %d, %d },\n",
                                        gt.syms[j], gt.data[j]);
                        for (j = 0; j < gt.cnt; j++)
                                fprintf(f, "\t{ %d, %d },\n",
                                        gt.syms[j], gt.data[j]);
@@ -2099,18 +2102,21 @@ The go to table is stored in a simple array of `sym` and corresponding
                                        prod_len = pr->body_size;
                                }
                        }
                                        prod_len = pr->body_size;
                                }
                        }
-
-                       if (prod >= 0)
-                               fprintf(f, "\t[%d] = { %d, goto_%d, %d, %d, %d, %d, %d, %d },\n",
-                                       i, is->go_to.cnt, i, prod,
-                                       g->productions[prod]->body_size,
-                                       g->productions[prod]->head->num,
+                       if (is->go_to.cnt)
+                               fprintf(f, "\t[%d] = { %d, goto_%d, ",
+                                       i, is->go_to.cnt, i);
+                       else
+                               fprintf(f, "\t[%d] = { 0, NULL, ", i);
+                       if (prod >= 0) {
+                               struct production *pr = g->productions[prod];
+                               fprintf(f, "%d, %d, %d, %d, %d, %d },\n", prod,
+                                       pr->body_size,
+                                       pr->head->num,
                                        is->starts_line,
                                        is->starts_line,
-                                       g->productions[prod]->line_like,
+                                       pr->line_like,
                                        is->min_prefix);
                                        is->min_prefix);
-                       else
-                               fprintf(f, "\t[%d] = { %d, goto_%d, -1, -1, -1, %d, 0, %d },\n",
-                                       i, is->go_to.cnt, i,
+                       } else
+                               fprintf(f, "-1, -1, -1, %d, 0, %d },\n",
                                        is->starts_line, is->min_prefix);
                }
                fprintf(f, "};\n\n");
                                        is->starts_line, is->min_prefix);
                }
                fprintf(f, "};\n\n");