X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/579b0ea9f485f812fd76a1764fb5bb4efc932f70..0c61f9637a469ac7a28b5a329551b03e6ad14d62:/src/declare.c
diff --git a/src/declare.c b/src/declare.c
index 90a593d..4fc9fee 100644
--- a/src/declare.c
+++ b/src/declare.c
@@ -1,8 +1,28 @@
+/*
+ * Render C declarations.
+ * Copyright © 2011, 2021 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
#include
+#include
#include
#include "cdecl.h"
-#include "output.h"
+#include "cdecl-internal.h"
static size_t declare_specs(char *buf, size_t n, struct cdecl_declspec *s)
{
@@ -65,8 +85,18 @@ static size_t declare_pointer(char *buf, size_t n, struct cdecl_pointer *p)
else
ret += cdecl__advance_(&buf, &n, rc);
- rc = cdecl__explain_qualifiers(buf, n, p->qualifiers);
- return ret + cdecl__advance(&buf, &n, rc);
+ rc = cdecl__explain_specs(buf, n, p->qualifiers, CDECL_SPEC_QUAL);
+ return ret + rc;
+}
+
+static bool pointer_needs_space(struct cdecl_declarator *d)
+{
+ assert(d->type == CDECL_DECL_POINTER);
+
+ if (d->u.pointer.qualifiers)
+ return d->child->type != CDECL_DECL_NULL;
+
+ return false;
}
static size_t declare_array(char *buf, size_t n, struct cdecl_array *a)
@@ -122,7 +152,10 @@ declare_declarator(char *buf, size_t n, struct cdecl_declarator *d)
break;
case CDECL_DECL_POINTER:
rc = declare_pointer(buf, n, &d->u.pointer);
- ret += cdecl__advance_(&buf, &n, rc);
+ if (pointer_needs_space(d))
+ ret += cdecl__advance(&buf, &n, rc);
+ else
+ ret += cdecl__advance_(&buf, &n, rc);
break;
/*
* Arrays and functions are special: since they are postfix,