Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] attribute: simplify parsing of attributes
@ 2020-07-22 21:51 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-07-22 21:51 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 21:51 [PATCH] attribute: simplify parsing of attributes Luc Van Oostenryck

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