| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: cgram.y,v 1.316 2021/07/11 20:25:54 rillig Exp $ */ | | 2 | /* $NetBSD: cgram.y,v 1.317 2021/07/11 20:37:21 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.316 2021/07/11 20:25:54 rillig Exp $"); | | 38 | __RCSID("$NetBSD: cgram.y,v 1.317 2021/07/11 20:37:21 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. |
| @@ -1712,51 +1712,51 @@ expr: /* C99 6.5 */ | | | @@ -1712,51 +1712,51 @@ expr: /* C99 6.5 */ |
1712 | | expr T_QUEST expr T_COLON expr { | | 1712 | | expr T_QUEST expr T_COLON expr { |
1713 | $$ = build(QUEST, $1, build(COLON, $3, $5)); | | 1713 | $$ = build(QUEST, $1, build(COLON, $3, $5)); |
1714 | } | | 1714 | } |
1715 | | expr T_ASSIGN expr { | | 1715 | | expr T_ASSIGN expr { |
1716 | $$ = build(ASSIGN, $1, $3); | | 1716 | $$ = build(ASSIGN, $1, $3); |
1717 | } | | 1717 | } |
1718 | | expr T_OPASSIGN expr { | | 1718 | | expr T_OPASSIGN expr { |
1719 | $$ = build($2, $1, $3); | | 1719 | $$ = build($2, $1, $3); |
1720 | } | | 1720 | } |
1721 | | expr T_COMMA expr { | | 1721 | | expr T_COMMA expr { |
1722 | $$ = build(COMMA, $1, $3); | | 1722 | $$ = build(COMMA, $1, $3); |
1723 | } | | 1723 | } |
1724 | | cast_expression | | 1724 | | cast_expression |
1725 | | generic_selection /* TODO: move to primary_expression */ | | | |
1726 | ; | | 1725 | ; |
1727 | | | 1726 | |
1728 | assignment_expression: /* C99 6.5.16 */ | | 1727 | assignment_expression: /* C99 6.5.16 */ |
1729 | expr %prec T_ASSIGN | | 1728 | expr %prec T_ASSIGN |
1730 | ; | | 1729 | ; |
1731 | | | 1730 | |
1732 | primary_expression: /* C99 6.5.1 */ | | 1731 | primary_expression: /* C99 6.5.1 */ |
1733 | T_NAME { | | 1732 | T_NAME { |
1734 | /* XXX really necessary? */ | | 1733 | /* XXX really necessary? */ |
1735 | if (yychar < 0) | | 1734 | if (yychar < 0) |
1736 | yychar = yylex(); | | 1735 | yychar = yylex(); |
1737 | $$ = new_name_node(getsym($1), yychar); | | 1736 | $$ = new_name_node(getsym($1), yychar); |
1738 | } | | 1737 | } |
1739 | | T_CON { | | 1738 | | T_CON { |
1740 | $$ = expr_new_constant(gettyp($1->v_tspec), $1); | | 1739 | $$ = expr_new_constant(gettyp($1->v_tspec), $1); |
1741 | } | | 1740 | } |
1742 | | string { | | 1741 | | string { |
1743 | $$ = new_string_node($1); | | 1742 | $$ = new_string_node($1); |
1744 | } | | 1743 | } |
1745 | | T_LPAREN expr T_RPAREN { | | 1744 | | T_LPAREN expr T_RPAREN { |
1746 | if ($2 != NULL) | | 1745 | if ($2 != NULL) |
1747 | $2->tn_parenthesized = true; | | 1746 | $2->tn_parenthesized = true; |
1748 | $$ = $2; | | 1747 | $$ = $2; |
1749 | } | | 1748 | } |
| | | 1749 | | generic_selection |
1750 | /* GCC primary-expression, see c_parser_postfix_expression */ | | 1750 | /* GCC primary-expression, see c_parser_postfix_expression */ |
1751 | | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN { | | 1751 | | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN { |
1752 | symtyp = FMEMBER; | | 1752 | symtyp = FMEMBER; |
1753 | $$ = build_offsetof($3, getsym($5)); | | 1753 | $$ = build_offsetof($3, getsym($5)); |
1754 | } | | 1754 | } |
1755 | ; | | 1755 | ; |
1756 | | | 1756 | |
1757 | postfix_expression: /* C99 6.5.2 */ | | 1757 | postfix_expression: /* C99 6.5.2 */ |
1758 | primary_expression | | 1758 | primary_expression |
1759 | | postfix_expression T_LBRACK expr T_RBRACK { | | 1759 | | postfix_expression T_LBRACK expr T_RBRACK { |
1760 | $$ = build(INDIR, build(PLUS, $1, $3), NULL); | | 1760 | $$ = build(INDIR, build(PLUS, $1, $3), NULL); |
1761 | } | | 1761 | } |
1762 | | postfix_expression T_LPAREN T_RPAREN { | | 1762 | | postfix_expression T_LPAREN T_RPAREN { |