Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: clean up grammar for type-qualifier



details:   https://anonhg.NetBSD.org/src/rev/da6ba4df5d0e
branches:  trunk
changeset: 373148:da6ba4df5d0e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 21 12:45:27 2023 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)

diffs (73 lines):

diff -r 266af144bc16 -r da6ba4df5d0e usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jan 21 11:57:03 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jan 21 12:45:27 2023 +0000
@@ -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 @@
 %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 @@
        ;
 
 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:           /* 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.



Home | Main Index | Thread Index | Old Index