]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Merge some output strings.
authorNick Bowler <nbowler@draconx.ca>
Thu, 22 Feb 2024 04:14:33 +0000 (23:14 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 23 Feb 2024 01:36:33 +0000 (20:36 -0500)
A couple of conditional parts of the English output can be merged into a
single print with a single string which is offset by some amount.  This
gives a modest size reduction.

src/explain.c

index 722e721f8ca114498c906927d9971ae88f3f4bec..10a7064419dc885e945d067180f997e8d2f72ce1 100644 (file)
@@ -67,16 +67,12 @@ explain_array(struct output_state *dst, struct cdecl_array *a)
 {
        size_t rc = 0;
 
-       if (a->vla)
-               cdecl__emit(dst, "variable-length ");
-       cdecl__emit(dst, "array ");
-
+       cdecl__emit(dst, "variable-length array " + (a->vla ? 0 : 16));
        if (a->vla) {
                rc = cdecl__emit(dst, a->vla);
        } else {
                rc = cdecl__emit_uint(dst, a->length);
        }
-
        cdecl__emit(dst, " of " + !rc);
 }
 
@@ -99,8 +95,9 @@ static void explain_decl(struct output_state *dst, struct cdecl *decl)
 static void
 explain_function(struct output_state *dst, struct cdecl_function *f)
 {
-       cdecl__emit(dst, "function ");
+       int tail_offset = 7;
 
+       cdecl__emit(dst, "function ");
        if (f->parameters) {
                struct cdecl *p;
 
@@ -112,13 +109,9 @@ explain_function(struct output_state *dst, struct cdecl_function *f)
                                cdecl__emit(dst, ", ");
                }
 
-               if (f->variadic)
-                       cdecl__emit(dst, ", ...) ");
-               else
-                       cdecl__emit(dst, ") ");
+               tail_offset = f->variadic ? 0 : 5;
        }
-
-       cdecl__emit(dst, "returning ");
+       cdecl__emit(dst, ", ...) returning " + tail_offset);
 }
 
 static void