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: extract clrtyp from declaration_sp...



details:   https://anonhg.NetBSD.org/src/rev/86d44b04a92d
branches:  trunk
changeset: 1022243:86d44b04a92d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 10 17:06:56 2021 +0000

description:
lint: extract clrtyp from declaration_specifiers

This makes the grammar more uniform and thereby easier to understand.
The actions clrtyp and deftyp now come in pairs almost everywhere.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  45 ++++++++++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 21 deletions(-)

diffs (141 lines):

diff -r f38f28acb15c -r 86d44b04a92d usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jul 10 16:54:40 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jul 10 17:06:56 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.293 2021/07/10 16:54:40 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.294 2021/07/10 17:06:56 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.293 2021/07/10 16:54:40 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.294 2021/07/10 17:06:56 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -447,8 +447,8 @@
        | clrtyp declmods deftyp notype_decl {
                $$ = $4;
          }
-       | declaration_specifiers deftyp type_decl {
-               $$ = $3;
+       | clrtyp declaration_specifiers deftyp type_decl {
+               $$ = $4;
          }
        ;
 
@@ -474,7 +474,7 @@
                warning(2);
          }
        | clrtyp declmods deftyp notype_init_decls T_SEMI
-       | declaration_specifiers deftyp T_SEMI {
+       | clrtyp declaration_specifiers deftyp T_SEMI {
                if (!dcs->d_nonempty_decl) {
                        /* empty declaration */
                        warning(2);
@@ -483,14 +483,14 @@
                        warning(3, type_name(dcs->d_type));
                }
          }
-       | declaration_specifiers deftyp type_init_decls T_SEMI {
+       | clrtyp declaration_specifiers deftyp type_init_decls T_SEMI {
                if (dcs->d_nonempty_decl) {
                        /* '%s' declared in argument declaration list */
                        warning(3, type_name(dcs->d_type));
                }
          }
        | clrtyp declmods error
-       | declaration_specifiers error
+       | clrtyp declaration_specifiers error
        ;
 
 declaration:                   /* C99 6.7 */
@@ -509,7 +509,7 @@
                }
          }
        | clrtyp declmods deftyp notype_init_decls T_SEMI
-       | declaration_specifiers deftyp T_SEMI {
+       | clrtyp declaration_specifiers deftyp T_SEMI {
                if (dcs->d_scl == TYPEDEF) {
                        /* typedef declares no type name */
                        warning(72);
@@ -518,7 +518,7 @@
                        warning(2);
                }
          }
-       | declaration_specifiers deftyp type_init_decls T_SEMI
+       | clrtyp declaration_specifiers deftyp type_init_decls T_SEMI
        ;
 
 clrtyp:
@@ -534,11 +534,11 @@
        ;
 
 declaration_specifiers:                /* C99 6.7 */
-         clrtyp typespec {
-               add_type($2);
+         typespec {
+               add_type($1);
          }
-       | clrtyp declmods typespec {
-               add_type($3);
+       | declmods typespec {
+               add_type($2);
          }
        | type_attribute declaration_specifiers
        | declaration_specifiers declmod
@@ -709,6 +709,7 @@
        | type_attribute noclass_declspecs_postfix
        ;
 
+/* TODO: pair up clrtyp with deftyp */
 noclass_declspecs_postfix:
          clrtyp typespec {
                add_type($2);
@@ -1153,20 +1154,20 @@
          clrtyp declmods deftyp {
                $$ = declare_argument(abstract_name(), false);
          }
-       | declaration_specifiers deftyp {
+       | clrtyp declaration_specifiers deftyp {
                $$ = declare_argument(abstract_name(), false);
          }
        | clrtyp declmods deftyp notype_param_decl {
                $$ = declare_argument($4, false);
          }
-       | declaration_specifiers deftyp type_param_decl {
-               $$ = declare_argument($3, false);
+       | clrtyp declaration_specifiers deftyp type_param_decl {
+               $$ = declare_argument($4, false);
          }
        | clrtyp declmods deftyp abstract_declarator {
                $$ = declare_argument($4, false);
          }
-       | declaration_specifiers deftyp abstract_declarator {
-               $$ = declare_argument($3, false);
+       | clrtyp declaration_specifiers deftyp abstract_declarator {
+               $$ = declare_argument($4, false);
          }
        ;
 
@@ -1539,11 +1540,13 @@
        ;
 
 for_exprs:                     /* see C99 6.8.5 */
-         for_start declaration_specifiers deftyp notype_init_decls T_SEMI
-           expr_opt T_SEMI expr_opt T_RPAREN {
+         for_start
+           clrtyp declaration_specifiers deftyp notype_init_decls T_SEMI
+           expr_opt T_SEMI
+           expr_opt T_RPAREN {
                /* variable declaration in for loop */
                c99ism(325);
-               for1(NULL, $6, $8);
+               for1(NULL, $7, $9);
                clear_warning_flags();
            }
          | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN {



Home | Main Index | Thread Index | Old Index