diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-06-13 13:01:17 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-25 23:19:12 +0200 |
commit | c6b40f4538f8fb3c55ef65f31808b8905a375b6e (patch) | |
tree | 8f2ae82e704140e34ddc917e1e971d77c7e2524d | |
parent | e7dad08db283421a46c138f6aaee19505a96bc19 (diff) | |
download | sparse-c6b40f4538f8fb3c55ef65f31808b8905a375b6e.tar.gz |
attribute: split handle_asm_name() from handle_attributes()
handle_attributes() handles attributes but also the asm names.
These asm names must occur before the attributes and only once
while the attributes may occur multiple time. Also, these asm
names are not allowed everywhere attributes, only in declarations.
It's maybe handy to process both in the same function but it's
also slightly confusing. So, move the handling of the asm names
in a separate function.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | parse.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -1742,6 +1742,20 @@ static struct token *parameter_type_list(struct token *, struct symbol *); static struct token *identifier_list(struct token *, struct symbol *); static struct token *declarator(struct token *token, struct decl_state *ctx); +static struct token *handle_asm_name(struct token *token, struct decl_state *ctx) +{ + struct symbol *keyword; + + if (token_type(token) != TOKEN_IDENT) + return token; + keyword = lookup_keyword(token->ident, NS_KEYWORD); + if (!keyword || keyword->type != SYM_KEYWORD) + return token; + if (!(keyword->op->type & KW_ASM)) + return token; + return keyword->op->declarator(token->next, ctx); +} + static struct token *skip_attribute(struct token *token) { token = token->next; @@ -1798,7 +1812,6 @@ static struct token *handle_attributes(struct token *token, struct decl_state *c if (!(keyword->op->type & keywords)) break; token = keyword->op->declarator(token->next, ctx); - keywords &= KW_ATTRIBUTE; } return token; } @@ -3018,7 +3031,8 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis saved = ctx.ctype; token = declarator(token, &ctx); - token = handle_attributes(token, &ctx, KW_ATTRIBUTE | KW_ASM); + token = handle_asm_name(token, &ctx); + token = handle_attributes(token, &ctx, KW_ATTRIBUTE); apply_modifiers(token->pos, &ctx); decl->ctype = ctx.ctype; @@ -3142,7 +3156,8 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis ctx.ctype = saved; token = handle_attributes(token, &ctx, KW_ATTRIBUTE); token = declarator(token, &ctx); - token = handle_attributes(token, &ctx, KW_ATTRIBUTE | KW_ASM); + token = handle_asm_name(token, &ctx); + token = handle_attributes(token, &ctx, KW_ATTRIBUTE); apply_modifiers(token->pos, &ctx); decl->ctype = ctx.ctype; decl->ctype.modifiers |= mod; |