Module Name: src
Committed By: rillig
Date: Thu Sep 14 21:08:12 UTC 2023
Modified Files:
src/usr.bin/xlint/lint1: README.md lint1.h op.h oper.c
Removed Files:
src/usr.bin/xlint/lint1: ops.def
Log Message:
lint: remove preprocessor magic from definition of operators
No binary change.
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.31 -r0 src/usr.bin/xlint/lint1/ops.def
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/README.md
diff -u src/usr.bin/xlint/lint1/README.md:1.13 src/usr.bin/xlint/lint1/README.md:1.14
--- src/usr.bin/xlint/lint1/README.md:1.13 Wed Aug 2 18:51:25 2023
+++ src/usr.bin/xlint/lint1/README.md Thu Sep 14 21:08:12 2023
@@ -1,4 +1,4 @@
-[//]: # ($NetBSD: README.md,v 1.13 2023/08/02 18:51:25 rillig Exp $)
+[//]: # ($NetBSD: README.md,v 1.14 2023/09/14 21:08:12 rillig Exp $)
# Introduction
@@ -105,7 +105,7 @@ it needs to be copied using `block_dup_t
When lint parses an expression,
it builds a tree of nodes representing the AST.
Each node has an operator that defines which other members may be accessed.
-The operators and their properties are defined in `ops.def`.
+The operators and their properties are defined in `oper.c`.
Some examples for operators:
| Operator | Meaning |
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.201 src/usr.bin/xlint/lint1/lint1.h:1.202
--- src/usr.bin/xlint/lint1/lint1.h:1.201 Wed Sep 13 20:31:58 2023
+++ src/usr.bin/xlint/lint1/lint1.h Thu Sep 14 21:08:12 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.201 2023/09/13 20:31:58 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.202 2023/09/14 21:08:12 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -111,7 +111,7 @@ typedef struct {
* Set if an integer constant is unsigned only in C90 and later, but
* not in traditional C.
*
- * See the operators table in ops.def, columns "l r".
+ * See the operators table in oper.c, columns "l r".
*/
bool v_unsigned_since_c90;
bool v_char_constant;
Index: src/usr.bin/xlint/lint1/op.h
diff -u src/usr.bin/xlint/lint1/op.h:1.22 src/usr.bin/xlint/lint1/op.h:1.23
--- src/usr.bin/xlint/lint1/op.h:1.22 Wed Sep 13 20:31:58 2023
+++ src/usr.bin/xlint/lint1/op.h Thu Sep 14 21:08:12 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: op.h,v 1.22 2023/09/13 20:31:58 rillig Exp $ */
+/* $NetBSD: op.h,v 1.23 2023/09/14 21:08:12 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -34,7 +34,7 @@
#include <stdbool.h>
/*
- * Various information about operators; see ops.def.
+ * Various information about operators.
*/
typedef struct {
bool m_binary: 1;
@@ -60,17 +60,87 @@ typedef struct {
const char *m_name;
} mod_t;
-extern const mod_t modtab[];
+typedef enum {
+ NOOP,
+ ARROW,
+ POINT,
+ NOT,
+ COMPL,
+ INC, /* does not appear in the tree */
+ DEC, /* does not appear in the tree */
+ INCBEF,
+ DECBEF,
+ INCAFT,
+ DECAFT,
+ UPLUS,
+ UMINUS,
+ INDIR,
+ ADDR,
-#define begin_ops() typedef enum {
-#define op(name, repr, \
- is_binary, is_logical, takes_bool, requires_bool, \
- is_integer, is_complex, is_arithmetic, is_scalar, \
- can_fold, is_value, unused, balances_operands, \
- side_effects, left_unsigned, right_unsigned, \
- precedence_confusion, is_comparison, \
- valid_on_enum, bad_on_enum, warn_if_eq, \
- has_operands) \
- name,
-#define end_ops() } op_t;
-#include "ops.def"
+ MULT,
+ DIV,
+ MOD,
+ PLUS,
+ MINUS,
+ SHL,
+ SHR,
+
+ LT,
+ LE,
+ GT,
+ GE,
+ EQ,
+ NE,
+
+ BITAND,
+ BITXOR,
+ BITOR,
+ LOGAND,
+ LOGOR,
+ QUEST,
+ COLON,
+
+ ASSIGN,
+ MULASS,
+ DIVASS,
+ MODASS,
+ ADDASS,
+ SUBASS,
+ SHLASS,
+ SHRASS,
+ ANDASS,
+ XORASS,
+ ORASS,
+
+ NAME,
+ CON,
+ STRING,
+ FSEL,
+ CALL,
+ COMMA,
+ CVT,
+ ICALL,
+ LOAD,
+ /*
+ * PUSH is a virtual node that is used to concatenate arguments in a
+ * function call expression. The PUSH nodes are ordered from right to
+ * left. For example, the function call f(17, 23) is represented as
+ * CALL(f, PUSH(23, PUSH(17, NULL))).
+ */
+ PUSH,
+ RETURN,
+ REAL,
+ IMAG,
+
+ INIT, /* does not appear in the tree */
+ CASE, /* does not appear in the tree */
+ /*
+ * FARG is only used temporarily in check_prototype_argument to check
+ * type compatibility and conversion for function arguments.
+ */
+ FARG, /* does not appear in the tree */
+} op_t;
+
+#define NOPS ((int)FARG + 1)
+
+extern const mod_t modtab[NOPS];
Index: src/usr.bin/xlint/lint1/oper.c
diff -u src/usr.bin/xlint/lint1/oper.c:1.12 src/usr.bin/xlint/lint1/oper.c:1.13
--- src/usr.bin/xlint/lint1/oper.c:1.12 Wed Sep 13 20:31:58 2023
+++ src/usr.bin/xlint/lint1/oper.c Thu Sep 14 21:08:12 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: oper.c,v 1.12 2023/09/13 20:31:58 rillig Exp $ */
+/* $NetBSD: oper.c,v 1.13 2023/09/14 21:08:12 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -29,32 +29,110 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/types.h>
#include "op.h"
#include "param.h"
-const mod_t modtab[NOPS] =
-#define begin_ops() {
-#define op(name, repr, \
- is_binary, is_logical, takes_bool, requires_bool, \
- is_integer, is_complex, is_arithmetic, is_scalar, \
- can_fold, is_value, unused, balances_operands, \
- side_effects, left_unsigned, right_unsigned, \
- precedence_confusion, is_comparison, \
- valid_on_enum, bad_on_enum, warn_if_eq, has_operands) \
- { \
- is_binary + 0 > 0, is_logical + 0 > 0, \
- takes_bool + 0 > 0, requires_bool + 0 > 0, \
- is_integer + 0 > 0, is_complex + 0 > 0, \
- is_arithmetic + 0 > 0, is_scalar + 0 > 0, \
- can_fold + 0 > 0, is_value + 0 > 0, \
- balances_operands + 0 > 0, \
- side_effects + 0 > 0, left_unsigned + 0 > 0, \
- right_unsigned + 0 > 0, precedence_confusion + 0 > 0, \
- is_comparison + 0 > 0, valid_on_enum + 0 > 0, \
- bad_on_enum + 0 > 0, warn_if_eq + 0 > 0, \
- has_operands + 0 > 0, \
- repr, \
- },
-#define end_ops(n) };
-#include "ops.def"
+#define X true
+#define _ false
+
+const mod_t modtab[NOPS] = {
+
+/*-
+ * Operator properties:
+ *
+ * b binary
+ * l logical
+ * b takes _Bool
+ * z compares with zero
+ * i requires integer
+ * c requires integer or complex
+ * a requires arithmetic
+ * s requires scalar
+ * f fold constant operands
+ * v value context
+ * b balance operands
+ * s has side effects
+ * l warn if left operand unsigned
+ * r warn if right operand unsigned
+ * p possible precedence confusion
+ * c comparison
+ * e valid on enum
+ * e bad on enum
+ * = warn if operand '='
+ * o has operands
+ */
+
+/* b l b z i c a s f v b s l r p c e e = o */
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "no-op" },
+ {X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "->" },
+ {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
+ * pointer arithmetics, see build_prepost_incdec and build_plus_minus.
+ */
+ {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "++x" },
+ {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "--x" },
+ {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "x++" },
+ {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "x--" },
+ {_,_,_,_,_,_,X,_,X,X,_,_,_,_,_,_,_,X,X,X, "+" },
+ {_,_,_,_,_,_,X,_,X,X,_,_,X,_,_,_,_,X,X,X, "-" },
+ {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "*" },
+ {_,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "&" },
+/* b l b z i c a s f v b s l r p c e e = o */
+ {X,_,_,_,_,_,X,_,X,X,X,_,_,X,_,_,_,X,X,X, "*" },
+ {X,_,_,_,_,_,X,_,X,X,X,_,X,X,_,_,_,X,X,X, "/" },
+ {X,_,_,_,X,_,_,_,X,X,X,_,X,X,_,_,_,X,X,X, "%" },
+ {X,_,_,_,_,_,_,X,X,X,X,_,_,_,_,_,_,X,_,X, "+" },
+ {X,_,_,_,_,_,_,X,X,X,X,_,_,_,_,_,_,X,_,X, "-" },
+ {X,_,_,_,X,_,_,_,X,X,_,_,_,_,X,_,_,X,X,X, "<<" },
+ {X,_,_,_,X,_,_,_,X,X,_,_,X,_,X,_,_,X,X,X, ">>" },
+/* b l b z i c a s f v b s l r p c e e = o */
+ {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, "<" },
+ {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, "<=" },
+ {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, ">" },
+ {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, ">=" },
+ {X,X,X,_,_,_,_,X,X,X,X,_,_,_,_,X,X,_,X,X, "==" },
+ {X,X,X,_,_,_,_,X,X,X,X,_,_,_,_,X,X,_,X,X, "!=" },
+/* b l b z i c a s f v b s l r p c e e = o */
+ {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "&" },
+ {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "^" },
+ {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "|" },
+ {X,X,X,X,_,_,_,X,X,_,_,_,_,_,_,_,_,X,_,X, "&&" },
+ {X,X,X,X,_,_,_,X,X,_,_,_,_,_,X,_,_,X,_,X, "||" },
+ {X,_,_,X,_,_,_,_,X,_,_,_,_,_,_,_,_,_,_,X, "?" },
+ {X,_,X,_,_,_,_,_,_,X,X,_,_,_,_,_,X,_,_,X, ":" },
+/* b l b z i c a s f v b s l r p c e e = o */
+ {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "=" },
+ {X,_,_,_,_,_,X,_,_,_,_,X,_,_,_,_,_,X,_,X, "*=" },
+ {X,_,_,_,_,_,X,_,_,_,_,X,_,X,_,_,_,X,_,X, "/=" },
+ {X,_,_,_,X,_,_,_,_,_,_,X,_,X,_,_,_,X,_,X, "%=" },
+ {X,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "+=" },
+ {X,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "-=" },
+ {X,_,_,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "<<=" },
+ {X,_,_,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, ">>=" },
+ {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "&=" },
+ {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "^=" },
+ {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "|=" },
+/* b l b z i c a s f v b s l r p c e e = o */
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "name" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "constant" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "string" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "fsel" },
+ {X,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,X, "call" },
+ {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X,X, "," },
+ {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "convert" },
+ {X,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,X, "icall" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "load" },
+ {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "push" },
+ {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "return" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "real" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "imag" },
+ {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "init" },
+ {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "case" },
+ {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,X,_,_,X, "farg" },
+};