]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse.y
Make an explicit null declarator type.
[cdecl99.git] / src / parse.y
index f7ef80c62479fb2fae74f12aca2c99ae6b0b375f..7d4c3dc0c889f88469c4905f9f8cf36fa685b33d 100644 (file)
@@ -79,20 +79,22 @@ static void free_declarator(struct cdecl_declarator *x)
        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_POINTER:
                        free_declspec(x->u.pointer.qualifiers);
-                       free_declarator(x->u.pointer.declarator);
                        break;
                case CDECL_DECL_ARRAY:
                        free(x->u.array.vla);
-                       free_declarator(x->u.array.declarator);
                        break;
                default:
                        assert(0);
                }
+
+               free_declarator(x->child);
                free(x);
                x = p;
        }
@@ -161,9 +163,9 @@ void cdecl_free(struct cdecl *decl)
 %type <strval>     vla_ident
 %type <uintval>    declspec_simple typespec_simple qualifier_simple
 %type <declspec>   declspec_notype declspec_noid typespec_noid typespec
-%type <declspec>   qualifier qualifiers pointer
+%type <declspec>   qualifier qualifiers
 %type <declspec>   declspecs declspecs_noid
-%type <declarator> direct_declarator declarator declarators array
+%type <declarator> direct_declarator declarator declarators pointer array
 %type <decl>       declaration
 
 %%
@@ -256,8 +258,6 @@ typespec: typespec_noid | T_STRUCT T_IDENT {
 
 declspec_noid: declspec_notype | typespec_noid
 
-pointer: T_ASTERISK qualifiers { $$ = $2; }
-
 vla_ident: T_IDENT | T_ASTERISK {
        ALLOC($$, sizeof "");
        strcpy($$, "");
@@ -279,24 +279,30 @@ array: T_LBRACKET T_UINT T_RBRACKET {
                .type = CDECL_DECL_ARRAY);
 }
 
-declarator: direct_declarator | pointer direct_declarator {
+pointer: T_ASTERISK qualifiers direct_declarator {
        ALLOC_STRUCT($$, struct cdecl_declarator,
                .type = CDECL_DECL_POINTER,
-               .u.pointer.qualifiers = $1,
-               .u.pointer.declarator = $2);
+               .u.pointer.qualifiers = $2,
+               .child = $3);
+} | T_ASTERISK qualifiers pointer {
+       ALLOC_STRUCT($$, struct cdecl_declarator,
+               .type = CDECL_DECL_POINTER,
+               .u.pointer.qualifiers = $2,
+               .child = $3);
 }
 
+declarator: direct_declarator | pointer
+
 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,
                .u.ident = $1);
 } | direct_declarator array {
        $$ = $2;
-       $$->u.array.declarator = $1;
+       $$->child = $1;
 } | T_LPAREN declarator T_RPAREN {
        $$ = $2;
 };