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: merge duplicate code for struct an...



details:   https://anonhg.NetBSD.org/src/rev/b45b2b00bce4
branches:  trunk
changeset: 1022258:b45b2b00bce4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 10 20:44:23 2021 +0000

description:
lint: merge duplicate code for struct and enum tags

This is a tricky area.  Inlining identifier_sym did not work because of
the side-effects of getsym.  In situations where two identifiers of
different kinds follow each other, such as 'enum id1 id2', the timing is
crucial, and inlining identifier_sym would have led to an internal error
in getsym.  The symbol type has to be reset from FTAG to FVFT before
reading the next token.

No functional change.

diffstat:

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

diffs (132 lines):

diff -r e8feb4519228 -r b45b2b00bce4 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jul 10 20:22:37 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jul 10 20:44:23 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.300 2021/07/10 19:29:28 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.301 2021/07/10 20:44:23 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.300 2021/07/10 19:29:28 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.301 2021/07/10 20:44:23 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -285,10 +285,9 @@
 %type  <y_type>        notype_type_specifier
 %type  <y_type>        struct_or_union_specifier
 %type  <y_type>        enum_specifier
-%type  <y_sym>         struct_tag
-%type  <y_sym>         enum_tag
 %type  <y_tspec>       struct_or_union
 %type  <y_sym>         braced_struct_declaration_list
+%type  <y_sym>         identifier_sym
 %type  <y_name>        identifier
 %type  <y_sym>         struct_declaration_list_semi
 %type  <y_sym>         struct_declaration_list
@@ -302,7 +301,6 @@
 %type  <y_sym>         enum_declaration
 %type  <y_sym>         enumerator_list
 %type  <y_sym>         enumerator
-%type  <y_sym>         enumeration_constant
 %type  <y_sym>         notype_direct_decl
 %type  <y_sym>         type_direct_decl
 %type  <y_qual_ptr>    pointer
@@ -597,7 +595,7 @@
        ;
 
 struct_or_union_specifier:     /* C99 6.7.2.1 */
-         struct_or_union struct_tag {
+         struct_or_union identifier_sym {
                /*
                 * STDC requires that "struct a;" always introduces
                 * a new tag if "a" is not declared at current level
@@ -607,7 +605,7 @@
                 */
                $$ = mktag($2, $1, false, yychar == T_SEMI);
          }
-       | struct_or_union struct_tag {
+       | struct_or_union identifier_sym {
                dcs->d_tagtyp = mktag($2, $1, true, false);
          } braced_struct_declaration_list {
                $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
@@ -632,12 +630,6 @@
          } type_attribute_list_opt
        ;
 
-struct_tag:
-         identifier {
-               $$ = getsym($1);
-         }
-       ;
-
 braced_struct_declaration_list:
          T_LBRACE {
                symtyp = FVFT;
@@ -781,10 +773,10 @@
        ;
 
 enum_specifier:                /* C99 6.7.2.2 */
-         enum enum_tag {
+         enum identifier_sym {
                $$ = mktag($2, ENUM, false, false);
          }
-       | enum enum_tag {
+       | enum identifier_sym {
                dcs->d_tagtyp = mktag($2, ENUM, true, false);
          } enum_declaration {
                $$ = complete_tag_enum(dcs->d_tagtyp, $4);
@@ -807,12 +799,6 @@
          }
        ;
 
-enum_tag:
-         identifier {
-               $$ = getsym($1);
-         }
-       ;
-
 enum_declaration:
          T_LBRACE {
                symtyp = FVFT;
@@ -846,20 +832,14 @@
        ;
 
 enumerator:                    /* C99 6.7.2.2 */
-         enumeration_constant {
+         identifier_sym {
                $$ = enumeration_constant($1, enumval, true);
          }
-       | enumeration_constant T_ASSIGN constant_expr {
+       | identifier_sym T_ASSIGN constant_expr {
                $$ = enumeration_constant($1, to_int_constant($3, true), false);
          }
        ;
 
-enumeration_constant:          /* C99 6.4.4.3 */
-         identifier {
-               $$ = getsym($1);
-         }
-       ;
-
 
 /*
  * For an explanation of 'notype' in the following rules, see the Bison
@@ -1897,6 +1877,12 @@
          }
        ;
 
+identifier_sym:
+         identifier {
+               $$ = getsym($1);
+         }
+       ;
+
 identifier:                    /* C99 6.4.2.1 */
          T_NAME {
                $$ = $1;



Home | Main Index | Thread Index | Old Index