| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: cgram.y,v 1.325 2021/07/15 17:20:57 rillig Exp $ */ | | 2 | /* $NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 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.325 2021/07/15 17:20:57 rillig Exp $"); | | 38 | __RCSID("$NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 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 | |
47 | extern char *yytext; | | 47 | extern 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. |
| @@ -171,27 +171,27 @@ anonymize(sym_t *s) | | | @@ -171,27 +171,27 @@ anonymize(sym_t *s) |
171 | %token T_COMMA | | 171 | %token T_COMMA |
172 | %token T_SEMI | | 172 | %token T_SEMI |
173 | %token T_ELLIPSIS | | 173 | %token T_ELLIPSIS |
174 | %token T_REAL | | 174 | %token T_REAL |
175 | %token T_IMAG | | 175 | %token T_IMAG |
176 | %token T_GENERIC | | 176 | %token T_GENERIC |
177 | %token T_NORETURN | | 177 | %token T_NORETURN |
178 | | | 178 | |
179 | /* storage classes (extern, static, auto, register and typedef) */ | | 179 | /* storage classes (extern, static, auto, register and typedef) */ |
180 | %token <y_scl> T_SCLASS | | 180 | %token <y_scl> T_SCLASS |
181 | | | 181 | |
182 | /* | | 182 | /* |
183 | * predefined type keywords (char, int, short, long, unsigned, signed, | | 183 | * predefined type keywords (char, int, short, long, unsigned, signed, |
184 | * float, double, void); see T_TYPENAME | | 184 | * float, double, void); see T_TYPENAME for types from typedef |
185 | */ | | 185 | */ |
186 | %token <y_tspec> T_TYPE | | 186 | %token <y_tspec> T_TYPE |
187 | | | 187 | |
188 | /* qualifiers (const, volatile, restrict, _Thread_local) */ | | 188 | /* qualifiers (const, volatile, restrict, _Thread_local) */ |
189 | %token <y_tqual> T_QUAL | | 189 | %token <y_tqual> T_QUAL |
190 | | | 190 | |
191 | /* struct or union */ | | 191 | /* struct or union */ |
192 | %token <y_tspec> T_STRUCT_OR_UNION | | 192 | %token <y_tspec> T_STRUCT_OR_UNION |
193 | | | 193 | |
194 | /* remaining keywords */ | | 194 | /* remaining keywords */ |
195 | %token T_ASM | | 195 | %token T_ASM |
196 | %token T_BREAK | | 196 | %token T_BREAK |
197 | %token T_CASE | | 197 | %token T_CASE |
| @@ -517,27 +517,27 @@ comma_opt: /* helper for 'postfix_expr | | | @@ -517,27 +517,27 @@ comma_opt: /* helper for 'postfix_expr |
517 | /* | | 517 | /* |
518 | * The inner part of a GCC statement-expression of the form ({ ... }). | | 518 | * The inner part of a GCC statement-expression of the form ({ ... }). |
519 | * | | 519 | * |
520 | * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html | | 520 | * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html |
521 | */ | | 521 | */ |
522 | gcc_statement_expr_list: | | 522 | gcc_statement_expr_list: |
523 | gcc_statement_expr_item | | 523 | gcc_statement_expr_item |
524 | | gcc_statement_expr_list gcc_statement_expr_item { | | 524 | | gcc_statement_expr_list gcc_statement_expr_item { |
525 | $$ = $2; | | 525 | $$ = $2; |
526 | } | | 526 | } |
527 | ; | | 527 | ; |
528 | | | 528 | |
529 | gcc_statement_expr_item: | | 529 | gcc_statement_expr_item: |
530 | declaration { | | 530 | declaration_or_error { |
531 | clear_warning_flags(); | | 531 | clear_warning_flags(); |
532 | $$ = NULL; | | 532 | $$ = NULL; |
533 | } | | 533 | } |
534 | | non_expr_statement { | | 534 | | non_expr_statement { |
535 | $$ = expr_zalloc_tnode(); | | 535 | $$ = expr_zalloc_tnode(); |
536 | $$->tn_type = gettyp(VOID); | | 536 | $$->tn_type = gettyp(VOID); |
537 | } | | 537 | } |
538 | | expression T_SEMI { | | 538 | | expression T_SEMI { |
539 | if ($1 == NULL) { /* in case of syntax errors */ | | 539 | if ($1 == NULL) { /* in case of syntax errors */ |
540 | $$ = expr_zalloc_tnode(); | | 540 | $$ = expr_zalloc_tnode(); |
541 | $$->tn_type = gettyp(VOID); | | 541 | $$->tn_type = gettyp(VOID); |
542 | } else { | | 542 | } else { |
543 | /* XXX: do that only on the last name */ | | 543 | /* XXX: do that only on the last name */ |
| @@ -710,49 +710,53 @@ constant_expr_list_opt: /* helper for g | | | @@ -710,49 +710,53 @@ constant_expr_list_opt: /* helper for g |
710 | /* empty */ | | 710 | /* empty */ |
711 | | constant_expr_list | | 711 | | constant_expr_list |
712 | ; | | 712 | ; |
713 | | | 713 | |
714 | constant_expr_list: /* helper for gcc_attribute */ | | 714 | constant_expr_list: /* helper for gcc_attribute */ |
715 | constant_expr | | 715 | constant_expr |
716 | | constant_expr_list T_COMMA constant_expr | | 716 | | constant_expr_list T_COMMA constant_expr |
717 | ; | | 717 | ; |
718 | | | 718 | |
719 | constant_expr: /* C99 6.6 */ | | 719 | constant_expr: /* C99 6.6 */ |
720 | conditional_expression | | 720 | conditional_expression |
721 | ; | | 721 | ; |
722 | | | 722 | |
| | | 723 | declaration_or_error: |
| | | 724 | declaration |
| | | 725 | | error T_SEMI |
| | | 726 | ; |
| | | 727 | |
723 | declaration: /* C99 6.7 */ | | 728 | declaration: /* C99 6.7 */ |
724 | begin_type_declmods end_type T_SEMI { | | 729 | begin_type_declmods end_type T_SEMI { |
725 | if (dcs->d_scl == TYPEDEF) { | | 730 | if (dcs->d_scl == TYPEDEF) { |
726 | /* typedef declares no type name */ | | 731 | /* typedef declares no type name */ |
727 | warning(72); | | 732 | warning(72); |
728 | } else { | | 733 | } else { |
729 | /* empty declaration */ | | 734 | /* empty declaration */ |
730 | warning(2); | | 735 | warning(2); |
731 | } | | 736 | } |
732 | } | | 737 | } |
733 | | begin_type_declmods end_type notype_init_declarators T_SEMI | | 738 | | begin_type_declmods end_type notype_init_declarators T_SEMI |
734 | | begin_type_declaration_specifiers end_type T_SEMI { | | 739 | | begin_type_declaration_specifiers end_type T_SEMI { |
735 | if (dcs->d_scl == TYPEDEF) { | | 740 | if (dcs->d_scl == TYPEDEF) { |
736 | /* typedef declares no type name */ | | 741 | /* typedef declares no type name */ |
737 | warning(72); | | 742 | warning(72); |
738 | } else if (!dcs->d_nonempty_decl) { | | 743 | } else if (!dcs->d_nonempty_decl) { |
739 | /* empty declaration */ | | 744 | /* empty declaration */ |
740 | warning(2); | | 745 | warning(2); |
741 | } | | 746 | } |
742 | } | | 747 | } |
743 | | begin_type_declaration_specifiers end_type | | 748 | | begin_type_declaration_specifiers end_type |
744 | type_init_declarators T_SEMI | | 749 | type_init_declarators T_SEMI |
745 | | error T_SEMI | | | |
746 | ; | | 750 | ; |
747 | | | 751 | |
748 | begin_type_declaration_specifiers: /* see C99 6.7 */ | | 752 | begin_type_declaration_specifiers: /* see C99 6.7 */ |
749 | begin_type_typespec { | | 753 | begin_type_typespec { |
750 | add_type($1); | | 754 | add_type($1); |
751 | } | | 755 | } |
752 | | begin_type_declmods type_specifier { | | 756 | | begin_type_declmods type_specifier { |
753 | add_type($2); | | 757 | add_type($2); |
754 | } | | 758 | } |
755 | | type_attribute begin_type_declaration_specifiers | | 759 | | type_attribute begin_type_declaration_specifiers |
756 | | begin_type_declaration_specifiers declmod | | 760 | | begin_type_declaration_specifiers declmod |
757 | | begin_type_declaration_specifiers notype_type_specifier { | | 761 | | begin_type_declaration_specifiers notype_type_specifier { |
758 | add_type($2); | | 762 | add_type($2); |
| @@ -1662,27 +1666,27 @@ compound_statement_rbrace: | | | @@ -1662,27 +1666,27 @@ compound_statement_rbrace: |
1662 | ; | | 1666 | ; |
1663 | | | 1667 | |
1664 | block_item_list: /* C99 6.8.2 */ | | 1668 | block_item_list: /* C99 6.8.2 */ |
1665 | block_item | | 1669 | block_item |
1666 | | block_item_list block_item { | | 1670 | | block_item_list block_item { |
1667 | if (!Sflag && $1 && !$2) | | 1671 | if (!Sflag && $1 && !$2) |
1668 | /* declarations after statements is a C99 feature */ | | 1672 | /* declarations after statements is a C99 feature */ |
1669 | c99ism(327); | | 1673 | c99ism(327); |
1670 | $$ = $1 || $2; | | 1674 | $$ = $1 || $2; |
1671 | } | | 1675 | } |
1672 | ; | | 1676 | ; |
1673 | | | 1677 | |
1674 | block_item: /* C99 6.8.2 */ | | 1678 | block_item: /* C99 6.8.2 */ |
1675 | declaration { | | 1679 | declaration_or_error { |
1676 | $$ = false; | | 1680 | $$ = false; |
1677 | restore_warning_flags(); | | 1681 | restore_warning_flags(); |
1678 | } | | 1682 | } |
1679 | | statement { | | 1683 | | statement { |
1680 | $$ = true; | | 1684 | $$ = true; |
1681 | restore_warning_flags(); | | 1685 | restore_warning_flags(); |
1682 | } | | 1686 | } |
1683 | ; | | 1687 | ; |
1684 | | | 1688 | |
1685 | expression_statement: /* C99 6.8.3 */ | | 1689 | expression_statement: /* C99 6.8.3 */ |
1686 | expression T_SEMI { | | 1690 | expression T_SEMI { |
1687 | expr($1, false, false, false, false); | | 1691 | expr($1, false, false, false, false); |
1688 | seen_fallthrough = false; | | 1692 | seen_fallthrough = false; |