From 3a16f78e73f4e46cdfc81f4d43906126daf8cba6 Mon Sep 17 00:00:00 2001 From: rillig Date: Thu, 8 Jul 2021 04:09:10 +0000 Subject: [PATCH] lint: add grammar rule type_attribute_list_opt Since type attributes (and GCC attributes as well) often modify the preceding identifier, without referring to $$, the easiest way to integrate them into the grammar is to define a separate grammar rule that can be placed wherever these attributes are allowed. This avoids duplicate actions like in direct_param_decl. No functional change. --- usr.bin/xlint/lint1/cgram.y | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index d46f9115f099..38baeccebe92 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.270 2021/07/08 03:55:54 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.271 2021/07/08 04:09:10 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.270 2021/07/08 03:55:54 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.271 2021/07/08 04:09:10 rillig Exp $"); #endif #include @@ -343,7 +343,6 @@ anonymize(sym_t *s) %type generic_assoc_list %type generic_association - %% program: @@ -645,14 +644,13 @@ struct_spec: ; struct: - struct type_attribute - | T_STRUCT_OR_UNION { + T_STRUCT_OR_UNION { symtyp = FTAG; begin_declaration_level($1 == STRUCT ? MOS : MOU); dcs->d_offset = 0; dcs->d_sou_align_in_bits = CHAR_SIZE; $$ = $1; - } + } type_attribute_list_opt ; struct_tag: @@ -1035,10 +1033,7 @@ notype_param_decl: ; direct_param_decl: - identifier type_attribute_list { - $$ = declarator_name(getsym($1)); - } - | identifier { + identifier type_attribute_list_opt { $$ = declarator_name(getsym($1)); } | T_LPAREN notype_param_decl T_RPAREN { @@ -1058,8 +1053,7 @@ direct_param_decl: ; direct_notype_param_decl: - /* XXX: missing identifier type_attribute_list? */ - identifier { + identifier /* XXX: missing type_attribute_list_opt? */ { $$ = declarator_name(getsym($1)); } | T_LPAREN notype_param_decl T_RPAREN { @@ -1982,6 +1976,11 @@ comma_opt: /* GCC extensions */ +type_attribute_list_opt: + /* empty */ + | type_attribute_list + ; + type_attribute_list: type_attribute | type_attribute_list type_attribute