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.
This commit is contained in:
parent
cd38323370
commit
5bd0234249
|
@ -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 @@ anonymize(sym_t *s)
|
|||
}
|
||||
%}
|
||||
|
||||
%expect 177
|
||||
%expect 185
|
||||
|
||||
%union {
|
||||
val_t *y_val;
|
||||
|
@ -1826,6 +1826,11 @@ read_until_rparen:
|
|||
}
|
||||
;
|
||||
|
||||
declaration_list_opt:
|
||||
/* empty */
|
||||
| declaration_list
|
||||
;
|
||||
|
||||
declaration_list:
|
||||
declaration {
|
||||
clear_warning_flags();
|
||||
|
@ -1913,7 +1918,7 @@ term:
|
|||
$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 @@ term:
|
|||
$$ = 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue