oper.c revision 1.13 1 /* $NetBSD: oper.c,v 1.13 2023/09/14 21:08:12 rillig Exp $ */
2
3 /*-
4 * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland Illig.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "op.h"
33 #include "param.h"
34
35 #define X true
36 #define _ false
37
38 const mod_t modtab[NOPS] = {
39
40 /*-
41 * Operator properties:
42 *
43 * b binary
44 * l logical
45 * b takes _Bool
46 * z compares with zero
47 * i requires integer
48 * c requires integer or complex
49 * a requires arithmetic
50 * s requires scalar
51 * f fold constant operands
52 * v value context
53 * b balance operands
54 * s has side effects
55 * l warn if left operand unsigned
56 * r warn if right operand unsigned
57 * p possible precedence confusion
58 * c comparison
59 * e valid on enum
60 * e bad on enum
61 * = warn if operand '='
62 * o has operands
63 */
64
65 /* b l b z i c a s f v b s l r p c e e = o */
66 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "no-op" },
67 {X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "->" },
68 {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "." },
69 {_,X,X,X,_,_,_,X,X,_,_,_,_,_,_,_,_,X,_,X, "!" },
70 {_,_,_,_,_,X,_,_,X,X,_,_,_,_,_,_,_,X,X,X, "~" },
71 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "++" },
72 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "--" },
73 /*
74 * The '++' and '--' operators are conceptually unary operators, but
75 * lint implements them as binary operators due to the pre-multiplied
76 * pointer arithmetics, see build_prepost_incdec and build_plus_minus.
77 */
78 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "++x" },
79 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "--x" },
80 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "x++" },
81 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "x--" },
82 {_,_,_,_,_,_,X,_,X,X,_,_,_,_,_,_,_,X,X,X, "+" },
83 {_,_,_,_,_,_,X,_,X,X,_,_,X,_,_,_,_,X,X,X, "-" },
84 {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "*" },
85 {_,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "&" },
86 /* b l b z i c a s f v b s l r p c e e = o */
87 {X,_,_,_,_,_,X,_,X,X,X,_,_,X,_,_,_,X,X,X, "*" },
88 {X,_,_,_,_,_,X,_,X,X,X,_,X,X,_,_,_,X,X,X, "/" },
89 {X,_,_,_,X,_,_,_,X,X,X,_,X,X,_,_,_,X,X,X, "%" },
90 {X,_,_,_,_,_,_,X,X,X,X,_,_,_,_,_,_,X,_,X, "+" },
91 {X,_,_,_,_,_,_,X,X,X,X,_,_,_,_,_,_,X,_,X, "-" },
92 {X,_,_,_,X,_,_,_,X,X,_,_,_,_,X,_,_,X,X,X, "<<" },
93 {X,_,_,_,X,_,_,_,X,X,_,_,X,_,X,_,_,X,X,X, ">>" },
94 /* b l b z i c a s f v b s l r p c e e = o */
95 {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, "<" },
96 {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, "<=" },
97 {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, ">" },
98 {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, ">=" },
99 {X,X,X,_,_,_,_,X,X,X,X,_,_,_,_,X,X,_,X,X, "==" },
100 {X,X,X,_,_,_,_,X,X,X,X,_,_,_,_,X,X,_,X,X, "!=" },
101 /* b l b z i c a s f v b s l r p c e e = o */
102 {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "&" },
103 {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "^" },
104 {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "|" },
105 {X,X,X,X,_,_,_,X,X,_,_,_,_,_,_,_,_,X,_,X, "&&" },
106 {X,X,X,X,_,_,_,X,X,_,_,_,_,_,X,_,_,X,_,X, "||" },
107 {X,_,_,X,_,_,_,_,X,_,_,_,_,_,_,_,_,_,_,X, "?" },
108 {X,_,X,_,_,_,_,_,_,X,X,_,_,_,_,_,X,_,_,X, ":" },
109 /* b l b z i c a s f v b s l r p c e e = o */
110 {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "=" },
111 {X,_,_,_,_,_,X,_,_,_,_,X,_,_,_,_,_,X,_,X, "*=" },
112 {X,_,_,_,_,_,X,_,_,_,_,X,_,X,_,_,_,X,_,X, "/=" },
113 {X,_,_,_,X,_,_,_,_,_,_,X,_,X,_,_,_,X,_,X, "%=" },
114 {X,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "+=" },
115 {X,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "-=" },
116 {X,_,_,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "<<=" },
117 {X,_,_,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, ">>=" },
118 {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "&=" },
119 {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "^=" },
120 {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "|=" },
121 /* b l b z i c a s f v b s l r p c e e = o */
122 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "name" },
123 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "constant" },
124 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "string" },
125 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "fsel" },
126 {X,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,X, "call" },
127 {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X,X, "," },
128 {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "convert" },
129 {X,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,X, "icall" },
130 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "load" },
131 {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "push" },
132 {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "return" },
133 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "real" },
134 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "imag" },
135 {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "init" },
136 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "case" },
137 {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,X,_,_,X, "farg" },
138 };
139