Linux-Sparse Archive on lore.kernel.org
 help / color / 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] attribute: simplify parsing of attributes
Date: Wed, 22 Jul 2020 23:51:48 +0200
Message-ID: <20200722215148.37168-1-luc.vanoostenryck@gmail.com> (raw)

In the loop doing the parsing of attributes, it's first checked
if EOF is reached, then if the token is ';' but these tests are
not needed since they're subsumed by the third one: checking if
the token is an identifier.

So, remove the tests for EOF and ';', and change the for-loop
into a while-loop checking for TOKEN_IDENT. As a bonus, remove
the local variable holding the identifier since it's there only
for historical reasons.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/parse.c b/parse.c
index cc5dbd522b3e..b07237eee0bf 100644
--- a/parse.c
+++ b/parse.c
@@ -1362,18 +1362,8 @@ static struct token *attribute_specifier(struct token *token, struct decl_state
 	token = expect(token, '(', "after attribute");
 	token = expect(token, '(', "after attribute");
 
-	for (;;) {
-		struct ident *attribute_name;
-		struct symbol *attr;
-
-		if (eof_token(token))
-			break;
-		if (match_op(token, ';'))
-			break;
-		if (token_type(token) != TOKEN_IDENT)
-			break;
-		attribute_name = token->ident;
-		attr = lookup_keyword(attribute_name, NS_KEYWORD);
+	while (token_type(token) == TOKEN_IDENT) {
+		struct symbol *attr = lookup_keyword(token->ident, NS_KEYWORD);
 		if (attr && attr->op->attribute)
 			token = attr->op->attribute(token->next, attr, ctx);
 		else
@@ -1784,13 +1774,7 @@ static struct token *skip_attributes(struct token *token)
 			break;
 		token = expect(token->next, '(', "after attribute");
 		token = expect(token, '(', "after attribute");
-		for (;;) {
-			if (eof_token(token))
-				break;
-			if (match_op(token, ';'))
-				break;
-			if (token_type(token) != TOKEN_IDENT)
-				break;
+		while (token_type(token) == TOKEN_IDENT) {
 			token = skip_attribute(token);
 			if (!match_op(token, ','))
 				break;
-- 
2.27.0


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200722215148.37168-1-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

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git