genksyms: Minor parser cleanup
authorMichal Marek <mmarek@suse.cz>
Fri, 7 Oct 2011 22:48:29 +0000 (00:48 +0200)
committerMichal Marek <mmarek@suse.cz>
Tue, 11 Oct 2011 09:59:19 +0000 (11:59 +0200)
Move the identical logic for recording a struct/union/enum definition to
a function.

scripts/genksyms/parse.y

index ba5c242866c11b4c0803822bd45b940ad16b8474..a783ad4e2b51b1b0974e34f78b647db23bd9aa41 100644 (file)
@@ -51,6 +51,18 @@ remove_list(struct string_list **pb, struct string_list **pe)
   free_list(b, e);
 }
 
+/* Record definition of a struct/union/enum */
+static void record_compound(struct string_list **keyw,
+                      struct string_list **ident,
+                      struct string_list **body,
+                      enum symbol_type type)
+{
+       struct string_list *b = *body, *i = *ident, *r;
+       r = copy_node(i); r->tag = type;
+       r->next = (*keyw)->next; *body = r; (*keyw)->next = NULL;
+       add_symbol(i->string, type, b, is_extern);
+}
+
 %}
 
 %token ASM_KEYW
@@ -215,26 +227,11 @@ type_specifier:
 
        /* Full definitions of an s/u/e.  Record it.  */
        | STRUCT_KEYW IDENT class_body
-               { struct string_list *s = *$3, *i = *$2, *r;
-                 r = copy_node(i); r->tag = SYM_STRUCT;
-                 r->next = (*$1)->next; *$3 = r; (*$1)->next = NULL;
-                 add_symbol(i->string, SYM_STRUCT, s, is_extern);
-                 $$ = $3;
-               }
+               { record_compound($1, $2, $3, SYM_STRUCT); $$ = $3; }
        | UNION_KEYW IDENT class_body
-               { struct string_list *s = *$3, *i = *$2, *r;
-                 r = copy_node(i); r->tag = SYM_UNION;
-                 r->next = (*$1)->next; *$3 = r; (*$1)->next = NULL;
-                 add_symbol(i->string, SYM_UNION, s, is_extern);
-                 $$ = $3;
-               }
+               { record_compound($1, $2, $3, SYM_UNION); $$ = $3; }
        | ENUM_KEYW IDENT enum_body
-               { struct string_list *s = *$3, *i = *$2, *r;
-                 r = copy_node(i); r->tag = SYM_ENUM;
-                 r->next = (*$1)->next; *$3 = r; (*$1)->next = NULL;
-                 add_symbol(i->string, SYM_ENUM, s, is_extern);
-                 $$ = $3;
-               }
+               { record_compound($1, $2, $3, SYM_ENUM); $$ = $3; }
        /*
         * Anonymous enum definition. Tell add_symbol() to restart its counter.
         */