mirror of
https://github.com/github/codeql.git
synced 2026-02-11 20:51:06 +01:00
Java: Rename UnaryExpr.getExpr to getOperand.
This commit is contained in:
@@ -2,7 +2,7 @@ import java
|
||||
|
||||
from UnaryExpr ue
|
||||
where
|
||||
not exists(ue.getExpr())
|
||||
not exists(ue.getOperand())
|
||||
or
|
||||
exists(Expr e, int i | e.isNthChildOf(ue, i) and i != 0)
|
||||
select ue
|
||||
|
||||
@@ -22,7 +22,7 @@ module CalculateConstants<getBoolValSig/1 getBoolVal, getIntValSig/1 getIntVal>
|
||||
boolean calculateBooleanValue(Expr e) {
|
||||
// No casts relevant to booleans.
|
||||
// `!` is the only unary operator that evaluates to a boolean.
|
||||
result = getBoolVal(e.(LogNotExpr).getExpr()).booleanNot()
|
||||
result = getBoolVal(e.(LogNotExpr).getOperand()).booleanNot()
|
||||
or
|
||||
// Handle binary expressions that have integer operands and a boolean result.
|
||||
exists(BinaryExpr b, int left, int right |
|
||||
@@ -115,11 +115,11 @@ module CalculateConstants<getBoolValSig/1 getBoolVal, getIntValSig/1 getIntVal>
|
||||
else result = val
|
||||
)
|
||||
or
|
||||
result = getIntVal(e.(PlusExpr).getExpr())
|
||||
result = getIntVal(e.(PlusExpr).getOperand())
|
||||
or
|
||||
result = -getIntVal(e.(MinusExpr).getExpr())
|
||||
result = -getIntVal(e.(MinusExpr).getOperand())
|
||||
or
|
||||
result = getIntVal(e.(BitNotExpr).getExpr()).bitNot()
|
||||
result = getIntVal(e.(BitNotExpr).getOperand()).bitNot()
|
||||
or
|
||||
// No `int` value for `LogNotExpr`.
|
||||
exists(BinaryExpr b, int v1, int v2 |
|
||||
|
||||
@@ -827,7 +827,7 @@ private module ControlFlowGraphImpl {
|
||||
index = 1 and result = e.getRightOperand()
|
||||
)
|
||||
or
|
||||
index = 0 and result = this.(UnaryExpr).getExpr()
|
||||
index = 0 and result = this.(UnaryExpr).getOperand()
|
||||
or
|
||||
index = 0 and result = this.(CastingExpr).getExpr()
|
||||
or
|
||||
@@ -1044,7 +1044,7 @@ private module ControlFlowGraphImpl {
|
||||
or
|
||||
// The last node of a `LogNotExpr` is in its sub-expression with an inverted boolean completion
|
||||
// (or a `normalCompletion`).
|
||||
exists(Completion subcompletion | last(n.(LogNotExpr).getExpr(), last, subcompletion) |
|
||||
exists(Completion subcompletion | last(n.(LogNotExpr).getOperand(), last, subcompletion) |
|
||||
subcompletion = NormalCompletion() and
|
||||
completion = NormalCompletion() and
|
||||
not inBooleanContext(n)
|
||||
@@ -1356,7 +1356,7 @@ private module ControlFlowGraphImpl {
|
||||
(
|
||||
result = first(n.asExpr().(AndLogicalExpr).getLeftOperand()) or
|
||||
result = first(n.asExpr().(OrLogicalExpr).getLeftOperand()) or
|
||||
result = first(n.asExpr().(LogNotExpr).getExpr()) or
|
||||
result = first(n.asExpr().(LogNotExpr).getOperand()) or
|
||||
result = first(n.asExpr().(ConditionalExpr).getCondition())
|
||||
)
|
||||
or
|
||||
|
||||
@@ -113,7 +113,7 @@ class Expr extends ExprParent, @expr {
|
||||
if this instanceof CastingExpr or this instanceof NotNullExpr
|
||||
then
|
||||
result = this.(CastingExpr).getExpr().getUnderlyingExpr() or
|
||||
result = this.(NotNullExpr).getExpr().getUnderlyingExpr()
|
||||
result = this.(NotNullExpr).getOperand().getUnderlyingExpr()
|
||||
else result = this
|
||||
}
|
||||
}
|
||||
@@ -144,13 +144,13 @@ class CompileTimeConstantExpr extends Expr {
|
||||
this.(CastingExpr).getExpr().isCompileTimeConstant()
|
||||
or
|
||||
// The unary operators `+`, `-`, `~`, and `!` (but not `++` or `--`).
|
||||
this.(PlusExpr).getExpr().isCompileTimeConstant()
|
||||
this.(PlusExpr).getOperand().isCompileTimeConstant()
|
||||
or
|
||||
this.(MinusExpr).getExpr().isCompileTimeConstant()
|
||||
this.(MinusExpr).getOperand().isCompileTimeConstant()
|
||||
or
|
||||
this.(BitNotExpr).getExpr().isCompileTimeConstant()
|
||||
this.(BitNotExpr).getOperand().isCompileTimeConstant()
|
||||
or
|
||||
this.(LogNotExpr).getExpr().isCompileTimeConstant()
|
||||
this.(LogNotExpr).getOperand().isCompileTimeConstant()
|
||||
or
|
||||
// The multiplicative operators `*`, `/`, and `%`,
|
||||
// the additive operators `+` and `-`,
|
||||
@@ -943,7 +943,7 @@ class LogicExpr extends Expr {
|
||||
/** Gets an operand of this logical expression. */
|
||||
Expr getAnOperand() {
|
||||
this.(BinaryExpr).getAnOperand() = result or
|
||||
this.(UnaryExpr).getExpr() = result
|
||||
this.(UnaryExpr).getOperand() = result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1039,8 +1039,15 @@ class ReferenceEqualityTest extends EqualityTest {
|
||||
|
||||
/** A common super-class that represents unary operator expressions. */
|
||||
class UnaryExpr extends Expr, @unaryexpr {
|
||||
/**
|
||||
* DEPRECATED: Use getOperand() instead.
|
||||
*
|
||||
* Gets the operand expression.
|
||||
*/
|
||||
deprecated Expr getExpr() { result.getParent() = this }
|
||||
|
||||
/** Gets the operand expression. */
|
||||
Expr getExpr() { result.getParent() = this }
|
||||
Expr getOperand() { result.getParent() = this }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1773,14 +1780,14 @@ class VariableUpdate extends Expr {
|
||||
VariableUpdate() {
|
||||
this.(Assignment).getDest() instanceof VarAccess or
|
||||
this instanceof LocalVariableDeclExpr or
|
||||
this.(UnaryAssignExpr).getExpr() instanceof VarAccess
|
||||
this.(UnaryAssignExpr).getOperand() instanceof VarAccess
|
||||
}
|
||||
|
||||
/** Gets the destination of this variable update. */
|
||||
Variable getDestVar() {
|
||||
result.getAnAccess() = this.(Assignment).getDest() or
|
||||
result = this.(LocalVariableDeclExpr).getVariable() or
|
||||
result.getAnAccess() = this.(UnaryAssignExpr).getExpr()
|
||||
result.getAnAccess() = this.(UnaryAssignExpr).getOperand()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1970,7 +1977,7 @@ class VarAccess extends Expr, @varaccess {
|
||||
*/
|
||||
predicate isVarWrite() {
|
||||
exists(Assignment a | a.getDest() = this) or
|
||||
exists(UnaryAssignExpr e | e.getExpr() = this)
|
||||
exists(UnaryAssignExpr e | e.getOperand() = this)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -257,7 +257,7 @@ private class PpUnaryExpr extends PpAst, UnaryExpr {
|
||||
i = 2 and result = "--" and this instanceof PostDecExpr
|
||||
}
|
||||
|
||||
override PpAst getChild(int i) { i = 1 and result = this.getExpr() }
|
||||
override PpAst getChild(int i) { i = 1 and result = this.getOperand() }
|
||||
}
|
||||
|
||||
private class PpCastExpr extends PpAst, CastExpr {
|
||||
|
||||
@@ -184,7 +184,7 @@ class ForStmt extends ConditionalStmt, @forstmt {
|
||||
Variable getAnIterationVariable() {
|
||||
// Check that the variable is assigned to, incremented or decremented in the update expression, and...
|
||||
exists(Expr update | update = this.getAnUpdate().getAChildExpr*() |
|
||||
update.(UnaryAssignExpr).getExpr() = result.getAnAccess() or
|
||||
update.(UnaryAssignExpr).getOperand() = result.getAnAccess() or
|
||||
update = result.getAnAssignedValue()
|
||||
) and
|
||||
// ...that it is checked or used in the condition.
|
||||
|
||||
@@ -93,7 +93,7 @@ class ArithExpr extends Expr {
|
||||
) and
|
||||
forall(Expr e |
|
||||
e = this.(BinaryExpr).getAnOperand() or
|
||||
e = this.(UnaryAssignExpr).getExpr() or
|
||||
e = this.(UnaryAssignExpr).getOperand() or
|
||||
e = this.(AssignOp).getSource()
|
||||
|
|
||||
e.getType() instanceof NumType
|
||||
@@ -114,7 +114,7 @@ class ArithExpr extends Expr {
|
||||
*/
|
||||
Expr getLeftOperand() {
|
||||
result = this.(BinaryExpr).getLeftOperand() or
|
||||
result = this.(UnaryAssignExpr).getExpr() or
|
||||
result = this.(UnaryAssignExpr).getOperand() or
|
||||
result = this.(AssignOp).getDest()
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ class ArithExpr extends Expr {
|
||||
/** Gets an operand of this arithmetic expression. */
|
||||
Expr getAnOperand() {
|
||||
result = this.(BinaryExpr).getAnOperand() or
|
||||
result = this.(UnaryAssignExpr).getExpr() or
|
||||
result = this.(UnaryAssignExpr).getOperand() or
|
||||
result = this.(AssignOp).getSource()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java
|
||||
* Used as basis for the transitive closure in `exprImplies`.
|
||||
*/
|
||||
private predicate exprImpliesStep(Expr e1, boolean b1, Expr e2, boolean b2) {
|
||||
e1.(LogNotExpr).getExpr() = e2 and
|
||||
e1.(LogNotExpr).getOperand() = e2 and
|
||||
b2 = b1.booleanNot() and
|
||||
(b1 = true or b1 = false)
|
||||
or
|
||||
|
||||
@@ -279,9 +279,7 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
|
||||
}
|
||||
}
|
||||
|
||||
class NotExpr extends Expr instanceof J::LogNotExpr {
|
||||
Expr getOperand() { result = this.(J::LogNotExpr).getExpr() }
|
||||
}
|
||||
class NotExpr = J::LogNotExpr;
|
||||
|
||||
class IdExpr extends Expr {
|
||||
IdExpr() { this instanceof AssignExpr or this instanceof CastExpr }
|
||||
|
||||
@@ -64,7 +64,7 @@ private predicate unboxed(Expr e) {
|
||||
bin.getType() instanceof PrimitiveType
|
||||
)
|
||||
or
|
||||
exists(UnaryExpr un | un.getExpr() = e)
|
||||
exists(UnaryExpr un | un.getOperand() = e)
|
||||
or
|
||||
exists(ChooseExpr cond | cond.getType() instanceof PrimitiveType | cond.getAResultExpr() = e)
|
||||
or
|
||||
|
||||
@@ -173,23 +173,23 @@ module Sem implements Semantic<Location> {
|
||||
}
|
||||
|
||||
class NegateExpr extends UnaryExpr instanceof MinusExpr {
|
||||
override Expr getOperand() { result = super.getExpr() }
|
||||
override Expr getOperand() { result = MinusExpr.super.getOperand() }
|
||||
}
|
||||
|
||||
class PreIncExpr extends UnaryExpr instanceof J::PreIncExpr {
|
||||
override Expr getOperand() { result = super.getExpr() }
|
||||
override Expr getOperand() { result = J::PreIncExpr.super.getOperand() }
|
||||
}
|
||||
|
||||
class PreDecExpr extends UnaryExpr instanceof J::PreDecExpr {
|
||||
override Expr getOperand() { result = super.getExpr() }
|
||||
override Expr getOperand() { result = J::PreDecExpr.super.getOperand() }
|
||||
}
|
||||
|
||||
class PostIncExpr extends UnaryExpr instanceof J::PostIncExpr {
|
||||
override Expr getOperand() { result = super.getExpr() }
|
||||
override Expr getOperand() { result = J::PostIncExpr.super.getOperand() }
|
||||
}
|
||||
|
||||
class PostDecExpr extends UnaryExpr instanceof J::PostDecExpr {
|
||||
override Expr getOperand() { result = super.getExpr() }
|
||||
override Expr getOperand() { result = J::PostDecExpr.super.getOperand() }
|
||||
}
|
||||
|
||||
class CopyValueExpr extends UnaryExpr {
|
||||
@@ -200,7 +200,7 @@ module Sem implements Semantic<Location> {
|
||||
}
|
||||
|
||||
override Expr getOperand() {
|
||||
result = this.(J::PlusExpr).getExpr() or
|
||||
result = this.(J::PlusExpr).getOperand() or
|
||||
result = this.(J::AssignExpr).getSource() or
|
||||
result = this.(J::LocalVariableDeclExpr).getInit()
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ module FlowStepsInput implements UniversalFlow::UniversalFlowInput<Location> {
|
||||
or
|
||||
n2.asSsa().(Base::SsaCapturedDefinition).captures(n1.asSsa())
|
||||
or
|
||||
n2.asExpr().(NotNullExpr).getExpr() = n1.asExpr()
|
||||
n2.asExpr().(NotNullExpr).getOperand() = n1.asExpr()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,7 +87,7 @@ private module BaseSsaImpl {
|
||||
result = TLocalVar(v.getCallable(), v)
|
||||
)
|
||||
or
|
||||
result.getAnAccess() = upd.(UnaryAssignExpr).getExpr()
|
||||
result.getAnAccess() = upd.(UnaryAssignExpr).getOperand()
|
||||
}
|
||||
|
||||
/** Holds if `n` updates the local variable `v`. */
|
||||
|
||||
@@ -201,7 +201,7 @@ predicate simpleAstFlowStep(Expr e1, Expr e2) {
|
||||
or
|
||||
e2 = any(StmtExpr stmtExpr | e1 = stmtExpr.getResultExpr())
|
||||
or
|
||||
e2 = any(NotNullExpr nne | e1 = nne.getExpr())
|
||||
e2 = any(NotNullExpr nne | e1 = nne.getOperand())
|
||||
or
|
||||
e2.(WhenExpr).getBranch(_).getAResult() = e1
|
||||
or
|
||||
|
||||
@@ -302,7 +302,7 @@ private module Cached {
|
||||
result = TLocalVar(v.getCallable(), v)
|
||||
)
|
||||
or
|
||||
result.getAnAccess() = upd.(UnaryAssignExpr).getExpr()
|
||||
result.getAnAccess() = upd.(UnaryAssignExpr).getOperand()
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -69,10 +69,10 @@ module Private {
|
||||
|
||||
/** Returns the operand of this expression. */
|
||||
Expr getOperand() {
|
||||
result = this.(J::PreIncExpr).getExpr() or
|
||||
result = this.(J::PreDecExpr).getExpr() or
|
||||
result = this.(J::MinusExpr).getExpr() or
|
||||
result = this.(J::BitNotExpr).getExpr()
|
||||
result = this.(J::PreIncExpr).getOperand() or
|
||||
result = this.(J::PreDecExpr).getOperand() or
|
||||
result = this.(J::MinusExpr).getOperand() or
|
||||
result = this.(J::BitNotExpr).getOperand()
|
||||
}
|
||||
|
||||
/** Returns the operation representing this expression. */
|
||||
@@ -258,12 +258,12 @@ private module Impl {
|
||||
|
||||
/** Returns the operand of the operation if `e` is a decrement. */
|
||||
Expr getDecrementOperand(Element e) {
|
||||
result = e.(PostDecExpr).getExpr() or result = e.(PreDecExpr).getExpr()
|
||||
result = e.(PostDecExpr).getOperand() or result = e.(PreDecExpr).getOperand()
|
||||
}
|
||||
|
||||
/** Returns the operand of the operation if `e` is an increment. */
|
||||
Expr getIncrementOperand(Element e) {
|
||||
result = e.(PostIncExpr).getExpr() or result = e.(PreIncExpr).getExpr()
|
||||
result = e.(PostIncExpr).getOperand() or result = e.(PreIncExpr).getOperand()
|
||||
}
|
||||
|
||||
/** Gets the variable underlying the implicit SSA variable `v`. */
|
||||
@@ -287,14 +287,14 @@ private module Impl {
|
||||
|
||||
/** Holds if `f` is accessed in an increment operation. */
|
||||
predicate fieldIncrementOperationOperand(Field f) {
|
||||
any(PostIncExpr inc).getExpr() = f.getAnAccess() or
|
||||
any(PreIncExpr inc).getExpr() = f.getAnAccess()
|
||||
any(PostIncExpr inc).getOperand() = f.getAnAccess() or
|
||||
any(PreIncExpr inc).getOperand() = f.getAnAccess()
|
||||
}
|
||||
|
||||
/** Holds if `f` is accessed in a decrement operation. */
|
||||
predicate fieldDecrementOperationOperand(Field f) {
|
||||
any(PostDecExpr dec).getExpr() = f.getAnAccess() or
|
||||
any(PreDecExpr dec).getExpr() = f.getAnAccess()
|
||||
any(PostDecExpr dec).getOperand() = f.getAnAccess() or
|
||||
any(PreDecExpr dec).getOperand() = f.getAnAccess()
|
||||
}
|
||||
|
||||
/** Returns possible signs of `f` based on the declaration. */
|
||||
@@ -316,9 +316,9 @@ private module Impl {
|
||||
/** Returns a sub expression of `e` for expression types where the sign depends on the child. */
|
||||
Expr getASubExprWithSameSign(Expr e) {
|
||||
result = e.(AssignExpr).getSource() or
|
||||
result = e.(PlusExpr).getExpr() or
|
||||
result = e.(PostIncExpr).getExpr() or
|
||||
result = e.(PostDecExpr).getExpr() or
|
||||
result = e.(PlusExpr).getOperand() or
|
||||
result = e.(PostIncExpr).getOperand() or
|
||||
result = e.(PostDecExpr).getOperand() or
|
||||
result = e.(ChooseExpr).getAResultExpr() or
|
||||
result = e.(CastingExpr).getExpr()
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ private predicate reaches(Expr src, Argument arg) {
|
||||
or
|
||||
exists(StmtExpr e | e.getResultExpr() = src | reaches(e, arg))
|
||||
or
|
||||
exists(NotNullExpr e | e.getExpr() = src | reaches(e, arg))
|
||||
exists(NotNullExpr e | e.getOperand() = src | reaches(e, arg))
|
||||
or
|
||||
exists(WhenExpr e | e.getBranch(_).getAResult() = src | reaches(e, arg))
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ module InsecureRandomnessConfig implements DataFlow::ConfigSig {
|
||||
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
|
||||
n1.asExpr() = n2.asExpr().(BinaryExpr).getAnOperand()
|
||||
or
|
||||
n1.asExpr() = n2.asExpr().(UnaryExpr).getExpr()
|
||||
n1.asExpr() = n2.asExpr().(UnaryExpr).getOperand()
|
||||
or
|
||||
exists(MethodCall mc, string methodName |
|
||||
mc.getMethod().hasQualifiedName("org.owasp.esapi", "Encoder", methodName) and
|
||||
|
||||
@@ -32,7 +32,7 @@ class AnyAssignment extends Expr {
|
||||
/** The expression modified by this assignment. */
|
||||
Expr getDest() {
|
||||
this.(Assignment).getDest() = result or
|
||||
this.(UnaryAssignExpr).getExpr() = result
|
||||
this.(UnaryAssignExpr).getOperand() = result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ predicate subCondition(Expr cond, Expr subcond, boolean negated) {
|
||||
or
|
||||
subCondition(cond.(OrLogicalExpr).getAnOperand(), subcond, negated)
|
||||
or
|
||||
subCondition(cond.(LogNotExpr).getExpr(), subcond, negated.booleanNot())
|
||||
subCondition(cond.(LogNotExpr).getOperand(), subcond, negated.booleanNot())
|
||||
}
|
||||
|
||||
from
|
||||
|
||||
@@ -98,9 +98,9 @@ where
|
||||
or
|
||||
conditionalWithBool(e, pattern, rewrite)
|
||||
or
|
||||
e.(LogNotExpr).getExpr().(ComparisonOrEquality).negate(pattern, rewrite)
|
||||
e.(LogNotExpr).getOperand().(ComparisonOrEquality).negate(pattern, rewrite)
|
||||
or
|
||||
e.(LogNotExpr).getExpr() instanceof LogNotExpr and
|
||||
e.(LogNotExpr).getOperand() instanceof LogNotExpr and
|
||||
pattern = "!!A" and
|
||||
rewrite = "A"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import java
|
||||
import DeadLocals
|
||||
|
||||
predicate minusOne(MinusExpr e) { e.getExpr().(Literal).getValue() = "1" }
|
||||
predicate minusOne(MinusExpr e) { e.getOperand().(Literal).getValue() = "1" }
|
||||
|
||||
predicate flowStep(Expr decl, Expr init) {
|
||||
decl = init
|
||||
|
||||
@@ -66,7 +66,7 @@ where
|
||||
fr.getField() = f and
|
||||
not f.getDeclaringType() instanceof EnumType and
|
||||
forall(Assignment ae | ae.getDest() = f.getAnAccess() | ae.getSource() instanceof NullLiteral) and
|
||||
not exists(UnaryAssignExpr ua | ua.getExpr() = f.getAnAccess()) and
|
||||
not exists(UnaryAssignExpr ua | ua.getOperand() = f.getAnAccess()) and
|
||||
not f.isFinal() and
|
||||
// Exclude fields that may be accessed reflectively.
|
||||
not reflectivelyWritten(f) and
|
||||
|
||||
@@ -29,7 +29,7 @@ class NoMaybeElement extends MaybeElement {
|
||||
}
|
||||
|
||||
MaybeElement op(UnaryExpr e) {
|
||||
if exists(e.getExpr()) then result = TElement(e.getExpr()) else result = TNoElement()
|
||||
if exists(e.getOperand()) then result = TElement(e.getOperand()) else result = TNoElement()
|
||||
}
|
||||
|
||||
from Expr e
|
||||
|
||||
@@ -29,7 +29,7 @@ class NoMaybeElement extends MaybeElement {
|
||||
}
|
||||
|
||||
MaybeElement op(UnaryExpr e) {
|
||||
if exists(e.getExpr()) then result = TElement(e.getExpr()) else result = TNoElement()
|
||||
if exists(e.getOperand()) then result = TElement(e.getOperand()) else result = TNoElement()
|
||||
}
|
||||
|
||||
from Expr e
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import default
|
||||
|
||||
from MinusExpr me, Literal l
|
||||
where l = me.getExpr()
|
||||
where l = me.getOperand()
|
||||
select me, l
|
||||
|
||||
Reference in New Issue
Block a user