Skip to content

Commit 563be9f

Browse files
authored
Merge pull request #2719 from aschackmull/java/deprecate-parexpr
Java: Deprecate ParExpr
2 parents 209a306 + d8b8422 commit 563be9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+90
-182
lines changed

change-notes/1.24/analysis-java.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ The following changes in version 1.24 affect Java analysis in all applications.
3636
general file classification mechanism and thus suppression of alerts, and
3737
also any security queries using taint tracking, as test classes act as
3838
default barriers stopping taint flow.
39+
* Parentheses are now no longer modelled directly in the AST, that is, the
40+
`ParExpr` class is empty. Instead, a parenthesized expression can be
41+
identified with the `Expr.isParenthesized()` member predicate.

java/ql/src/Language Abuse/UselessUpcast.ql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java
1515
predicate usefulUpcast(CastExpr e) {
1616
// Upcasts that may be performed to affect resolution of methods or constructors.
1717
exists(Call c, int i, Callable target |
18-
c.getArgument(i).getProperExpr() = e and
18+
c.getArgument(i) = e and
1919
target = c.getCallee() and
2020
// An upcast to the type of the corresponding parameter.
2121
e.getType() = target.getParameterType(i)
@@ -31,27 +31,25 @@ predicate usefulUpcast(CastExpr e) {
3131
)
3232
or
3333
// Upcasts of a varargs argument.
34-
exists(Call c, int iArg, int iParam | c.getArgument(iArg).getProperExpr() = e |
34+
exists(Call c, int iArg, int iParam | c.getArgument(iArg) = e |
3535
c.getCallee().getParameter(iParam).isVarargs() and iArg >= iParam
3636
)
3737
or
3838
// Upcasts that are performed on an operand of a ternary expression.
39-
exists(ConditionalExpr ce |
40-
e = ce.getTrueExpr().getProperExpr() or e = ce.getFalseExpr().getProperExpr()
41-
)
39+
exists(ConditionalExpr ce | e = ce.getTrueExpr() or e = ce.getFalseExpr())
4240
or
4341
// Upcasts to raw types.
4442
e.getType() instanceof RawType
4543
or
4644
e.getType().(Array).getElementType() instanceof RawType
4745
or
4846
// Upcasts that are performed to affect field, private method, or static method resolution.
49-
exists(FieldAccess fa | e = fa.getQualifier().getProperExpr() |
47+
exists(FieldAccess fa | e = fa.getQualifier() |
5048
not e.getExpr().getType().(RefType).inherits(fa.getField())
5149
)
5250
or
5351
exists(MethodAccess ma, Method m |
54-
e = ma.getQualifier().getProperExpr() and
52+
e = ma.getQualifier() and
5553
m = ma.getMethod() and
5654
(m.isStatic() or m.isPrivate())
5755
|

java/ql/src/Likely Bugs/Arithmetic/BadCheckOdd.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java
1515
import semmle.code.java.Collections
1616

1717
predicate isDefinitelyPositive(Expr e) {
18-
isDefinitelyPositive(e.getProperExpr()) or
18+
isDefinitelyPositive(e) or
1919
e.(IntegerLiteral).getIntValue() >= 0 or
2020
e.(MethodAccess).getMethod() instanceof CollectionSizeMethod or
2121
e.(MethodAccess).getMethod() instanceof StringLengthMethod or
@@ -24,10 +24,10 @@ predicate isDefinitelyPositive(Expr e) {
2424

2525
from BinaryExpr t, RemExpr lhs, IntegerLiteral rhs, string parity
2626
where
27-
t.getLeftOperand().getProperExpr() = lhs and
28-
t.getRightOperand().getProperExpr() = rhs and
27+
t.getLeftOperand() = lhs and
28+
t.getRightOperand() = rhs and
2929
not isDefinitelyPositive(lhs.getLeftOperand()) and
30-
lhs.getRightOperand().getProperExpr().(IntegerLiteral).getIntValue() = 2 and
30+
lhs.getRightOperand().(IntegerLiteral).getIntValue() = 2 and
3131
(
3232
t instanceof EQExpr and rhs.getIntValue() = 1 and parity = "oddness"
3333
or

java/ql/src/Likely Bugs/Arithmetic/ConstantExpAppearsNonConstant.ql

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ predicate isConstantExp(Expr e) {
1717
// A literal is constant.
1818
e instanceof Literal
1919
or
20-
// A parenthesized expression is constant if its proper expression is.
21-
isConstantExp(e.(ParExpr).getProperExpr())
22-
or
2320
e instanceof TypeAccess
2421
or
2522
e instanceof ArrayTypeAccess
@@ -33,26 +30,22 @@ predicate isConstantExp(Expr e) {
3330
)
3431
or
3532
// A cast expression is constant if its expression is.
36-
exists(CastExpr c | c = e | isConstantExp(c.getExpr().getProperExpr()))
33+
exists(CastExpr c | c = e | isConstantExp(c.getExpr()))
3734
or
3835
// Multiplication by 0 is constant.
39-
exists(MulExpr m | m = e | eval(m.getAnOperand().getProperExpr()) = 0)
36+
exists(MulExpr m | m = e | eval(m.getAnOperand()) = 0)
4037
or
4138
// Integer remainder by 1 is constant.
4239
exists(RemExpr r | r = e |
4340
r.getLeftOperand().getType() instanceof IntegralType and
44-
eval(r.getRightOperand().getProperExpr()) = 1
41+
eval(r.getRightOperand()) = 1
4542
)
4643
or
47-
exists(AndBitwiseExpr a | a = e | eval(a.getAnOperand().getProperExpr()) = 0)
44+
exists(AndBitwiseExpr a | a = e | eval(a.getAnOperand()) = 0)
4845
or
49-
exists(AndLogicalExpr a | a = e |
50-
a.getAnOperand().getProperExpr().(BooleanLiteral).getBooleanValue() = false
51-
)
46+
exists(AndLogicalExpr a | a = e | a.getAnOperand().(BooleanLiteral).getBooleanValue() = false)
5247
or
53-
exists(OrLogicalExpr o | o = e |
54-
o.getAnOperand().getProperExpr().(BooleanLiteral).getBooleanValue() = true
55-
)
48+
exists(OrLogicalExpr o | o = e | o.getAnOperand().(BooleanLiteral).getBooleanValue() = true)
5649
}
5750

5851
from Expr e

java/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ float exprBound(Expr e) {
3535
/** A multiplication that does not overflow. */
3636
predicate small(MulExpr e) {
3737
exists(NumType t, float lhs, float rhs, float res | t = e.getType() |
38-
lhs = exprBound(e.getLeftOperand().getProperExpr()) and
39-
rhs = exprBound(e.getRightOperand().getProperExpr()) and
38+
lhs = exprBound(e.getLeftOperand()) and
39+
rhs = exprBound(e.getRightOperand()) and
4040
lhs * rhs = res and
4141
res <= t.getOrdPrimitiveType().getMaxValue()
4242
)
@@ -47,7 +47,7 @@ predicate small(MulExpr e) {
4747
*/
4848
Expr getRestrictedParent(Expr e) {
4949
result = e.getParent() and
50-
(result instanceof ArithExpr or result instanceof ConditionalExpr or result instanceof ParExpr)
50+
(result instanceof ArithExpr or result instanceof ConditionalExpr)
5151
}
5252

5353
from ConversionSite c, MulExpr e, NumType sourceType, NumType destType

java/ql/src/Likely Bugs/Comparison/DefineEqualsWhenAddingFields.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ predicate checksReferenceEquality(EqualsMethod em) {
3232
eq.getAnOperand().(VarAccess).getVariable() = em.getParameter(0) and
3333
(
3434
// `{ return (ojb==this); }`
35-
eq = blk.getStmt().(ReturnStmt).getResult().getProperExpr()
35+
eq = blk.getStmt().(ReturnStmt).getResult()
3636
or
3737
// `{ if (ojb==this) return true; else return false; }`
3838
exists(IfStmt ifStmt | ifStmt = blk.getStmt() |
39-
eq = ifStmt.getCondition().getProperExpr() and
39+
eq = ifStmt.getCondition() and
4040
ifStmt.getThen().(ReturnStmt).getResult().(BooleanLiteral).getBooleanValue() = true and
4141
ifStmt.getElse().(ReturnStmt).getResult().(BooleanLiteral).getBooleanValue() = false
4242
)

java/ql/src/Likely Bugs/Comparison/MissingInstanceofInEquals.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ReferenceEquals extends EqualsMethod {
4545
exists(Block b, ReturnStmt ret, EQExpr eq |
4646
this.getBody() = b and
4747
b.getStmt(0) = ret and
48-
ret.getResult().getProperExpr() = eq and
48+
ret.getResult() = eq and
4949
eq.getAnOperand() = this.getAParameter().getAnAccess() and
5050
(eq.getAnOperand() instanceof ThisAccess or eq.getAnOperand() instanceof FieldAccess)
5151
)

java/ql/src/Likely Bugs/Comparison/NoAssignInBooleanExprs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BooleanExpr extends Expr {
2626
}
2727

2828
private predicate assignAndCheck(AssignExpr e) {
29-
exists(BinaryExpr c | e = c.getAChildExpr().getProperExpr() |
29+
exists(BinaryExpr c | e = c.getAChildExpr() |
3030
c instanceof ComparisonExpr or
3131
c instanceof EqualityTest
3232
)

java/ql/src/Likely Bugs/Comparison/StringComparison.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class StringValue extends Expr {
2424
this.(MethodAccess).getMethod() = intern
2525
)
2626
or
27-
// Parenthesized expressions.
28-
this.(ParExpr).getExpr().(StringValue).isInterned()
29-
or
3027
// Ternary conditional operator.
3128
this.(ConditionalExpr).getTrueExpr().(StringValue).isInterned() and
3229
this.(ConditionalExpr).getFalseExpr().(StringValue).isInterned()
@@ -52,7 +49,7 @@ predicate variableValuesInterned(Variable v) {
5249
not v instanceof Parameter and
5350
// If the string is modified with `+=`, then the new string is not interned
5451
// even if the components are.
55-
not exists(AssignOp append | append.getDest().getProperExpr() = v.getAnAccess())
52+
not exists(AssignOp append | append.getDest() = v.getAnAccess())
5653
}
5754

5855
from EqualityTest e, StringValue lhs, StringValue rhs

java/ql/src/Likely Bugs/Comparison/UselessComparisonTest.ql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ Expr overFlowCand() {
127127
or
128128
exists(SsaExplicitUpdate x | result = x.getAUse() and x.getDefiningExpr() = overFlowCand())
129129
or
130-
result.(ParExpr).getExpr() = overFlowCand()
131-
or
132130
result.(AssignExpr).getRhs() = overFlowCand()
133131
or
134132
result.(LocalVariableDeclExpr).getInit() = overFlowCand()
@@ -165,8 +163,6 @@ Expr increaseOrDecreaseOfVar(SsaVariable v) {
165163
result = x.getAUse() and x.getDefiningExpr() = increaseOrDecreaseOfVar(v)
166164
)
167165
or
168-
result.(ParExpr).getExpr() = increaseOrDecreaseOfVar(v)
169-
or
170166
result.(AssignExpr).getRhs() = increaseOrDecreaseOfVar(v)
171167
or
172168
result.(LocalVariableDeclExpr).getInit() = increaseOrDecreaseOfVar(v)

0 commit comments

Comments
 (0)