Java: Deprecate ParExpr.

This commit is contained in:
Anders Schack-Mulligen
2020-01-29 15:52:07 +01:00
parent c4d2163321
commit 75c549baa1
48 changed files with 87 additions and 172 deletions

View File

@@ -15,7 +15,7 @@ import java
import semmle.code.java.Collections
predicate isDefinitelyPositive(Expr e) {
isDefinitelyPositive(e.getProperExpr()) or
isDefinitelyPositive(e) or
e.(IntegerLiteral).getIntValue() >= 0 or
e.(MethodAccess).getMethod() instanceof CollectionSizeMethod or
e.(MethodAccess).getMethod() instanceof StringLengthMethod or
@@ -24,10 +24,10 @@ predicate isDefinitelyPositive(Expr e) {
from BinaryExpr t, RemExpr lhs, IntegerLiteral rhs, string parity
where
t.getLeftOperand().getProperExpr() = lhs and
t.getRightOperand().getProperExpr() = rhs and
t.getLeftOperand() = lhs and
t.getRightOperand() = rhs and
not isDefinitelyPositive(lhs.getLeftOperand()) and
lhs.getRightOperand().getProperExpr().(IntegerLiteral).getIntValue() = 2 and
lhs.getRightOperand().(IntegerLiteral).getIntValue() = 2 and
(
t instanceof EQExpr and rhs.getIntValue() = 1 and parity = "oddness"
or

View File

@@ -17,9 +17,6 @@ predicate isConstantExp(Expr e) {
// A literal is constant.
e instanceof Literal
or
// A parenthesized expression is constant if its proper expression is.
isConstantExp(e.(ParExpr).getProperExpr())
or
e instanceof TypeAccess
or
e instanceof ArrayTypeAccess
@@ -33,25 +30,25 @@ predicate isConstantExp(Expr e) {
)
or
// A cast expression is constant if its expression is.
exists(CastExpr c | c = e | isConstantExp(c.getExpr().getProperExpr()))
exists(CastExpr c | c = e | isConstantExp(c.getExpr()))
or
// Multiplication by 0 is constant.
exists(MulExpr m | m = e | eval(m.getAnOperand().getProperExpr()) = 0)
exists(MulExpr m | m = e | eval(m.getAnOperand()) = 0)
or
// Integer remainder by 1 is constant.
exists(RemExpr r | r = e |
r.getLeftOperand().getType() instanceof IntegralType and
eval(r.getRightOperand().getProperExpr()) = 1
eval(r.getRightOperand()) = 1
)
or
exists(AndBitwiseExpr a | a = e | eval(a.getAnOperand().getProperExpr()) = 0)
exists(AndBitwiseExpr a | a = e | eval(a.getAnOperand()) = 0)
or
exists(AndLogicalExpr a | a = e |
a.getAnOperand().getProperExpr().(BooleanLiteral).getBooleanValue() = false
a.getAnOperand().(BooleanLiteral).getBooleanValue() = false
)
or
exists(OrLogicalExpr o | o = e |
o.getAnOperand().getProperExpr().(BooleanLiteral).getBooleanValue() = true
o.getAnOperand().(BooleanLiteral).getBooleanValue() = true
)
}

View File

@@ -35,8 +35,8 @@ float exprBound(Expr e) {
/** A multiplication that does not overflow. */
predicate small(MulExpr e) {
exists(NumType t, float lhs, float rhs, float res | t = e.getType() |
lhs = exprBound(e.getLeftOperand().getProperExpr()) and
rhs = exprBound(e.getRightOperand().getProperExpr()) and
lhs = exprBound(e.getLeftOperand()) and
rhs = exprBound(e.getRightOperand()) and
lhs * rhs = res and
res <= t.getOrdPrimitiveType().getMaxValue()
)
@@ -47,7 +47,7 @@ predicate small(MulExpr e) {
*/
Expr getRestrictedParent(Expr e) {
result = e.getParent() and
(result instanceof ArithExpr or result instanceof ConditionalExpr or result instanceof ParExpr)
(result instanceof ArithExpr or result instanceof ConditionalExpr)
}
from ConversionSite c, MulExpr e, NumType sourceType, NumType destType