9 size_t cdecl__advance_(char **buf, size_t *n, size_t amount)
22 size_t cdecl__advance(char **buf, size_t *n, size_t amount)
29 ret = cdecl__advance_(buf, n, amount);
30 rc = snprintf(*buf, *n, " ");
31 return ret + cdecl__advance_(buf, n, rc);
34 static size_t explain_storage(char *buf, size_t n, unsigned spec)
37 case CDECL_STOR_TYPEDEF:
38 return snprintf(buf, n, "typedef");
39 case CDECL_STOR_EXTERN:
40 return snprintf(buf, n, "extern");
41 case CDECL_STOR_STATIC:
42 return snprintf(buf, n, "static");
44 return snprintf(buf, n, "auto");
45 case CDECL_STOR_REGISTER:
46 return snprintf(buf, n, "register");
52 /* Renders the storage-class and function specifiers in canonical form. */
53 size_t cdecl__explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s)
55 unsigned long funcmap = 0;
56 size_t ret = 0, rc = 0;
58 for (struct cdecl_declspec *c = s; c; c = c->next) {
59 switch (cdecl_spec_kind(c)) {
61 funcmap |= 1ul << (c->type & 0xff);
64 /* Valid C declarations have at most one
65 * storage-class specifier. */
66 rc = explain_storage(buf, n, c->type);
71 if (funcmap & (1ul << (CDECL_FUNC_INLINE & 0xff))) {
72 ret += cdecl__advance(&buf, &n, rc);
73 rc = snprintf(buf, n, "inline");
79 size_t cdecl__explain_qualifiers(char *buf, size_t n, struct cdecl_declspec *s)
81 unsigned long qualmap = 0;
82 size_t ret = 0, rc = 0;
84 for (struct cdecl_declspec *c = s; c; c = c->next) {
85 if (cdecl_spec_kind(c) != CDECL_SPEC_QUAL)
87 qualmap |= 1ul << (c->type & 0xff);
90 if (qualmap & (1ul << (CDECL_QUAL_RESTRICT & 0xff))) {
91 ret += cdecl__advance(&buf, &n, rc);
92 rc = snprintf(buf, n, "restrict");
94 if (qualmap & (1ul << (CDECL_QUAL_VOLATILE & 0xff))) {
95 ret += cdecl__advance(&buf, &n, rc);
96 rc = snprintf(buf, n, "volatile");
98 if (qualmap & (1ul << (CDECL_QUAL_CONST & 0xff))) {
99 ret += cdecl__advance(&buf, &n, rc);
100 rc = snprintf(buf, n, "const");
106 /* Renders the type qualifiers and type specifiers in canonical form. */
107 size_t cdecl__explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s)
109 const char *tag = NULL;
110 unsigned long typemap;
113 typemap = cdecl__build_typemap(s);
117 for (struct cdecl_declspec *c = s; c; c = c->next) {
118 if (cdecl_spec_kind(c) != CDECL_SPEC_TYPE)
121 /* Valid C types have at most one identifier. */
126 rc = cdecl__explain_qualifiers(buf, n, s);
127 ret += cdecl__advance(&buf, &n, rc);
129 rc = snprintf(buf, n, "%s", cdecl__explain_typemap(typemap));
131 ret += cdecl__advance(&buf, &n, rc);
132 rc = snprintf(buf, n, "%s", tag);