-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);
+struct output_state {
+ char *dst;
+ size_t dstlen;
+ size_t accum;
+};
+
+size_t cdecl__advance(struct output_state *dst, size_t amount);
+size_t cdecl__emit(struct output_state *dst, const char *src);
+size_t cdecl__emit_uint(struct output_state *dst, cdecl_uintmax val);
+size_t cdecl__strlcpy(char *dst, const char *src, size_t len);
+
+const char *cdecl__emit_specs(struct output_state *dst,
+ struct cdecl_declspec *s,
+ unsigned mask);
+
+/*
+ * If s is a (len bytes long) string corresponding to a declaration
+ * specifier, then:
+ *
+ * - bits 7:0 (LSB) of the return value is the packed specifier type, and
+ * - bits 15:8 of the return value is the packed parser token.
+ *
+ * Otherwise, if english_mode is nonzero and s is an "english keyword",
+ * returns the appropriate packed parser token in bits 15:8.
+ *
+ * Otherwise, PACK_TOKEN(T_IDENT) is returned in bits 15:8.
+ */
+unsigned cdecl__to_keyword(const char *s, int len, int english_mode);
+
+/* Container for an allocated parser token's value */
+struct parse_item {
+ union {
+ struct cdecl_declarator declarator;
+ struct cdecl_declspec declspec;
+ struct cdecl decl;
+ } u;
+
+ char s[FLEXIBLE_ARRAY_MEMBER];
+};
+
+struct parse_item *cdecl__alloc_item(size_t s_sz);
+
+/*
+ * GCC enables -finline-small-functions in most optimization modes; this works
+ * on a highlevel estimate of how big a function actually is and occasionally
+ * this produces really bad results.
+ *
+ * While old versions of GCC do not support this attribute the result seems
+ * to be merely a warning so hopefully we can get away with this check and
+ * save a configure test.
+ */
+#ifndef CDECL__NOINLINE
+# if __GNUC__
+# define CDECL__NOINLINE __attribute__((__noinline__))
+# else
+# define CDECL__NOINLINE /**/
+# endif
+#endif
+
+/*
+ * Build-time hook for white-box testing of memory allocation behaviour.
+ */
+#if TEST_MALLOC_HOOK
+void *test_realloc_hook(void *, size_t);
+
+static inline void *test_wrap_malloc(size_t n)
+{
+ return test_realloc_hook(0, n);
+}
+
+static inline void test_wrap_free(void *p)
+{
+ test_realloc_hook(p, 0);
+}
+
+#undef realloc
+#define realloc test_realloc_hook
+#undef malloc
+#define malloc test_wrap_malloc
+#undef free
+#define free test_wrap_free
+#endif