Commit b06fcd6c83c231f51a86448bb33c4cd717fefee8
1 parent
cd96ea3a4f
Exists in
master
and in
20 other branches
genksyms: Minor parser cleanup
Move the identical logic for recording a struct/union/enum definition to a function.
Showing 1 changed file with 15 additions and 18 deletions Side-by-side Diff
scripts/genksyms/parse.y
... | ... | @@ -51,6 +51,18 @@ |
51 | 51 | free_list(b, e); |
52 | 52 | } |
53 | 53 | |
54 | +/* Record definition of a struct/union/enum */ | |
55 | +static void record_compound(struct string_list **keyw, | |
56 | + struct string_list **ident, | |
57 | + struct string_list **body, | |
58 | + enum symbol_type type) | |
59 | +{ | |
60 | + struct string_list *b = *body, *i = *ident, *r; | |
61 | + r = copy_node(i); r->tag = type; | |
62 | + r->next = (*keyw)->next; *body = r; (*keyw)->next = NULL; | |
63 | + add_symbol(i->string, type, b, is_extern); | |
64 | +} | |
65 | + | |
54 | 66 | %} |
55 | 67 | |
56 | 68 | %token ASM_KEYW |
57 | 69 | |
58 | 70 | |
... | ... | @@ -215,26 +227,11 @@ |
215 | 227 | |
216 | 228 | /* Full definitions of an s/u/e. Record it. */ |
217 | 229 | | STRUCT_KEYW IDENT class_body |
218 | - { struct string_list *s = *$3, *i = *$2, *r; | |
219 | - r = copy_node(i); r->tag = SYM_STRUCT; | |
220 | - r->next = (*$1)->next; *$3 = r; (*$1)->next = NULL; | |
221 | - add_symbol(i->string, SYM_STRUCT, s, is_extern); | |
222 | - $$ = $3; | |
223 | - } | |
230 | + { record_compound($1, $2, $3, SYM_STRUCT); $$ = $3; } | |
224 | 231 | | UNION_KEYW IDENT class_body |
225 | - { struct string_list *s = *$3, *i = *$2, *r; | |
226 | - r = copy_node(i); r->tag = SYM_UNION; | |
227 | - r->next = (*$1)->next; *$3 = r; (*$1)->next = NULL; | |
228 | - add_symbol(i->string, SYM_UNION, s, is_extern); | |
229 | - $$ = $3; | |
230 | - } | |
232 | + { record_compound($1, $2, $3, SYM_UNION); $$ = $3; } | |
231 | 233 | | ENUM_KEYW IDENT enum_body |
232 | - { struct string_list *s = *$3, *i = *$2, *r; | |
233 | - r = copy_node(i); r->tag = SYM_ENUM; | |
234 | - r->next = (*$1)->next; *$3 = r; (*$1)->next = NULL; | |
235 | - add_symbol(i->string, SYM_ENUM, s, is_extern); | |
236 | - $$ = $3; | |
237 | - } | |
234 | + { record_compound($1, $2, $3, SYM_ENUM); $$ = $3; } | |
238 | 235 | /* |
239 | 236 | * Anonymous enum definition. Tell add_symbol() to restart its counter. |
240 | 237 | */ |