1 /* $NetBSD: oper.c,v 1.16 2024/03/31 20:28:45 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 /* 72 * The '++' and '--' operators are conceptually unary operators, but 73 * lint implements them as binary operators due to the pre-multiplied 74 * pointer arithmetics, see build_prepost_incdec and build_plus_minus. 75 */ 76 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "++x" }, 77 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "--x" }, 78 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "x++" }, 79 {_,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "x--" }, 80 {_,_,_,_,_,_,X,_,X,X,_,_,_,_,_,_,_,X,X,X, "+" }, 81 {_,_,_,_,_,_,X,_,X,X,_,_,X,_,_,_,_,X,X,X, "-" }, 82 {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "*" }, 83 {_,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "&" }, 84 /* b l b z i c a s f v b s l r p c e e = o */ 85 {X,_,_,_,_,_,X,_,X,X,X,_,_,X,_,_,_,X,X,X, "*" }, 86 {X,_,_,_,_,_,X,_,X,X,X,_,X,X,_,_,_,X,X,X, "/" }, 87 {X,_,_,_,X,_,_,_,X,X,X,_,X,X,_,_,_,X,X,X, "%" }, 88 {X,_,_,_,_,_,_,X,X,X,X,_,_,_,_,_,_,X,_,X, "+" }, 89 {X,_,_,_,_,_,_,X,X,X,X,_,_,_,_,_,_,X,_,X, "-" }, 90 {X,_,_,_,X,_,_,_,X,X,_,_,_,_,X,_,_,X,X,X, "<<" }, 91 {X,_,_,_,X,_,_,_,X,X,_,_,X,_,X,_,_,X,X,X, ">>" }, 92 /* b l b z i c a s f v b s l r p c e e = o */ 93 {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, "<" }, 94 {X,X,_,_,_,_,_,X,X,X,X,_,X,X,_,X,X,_,X,X, "<=" }, 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, "==" }, 98 {X,X,X,_,_,_,_,X,X,X,X,_,_,_,_,X,X,_,X,X, "!=" }, 99 /* b l b z i c a s f v b s l r p c e e = o */ 100 {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "&" }, 101 {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "^" }, 102 {X,_,X,_,X,_,_,_,X,X,X,_,_,_,X,_,_,X,_,X, "|" }, 103 {X,X,X,X,_,_,_,X,X,_,_,_,_,_,_,_,_,X,_,X, "&&" }, 104 {X,X,X,X,_,_,_,X,X,_,_,_,_,_,X,_,_,X,_,X, "||" }, 105 {X,_,_,X,_,_,_,_,X,_,_,_,_,_,_,_,_,_,_,X, "?" }, 106 {X,_,X,_,_,_,_,_,_,X,X,_,_,_,_,_,X,_,_,X, ":" }, 107 /* b l b z i c a s f v b s l r p c e e = o */ 108 {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "=" }, 109 {X,_,_,_,_,_,X,_,_,_,_,X,_,_,_,_,_,X,_,X, "*=" }, 110 {X,_,_,_,_,_,X,_,_,_,_,X,_,X,_,_,_,X,_,X, "/=" }, 111 {X,_,_,_,X,_,_,_,_,_,_,X,_,X,_,_,_,X,_,X, "%=" }, 112 {X,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "+=" }, 113 {X,_,_,_,_,_,_,X,_,_,_,X,_,_,_,_,_,X,_,X, "-=" }, 114 {X,_,_,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "<<=" }, 115 {X,_,_,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, ">>=" }, 116 {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "&=" }, 117 {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "^=" }, 118 {X,_,X,_,X,_,_,_,_,_,_,X,_,_,_,_,_,X,_,X, "|=" }, 119 /* b l b z i c a s f v b s l r p c e e = o */ 120 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "name" }, 121 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "constant" }, 122 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "string" }, 123 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "fsel" }, 124 {_,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_, "call" }, 125 {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X,X, "," }, 126 {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "convert" }, 127 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "load" }, 128 {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "return" }, 129 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "real" }, 130 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "imag" }, 131 {X,_,X,_,_,_,_,_,_,_,_,X,_,_,_,_,X,_,_,X, "init" }, 132 {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_, "case" }, 133 {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,X,_,_,X, "farg" }, 134 }; 135