+#include "errmsg.h"
+
+/*
+ * Allocate a "parse item", which is a union of several parse tree
+ * structure types, together with a string buffer. The s_sz argument
+ * specifies the size of the string (including its terminator), which
+ * may be zero.
+ *
+ * The union's declarator member is pre-initialized to a valid "identifier"
+ * declarator, which shares several interesting offsets with the "declspec"
+ * structure for an "identifier" type specifier.
+ */
+struct parse_item *cdecl__alloc_item(size_t s_sz)
+{
+ struct parse_item *ret;
+
+ ret = malloc(offsetof(struct parse_item, s) + s_sz);
+ if (!ret) {
+ cdecl__errmsg(CDECL__ENOMEM);
+ return NULL;
+ }
+
+ ret->u.declarator.child = NULL;
+ ret->u.declarator.type = CDECL_DECL_IDENT;
+ ret->u.declarator.u.ident = ret->s;
+
+ return ret;
+}
+
+/*
+ * We can represent type specifiers as a bitmap, which gives us a finite
+ * list of acceptable bitmap values according to the C standard. However,
+ * the "long" specifier is allowed to occur more than once, but only at most
+ * 2 times. Treat it as a special case, assigning an unused bit to represent
+ * the second long.
+ */
+#define MAP_LLONG_BIT 31
+#define MAP_LONG_BIT (CDECL_TYPE_LONG-CDECL_SPEC_TYPE)
+#define CDECL_TYPE_LLONG (CDECL_SPEC_TYPE+MAP_LLONG_BIT)
+
+#include "typemap.h"