]> git.draconx.ca Git - cdecl99.git/commitdiff
Add support for empty declarators.
authorNick Bowler <nbowler@draconx.ca>
Mon, 4 Jul 2011 22:11:51 +0000 (18:11 -0400)
committerNick Bowler <nbowler@draconx.ca>
Mon, 4 Jul 2011 22:11:51 +0000 (18:11 -0400)
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
src/parse.y

index 6ab2796acbcc812cbfbccea87cac15480e0e1a20..002b85702104b7068fb63d5e558f54955ef0fc09 100644 (file)
@@ -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);
        }
 }
index 0a2c2b5a1f39c7c494755d2ae50eb8e5f48db039..f7ef80c62479fb2fae74f12aca2c99ae6b0b375f 100644 (file)
@@ -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);