Module Name:    src
Committed By:   rillig
Date:           Sat Jan 21 12:45:27 UTC 2023

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

Log Message:
lint: clean up grammar for type-qualifier

A type-qualifier by itself does not carry pointer information, so add a
helper rule in the grammar for those cases where a type-qualifier is
actually used in a type like 'int *const'.

This allows general type qualifier checks to be performed during
parsing, for example to ensure that '_Atomic' is only used in C11 or
later.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.427 -r1.428 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.427 src/usr.bin/xlint/lint1/cgram.y:1.428
--- src/usr.bin/xlint/lint1/cgram.y:1.427	Sat Jan 21 08:04:43 2023
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jan 21 12:45:27 2023
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.427 2023/01/21 08:04:43 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.428 2023/01/21 12:45:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.427 2023/01/21 08:04:43 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.428 2023/01/21 12:45:27 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -291,11 +291,12 @@ is_either(const char *s, const char *a, 
 %type	<y_sym>		enums_with_opt_comma
 %type	<y_sym>		enumerator_list
 %type	<y_sym>		enumerator
-%type	<y_qual_ptr>	type_qualifier
+%type	<y_tqual>	type_qualifier
 %type	<y_qual_ptr>	pointer
 %type	<y_qual_ptr>	asterisk
 %type	<y_qual_ptr>	type_qualifier_list_opt
 %type	<y_qual_ptr>	type_qualifier_list
+%type	<y_qual_ptr>	type_qualifier_list_elem
 %type	<y_sym>		notype_declarator
 %type	<y_sym>		type_declarator
 %type	<y_sym>		notype_direct_declarator
@@ -1098,13 +1099,7 @@ enumerator:			/* C99 6.7.2.2 */
 	;
 
 type_qualifier:			/* C99 6.7.3 */
-	  T_QUAL {
-		$$ = xcalloc(1, sizeof(*$$));
-		if ($1 == CONST)
-			$$->p_const = true;
-		if ($1 == VOLATILE)
-			$$->p_volatile = true;
-	  }
+	  T_QUAL
 	;
 
 pointer:			/* C99 6.7.5 */
@@ -1132,12 +1127,22 @@ type_qualifier_list_opt:	/* see C99 6.7.
 	;
 
 type_qualifier_list:		/* C99 6.7.5 */
-	  type_qualifier
-	| type_qualifier_list type_qualifier {
+	  type_qualifier_list_elem
+	| type_qualifier_list type_qualifier_list_elem {
 		$$ = merge_qualified_pointer($1, $2);
 	  }
 	;
 
+type_qualifier_list_elem:	/* helper for 'pointer' */
+	type_qualifier {
+		$$ = xcalloc(1, sizeof(*$$));
+		if ($1 == CONST)
+			$$->p_const = true;
+		if ($1 == VOLATILE)
+			$$->p_volatile = true;
+	  }
+	;
+
 /*
  * For an explanation of 'notype' in the following rules, see
  * https://www.gnu.org/software/bison/manual/bison.html#Semantic-Tokens.

Reply via email to