Fri Jul 9 20:36:34 2021 UTC ()
lint: remove 6 of the remaining 162 conflicts from the grammar

No functional change.


(rillig)
diff -r1.275 -r1.276 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.275 -r1.276 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/09 06:37:11 1.275
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/09 20:36:34 1.276
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.275 2021/07/09 06:37:11 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.276 2021/07/09 20:36:34 rillig Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.275 2021/07/09 06:37:11 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.276 2021/07/09 20:36:34 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
@@ -113,27 +113,27 @@ RESTORE_WARN_FLAGS(const char *file, siz @@ -113,27 +113,27 @@ RESTORE_WARN_FLAGS(const char *file, siz
113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__) 113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__)
114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__) 114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__)
115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__) 115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__)
116 116
117/* unbind the anonymous struct members from the struct */ 117/* unbind the anonymous struct members from the struct */
118static void 118static void
119anonymize(sym_t *s) 119anonymize(sym_t *s)
120{ 120{
121 for ( ; s != NULL; s = s->s_next) 121 for ( ; s != NULL; s = s->s_next)
122 s->s_styp = NULL; 122 s->s_styp = NULL;
123} 123}
124%} 124%}
125 125
126%expect 162 126%expect 156
127 127
128%union { 128%union {
129 val_t *y_val; 129 val_t *y_val;
130 sbuf_t *y_sb; 130 sbuf_t *y_sb;
131 sym_t *y_sym; 131 sym_t *y_sym;
132 op_t y_op; 132 op_t y_op;
133 scl_t y_scl; 133 scl_t y_scl;
134 tspec_t y_tspec; 134 tspec_t y_tspec;
135 tqual_t y_tqual; 135 tqual_t y_tqual;
136 type_t *y_type; 136 type_t *y_type;
137 tnode_t *y_tnode; 137 tnode_t *y_tnode;
138 range_t y_range; 138 range_t y_range;
139 strg_t *y_string; 139 strg_t *y_string;
@@ -929,54 +929,49 @@ type_init_decl: @@ -929,54 +929,49 @@ type_init_decl:
929 cgram_declare($1, false, $2); 929 cgram_declare($1, false, $2);
930 check_size($1); 930 check_size($1);
931 } 931 }
932 | type_decl asm_or_symbolrename_opt { 932 | type_decl asm_or_symbolrename_opt {
933 begin_initialization($1); 933 begin_initialization($1);
934 cgram_declare($1, true, $2); 934 cgram_declare($1, true, $2);
935 } T_ASSIGN initializer { 935 } T_ASSIGN initializer {
936 check_size($1); 936 check_size($1);
937 end_initialization(); 937 end_initialization();
938 } 938 }
939 ; 939 ;
940 940
941notype_decl: 941notype_decl:
942 notype_direct_decl 942 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */
943 | pointer notype_direct_decl { 943 type_attribute_list_opt notype_direct_decl {
944 $$ = add_pointer($2, $1); 944 $$ = $2;
 945 }
 946 | pointer type_attribute_list_opt notype_direct_decl {
 947 $$ = add_pointer($3, $1);
945 } 948 }
946 ; 949 ;
947 950
948type_decl: 951type_decl:
949 type_direct_decl 952 type_direct_decl
950 | pointer type_direct_decl { 953 | pointer type_direct_decl {
951 $$ = add_pointer($2, $1); 954 $$ = add_pointer($2, $1);
952 } 955 }
953 ; 956 ;
954 957
955/* 
956 * XXX: shift/reduce conflict, caused by: 
957 * type_attribute notype_direct_decl 
958 * notype_direct_decl type_attribute 
959 */ 
960notype_direct_decl: 958notype_direct_decl:
961 T_NAME { 959 T_NAME {
962 $$ = declarator_name(getsym($1)); 960 $$ = declarator_name(getsym($1));
963 } 961 }
964 | T_LPAREN type_decl T_RPAREN { 962 | T_LPAREN type_decl T_RPAREN {
965 $$ = $2; 963 $$ = $2;
966 } 964 }
967 | type_attribute notype_direct_decl { 
968 $$ = $2; 
969 } 
970 | notype_direct_decl T_LBRACK T_RBRACK { 965 | notype_direct_decl T_LBRACK T_RBRACK {
971 $$ = add_array($1, false, 0); 966 $$ = add_array($1, false, 0);
972 } 967 }
973 | notype_direct_decl T_LBRACK array_size T_RBRACK { 968 | notype_direct_decl T_LBRACK array_size T_RBRACK {
974 $$ = add_array($1, true, to_int_constant($3, false)); 969 $$ = add_array($1, true, to_int_constant($3, false));
975 } 970 }
976 | notype_direct_decl param_list asm_or_symbolrename_opt { 971 | notype_direct_decl param_list asm_or_symbolrename_opt {
977 $$ = add_function(symbolrename($1, $3), $2); 972 $$ = add_function(symbolrename($1, $3), $2);
978 end_declaration_level(); 973 end_declaration_level();
979 block_level--; 974 block_level--;
980 } 975 }
981 | notype_direct_decl type_attribute 976 | notype_direct_decl type_attribute
982 ; 977 ;