@@ -29,6 +29,12 @@ predicate isLogicalOrandBitwise(Expr exptmp) {
29
29
(
30
30
exptmp .( LogicalOrExpr ) .getRightOperand ( ) .( BinaryBitwiseOperation ) .getLeftOperand ( ) .getType ( )
31
31
instanceof BoolType and
32
+ / * *
33
+ * The essence of these lines is to improve the quality of detection by eliminating the situation
34
+ * of processing a logical type by bit operations. In fact , the predicate looks for a situation
35
+ * when the left operand of a bit operation has a boolean type , which already suggests that the priority is not correct .
36
+ * But if the right- hand operand is 0 or 1 , then there is a possibility that the author intended so.
37
+ * /
32
38
not exptmp
33
39
.( LogicalOrExpr )
34
40
.getRightOperand ( )
@@ -48,6 +54,12 @@ predicate isLogicalOrandBitwise(Expr exptmp) {
48
54
(
49
55
exptmp .( LogicalAndExpr ) .getRightOperand ( ) .( BinaryBitwiseOperation ) .getLeftOperand ( ) .getType ( )
50
56
instanceof BoolType and
57
+ / * *
58
+ * Looking for a situation in which the right- hand operand of a bit operation is not limited to 0 or 1 .
59
+ * In this case, the logical operation will be performed with the result of a binary operation that is not a Boolean type.
60
+ * In my opinion this indicates a priority error . after all, it will be quite difficult for a developer
61
+ * to evaluate the conversion of the results of a bit operation to a boolean type .
62
+ * /
51
63
not exptmp
52
64
.( LogicalAndExpr )
53
65
.getRightOperand ( )
@@ -165,12 +177,22 @@ where
165
177
isLogicalOrandBitwise ( exp ) and
166
178
msg = "Binary operations have higher priority."
167
179
or
180
+ / * *
181
+ * Looking for a situation where the equality of the sizes of the first operands
182
+ * might indicate that the developer planned to perform an operation between them.
183
+ * However , the absence of parentheses means that the rightmost operation will be performed initially.
184
+ * /
168
185
isBitwiseandBitwise ( exp ) and
169
186
isDifferentSize ( exp .( BinaryBitwiseOperation ) .getLeftOperand ( ) ,
170
187
exp .( BinaryBitwiseOperation ) .getRightOperand ( ) .( BinaryBitwiseOperation ) .getLeftOperand ( ) ,
171
188
exp .( BinaryBitwiseOperation ) .getRightOperand ( ) .( BinaryBitwiseOperation ) .getRightOperand ( ) ) and
172
189
msg = "Expression ranges do not match operation precedence."
173
190
or
191
+ / * *
192
+ * Looking for a out those expressions that, as a result of identifying the priority with parentheses,
193
+ * will give different values. As a consequence, this piece of code was supposed to find errors associated
194
+ * with possible outcomes of operations.
195
+ * /
174
196
isBitwiseandBitwise ( exp ) and
175
197
isDifferentResults ( exp .( BinaryBitwiseOperation ) .getLeftOperand ( ) ,
176
198
exp .( BinaryBitwiseOperation ) .getRightOperand ( ) .( BinaryBitwiseOperation ) .getLeftOperand ( ) ,
0 commit comments