Skip to content

Commit b06fcd6

Browse files
committed
genksyms: Minor parser cleanup
Move the identical logic for recording a struct/union/enum definition to a function.
1 parent cd96ea3 commit b06fcd6

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

‎scripts/genksyms/parse.y‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ remove_list(struct string_list **pb, struct string_list **pe)
5151
free_list(b, e);
5252
}
5353

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+
5466
%}
5567

5668
%token ASM_KEYW
@@ -215,26 +227,11 @@ type_specifier:
215227

216228
/* Full definitions of an s/u/e. Record it. */
217229
| 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; }
224231
| 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; }
231233
| 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; }
238235
/*
239236
* Anonymous enum definition. Tell add_symbol() to restart its counter.
240237
*/

0 commit comments

Comments
 (0)