Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: remove redundant operator properti...



details:   https://anonhg.NetBSD.org/src/rev/268cef914810
branches:  trunk
changeset: 960540:268cef914810
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Mar 20 20:39:35 2021 +0000

description:
lint: remove redundant operator properties table

It's enough to have modtab, which describes the properties of the
various operators.  There is no need to have a second table imods that
holds the same content.  Rather make modtab constant as well.

The only possible functional change is that the names of the internal
operators 'no-op', '++', '--', 'real', 'imag' and 'case' may appear in
diagnostics, where previously lint invoked undefined behavior by passing
a null pointer for a '%s' conversion specifier.

diffstat:

 usr.bin/xlint/lint1/main1.c |    5 +-
 usr.bin/xlint/lint1/op.h    |    8 +-
 usr.bin/xlint/lint1/oper.c  |   28 +------
 usr.bin/xlint/lint1/ops.def |  140 ++++++++++++++++++++++----------------------
 usr.bin/xlint/lint1/tree.c  |   18 ++--
 5 files changed, 90 insertions(+), 109 deletions(-)

diffs (truncated from 356 to 300 lines):

diff -r a9d4008f0992 -r 268cef914810 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Sat Mar 20 20:15:37 2021 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Sat Mar 20 20:39:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.37 2021/01/16 16:53:23 rillig Exp $        */
+/*     $NetBSD: main1.c,v 1.38 2021/03/20 20:39:35 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.37 2021/01/16 16:53:23 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.38 2021/03/20 20:39:35 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -253,7 +253,6 @@
        initmem();
        initdecl();
        initscan();
-       initmtab();
 
        if ((yyin = bltin()) == NULL)
                err(1, "cannot open builtins");
diff -r a9d4008f0992 -r 268cef914810 usr.bin/xlint/lint1/op.h
--- a/usr.bin/xlint/lint1/op.h  Sat Mar 20 20:15:37 2021 +0000
+++ b/usr.bin/xlint/lint1/op.h  Sat Mar 20 20:39:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: op.h,v 1.14 2021/03/20 20:15:37 rillig Exp $   */
+/*     $NetBSD: op.h,v 1.15 2021/03/20 20:39:35 rillig Exp $   */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -60,7 +60,7 @@
        const char *m_name;
 } mod_t;
 
-extern mod_t   modtab[];
+extern const mod_t modtab[];
 
 #define begin_ops() typedef enum {
 #define op(name, repr, \
@@ -68,11 +68,9 @@
                in, ic, ar, sc, \
                fo, va, ts, ba, \
                se, lu, ru, pc, \
-               cm, ve, de, ew, \
-               active) \
+               cm, ve, de, ew) \
        name,
 #define end_ops() } op_t;
 #include "ops.def"
 
 const char *getopname(op_t);
-void initmtab(void);
diff -r a9d4008f0992 -r 268cef914810 usr.bin/xlint/lint1/oper.c
--- a/usr.bin/xlint/lint1/oper.c        Sat Mar 20 20:15:37 2021 +0000
+++ b/usr.bin/xlint/lint1/oper.c        Sat Mar 20 20:39:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: oper.c,v 1.7 2021/03/20 20:15:37 rillig Exp $  */
+/*     $NetBSD: oper.c,v 1.8 2021/03/20 20:39:35 rillig Exp $  */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -33,27 +33,21 @@
 #include "op.h"
 #include "param.h"
 
-mod_t modtab[NOPS];
-
-static const struct {
-       mod_t   m;
-       bool    ok;
-} imods[] =
+const mod_t modtab[NOPS] =
 #define begin_ops() {
 #define op(name, repr, \
                bi, lo, tb, rb, \
                in, ic, ar, sc, \
                fo, va, ts, ba, \
                se, lu, ru, pc, \
-               cm, ve, de, ew, \
-               active) \
-       { { \
+               cm, ve, de, ew) \
+       { \
                bi + 0 > 0, lo + 0 > 0, tb + 0 > 0, rb + 0 > 0, \
                in + 0 > 0, ic + 0 > 0, ar + 0 > 0, sc + 0 > 0, \
                fo + 0 > 0, va + 0 > 0, ts + 0 > 0, ba + 0 > 0, \
                se + 0 > 0, lu + 0 > 0, ru + 0 > 0, pc + 0 > 0, \
                cm + 0 > 0, ve + 0 > 0, de + 0 > 0, ew + 0 > 0, \
-               repr }, (active) > 0 \
+               repr, \
        },
 #define end_ops(n) };
 #include "ops.def"
@@ -61,15 +55,5 @@
 const char *
 getopname(op_t op)
 {
-       return imods[op].m.m_name;
+       return modtab[op].m_name;
 }
-
-void
-initmtab(void)
-{
-       size_t i;
-
-       for (i = 0; i < sizeof imods / sizeof imods[0]; i++)
-               if (imods[i].ok)
-                       modtab[i] = imods[i].m;
-}
diff -r a9d4008f0992 -r 268cef914810 usr.bin/xlint/lint1/ops.def
--- a/usr.bin/xlint/lint1/ops.def       Sat Mar 20 20:15:37 2021 +0000
+++ b/usr.bin/xlint/lint1/ops.def       Sat Mar 20 20:39:35 2021 +0000
@@ -1,86 +1,86 @@
-/*     $NetBSD: ops.def,v 1.18 2021/03/20 20:15:37 rillig Exp $ */
+/*     $NetBSD: ops.def,v 1.19 2021/03/20 20:39:35 rillig Exp $ */
 
 begin_ops()
 
 /* See mod_t in op.h for the definition of the table columns. */
 
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    NOOP,   "no-op",         , , , , , , , , , , , , , , , , , , , ,0)
-op(    ARROW,  "->",           1, ,1, , , , , , ,1, , , , , , , , , , ,1)
-op(    POINT,  ".",            1, ,1, , , , , , , , , , , , , , , , , ,1)
-op(    NOT,    "!",             ,1,1,1, , , ,1,1, ,1, , , , , , , ,1, ,1)
-op(    COMPL,  "~",             , , , , ,1, , ,1,1, , , , , , , , ,1,1,1)
-op(    INC,    "++",            , , , , , , , , , , , , , , , , , , , ,0)
-op(    DEC,    "--",            , , , , , , , , , , , , , , , , , , , ,0)
-op(    INCBEF, "++x",           , , , , , , ,1, , , , ,1, , , , , ,1, ,1)
-op(    DECBEF, "--x",           , , , , , , ,1, , , , ,1, , , , , ,1, ,1)
-op(    INCAFT, "x++",           , , , , , , ,1, , , , ,1, , , , , ,1, ,1)
-op(    DECAFT, "x--",           , , , , , , ,1, , , , ,1, , , , , ,1, ,1)
-op(    UPLUS,  "+",             , , , , , ,1, ,1,1, , , , , , , , ,1,1,1)
-op(    UMINUS, "-",             , , , , , ,1, ,1,1, , , ,1, , , , ,1,1,1)
-op(    INDIR,  "*",             , , , , , , , , ,1, , , , , , , , , , ,1)
-op(    ADDR,   "&",             , ,1, , , , , , , , , , , , , , , , , ,1)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    NOOP,   "no-op",         , , , , , , , , , , , , , , , , , , , )
+op(    ARROW,  "->",           1, ,1, , , , , , ,1, , , , , , , , , , )
+op(    POINT,  ".",            1, ,1, , , , , , , , , , , , , , , , , )
+op(    NOT,    "!",             ,1,1,1, , , ,1,1, ,1, , , , , , , ,1, )
+op(    COMPL,  "~",             , , , , ,1, , ,1,1, , , , , , , , ,1,1)
+op(    INC,    "++",            , , , , , , , , , , , , , , , , , , , )
+op(    DEC,    "--",            , , , , , , , , , , , , , , , , , , , )
+op(    INCBEF, "++x",           , , , , , , ,1, , , , ,1, , , , , ,1, )
+op(    DECBEF, "--x",           , , , , , , ,1, , , , ,1, , , , , ,1, )
+op(    INCAFT, "x++",           , , , , , , ,1, , , , ,1, , , , , ,1, )
+op(    DECAFT, "x--",           , , , , , , ,1, , , , ,1, , , , , ,1, )
+op(    UPLUS,  "+",             , , , , , ,1, ,1,1, , , , , , , , ,1,1)
+op(    UMINUS, "-",             , , , , , ,1, ,1,1, , , ,1, , , , ,1,1)
+op(    INDIR,  "*",             , , , , , , , , ,1, , , , , , , , , , )
+op(    ADDR,   "&",             , ,1, , , , , , , , , , , , , , , , , )
 /* the operator 'arr[ind]' is translated to '*(arr + ind)' during parsing. */
 
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    MULT,   "*",            1, , , , , ,1, ,1,1, ,1, , ,1, , , ,1,1,1)
-op(    DIV,    "/",            1, , , , , ,1, ,1,1, ,1, ,1,1, , , ,1,1,1)
-op(    MOD,    "%",            1, , , ,1, , , ,1,1, ,1, ,1,1, , , ,1,1,1)
-op(    PLUS,   "+",            1, , , , , , ,1,1,1, ,1, , , , , , ,1, ,1)
-op(    MINUS,  "-",            1, , , , , , ,1,1,1, ,1, , , , , , ,1, ,1)
-op(    SHL,    "<<",           1, , , ,1, , , ,1,1, , , , , ,1, , ,1,1,1)
-op(    SHR,    ">>",           1, , , ,1, , , ,1,1, , , ,1, ,1, , ,1,1,1)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    MULT,   "*",            1, , , , , ,1, ,1,1, ,1, , ,1, , , ,1,1)
+op(    DIV,    "/",            1, , , , , ,1, ,1,1, ,1, ,1,1, , , ,1,1)
+op(    MOD,    "%",            1, , , ,1, , , ,1,1, ,1, ,1,1, , , ,1,1)
+op(    PLUS,   "+",            1, , , , , , ,1,1,1, ,1, , , , , , ,1, )
+op(    MINUS,  "-",            1, , , , , , ,1,1,1, ,1, , , , , , ,1, )
+op(    SHL,    "<<",           1, , , ,1, , , ,1,1, , , , , ,1, , ,1,1)
+op(    SHR,    ">>",           1, , , ,1, , , ,1,1, , , ,1, ,1, , ,1,1)
 
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    LT,     "<",            1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1)
-op(    LE,     "<=",           1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1)
-op(    GT,     ">",            1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1)
-op(    GE,     ">=",           1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1)
-op(    EQ,     "==",           1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1,1)
-op(    NE,     "!=",           1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1,1)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    LT,     "<",            1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
+op(    LE,     "<=",           1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
+op(    GT,     ">",            1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
+op(    GE,     ">=",           1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
+op(    EQ,     "==",           1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1)
+op(    NE,     "!=",           1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1)
 
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    BITAND, "&",            1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ,1)
-op(    BITXOR, "^",            1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ,1)
-op(    BITOR,  "|",            1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ,1)
-op(    LOGAND, "&&",           1,1,1,1, , , ,1,1, ,1, , , , , , , ,1, ,1)
-op(    LOGOR,  "||",           1,1,1,1, , , ,1,1, ,1, , , , ,1, , ,1, ,1)
-op(    QUEST,  "?",            1, , , , , , , ,1, ,1, , , , , , , , , ,1)
-op(    COLON,  ":",            1, ,1, , , , , , ,1, ,1, , , , , ,1, , ,1)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    BITAND, "&",            1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, )
+op(    BITXOR, "^",            1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, )
+op(    BITOR,  "|",            1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, )
+op(    LOGAND, "&&",           1,1,1,1, , , ,1,1, ,1, , , , , , , ,1, )
+op(    LOGOR,  "||",           1,1,1,1, , , ,1,1, ,1, , , , ,1, , ,1, )
+op(    QUEST,  "?",            1, , , , , , , ,1, ,1, , , , , , , , , )
+op(    COLON,  ":",            1, ,1, , , , , , ,1, ,1, , , , , ,1, , )
 
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    ASSIGN, "=",            1, ,1, , , , , , , , , ,1, , , , ,1, , ,1)
-op(    MULASS, "*=",           1, , , , , ,1, , , , , ,1, , , , , ,1, ,1)
-op(    DIVASS, "/=",           1, , , , , ,1, , , , , ,1, ,1, , , ,1, ,1)
-op(    MODASS, "%=",           1, , , ,1, , , , , , , ,1, ,1, , , ,1, ,1)
-op(    ADDASS, "+=",           1, , , , , , ,1, , , , ,1, , , , , ,1, ,1)
-op(    SUBASS, "-=",           1, , , , , , ,1, , , , ,1, , , , , ,1, ,1)
-op(    SHLASS, "<<=",          1, , , ,1, , , , , , , ,1, , , , , ,1, ,1)
-op(    SHRASS, ">>=",          1, , , ,1, , , , , , , ,1, , , , , ,1, ,1)
-op(    ANDASS, "&=",           1, ,1, ,1, , , , , , , ,1, , , , , ,1, ,1)
-op(    XORASS, "^=",           1, ,1, ,1, , , , , , , ,1, , , , , ,1, ,1)
-op(    ORASS,  "|=",           1, ,1, ,1, , , , , , , ,1, , , , , ,1, ,1)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    ASSIGN, "=",            1, ,1, , , , , , , , , ,1, , , , ,1, , )
+op(    MULASS, "*=",           1, , , , , ,1, , , , , ,1, , , , , ,1, )
+op(    DIVASS, "/=",           1, , , , , ,1, , , , , ,1, ,1, , , ,1, )
+op(    MODASS, "%=",           1, , , ,1, , , , , , , ,1, ,1, , , ,1, )
+op(    ADDASS, "+=",           1, , , , , , ,1, , , , ,1, , , , , ,1, )
+op(    SUBASS, "-=",           1, , , , , , ,1, , , , ,1, , , , , ,1, )
+op(    SHLASS, "<<=",          1, , , ,1, , , , , , , ,1, , , , , ,1, )
+op(    SHRASS, ">>=",          1, , , ,1, , , , , , , ,1, , , , , ,1, )
+op(    ANDASS, "&=",           1, ,1, ,1, , , , , , , ,1, , , , , ,1, )
+op(    XORASS, "^=",           1, ,1, ,1, , , , , , , ,1, , , , , ,1, )
+op(    ORASS,  "|=",           1, ,1, ,1, , , , , , , ,1, , , , , ,1, )
 
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    NAME,   "name",          , , , , , , , , , , , , , , , , , , , ,1)
-op(    CON,    "constant",      , , , , , , , , , , , , , , , , , , , ,1)
-op(    STRING, "string",        , , , , , , , , , , , , , , , , , , , ,1)
-op(    FSEL,   "fsel",          , , , , , , , , , , , , , , , , , , , ,1)
-op(    CALL,   "call",         1, , , , , , , , , , , ,1, , , , , , , ,1)
-op(    COMMA,  ",",            1, ,1, , , , , , , , , , , , , , , , ,1,1)
-op(    CVT,    "convert",       , , , , , , , , ,1, , , , , , , , , , ,1)
-op(    ICALL,  "icall",        1, , , , , , , , , , , ,1, , , , , , , ,1)
-op(    LOAD,   "load",          , , , , , , , , , , , , , , , , , , , ,1)
-op(    PUSH,   "push",          , , , , , , , , ,1, , , , , , , , , , ,1)
-op(    RETURN, "return",       1, ,1, , , , , , , , , ,1, , , , ,1, , ,1)
-op(    REAL,   "real",          , , , , , , , , , , , , , , , , , , , ,0)
-op(    IMAG,   "imag",          , , , , , , , , , , , , , , , , , , , ,0)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    NAME,   "name",          , , , , , , , , , , , , , , , , , , , )
+op(    CON,    "constant",      , , , , , , , , , , , , , , , , , , , )
+op(    STRING, "string",        , , , , , , , , , , , , , , , , , , , )
+op(    FSEL,   "fsel",          , , , , , , , , , , , , , , , , , , , )
+op(    CALL,   "call",         1, , , , , , , , , , , ,1, , , , , , , )
+op(    COMMA,  ",",            1, ,1, , , , , , , , , , , , , , , , ,1)
+op(    CVT,    "convert",       , , , , , , , , ,1, , , , , , , , , , )
+op(    ICALL,  "icall",        1, , , , , , , , , , , ,1, , , , , , , )
+op(    LOAD,   "load",          , , , , , , , , , , , , , , , , , , , )
+op(    PUSH,   "push",          , , , , , , , , ,1, , , , , , , , , , )
+op(    RETURN, "return",       1, ,1, , , , , , , , , ,1, , , , ,1, , )
+op(    REAL,   "real",          , , , , , , , , , , , , , , , , , , , )
+op(    IMAG,   "imag",          , , , , , , , , , , , , , , , , , , , )
 
 /* INIT, CASE and FARG are pseudo operators that don't appear in the tree. */
-/*     name    repr            b l b B i c a s f v t b s l r p c e e = act */
-op(    INIT,   "init",         1, ,1, , , , , , , , , , , , , , ,1, , ,1)
-op(    CASE,   "case",          , , , , , , , , , , , , , , , , , , , ,0)
-op(    FARG,   "farg",         1, ,1, , , , , , , , , , , , , , ,1, , ,1)
+/*     name    repr            b l b B i c a s f v t b s l r p c e e = */
+op(    INIT,   "init",         1, ,1, , , , , , , , , , , , , , ,1, , )
+op(    CASE,   "case",          , , , , , , , , , , , , , , , , , , , )
+op(    FARG,   "farg",         1, ,1, , , , , , , , , , , , , , ,1, , )
 
 end_ops()
 
diff -r a9d4008f0992 -r 268cef914810 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Mar 20 20:15:37 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Mar 20 20:39:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.239 2021/03/20 18:38:25 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.240 2021/03/20 20:39:35 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.239 2021/03/20 18:38:25 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.240 2021/03/20 20:39:35 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -490,7 +490,7 @@
 tnode_t *
 build(op_t op, tnode_t *ln, tnode_t *rn)
 {
-       mod_t   *mp;
+       const mod_t *mp;
        tnode_t *ntn;



Home | Main Index | Thread Index | Old Index