Module Name: src
Committed By: rillig
Date: Thu Sep 14 22:20:09 UTC 2023
Modified Files:
src/usr.bin/xlint/lint1: cgram.y op.h oper.c scan.l
Log Message:
lint: remove pseudo operators INC and DEC
These operators were not used in expressions, they were only used as
additional token info. Use a plain bool instead.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.473 -r1.474 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.139 -r1.140 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.473 src/usr.bin/xlint/lint1/cgram.y:1.474
--- src/usr.bin/xlint/lint1/cgram.y:1.473 Thu Sep 14 21:53:02 2023
+++ src/usr.bin/xlint/lint1/cgram.y Thu Sep 14 22:20:08 2023
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.473 2023/09/14 21:53:02 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.474 2023/09/14 22:20:08 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.473 2023/09/14 21:53:02 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.474 2023/09/14 22:20:08 rillig Exp $");
#endif
#include <limits.h>
@@ -138,6 +138,7 @@ is_either(const char *s, const char *a,
val_t *y_val;
sbuf_t *y_name;
sym_t *y_sym;
+ bool y_inc;
op_t y_op;
scl_t y_scl;
tspec_t y_tspec;
@@ -168,6 +169,7 @@ is_either(const char *s, const char *a,
debug_sym("", $$, "");
debug_pop_indented(indented);
} <y_sym>
+%printer { fprintf(yyo, "%s", $$ ? "++" : "--"); } <y_inc>
%printer { fprintf(yyo, "%s", op_name($$)); } <y_op>
%printer { fprintf(yyo, "%s", scl_name($$)); } <y_scl>
%printer { fprintf(yyo, "%s", tspec_name($$)); } <y_tspec>
@@ -197,7 +199,7 @@ is_either(const char *s, const char *a,
%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
%token T_POINT T_ARROW
%token T_COMPLEMENT T_LOGNOT
-%token <y_op> T_INCDEC
+%token <y_inc> T_INCDEC
%token T_SIZEOF
%token T_BUILTIN_OFFSETOF
%token T_TYPEOF
@@ -551,7 +553,7 @@ postfix_expression:
$$ = build_member_access($1, $2, $3, $4);
}
| postfix_expression T_INCDEC sys {
- $$ = build_unary($2 == INC ? INCAFT : DECAFT, $3, $1);
+ $$ = build_unary($2 ? INCAFT : DECAFT, $3, $1);
}
| T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */
sym_t *tmp = mktempsym($2);
@@ -643,7 +645,7 @@ argument_expression_list:
unary_expression:
postfix_expression
| T_INCDEC sys unary_expression {
- $$ = build_unary($1 == INC ? INCBEF : DECBEF, $2, $3);
+ $$ = build_unary($1 ? INCBEF : DECBEF, $2, $3);
}
| T_AMPER sys cast_expression {
$$ = build_unary(ADDR, $2, $3);
@@ -2244,6 +2246,7 @@ cgram_to_string(int token, YYSTYPE val)
switch (token) {
case T_INCDEC:
+ return val.y_inc ? "++" : "--";
case T_MULTIPLICATIVE:
case T_ADDITIVE:
case T_SHIFT:
Index: src/usr.bin/xlint/lint1/op.h
diff -u src/usr.bin/xlint/lint1/op.h:1.23 src/usr.bin/xlint/lint1/op.h:1.24
--- src/usr.bin/xlint/lint1/op.h:1.23 Thu Sep 14 21:08:12 2023
+++ src/usr.bin/xlint/lint1/op.h Thu Sep 14 22:20:08 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: op.h,v 1.23 2023/09/14 21:08:12 rillig Exp $ */
+/* $NetBSD: op.h,v 1.24 2023/09/14 22:20:08 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -66,8 +66,6 @@ typedef enum {
POINT,
NOT,
COMPL,
- INC, /* does not appear in the tree */
- DEC, /* does not appear in the tree */
INCBEF,
DECBEF,
INCAFT,
Index: src/usr.bin/xlint/lint1/oper.c
diff -u src/usr.bin/xlint/lint1/oper.c:1.13 src/usr.bin/xlint/lint1/oper.c:1.14
--- src/usr.bin/xlint/lint1/oper.c:1.13 Thu Sep 14 21:08:12 2023
+++ src/usr.bin/xlint/lint1/oper.c Thu Sep 14 22:20:08 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: oper.c,v 1.13 2023/09/14 21:08:12 rillig Exp $ */
+/* $NetBSD: oper.c,v 1.14 2023/09/14 22:20:08 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -68,8 +68,6 @@ const mod_t modtab[NOPS] = {
{X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "." },
{_,X,X,X,_,_,_,X,X,_,_,_,_,_,_,_,_,X,_,X, "!" },
{_,_,_,_,_,X,_,_,X,X,_,_,_,_,_,_,_,X,X,X, "~" },
- {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "++" },
- {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "--" },
/*
* The '++' and '--' operators are conceptually unary operators, but
* lint implements them as binary operators due to the pre-multiplied
Index: src/usr.bin/xlint/lint1/scan.l
diff -u src/usr.bin/xlint/lint1/scan.l:1.139 src/usr.bin/xlint/lint1/scan.l:1.140
--- src/usr.bin/xlint/lint1/scan.l:1.139 Thu Jul 13 08:40:38 2023
+++ src/usr.bin/xlint/lint1/scan.l Thu Sep 14 22:20:08 2023
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.139 2023/07/13 08:40:38 rillig Exp $ */
+/* $NetBSD: scan.l,v 1.140 2023/09/14 22:20:08 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: scan.l,v 1.139 2023/07/13 08:40:38 rillig Exp $");
+__RCSID("$NetBSD: scan.l,v 1.140 2023/09/14 22:20:08 rillig Exp $");
#endif
#include "lint1.h"
@@ -87,8 +87,8 @@ FSUF ([fFlL]?[i]?)
">=" return lex_operator(T_RELATIONAL, GE);
"<<" return lex_operator(T_SHIFT, SHL);
">>" return lex_operator(T_SHIFT, SHR);
-"++" return lex_operator(T_INCDEC, INC);
-"--" return lex_operator(T_INCDEC, DEC);
+"++" return yylval.y_inc = true, T_INCDEC;
+"--" return yylval.y_inc = false, T_INCDEC;
"->" return T_ARROW;
"." return T_POINT;
"+" return lex_operator(T_ADDITIVE, PLUS);