Now that we have a child pointers in every declarator, this is way
cleaner than abusing the identifier type.
/* Declarator types. */
enum {
/* Declarator types. */
enum {
CDECL_DECL_IDENT,
CDECL_DECL_POINTER,
CDECL_DECL_ARRAY,
CDECL_DECL_IDENT,
CDECL_DECL_POINTER,
CDECL_DECL_ARRAY,
explain_prologue(char *buf, size_t n, struct cdecl_declarator *d)
{
while (d) {
explain_prologue(char *buf, size_t n, struct cdecl_declarator *d)
{
while (d) {
- if (d->type == CDECL_DECL_IDENT) {
- if (!d->u.ident)
- return snprintf(buf, n, "type");
+ switch (d->type) {
+ case CDECL_DECL_NULL:
+ return snprintf(buf, n, "type");
+ case CDECL_DECL_IDENT:
return snprintf(buf, n, "declare %s as", d->u.ident);
}
return snprintf(buf, n, "declare %s as", d->u.ident);
}
- if (d->type == CDECL_DECL_IDENT)
+ if (d->type == CDECL_DECL_IDENT || d->type == CDECL_DECL_NULL)
return 0;
rc = explain_declarators(buf, n, d->child);
return 0;
rc = explain_declarators(buf, n, d->child);
while (x) {
p = x->next;
switch (x->type) {
while (x) {
p = x->next;
switch (x->type) {
+ case CDECL_DECL_NULL:
+ break;
case CDECL_DECL_IDENT:
free(x->u.ident);
break;
case CDECL_DECL_IDENT:
free(x->u.ident);
break;
-declarator: direct_declarator | pointer;
+declarator: direct_declarator | pointer
direct_declarator: {
ALLOC_STRUCT($$, struct cdecl_declarator,
direct_declarator: {
ALLOC_STRUCT($$, struct cdecl_declarator,
- .type = CDECL_DECL_IDENT,
- .u.ident = NULL);
+ .type = CDECL_DECL_NULL);
} | T_IDENT {
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_IDENT,
} | T_IDENT {
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_IDENT,