From 0d567b471af91e2627c94ab698a2a6d9597ba868 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 4 Jul 2011 18:11:51 -0400 Subject: [PATCH] Add support for empty declarators. This allows the parser to recognize type names which are required for function prototypes, as well as actual declarations. This also makes it easy to let the user ask for an explanation of types. For instance: explain int *(*[])[]; prints type array of pointer to array of pointer to int. --- src/explain.c | 5 ++++- src/parse.y | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/explain.c b/src/explain.c index 6ab2796..002b857 100644 --- a/src/explain.c +++ b/src/explain.c @@ -175,8 +175,11 @@ static size_t explain_prologue(char *buf, size_t n, struct cdecl_declarator *d) { while (d) { - if (d->type == CDECL_DECL_IDENT) + if (d->type == CDECL_DECL_IDENT) { + if (!d->u.ident) + return snprintf(buf, n, "type"); return snprintf(buf, n, "declare %s as", d->u.ident); + } d = next_declarator(d); } } diff --git a/src/parse.y b/src/parse.y index 0a2c2b5..f7ef80c 100644 --- a/src/parse.y +++ b/src/parse.y @@ -286,7 +286,11 @@ declarator: direct_declarator | pointer direct_declarator { .u.pointer.declarator = $2); } -direct_declarator: T_IDENT { +direct_declarator: { + ALLOC_STRUCT($$, struct cdecl_declarator, + .type = CDECL_DECL_IDENT, + .u.ident = NULL); +} | T_IDENT { ALLOC_STRUCT($$, struct cdecl_declarator, .type = CDECL_DECL_IDENT, .u.ident = $1); -- 2.43.2