Merge pull request #2719 from aschackmull/java/deprecate-parexpr

Java: Deprecate ParExpr
This commit is contained in:
yo-h
2020-01-30 18:23:13 -05:00
committed by GitHub
49 changed files with 90 additions and 182 deletions

View File

@@ -14,8 +14,7 @@ predicate locallySynchronizedOn(Expr e, SynchronizedStmt sync, Variable v) {
*/
predicate locallySynchronizedOnThis(Expr e, RefType thisType) {
exists(SynchronizedStmt sync | e.getEnclosingStmt().getEnclosingStmt+() = sync |
sync.getExpr().getProperExpr().(ThisAccess).getType().(RefType).getSourceDeclaration() =
thisType
sync.getExpr().(ThisAccess).getType().(RefType).getSourceDeclaration() = thisType
)
or
exists(SynchronizedCallable c | c = e.getEnclosingCallable() |

View File

@@ -289,8 +289,6 @@ private module ControlFlowGraphImpl {
logexpr.(UnaryExpr).getExpr() = b and inBooleanContext(logexpr)
)
or
exists(ParExpr parexpr | parexpr.getExpr() = b and inBooleanContext(parexpr))
or
exists(ConditionalExpr condexpr |
condexpr.getCondition() = b
or
@@ -574,8 +572,6 @@ private module ControlFlowGraphImpl {
or
result = first(n.(PostOrderNode).firstChild())
or
result = first(n.(ParExpr).getExpr())
or
result = first(n.(SynchronizedStmt).getExpr())
or
result = n and
@@ -708,9 +704,6 @@ private module ControlFlowGraphImpl {
last(condexpr.getTrueExpr(), last, completion)
)
or
// Parentheses are skipped in the CFG.
last(n.(ParExpr).getExpr(), last, completion)
or
// The last node of a node executed in post-order is the node itself.
n.(PostOrderNode).mayCompleteNormally() and last = n and completion = NormalCompletion()
or

View File

@@ -49,7 +49,7 @@ class AssignmentConversionContext extends ConversionSite {
AssignmentConversionContext() {
this = v.getAnAssignedValue()
or
exists(Assignment a | a.getDest().getProperExpr() = v.getAnAccess() and this = a.getSource())
exists(Assignment a | a.getDest() = v.getAnAccess() and this = a.getSource())
}
override Type getConversionTarget() { result = v.getType() }

View File

@@ -46,8 +46,12 @@ class Expr extends ExprParent, @expr {
*/
int getKind() { exprs(this, result, _, _, _) }
/** Gets this expression with any surrounding parentheses removed. */
Expr getProperExpr() {
/**
* DEPRECATED: This is no longer necessary. See `Expr.isParenthesized()`.
*
* Gets this expression with any surrounding parentheses removed.
*/
deprecated Expr getProperExpr() {
result = this.(ParExpr).getExpr().getProperExpr()
or
result = this and not this instanceof ParExpr
@@ -152,9 +156,6 @@ class CompileTimeConstantExpr extends Expr {
e.getFalseExpr().isCompileTimeConstant()
)
or
// Parenthesized expressions whose contained expression is a constant expression.
this.(ParExpr).getExpr().isCompileTimeConstant()
or
// Access to a final variable initialized by a compile-time constant.
exists(Variable v | this = v.getAnAccess() |
v.isFinal() and
@@ -169,8 +170,6 @@ class CompileTimeConstantExpr extends Expr {
string getStringValue() {
result = this.(StringLiteral).getRepresentedString()
or
result = this.(ParExpr).getExpr().(CompileTimeConstantExpr).getStringValue()
or
result =
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringValue()
@@ -296,9 +295,6 @@ class CompileTimeConstantExpr extends Expr {
else result = ce.getFalseExpr().(CompileTimeConstantExpr).getBooleanValue()
)
or
// Parenthesized expressions containing a boolean value.
result = this.(ParExpr).getExpr().(CompileTimeConstantExpr).getBooleanValue()
or
// Simple or qualified names where the variable is final and the initializer is a constant.
exists(Variable v | this = v.getAnAccess() |
result = v.getInitializer().(CompileTimeConstantExpr).getBooleanValue()
@@ -385,8 +381,6 @@ class CompileTimeConstantExpr extends Expr {
else result = ce.getFalseExpr().(CompileTimeConstantExpr).getIntValue()
)
or
result = this.(ParExpr).getExpr().(CompileTimeConstantExpr).getIntValue()
or
// If a `Variable` is a `CompileTimeConstantExpr`, its value is its initializer.
exists(Variable v | this = v.getAnAccess() |
result = v.getInitializer().(CompileTimeConstantExpr).getIntValue()
@@ -640,12 +634,8 @@ class BinaryExpr extends Expr, @binaryexpr {
/** Gets the operand on the right-hand side of this binary expression. */
Expr getRightOperand() { result.isNthChildOf(this, 1) }
/** Gets an operand (left or right), with any parentheses removed. */
Expr getAnOperand() {
exists(Expr r | r = this.getLeftOperand() or r = this.getRightOperand() |
result = r.getProperExpr()
)
}
/** Gets an operand (left or right). */
Expr getAnOperand() { result = this.getLeftOperand() or result = this.getRightOperand() }
/** The operands of this binary expression are `e` and `f`, in either order. */
predicate hasOperands(Expr e, Expr f) {
@@ -761,17 +751,14 @@ class NEExpr extends BinaryExpr, @neexpr {
* A bitwise expression.
*
* This includes expressions involving the operators
* `&`, `|`, `^`, or `~`,
* possibly parenthesized.
* `&`, `|`, `^`, or `~`.
*/
class BitwiseExpr extends Expr {
BitwiseExpr() {
exists(Expr proper | proper = this.getProperExpr() |
proper instanceof AndBitwiseExpr or
proper instanceof OrBitwiseExpr or
proper instanceof XorBitwiseExpr or
proper instanceof BitNotExpr
)
this instanceof AndBitwiseExpr or
this instanceof OrBitwiseExpr or
this instanceof XorBitwiseExpr or
this instanceof BitNotExpr
}
}
@@ -1128,10 +1115,14 @@ class SwitchExpr extends Expr, @switchexpr {
override string toString() { result = "switch (...)" }
}
/** A parenthesised expression. */
class ParExpr extends Expr, @parexpr {
/**
* DEPRECATED: Use `Expr.isParenthesized()` instead.
*
* A parenthesised expression.
*/
deprecated class ParExpr extends Expr, @parexpr {
/** Gets the expression inside the parentheses. */
Expr getExpr() { result.getParent() = this }
deprecated Expr getExpr() { result.getParent() = this }
/** Gets a printable representation of this expression. */
override string toString() { result = "(...)" }

View File

@@ -284,7 +284,7 @@ class NewInstance extends MethodAccess {
* cast.
*/
private Type getCastInferredConstructedTypes() {
exists(CastExpr cast | cast.getExpr() = this or cast.getExpr().(ParExpr).getExpr() = this |
exists(CastExpr cast | cast.getExpr() = this |
result = cast.getType()
or
// If we cast the result of this method, then this is either the type specified, or a

View File

@@ -246,8 +246,7 @@ private predicate formatStringFragment(Expr fmt) {
e.(AddExpr).getLeftOperand() = fmt or
e.(AddExpr).getRightOperand() = fmt or
e.(ConditionalExpr).getTrueExpr() = fmt or
e.(ConditionalExpr).getFalseExpr() = fmt or
e.(ParExpr).getExpr() = fmt
e.(ConditionalExpr).getFalseExpr() = fmt
)
}
@@ -268,8 +267,6 @@ private predicate formatStringValue(Expr e, string fmtvalue) {
or
e.getType() instanceof EnumType and fmtvalue = "x" // dummy value
or
formatStringValue(e.(ParExpr).getExpr(), fmtvalue)
or
exists(Variable v |
e = v.getAnAccess() and
v.isFinal() and

View File

@@ -16,9 +16,7 @@ class Variable extends @variable, Annotatable, Element, Modifiable {
Expr getAnAssignedValue() {
exists(LocalVariableDeclExpr e | e.getVariable() = this and result = e.getInit())
or
exists(AssignExpr e |
e.getDest().getProperExpr() = this.getAnAccess() and result = e.getSource()
)
exists(AssignExpr e | e.getDest() = this.getAnAccess() and result = e.getSource())
}
/** Gets the initializer expression of this variable. */

View File

@@ -6,10 +6,6 @@ import java
* Used as basis for the transitive closure in `exprImplies`.
*/
private predicate exprImpliesStep(Expr e1, boolean b1, Expr e2, boolean b2) {
e1.(ParExpr).getProperExpr() = e2 and
b2 = b1 and
(b1 = true or b1 = false)
or
e1.(LogNotExpr).getExpr() = e2 and
b2 = b1.booleanNot() and
(b1 = true or b1 = false)

View File

@@ -103,8 +103,8 @@ class Guard extends ExprParent {
*/
BasicBlock getBasicBlock() {
result = this.(Expr).getBasicBlock() or
result = this.(SwitchCase).getSwitch().getExpr().getProperExpr().getBasicBlock() or
result = this.(SwitchCase).getSwitchExpr().getExpr().getProperExpr().getBasicBlock()
result = this.(SwitchCase).getSwitch().getExpr().getBasicBlock() or
result = this.(SwitchCase).getSwitchExpr().getExpr().getBasicBlock()
}
/**
@@ -115,9 +115,9 @@ class Guard extends ExprParent {
*/
predicate isEquality(Expr e1, Expr e2, boolean polarity) {
exists(Expr exp1, Expr exp2 | equalityGuard(this, exp1, exp2, polarity) |
e1 = exp1.getProperExpr() and e2 = exp2.getProperExpr()
e1 = exp1 and e2 = exp2
or
e2 = exp1.getProperExpr() and e1 = exp2.getProperExpr()
e2 = exp1 and e1 = exp2
)
}
@@ -265,7 +265,7 @@ private predicate equalityGuard(Guard g, Expr e1, Expr e2, boolean polarity) {
exists(ConstCase cc |
cc = g and
polarity = true and
cc.getSelectorExpr().getProperExpr() = e1 and
cc.getSelectorExpr() = e1 and
cc.getValue() = e2 and
strictcount(cc.getValue(_)) = 1
)

View File

@@ -93,8 +93,6 @@ class ConstantExpr extends Expr {
// A binary expression where both sides are constant
this.(BinaryExpr).getLeftOperand() instanceof ConstantExpr and
this.(BinaryExpr).getRightOperand() instanceof ConstantExpr
or
this.(ParExpr).getExpr() instanceof ConstantExpr
)
}
@@ -108,8 +106,6 @@ class ConstantExpr extends Expr {
or
result = this.(FieldRead).getField().(ConstantField).getConstantValue().getBooleanValue()
or
result = this.(ParExpr).getExpr().(ConstantExpr).getBooleanValue()
or
// Handle binary expressions that have integer operands and a boolean result.
exists(BinaryExpr b, int left, int right |
b = this and

View File

@@ -19,10 +19,6 @@ private import semmle.code.java.dataflow.IntegerGuards
* Restricted to BaseSSA-based reasoning.
*/
predicate implies_v1(Guard g1, boolean b1, Guard g2, boolean b2) {
g1.(ParExpr).getExpr() = g2 and
b1 = b2 and
(b1 = true or b1 = false)
or
g1.(AndBitwiseExpr).getAnOperand() = g2 and b1 = true and b2 = true
or
g1.(OrBitwiseExpr).getAnOperand() = g2 and b1 = false and b2 = false
@@ -220,13 +216,11 @@ private predicate hasPossibleUnknownValue(SsaVariable v) {
* `ConditionalExpr`s. Parentheses are also removed.
*/
private Expr possibleValue(Expr e) {
result = possibleValue(e.(ParExpr).getExpr())
or
result = possibleValue(e.(ConditionalExpr).getTrueExpr())
or
result = possibleValue(e.(ConditionalExpr).getFalseExpr())
or
result = e and not e instanceof ParExpr and not e instanceof ConditionalExpr
result = e and not e instanceof ConditionalExpr
}
/**
@@ -253,7 +247,7 @@ private predicate possibleValue(SsaVariable v, boolean fromBackEdge, Expr e, Abs
not hasPossibleUnknownValue(v) and
exists(SsaExplicitUpdate def |
def = getADefinition(v, fromBackEdge) and
e = possibleValue(def.getDefiningExpr().(VariableAssign).getSource().getProperExpr()) and
e = possibleValue(def.getDefiningExpr().(VariableAssign).getSource()) and
k.getExpr() = e
)
}
@@ -305,7 +299,7 @@ private predicate guardControlsPhiBranch(
SsaExplicitUpdate upd, SsaPhiNode phi, Guard guard, boolean branch, Expr e
) {
guard.directlyControls(upd.getBasicBlock(), branch) and
upd.getDefiningExpr().(VariableAssign).getSource().getProperExpr() = e and
upd.getDefiningExpr().(VariableAssign).getSource() = e and
upd = phi.getAPhiInput() and
guard.getBasicBlock().bbStrictlyDominates(phi.getBasicBlock())
}
@@ -319,12 +313,12 @@ private predicate guardControlsPhiBranch(
*/
private predicate conditionalAssign(SsaVariable v, Guard guard, boolean branch, Expr e) {
exists(ConditionalExpr c |
v.(SsaExplicitUpdate).getDefiningExpr().(VariableAssign).getSource().getProperExpr() = c and
guard = c.getCondition().getProperExpr()
v.(SsaExplicitUpdate).getDefiningExpr().(VariableAssign).getSource() = c and
guard = c.getCondition()
|
branch = true and e = c.getTrueExpr().getProperExpr()
branch = true and e = c.getTrueExpr()
or
branch = false and e = c.getFalseExpr().getProperExpr()
branch = false and e = c.getFalseExpr()
)
or
exists(SsaExplicitUpdate upd, SsaPhiNode phi |

View File

@@ -24,9 +24,9 @@ predicate conditionCheckMethod(Method m, boolean checkTrue) {
not m.isOverridable() and
p.getType() instanceof BooleanType and
m.getBody().getStmt(0) = ifstmt and
ifstmt.getCondition().getProperExpr() = cond and
ifstmt.getCondition() = cond and
(
cond.(LogNotExpr).getExpr().getProperExpr().(VarAccess).getVariable() = p and checkTrue = true
cond.(LogNotExpr).getExpr().(VarAccess).getVariable() = p and checkTrue = true
or
cond.(VarAccess).getVariable() = p and checkTrue = false
) and
@@ -41,9 +41,9 @@ predicate conditionCheckMethod(Method m, boolean checkTrue) {
not m.isOverridable() and
m.getBody().getStmt(0).(ExprStmt).getExpr() = ma and
conditionCheck(ma, ct) and
ma.getArgument(0).getProperExpr() = arg and
ma.getArgument(0) = arg and
(
arg.(LogNotExpr).getExpr().getProperExpr().(VarAccess).getVariable() = p and
arg.(LogNotExpr).getExpr().(VarAccess).getVariable() = p and
checkTrue = ct.booleanNot()
or
arg.(VarAccess).getVariable() = p and checkTrue = ct

View File

@@ -10,7 +10,6 @@ private import RangeAnalysis
/** Gets an expression that might have the value `i`. */
private Expr exprWithIntValue(int i) {
result.(ConstantIntegerExpr).getIntValue() = i or
result.(ParExpr).getExpr() = exprWithIntValue(i) or
result.(ConditionalExpr).getTrueExpr() = exprWithIntValue(i) or
result.(ConditionalExpr).getFalseExpr() = exprWithIntValue(i)
}
@@ -142,25 +141,25 @@ Expr intBoundGuard(RValue x, boolean branch_with_lower_bound_k, int k) {
x.getVariable().getType() instanceof IntegralType
|
// c < x
comp.getLesserOperand().getProperExpr() = c and
comp.getLesserOperand() = c and
comp.isStrict() and
branch_with_lower_bound_k = true and
val + 1 = k
or
// c <= x
comp.getLesserOperand().getProperExpr() = c and
comp.getLesserOperand() = c and
not comp.isStrict() and
branch_with_lower_bound_k = true and
val = k
or
// x < c
comp.getGreaterOperand().getProperExpr() = c and
comp.getGreaterOperand() = c and
comp.isStrict() and
branch_with_lower_bound_k = false and
val = k
or
// x <= c
comp.getGreaterOperand().getProperExpr() = c and
comp.getGreaterOperand() = c and
not comp.isStrict() and
branch_with_lower_bound_k = false and
val + 1 = k

View File

@@ -76,8 +76,6 @@ private Expr modExpr(Expr arg, int mod) {
c.getIntValue() = mod - 1 and
result.(AndBitwiseExpr).hasOperands(arg, c)
)
or
result.(ParExpr).getExpr() = modExpr(arg, mod)
}
/**

View File

@@ -11,7 +11,6 @@ private import IntegerGuards
/** Gets an expression that is always `null`. */
Expr alwaysNullExpr() {
result instanceof NullLiteral or
result.(ParExpr).getExpr() = alwaysNullExpr() or
result.(CastExpr).getExpr() = alwaysNullExpr()
}
@@ -60,8 +59,6 @@ Expr clearlyNotNullExpr(Expr reason) {
reason = result
)
or
result.(ParExpr).getExpr() = clearlyNotNullExpr(reason)
or
result.(CastExpr).getExpr() = clearlyNotNullExpr(reason)
or
result.(AssignExpr).getSource() = clearlyNotNullExpr(reason)

View File

@@ -45,7 +45,6 @@ private import semmle.code.java.frameworks.Assertions
/** Gets an expression that may be `null`. */
Expr nullExpr() {
result instanceof NullLiteral or
result.(ParExpr).getExpr() = nullExpr() or
result.(ConditionalExpr).getTrueExpr() = nullExpr() or
result.(ConditionalExpr).getFalseExpr() = nullExpr() or
result.(AssignExpr).getSource() = nullExpr() or
@@ -131,11 +130,8 @@ predicate dereference(Expr e) {
* The `VarAccess` is included for nicer error reporting.
*/
private ControlFlowNode varDereference(SsaVariable v, VarAccess va) {
exists(Expr e |
dereference(e) and
e = sameValue(v, va) and
result = e.getProperExpr()
)
dereference(result) and
result = sameValue(v, va)
}
/**
@@ -442,8 +438,8 @@ private predicate nullDerefCandidate(SsaVariable origin, VarAccess va) {
/** A variable that is assigned `null` if the given condition takes the given branch. */
private predicate varConditionallyNull(SsaExplicitUpdate v, ConditionBlock cond, boolean branch) {
exists(ConditionalExpr condexpr |
v.getDefiningExpr().(VariableAssign).getSource().getProperExpr() = condexpr and
condexpr.getCondition().getProperExpr() = cond.getCondition()
v.getDefiningExpr().(VariableAssign).getSource() = condexpr and
condexpr.getCondition() = cond.getCondition()
|
condexpr.getTrueExpr() = nullExpr() and
branch = true and

View File

@@ -131,7 +131,7 @@ private predicate boundCondition(
or
exists(SubExpr sub, ConstantIntegerExpr c, int d |
// (v - d) - e < c
comp.getLesserOperand().getProperExpr() = sub and
comp.getLesserOperand() = sub and
comp.getGreaterOperand() = c and
sub.getLeftOperand() = ssaRead(v, d) and
sub.getRightOperand() = e and
@@ -139,7 +139,7 @@ private predicate boundCondition(
delta = d + c.getIntValue()
or
// (v - d) - e > c
comp.getGreaterOperand().getProperExpr() = sub and
comp.getGreaterOperand() = sub and
comp.getLesserOperand() = c and
sub.getLeftOperand() = ssaRead(v, d) and
sub.getRightOperand() = e and
@@ -147,7 +147,7 @@ private predicate boundCondition(
delta = d + c.getIntValue()
or
// e - (v - d) < c
comp.getLesserOperand().getProperExpr() = sub and
comp.getLesserOperand() = sub and
comp.getGreaterOperand() = c and
sub.getLeftOperand() = e and
sub.getRightOperand() = ssaRead(v, d) and
@@ -155,7 +155,7 @@ private predicate boundCondition(
delta = d - c.getIntValue()
or
// e - (v - d) > c
comp.getGreaterOperand().getProperExpr() = sub and
comp.getGreaterOperand() = sub and
comp.getLesserOperand() = c and
sub.getLeftOperand() = e and
sub.getRightOperand() = ssaRead(v, d) and

View File

@@ -26,8 +26,6 @@ private predicate nonNullSsaFwdStep(SsaVariable v, SsaVariable phi) {
}
private predicate nonNullDefStep(Expr e1, Expr e2) {
e2.(ParExpr).getExpr() = e1
or
exists(ConditionalExpr cond | cond = e2 |
cond.getTrueExpr() = e1 and cond.getFalseExpr() instanceof NullLiteral
or
@@ -104,8 +102,6 @@ class ConstantIntegerExpr extends Expr {
Expr ssaRead(SsaVariable v, int delta) {
result = v.getAUse() and delta = 0
or
result.(ParExpr).getExpr() = ssaRead(v, delta)
or
exists(int d1, ConstantIntegerExpr c |
result.(AddExpr).hasOperands(ssaRead(v, d1), c) and
delta = d1 - c.getIntValue()
@@ -264,8 +260,6 @@ predicate ssaUpdateStep(SsaExplicitUpdate v, Expr e, int delta) {
* Holds if `e1 + delta` equals `e2`.
*/
predicate valueFlowStep(Expr e2, Expr e1, int delta) {
e2.(ParExpr).getExpr() = e1 and delta = 0
or
e2.(AssignExpr).getSource() = e1 and delta = 0
or
e2.(PlusExpr).getExpr() = e1 and delta = 0

View File

@@ -1129,7 +1129,5 @@ Expr sameValue(SsaVariable v, VarAccess va) {
or
result.(AssignExpr).getSource() = sameValue(v, va)
or
result.(ParExpr).getExpr() = sameValue(v, va)
or
result.(RefTypeCastExpr).getExpr() = sameValue(v, va)
}

View File

@@ -476,8 +476,6 @@ private Sign exprSign(Expr e) {
(
unknownSign(e)
or
result = exprSign(e.(ParExpr).getExpr())
or
exists(SsaVariable v | v.getAUse() = e |
result = ssaSign(v, any(SsaReadPositionBlock bb | bb.getBlock() = e.getBasicBlock()))
or

View File

@@ -109,8 +109,6 @@ private predicate step(TypeFlowNode n1, TypeFlowNode n2) {
or
n2.asExpr() = n1.asSsa().getAUse()
or
n2.asExpr().(ParExpr).getExpr() = n1.asExpr()
or
n2.asExpr().(CastExpr).getExpr() = n1.asExpr() and
not n2.asExpr().getType() instanceof PrimitiveType
or

View File

@@ -390,8 +390,6 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
or
ThisFlow::adjacentThisRefs(node1.(PostUpdateNode).getPreUpdateNode(), node2)
or
node2.asExpr().(ParExpr).getExpr() = node1.asExpr()
or
node2.asExpr().(CastExpr).getExpr() = node1.asExpr()
or
node2.asExpr().(ConditionalExpr).getTrueExpr() = node1.asExpr()

View File

@@ -11,8 +11,6 @@ Expr valueFlow(Expr src) {
src = c.getTrueExpr() or
src = c.getFalseExpr()
)
or
src = result.(ParExpr).getExpr()
}
/**

View File

@@ -192,8 +192,6 @@ private predicate flowStep(RelevantNode n1, RelevantNode n2) {
n2.asExpr().(MethodAccess).getMethod() = getValue
)
or
n2.asExpr().(ParExpr).getExpr() = n1.asExpr()
or
n2.asExpr().(CastExpr).getExpr() = n1.asExpr()
or
n2.asExpr().(ConditionalExpr).getTrueExpr() = n1.asExpr()

View File

@@ -98,8 +98,6 @@ private predicate step(Node n1, Node n2) {
n2.asExpr().(FieldRead).getField() = f
)
or
n2.asExpr().(ParExpr).getExpr() = n1.asExpr()
or
n2.asExpr().(CastExpr).getExpr() = n1.asExpr()
or
n2.asExpr().(ConditionalExpr).getTrueExpr() = n1.asExpr()

View File

@@ -109,6 +109,6 @@ predicate assertFail(BasicBlock bb, ControlFlowNode n) {
n = m.getACheck(any(BooleanLiteral b | b.getBooleanValue() = true))
) or
exists(AssertFailMethod m | n = m.getACheck()) or
n.(AssertStmt).getExpr().getProperExpr().(BooleanLiteral).getBooleanValue() = false
n.(AssertStmt).getExpr().(BooleanLiteral).getBooleanValue() = false
)
}