]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Simplify internal specifier printing functions.
authorNick Bowler <nbowler@draconx.ca>
Thu, 22 Jun 2023 00:35:58 +0000 (20:35 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 22 Jun 2023 00:43:45 +0000 (20:43 -0400)
Since reworking how specifiers are printed, the "pre"/"post" specifier
printing functions are pretty much pointless, and can (mostly) be
deleted, which reduces the library size somewhat.

src/cdecl-internal.h
src/declare.c
src/explain.c
src/output.c

index 713e1374e9a92c696e16c2f8ccfc84e12899a511..ab884898fa3ce2c3224b7a29240c612562521e96 100644 (file)
@@ -44,7 +44,5 @@ size_t cdecl__advance_(char **buf, size_t *n, size_t amount);
 size_t cdecl__advance(char **buf, size_t *n, size_t amount);
 size_t cdecl__explain_specs(char *buf, size_t n, struct cdecl_declspec *s,
                                                  unsigned mask);
-size_t cdecl__explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s);
-size_t cdecl__explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s);
 
 #endif
index 4fc9feeebea7f84aa0e0dca21e234bfd7315ce6f..3b0b7006ed71a1bdb416e7a9ccb52d986eb549cc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Render C declarations.
- *  Copyright © 2011, 2021 Nick Bowler
+ *  Copyright © 2011, 2021, 2023 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include "cdecl.h"
 #include "cdecl-internal.h"
 
-static size_t declare_specs(char *buf, size_t n, struct cdecl_declspec *s)
-{
-       size_t ret = 0, rc;
-
-       if (!s)
-               return 0;
-
-       rc = cdecl__explain_pre_specs(buf, n, s);
-       ret += cdecl__advance(&buf, &n, rc);
-
-       rc = cdecl__explain_post_specs(buf, n, s);
-       return ret + rc;
-}
-
 static size_t
 declare_declarator(char *buf, size_t n, struct cdecl_declarator *d);
 
@@ -45,7 +31,7 @@ static size_t declare_decl(char *buf, size_t n, struct cdecl *decl)
 {
        size_t ret = 0, rc;
 
-       rc = declare_specs(buf, n, decl->specifiers);
+       rc = cdecl__explain_specs(buf, n, decl->specifiers, -1);
        if (decl->declarators->type != CDECL_DECL_NULL)
                ret += cdecl__advance(&buf, &n, rc);
        else
index 0d9c95740ca03ece599a610c881db74ccdcc540e..877d6db511363437253a6f9b912aa85199a8dfd9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Render C declarations as English.
- *  Copyright © 2011, 2021 Nick Bowler
+ *  Copyright © 2011, 2021, 2023 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include "cdecl.h"
 #include "cdecl-internal.h"
 
+static size_t explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s)
+{
+       return cdecl__explain_specs(buf, n, s, CDECL_SPEC_FUNC|CDECL_SPEC_STOR);
+}
+
+static size_t explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s)
+{
+       return cdecl__explain_specs(buf, n, s, CDECL_SPEC_QUAL|CDECL_SPEC_TYPE);
+}
+
 /*
  * Renders the start of the thing being declared.  If top is true, print
  * the "declare" or "type" keywords at the front, as appropriate.
@@ -98,13 +108,13 @@ static size_t explain_decl(char *buf, size_t n, struct cdecl *decl, bool top)
        rc = explain_prologue(buf, n, decl->declarators, top);
        ret += cdecl__advance(&buf, &n, rc);
 
-       rc = cdecl__explain_pre_specs(buf, n, decl->specifiers);
+       rc = explain_pre_specs(buf, n, decl->specifiers);
        ret += cdecl__advance(&buf, &n, rc);
 
        rc = explain_declarators(buf, n, decl->declarators);
        ret += cdecl__advance(&buf, &n, rc);
 
-       return ret + cdecl__explain_post_specs(buf, n, decl->specifiers);
+       return ret + explain_post_specs(buf, n, decl->specifiers);
 }
 
 static size_t explain_function(char *buf, size_t n, struct cdecl_function *f)
index f691765ea592187d038b3d1dd16a2e080bef41b7..f52661dc6debd7d4080d02f401f60cddfa1daa7a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Helper functions for outputting text.
- *  Copyright © 2011, 2021 Nick Bowler
+ *  Copyright © 2011, 2021, 2023 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -83,15 +83,3 @@ size_t cdecl__explain_specs(char *buf, size_t n, struct cdecl_declspec *s,
 
        return ret + rc;
 }
-
-/* Renders the storage-class and function specifiers in canonical form. */
-size_t cdecl__explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s)
-{
-       return cdecl__explain_specs(buf, n, s, CDECL_SPEC_FUNC|CDECL_SPEC_STOR);
-}
-
-/* Renders the type qualifiers and type specifiers in canonical form. */
-size_t cdecl__explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s)
-{
-       return cdecl__explain_specs(buf, n, s, CDECL_SPEC_QUAL|CDECL_SPEC_TYPE);
-}