Skip to content

Commit 5e6e64b

Browse files
committed
Java: Rename UnaryExpr.getExpr to getOperand.
1 parent 6fbf727 commit 5e6e64b

File tree

26 files changed

+67
-62
lines changed

26 files changed

+67
-62
lines changed

java/ql/consistency-queries/UnaryExpr.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import java
22

33
from UnaryExpr ue
44
where
5-
not exists(ue.getExpr())
5+
not exists(ue.getOperand())
66
or
77
exists(Expr e, int i | e.isNthChildOf(ue, i) and i != 0)
88
select ue

java/ql/lib/semmle/code/java/Constants.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module CalculateConstants<getBoolValSig/1 getBoolVal, getIntValSig/1 getIntVal>
2222
boolean calculateBooleanValue(Expr e) {
2323
// No casts relevant to booleans.
2424
// `!` is the only unary operator that evaluates to a boolean.
25-
result = getBoolVal(e.(LogNotExpr).getExpr()).booleanNot()
25+
result = getBoolVal(e.(LogNotExpr).getOperand()).booleanNot()
2626
or
2727
// Handle binary expressions that have integer operands and a boolean result.
2828
exists(BinaryExpr b, int left, int right |
@@ -115,11 +115,11 @@ module CalculateConstants<getBoolValSig/1 getBoolVal, getIntValSig/1 getIntVal>
115115
else result = val
116116
)
117117
or
118-
result = getIntVal(e.(PlusExpr).getExpr())
118+
result = getIntVal(e.(PlusExpr).getOperand())
119119
or
120-
result = -getIntVal(e.(MinusExpr).getExpr())
120+
result = -getIntVal(e.(MinusExpr).getOperand())
121121
or
122-
result = getIntVal(e.(BitNotExpr).getExpr()).bitNot()
122+
result = getIntVal(e.(BitNotExpr).getOperand()).bitNot()
123123
or
124124
// No `int` value for `LogNotExpr`.
125125
exists(BinaryExpr b, int v1, int v2 |

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ private module ControlFlowGraphImpl {
827827
index = 1 and result = e.getRightOperand()
828828
)
829829
or
830-
index = 0 and result = this.(UnaryExpr).getExpr()
830+
index = 0 and result = this.(UnaryExpr).getOperand()
831831
or
832832
index = 0 and result = this.(CastingExpr).getExpr()
833833
or
@@ -1044,7 +1044,7 @@ private module ControlFlowGraphImpl {
10441044
or
10451045
// The last node of a `LogNotExpr` is in its sub-expression with an inverted boolean completion
10461046
// (or a `normalCompletion`).
1047-
exists(Completion subcompletion | last(n.(LogNotExpr).getExpr(), last, subcompletion) |
1047+
exists(Completion subcompletion | last(n.(LogNotExpr).getOperand(), last, subcompletion) |
10481048
subcompletion = NormalCompletion() and
10491049
completion = NormalCompletion() and
10501050
not inBooleanContext(n)
@@ -1356,7 +1356,7 @@ private module ControlFlowGraphImpl {
13561356
(
13571357
result = first(n.asExpr().(AndLogicalExpr).getLeftOperand()) or
13581358
result = first(n.asExpr().(OrLogicalExpr).getLeftOperand()) or
1359-
result = first(n.asExpr().(LogNotExpr).getExpr()) or
1359+
result = first(n.asExpr().(LogNotExpr).getOperand()) or
13601360
result = first(n.asExpr().(ConditionalExpr).getCondition())
13611361
)
13621362
or

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Expr extends ExprParent, @expr {
113113
if this instanceof CastingExpr or this instanceof NotNullExpr
114114
then
115115
result = this.(CastingExpr).getExpr().getUnderlyingExpr() or
116-
result = this.(NotNullExpr).getExpr().getUnderlyingExpr()
116+
result = this.(NotNullExpr).getOperand().getUnderlyingExpr()
117117
else result = this
118118
}
119119
}
@@ -144,13 +144,13 @@ class CompileTimeConstantExpr extends Expr {
144144
this.(CastingExpr).getExpr().isCompileTimeConstant()
145145
or
146146
// The unary operators `+`, `-`, `~`, and `!` (but not `++` or `--`).
147-
this.(PlusExpr).getExpr().isCompileTimeConstant()
147+
this.(PlusExpr).getOperand().isCompileTimeConstant()
148148
or
149-
this.(MinusExpr).getExpr().isCompileTimeConstant()
149+
this.(MinusExpr).getOperand().isCompileTimeConstant()
150150
or
151-
this.(BitNotExpr).getExpr().isCompileTimeConstant()
151+
this.(BitNotExpr).getOperand().isCompileTimeConstant()
152152
or
153-
this.(LogNotExpr).getExpr().isCompileTimeConstant()
153+
this.(LogNotExpr).getOperand().isCompileTimeConstant()
154154
or
155155
// The multiplicative operators `*`, `/`, and `%`,
156156
// the additive operators `+` and `-`,
@@ -943,7 +943,7 @@ class LogicExpr extends Expr {
943943
/** Gets an operand of this logical expression. */
944944
Expr getAnOperand() {
945945
this.(BinaryExpr).getAnOperand() = result or
946-
this.(UnaryExpr).getExpr() = result
946+
this.(UnaryExpr).getOperand() = result
947947
}
948948
}
949949

@@ -1039,8 +1039,15 @@ class ReferenceEqualityTest extends EqualityTest {
10391039

10401040
/** A common super-class that represents unary operator expressions. */
10411041
class UnaryExpr extends Expr, @unaryexpr {
1042+
/**
1043+
* DEPRECATED: Use getOperand() instead.
1044+
*
1045+
* Gets the operand expression.
1046+
*/
1047+
deprecated Expr getExpr() { result.getParent() = this }
1048+
10421049
/** Gets the operand expression. */
1043-
Expr getExpr() { result.getParent() = this }
1050+
Expr getOperand() { result.getParent() = this }
10441051
}
10451052

10461053
/**
@@ -1773,14 +1780,14 @@ class VariableUpdate extends Expr {
17731780
VariableUpdate() {
17741781
this.(Assignment).getDest() instanceof VarAccess or
17751782
this instanceof LocalVariableDeclExpr or
1776-
this.(UnaryAssignExpr).getExpr() instanceof VarAccess
1783+
this.(UnaryAssignExpr).getOperand() instanceof VarAccess
17771784
}
17781785

17791786
/** Gets the destination of this variable update. */
17801787
Variable getDestVar() {
17811788
result.getAnAccess() = this.(Assignment).getDest() or
17821789
result = this.(LocalVariableDeclExpr).getVariable() or
1783-
result.getAnAccess() = this.(UnaryAssignExpr).getExpr()
1790+
result.getAnAccess() = this.(UnaryAssignExpr).getOperand()
17841791
}
17851792
}
17861793

@@ -1970,7 +1977,7 @@ class VarAccess extends Expr, @varaccess {
19701977
*/
19711978
predicate isVarWrite() {
19721979
exists(Assignment a | a.getDest() = this) or
1973-
exists(UnaryAssignExpr e | e.getExpr() = this)
1980+
exists(UnaryAssignExpr e | e.getOperand() = this)
19741981
}
19751982

19761983
/**

java/ql/lib/semmle/code/java/PrettyPrintAst.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private class PpUnaryExpr extends PpAst, UnaryExpr {
257257
i = 2 and result = "--" and this instanceof PostDecExpr
258258
}
259259

260-
override PpAst getChild(int i) { i = 1 and result = this.getExpr() }
260+
override PpAst getChild(int i) { i = 1 and result = this.getOperand() }
261261
}
262262

263263
private class PpCastExpr extends PpAst, CastExpr {

java/ql/lib/semmle/code/java/Statement.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class ForStmt extends ConditionalStmt, @forstmt {
184184
Variable getAnIterationVariable() {
185185
// Check that the variable is assigned to, incremented or decremented in the update expression, and...
186186
exists(Expr update | update = this.getAnUpdate().getAChildExpr*() |
187-
update.(UnaryAssignExpr).getExpr() = result.getAnAccess() or
187+
update.(UnaryAssignExpr).getOperand() = result.getAnAccess() or
188188
update = result.getAnAssignedValue()
189189
) and
190190
// ...that it is checked or used in the condition.

java/ql/lib/semmle/code/java/arithmetic/Overflow.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ArithExpr extends Expr {
9393
) and
9494
forall(Expr e |
9595
e = this.(BinaryExpr).getAnOperand() or
96-
e = this.(UnaryAssignExpr).getExpr() or
96+
e = this.(UnaryAssignExpr).getOperand() or
9797
e = this.(AssignOp).getSource()
9898
|
9999
e.getType() instanceof NumType
@@ -114,7 +114,7 @@ class ArithExpr extends Expr {
114114
*/
115115
Expr getLeftOperand() {
116116
result = this.(BinaryExpr).getLeftOperand() or
117-
result = this.(UnaryAssignExpr).getExpr() or
117+
result = this.(UnaryAssignExpr).getOperand() or
118118
result = this.(AssignOp).getDest()
119119
}
120120

@@ -128,7 +128,7 @@ class ArithExpr extends Expr {
128128
/** Gets an operand of this arithmetic expression. */
129129
Expr getAnOperand() {
130130
result = this.(BinaryExpr).getAnOperand() or
131-
result = this.(UnaryAssignExpr).getExpr() or
131+
result = this.(UnaryAssignExpr).getOperand() or
132132
result = this.(AssignOp).getSource()
133133
}
134134
}

java/ql/lib/semmle/code/java/comparison/Comparison.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java
99
* Used as basis for the transitive closure in `exprImplies`.
1010
*/
1111
private predicate exprImpliesStep(Expr e1, boolean b1, Expr e2, boolean b2) {
12-
e1.(LogNotExpr).getExpr() = e2 and
12+
e1.(LogNotExpr).getOperand() = e2 and
1313
b2 = b1.booleanNot() and
1414
(b1 = true or b1 = false)
1515
or

java/ql/lib/semmle/code/java/controlflow/Guards.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
279279
}
280280
}
281281

282-
class NotExpr extends Expr instanceof J::LogNotExpr {
283-
Expr getOperand() { result = this.(J::LogNotExpr).getExpr() }
284-
}
282+
class NotExpr = J::LogNotExpr;
285283

286284
class IdExpr extends Expr {
287285
IdExpr() { this instanceof AssignExpr or this instanceof CastExpr }

java/ql/lib/semmle/code/java/dataflow/Nullness.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private predicate unboxed(Expr e) {
6464
bin.getType() instanceof PrimitiveType
6565
)
6666
or
67-
exists(UnaryExpr un | un.getExpr() = e)
67+
exists(UnaryExpr un | un.getOperand() = e)
6868
or
6969
exists(ChooseExpr cond | cond.getType() instanceof PrimitiveType | cond.getAResultExpr() = e)
7070
or

0 commit comments

Comments
 (0)