Module Name: src
Committed By: rillig
Date: Sun Jul 11 18:03:47 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: cgram.y scan.l
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/xlint/lint1/scan.l
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.309 src/usr.bin/xlint/lint1/cgram.y:1.310
--- src/usr.bin/xlint/lint1/cgram.y:1.309 Sun Jul 11 17:52:20 2021
+++ src/usr.bin/xlint/lint1/cgram.y Sun Jul 11 18:03:47 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 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.309 2021/07/11 17:52:20 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $");
#endif
#include <limits.h>
@@ -145,7 +145,7 @@ anonymize(sym_t *s)
%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
%token T_POINT T_ARROW
-%token <y_op> T_UNARY
+%token T_COMPLEMENT T_LOGNOT
%token <y_op> T_INCDEC
%token T_SIZEOF
%token T_BUILTIN_OFFSETOF
@@ -1823,8 +1823,11 @@ unary_expression: /* C99 6.5.3 */
}
$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
}
- | T_UNARY term {
- $$ = build($1, $2, NULL);
+ | T_COMPLEMENT term {
+ $$ = build(COMPL, $2, NULL);
+ }
+ | T_LOGNOT term {
+ $$ = build(NOT, $2, NULL);
}
| T_SIZEOF unary_expression {
$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
Index: src/usr.bin/xlint/lint1/scan.l
diff -u src/usr.bin/xlint/lint1/scan.l:1.134 src/usr.bin/xlint/lint1/scan.l:1.135
--- src/usr.bin/xlint/lint1/scan.l:1.134 Sun Jun 20 18:15:12 2021
+++ src/usr.bin/xlint/lint1/scan.l Sun Jul 11 18:03:47 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $ */
+/* $NetBSD: scan.l,v 1.135 2021/07/11 18:03:47 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: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $");
+__RCSID("$NetBSD: scan.l,v 1.135 2021/07/11 18:03:47 rillig Exp $");
#endif
#include "lint1.h"
@@ -101,8 +101,8 @@ TL ([fFlL]?[i]?)
"*" return T_ASTERISK;
"/" return lex_operator(T_MULTIPLICATIVE, DIV);
"%" return lex_operator(T_MULTIPLICATIVE, MOD);
-"!" return lex_operator(T_UNARY, NOT);
-"~" return lex_operator(T_UNARY, COMPL);
+"!" return T_LOGNOT;
+"~" return T_COMPLEMENT;
"\"" return lex_string();
"L\"" return lex_wide_string();
";" return T_SEMI;