linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 02/10] attribute: split handle_asm_name() from handle_attributes()
Date: Sun,  9 Aug 2020 22:53:21 +0200	[thread overview]
Message-ID: <20200809205329.42811-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200809205329.42811-1-luc.vanoostenryck@gmail.com>

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>
---
 parse.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/parse.c b/parse.c
index 19520eaebf38..cf897e5d2804 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
-- 
2.28.0


  parent reply	other threads:[~2020-08-09 20:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 20:53 [PATCH 00/10] separate parsing of asm-names from attributes Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 01/10] use lookup_keyword() for qualifiers Luc Van Oostenryck
2020-08-09 20:53 ` Luc Van Oostenryck [this message]
2020-08-09 20:53 ` [PATCH 03/10] attribute: fold parse_asm_declarator() into handle_asm_name() Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 04/10] attribute: remove argument 'keywords' from handle_attributes() Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 05/10] attribute: directly use attribute_specifier() to handle attributes Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 06/10] attribute: factorize matching of '__attribute__' Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 07/10] attribute: no need to lookup '__attribute__' in NS_KEYWORD Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 08/10] testing for SYM_KEYWORD is unneeded for lookup_keyword() Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 09/10] testing for sym->op " Luc Van Oostenryck
2020-08-09 20:53 ` [PATCH 10/10] keyword type is a bitmask and must be tested so Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200809205329.42811-3-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).