From: Nick Bowler Date: Thu, 22 Jun 2023 00:35:58 +0000 (-0400) Subject: libcdecl: Simplify internal specifier printing functions. X-Git-Tag: v1.3~160 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/8e320b09c58bbf947dbdc5e0019bdaad478591fe libcdecl: Simplify internal specifier printing functions. 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. --- diff --git a/src/cdecl-internal.h b/src/cdecl-internal.h index 713e137..ab88489 100644 --- a/src/cdecl-internal.h +++ b/src/cdecl-internal.h @@ -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 diff --git a/src/declare.c b/src/declare.c index 4fc9fee..3b0b700 100644 --- a/src/declare.c +++ b/src/declare.c @@ -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 @@ -24,20 +24,6 @@ #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 diff --git a/src/explain.c b/src/explain.c index 0d9c957..877d6db 100644 --- a/src/explain.c +++ b/src/explain.c @@ -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 @@ -27,6 +27,16 @@ #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) diff --git a/src/output.c b/src/output.c index f691765..f52661d 100644 --- a/src/output.c +++ b/src/output.c @@ -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); -}