Module Name:    src
Committed By:   rillig
Date:           Tue Jul  6 18:22:41 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: move grammar rules for GCC __attribute__ to the bottom

In GCC 2.95.3, attributes had already been available for functions,
variables and types.  At that time they were indeed related to
declarations, and that's where they ended up in lint's grammar.  Later,
attributes were extended to labels, enumerators and statements as well.

To keep the grammar for declarations short and comprehensible, move the
rather large part about __attribute__ at the bottom of the grammar,
creating a new section called "GCC extensions".

The grammar rules are not named accurately (and never were).  They are
called "type attributes" but apply not only to types.  These names will
be improved in a follow-up commit.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/cgram.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.259 src/usr.bin/xlint/lint1/cgram.y:1.260
--- src/usr.bin/xlint/lint1/cgram.y:1.259	Tue Jul  6 17:52:04 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Jul  6 18:22:40 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.259 2021/07/06 17:52:04 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.260 2021/07/06 18:22:40 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.259 2021/07/06 17:52:04 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.260 2021/07/06 18:22:40 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -538,114 +538,6 @@ declaration:			/* C99 6.7 */
 	| error T_SEMI
 	;
 
-type_attribute_format_type:
-	  T_AT_FORMAT_GNU_PRINTF
-	| T_AT_FORMAT_PRINTF
-	| T_AT_FORMAT_SCANF
-	| T_AT_FORMAT_STRFMON
-	| T_AT_FORMAT_STRFTIME
-	| T_AT_FORMAT_SYSLOG
-	;
-
-type_attribute_bounded_type:
-	  T_AT_MINBYTES
-	| T_AT_STRING
-	| T_AT_BUFFER
-	;
-
-
-type_attribute_spec:
-	  /* empty */
-	| T_AT_ALWAYS_INLINE
-	| T_AT_ALIAS T_LPAREN string T_RPAREN
-	| T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN
-	| T_AT_ALIGNED
-	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN
-	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN
-	| T_AT_BOUNDED T_LPAREN type_attribute_bounded_type
-	  T_COMMA constant_expr T_COMMA constant_expr T_RPAREN
-	| T_AT_COLD
-	| T_AT_COMMON
-	| T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN
-	| T_AT_CONSTRUCTOR
-	| T_AT_DEPRECATED T_LPAREN string T_RPAREN
-	| T_AT_DEPRECATED
-	| T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN
-	| T_AT_DESTRUCTOR
-	| T_AT_FALLTHROUGH {
-		fallthru(1);
-	  }
-	| T_AT_FORMAT T_LPAREN type_attribute_format_type T_COMMA
-	    constant_expr T_COMMA constant_expr T_RPAREN
-	| T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
-	| T_AT_GNU_INLINE
-	| T_AT_MALLOC
-	| T_AT_MAY_ALIAS
-	| T_AT_MODE T_LPAREN T_NAME T_RPAREN
-	| T_AT_NOINLINE
-	| T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
-	| T_AT_NONNULL
-	| T_AT_NONSTRING
-	| T_AT_NORETURN
-	| T_AT_NOTHROW
-	| T_AT_NO_INSTRUMENT_FUNCTION
-	| T_AT_OPTIMIZE T_LPAREN string T_RPAREN
-	| T_AT_PACKED {
-		addpacked();
-	  }
-	| T_AT_PCS T_LPAREN string T_RPAREN
-	| T_AT_PURE
-	| T_AT_RETURNS_TWICE
-	| T_AT_SECTION T_LPAREN string T_RPAREN
-	| T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
-	| T_AT_SENTINEL
-	| T_AT_TLS_MODEL T_LPAREN string T_RPAREN
-	| T_AT_TUNION
-	| T_AT_UNUSED {
-		add_attr_used();
-	  }
-	| T_AT_USED {
-		add_attr_used();
-	  }
-	| T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
-	| T_AT_WARN_UNUSED_RESULT
-	| T_AT_WEAK
-	| T_QUAL {
-		if ($1 != CONST)
-			yyerror("Bad attribute");
-	  }
-	;
-
-type_attribute_spec_list:
-	  type_attribute_spec
-	| type_attribute_spec_list T_COMMA type_attribute_spec
-	;
-
-align_as:
-	  typespec
-	| constant_expr
-	;
-
-type_attribute:
-	  T_ATTRIBUTE T_LPAREN T_LPAREN {
-	    attron = true;
-	  } type_attribute_spec_list {
-	    attron = false;
-	  } T_RPAREN T_RPAREN
-	| T_ALIGNAS T_LPAREN align_as T_RPAREN {
-	  }
-	| T_PACKED {
-		addpacked();
-	  }
-	| T_NORETURN {
-	  }
-	;
-
-type_attribute_list:
-	  type_attribute
-	| type_attribute_list type_attribute
-	;
-
 clrtyp:
 	  /* empty */ {
 		clrtyp();
@@ -1228,6 +1120,11 @@ type_qualifier:
 	  }
 	;
 
+align_as:			/* See alignment-specifier in C11 6.7.5 */
+	  typespec
+	| constant_expr
+	;
+
 param_list:
 	  id_list_lparen identifier_list T_RPAREN {
 		$$ = $2;
@@ -2077,6 +1974,113 @@ comma_opt:
 	| T_COMMA
 	;
 
+/* GCC extensions */
+
+/* TODO: split into type_attribute and gcc_attribute */
+
+type_attribute_list:
+	  type_attribute
+	| type_attribute_list type_attribute
+	;
+
+type_attribute:
+	  T_ATTRIBUTE T_LPAREN T_LPAREN {
+	    attron = true;
+	  } type_attribute_spec_list {
+	    attron = false;
+	  } T_RPAREN T_RPAREN
+	| T_ALIGNAS T_LPAREN align_as T_RPAREN {
+	  }
+	| T_PACKED {
+		addpacked();
+	  }
+	| T_NORETURN {
+	  }
+	;
+
+/* https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html */
+type_attribute_spec_list:
+	  type_attribute_spec
+	| type_attribute_spec_list T_COMMA type_attribute_spec
+	;
+
+type_attribute_spec:
+	  /* empty */
+	| T_AT_ALWAYS_INLINE
+	| T_AT_ALIAS T_LPAREN string T_RPAREN
+	| T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN
+	| T_AT_ALIGNED
+	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN
+	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN
+	| T_AT_BOUNDED T_LPAREN type_attribute_bounded_type
+	  T_COMMA constant_expr T_COMMA constant_expr T_RPAREN
+	| T_AT_COLD
+	| T_AT_COMMON
+	| T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN
+	| T_AT_CONSTRUCTOR
+	| T_AT_DEPRECATED T_LPAREN string T_RPAREN
+	| T_AT_DEPRECATED
+	| T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN
+	| T_AT_DESTRUCTOR
+	| T_AT_FALLTHROUGH {
+		fallthru(1);
+	  }
+	| T_AT_FORMAT T_LPAREN type_attribute_format_type T_COMMA
+	    constant_expr T_COMMA constant_expr T_RPAREN
+	| T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
+	| T_AT_GNU_INLINE
+	| T_AT_MALLOC
+	| T_AT_MAY_ALIAS
+	| T_AT_MODE T_LPAREN T_NAME T_RPAREN
+	| T_AT_NOINLINE
+	| T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
+	| T_AT_NONNULL
+	| T_AT_NONSTRING
+	| T_AT_NORETURN
+	| T_AT_NOTHROW
+	| T_AT_NO_INSTRUMENT_FUNCTION
+	| T_AT_OPTIMIZE T_LPAREN string T_RPAREN
+	| T_AT_PACKED {
+		addpacked();
+	  }
+	| T_AT_PCS T_LPAREN string T_RPAREN
+	| T_AT_PURE
+	| T_AT_RETURNS_TWICE
+	| T_AT_SECTION T_LPAREN string T_RPAREN
+	| T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
+	| T_AT_SENTINEL
+	| T_AT_TLS_MODEL T_LPAREN string T_RPAREN
+	| T_AT_TUNION
+	| T_AT_UNUSED {
+		add_attr_used();
+	  }
+	| T_AT_USED {
+		add_attr_used();
+	  }
+	| T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
+	| T_AT_WARN_UNUSED_RESULT
+	| T_AT_WEAK
+	| T_QUAL {
+		if ($1 != CONST)
+			yyerror("Bad attribute");
+	  }
+	;
+
+type_attribute_bounded_type:
+	  T_AT_MINBYTES
+	| T_AT_STRING
+	| T_AT_BUFFER
+	;
+
+type_attribute_format_type:
+	  T_AT_FORMAT_GNU_PRINTF
+	| T_AT_FORMAT_PRINTF
+	| T_AT_FORMAT_SCANF
+	| T_AT_FORMAT_STRFMON
+	| T_AT_FORMAT_STRFTIME
+	| T_AT_FORMAT_SYSLOG
+	;
+
 %%
 
 /* ARGSUSED */

Reply via email to