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 in grammar fo...



details:   https://anonhg.NetBSD.org/src/rev/696a88ed421d
branches:  trunk
changeset: 961865:696a88ed421d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Apr 23 20:26:43 2021 +0000

description:
lint: merge duplicate code in grammar for GCC compound expressions

This increases the number of shift/reduce conflicts, once again.  I
don't know why since the previous two grammar rules only differed in a
single detail.  One of them had a declaration_list while the other
didn't.  This difference is exactly what declaration_list_opt is for.

Anyway, the tests for both cases (with and without declarations) work
exactly as before.

Merging this duplicate code will probably make it easier to fix the
current limitation in lint regarding GCC compound expressions that a
statement followed by a declaration generates a syntax error.

Fixing this is not trivial, my first attempt failed either with
segmentation faults or with sym->s_type becoming NOSPEC during the
expression.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  25 +++++++++----------------
 1 files changed, 9 insertions(+), 16 deletions(-)

diffs (68 lines):

diff -r 988be23cd8de -r 696a88ed421d usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Apr 23 20:13:29 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Apr 23 20:26:43 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.220 2021/04/20 21:48:39 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.221 2021/04/23 20:26:43 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.220 2021/04/20 21:48:39 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.221 2021/04/23 20:26:43 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -123,7 +123,7 @@
 }
 %}
 
-%expect 177
+%expect 185
 
 %union {
        val_t   *y_val;
@@ -1826,6 +1826,11 @@
          }
        ;
 
+declaration_list_opt:
+         /* empty */
+       | declaration_list
+       ;
+
 declaration_list:
          declaration {
                clear_warning_flags();
@@ -1913,7 +1918,7 @@
                        $2->tn_parenthesized = true;
                $$ = $2;
          }
-       | T_LPAREN compound_statement_lbrace declaration_list
+       | T_LPAREN compound_statement_lbrace declaration_list_opt
            expr_statement_list {
                block_level--;
                mem_block_level--;
@@ -1926,18 +1931,6 @@
                $$ = new_name_node(*current_initsym(), 0);
                end_initialization();
         }
-       | T_LPAREN compound_statement_lbrace expr_statement_list {
-               block_level--;
-               mem_block_level--;
-               begin_initialization(mktempsym($3->tn_type));
-               mem_block_level++;
-               block_level++;
-               /* ({ }) is a GCC extension */
-               gnuism(320);
-        } compound_statement_rbrace T_RPAREN {
-               $$ = new_name_node(*current_initsym(), 0);
-               end_initialization();
-        }
        | term T_INCDEC {
                $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
          }



Home | Main Index | Thread Index | Old Index