Sun Jul 11 18:03:47 2021 UTC ()
lint: use separate tokens for logical not and bitwise complement

The token T_UNARY was misleading since it only captured 2 of the 6
operators that C99 calls unary-operator.  Make the grammar easier to
understand by explicitly listing these 2 operators.

No functional change.


(rillig)
diff -r1.309 -r1.310 src/usr.bin/xlint/lint1/cgram.y
diff -r1.134 -r1.135 src/usr.bin/xlint/lint1/scan.l

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/11 17:52:20 1.309
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/11 18:03:47 1.310
@@ -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
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.
@@ -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
1839term: /* see C99 6.5.1 */ 1842term: /* see C99 6.5.1 */
1840 unary_expression 1843 unary_expression

cvs diff -r1.134 -r1.135 src/usr.bin/xlint/lint1/scan.l (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/scan.l 2021/06/20 18:15:12 1.134
+++ src/usr.bin/xlint/lint1/scan.l 2021/07/11 18:03:47 1.135
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $ */ 2/* $NetBSD: scan.l,v 1.135 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: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $"); 38__RCSID("$NetBSD: scan.l,v 1.135 2021/07/11 18:03:47 rillig Exp $");
39#endif 39#endif
40 40
41#include "lint1.h" 41#include "lint1.h"
42#include "cgram.h" 42#include "cgram.h"
43 43
44%} 44%}
45 45
46 46
47L [_A-Za-z] 47L [_A-Za-z]
48D [0-9] 48D [0-9]
49NZD [1-9] 49NZD [1-9]
50BD [0-1] 50BD [0-1]
51OD [0-7] 51OD [0-7]
@@ -91,28 +91,28 @@ TL ([fFlL]?[i]?) @@ -91,28 +91,28 @@ TL ([fFlL]?[i]?)
91"<=" return lex_operator(T_RELATIONAL, LE); 91"<=" return lex_operator(T_RELATIONAL, LE);
92">=" return lex_operator(T_RELATIONAL, GE); 92">=" return lex_operator(T_RELATIONAL, GE);
93"<<" return lex_operator(T_SHIFT, SHL); 93"<<" return lex_operator(T_SHIFT, SHL);
94">>" return lex_operator(T_SHIFT, SHR); 94">>" return lex_operator(T_SHIFT, SHR);
95"++" return lex_operator(T_INCDEC, INC); 95"++" return lex_operator(T_INCDEC, INC);
96"--" return lex_operator(T_INCDEC, DEC); 96"--" return lex_operator(T_INCDEC, DEC);
97"->" return T_ARROW; 97"->" return T_ARROW;
98"." return T_POINT; 98"." return T_POINT;
99"+" return lex_operator(T_ADDITIVE, PLUS); 99"+" return lex_operator(T_ADDITIVE, PLUS);
100"-" return lex_operator(T_ADDITIVE, MINUS); 100"-" return lex_operator(T_ADDITIVE, MINUS);
101"*" return T_ASTERISK; 101"*" return T_ASTERISK;
102"/" return lex_operator(T_MULTIPLICATIVE, DIV); 102"/" return lex_operator(T_MULTIPLICATIVE, DIV);
103"%" return lex_operator(T_MULTIPLICATIVE, MOD); 103"%" return lex_operator(T_MULTIPLICATIVE, MOD);
104"!" return lex_operator(T_UNARY, NOT); 104"!" return T_LOGNOT;
105"~" return lex_operator(T_UNARY, COMPL); 105"~" return T_COMPLEMENT;
106"\"" return lex_string(); 106"\"" return lex_string();
107"L\"" return lex_wide_string(); 107"L\"" return lex_wide_string();
108";" return T_SEMI; 108";" return T_SEMI;
109"{" return T_LBRACE; 109"{" return T_LBRACE;
110"}" return T_RBRACE; 110"}" return T_RBRACE;
111"," return T_COMMA; 111"," return T_COMMA;
112":" return T_COLON; 112":" return T_COLON;
113"?" return T_QUEST; 113"?" return T_QUEST;
114"[" return T_LBRACK; 114"[" return T_LBRACK;
115"]" return T_RBRACK; 115"]" return T_RBRACK;
116"(" return T_LPAREN; 116"(" return T_LPAREN;
117")" return T_RPAREN; 117")" return T_RPAREN;
118"..." return T_ELLIPSIS; 118"..." return T_ELLIPSIS;