| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $ */ | | 2 | /* $NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 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.309 2021/07/11 17:52:20 rillig Exp $"); | | 38 | __RCSID("$NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 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. |
| @@ -135,27 +135,27 @@ anonymize(sym_t *s) | | | @@ -135,27 +135,27 @@ anonymize(sym_t *s) |
135 | tspec_t y_tspec; | | 135 | tspec_t y_tspec; |
136 | tqual_t y_tqual; | | 136 | tqual_t y_tqual; |
137 | type_t *y_type; | | 137 | type_t *y_type; |
138 | tnode_t *y_tnode; | | 138 | tnode_t *y_tnode; |
139 | range_t y_range; | | 139 | range_t y_range; |
140 | strg_t *y_string; | | 140 | strg_t *y_string; |
141 | qual_ptr *y_qual_ptr; | | 141 | qual_ptr *y_qual_ptr; |
142 | bool y_seen_statement; | | 142 | bool y_seen_statement; |
143 | struct generic_association *y_generic; | | 143 | struct generic_association *y_generic; |
144 | }; | | 144 | }; |
145 | | | 145 | |
146 | %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN | | 146 | %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN |
147 | %token T_POINT T_ARROW | | 147 | %token T_POINT T_ARROW |
148 | %token <y_op> T_UNARY | | 148 | %token T_COMPLEMENT T_LOGNOT |
149 | %token <y_op> T_INCDEC | | 149 | %token <y_op> T_INCDEC |
150 | %token T_SIZEOF | | 150 | %token T_SIZEOF |
151 | %token T_BUILTIN_OFFSETOF | | 151 | %token T_BUILTIN_OFFSETOF |
152 | %token T_TYPEOF | | 152 | %token T_TYPEOF |
153 | %token T_EXTENSION | | 153 | %token T_EXTENSION |
154 | %token T_ALIGNAS | | 154 | %token T_ALIGNAS |
155 | %token T_ALIGNOF | | 155 | %token T_ALIGNOF |
156 | %token T_ASTERISK | | 156 | %token T_ASTERISK |
157 | %token <y_op> T_MULTIPLICATIVE | | 157 | %token <y_op> T_MULTIPLICATIVE |
158 | %token <y_op> T_ADDITIVE | | 158 | %token <y_op> T_ADDITIVE |
159 | %token <y_op> T_SHIFT | | 159 | %token <y_op> T_SHIFT |
160 | %token <y_op> T_RELATIONAL | | 160 | %token <y_op> T_RELATIONAL |
161 | %token <y_op> T_EQUALITY | | 161 | %token <y_op> T_EQUALITY |
| @@ -1813,28 +1813,31 @@ unary_expression: /* C99 6.5.3 */ | | | @@ -1813,28 +1813,31 @@ unary_expression: /* C99 6.5.3 */ |
1813 | | T_AMPER term { | | 1813 | | T_AMPER term { |
1814 | $$ = build(ADDR, $2, NULL); | | 1814 | $$ = build(ADDR, $2, NULL); |
1815 | } | | 1815 | } |
1816 | | T_ASTERISK term { | | 1816 | | T_ASTERISK term { |
1817 | $$ = build(INDIR, $2, NULL); | | 1817 | $$ = build(INDIR, $2, NULL); |
1818 | } | | 1818 | } |
1819 | | T_ADDITIVE term { | | 1819 | | T_ADDITIVE term { |
1820 | if (tflag && $1 == PLUS) { | | 1820 | if (tflag && $1 == PLUS) { |
1821 | /* unary + is illegal in traditional C */ | | 1821 | /* unary + is illegal in traditional C */ |
1822 | warning(100); | | 1822 | warning(100); |
1823 | } | | 1823 | } |
1824 | $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL); | | 1824 | $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL); |
1825 | } | | 1825 | } |
1826 | | T_UNARY term { | | 1826 | | T_COMPLEMENT term { |
1827 | $$ = build($1, $2, NULL); | | 1827 | $$ = build(COMPL, $2, NULL); |
| | | 1828 | } |
| | | 1829 | | T_LOGNOT term { |
| | | 1830 | $$ = build(NOT, $2, NULL); |
1828 | } | | 1831 | } |
1829 | | T_SIZEOF unary_expression { | | 1832 | | T_SIZEOF unary_expression { |
1830 | $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type); | | 1833 | $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type); |
1831 | if ($$ != NULL) | | 1834 | if ($$ != NULL) |
1832 | check_expr_misc($2, false, false, false, false, false, true); | | 1835 | check_expr_misc($2, false, false, false, false, false, true); |
1833 | } | | 1836 | } |
1834 | | T_SIZEOF T_LPAREN type_name T_RPAREN { | | 1837 | | T_SIZEOF T_LPAREN type_name T_RPAREN { |
1835 | $$ = build_sizeof($3); | | 1838 | $$ = build_sizeof($3); |
1836 | } | | 1839 | } |
1837 | ; | | 1840 | ; |
1838 | | | 1841 | |
1839 | term: /* see C99 6.5.1 */ | | 1842 | term: /* see C99 6.5.1 */ |
1840 | unary_expression | | 1843 | unary_expression |