Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3d50e8

Browse files
committed
Python (pruning): Refactor a bit and all comments for clarity.
1 parent e1fb1d2 commit a3d50e8

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

python/ql/src/semmle/python/Exprs.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ class NegativeIntegerLiteral extends ImmutableLiteral, UnaryExpr {
466466
}
467467

468468
override Object getLiteralObject() {
469-
py_cobjecttypes(result, theIntType()) and py_cobjectnames(result, "-" + this.getOperand().(IntegerLiteral).getN())
470-
or
471-
py_cobjecttypes(result, theLongType()) and py_cobjectnames(result, "-" + this.getOperand().(IntegerLiteral).getN())
469+
(py_cobjecttypes(result, theIntType()) or py_cobjecttypes(result, theLongType()))
470+
and
471+
py_cobjectnames(result, "-" + this.getOperand().(IntegerLiteral).getN())
472472
}
473473

474474
}

python/ql/src/semmle/python/Pruning.qll

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ module Pruner {
190190
* same variable.
191191
* For example `x > 0` implies that `not bool(x)` is `False`.
192192
*/
193-
abstract predicate impliesFalse(Constraint other);
193+
abstract predicate contradicts(Constraint other);
194194

195195
}
196196

@@ -279,13 +279,14 @@ module Pruner {
279279
value = this.booleanValue()
280280
}
281281

282-
override predicate impliesFalse(Constraint other) {
282+
override predicate contradicts(Constraint other) {
283283
other.constrainsVariableToBe(this.booleanValue().booleanNot())
284284
}
285285

286286
}
287287

288-
/** A constraint that the variable is None `(var is None) is True` or not None `(var is None) is False` */
288+
/** A constraint that the variable is None `(var is None) is True` or not None `(var is None) is False`.
289+
* This includes the `is not` operator, `x is not None` being equivalent to `not x is None` */
289290
class IsNone extends Constraint, TIsNone {
290291

291292
private boolean isNone() {
@@ -306,7 +307,7 @@ module Pruner {
306307
value = false and this.isNone() = true
307308
}
308309

309-
override predicate impliesFalse(Constraint other) {
310+
override predicate contradicts(Constraint other) {
310311
other = TIsNone(this.isNone().booleanNot())
311312
or
312313
this.isNone() = true and other = TTruthy(true)
@@ -351,7 +352,7 @@ module Pruner {
351352
)
352353
}
353354

354-
override predicate impliesFalse(Constraint other) {
355+
override predicate contradicts(Constraint other) {
355356
exists(boolean b |
356357
this.constrainsVariableToBe(b) and other.constrainsVariableToBe(b.booleanNot())
357358
)
@@ -481,7 +482,7 @@ module Pruner {
481482
module_import(asgn, var) and result = true
482483
}
483484

484-
/** Gets the constraint on `var` resulting from the an assignment in `asgn` */
485+
/** Gets the constraint on `var` resulting from the assignment in `asgn` */
485486
Constraint constraintFromAssignment(SsaVariable var, UnprunedBasicBlock asgn) {
486487
exists(CompareOp op, int k |
487488
int_assignment(asgn.getANode(), var, op, k) and
@@ -536,7 +537,7 @@ module Pruner {
536537
predicate unreachableEdge(UnprunedBasicBlock pred, UnprunedBasicBlock succ) {
537538
exists(Constraint pre, Constraint cond |
538539
controllingConditions(pred, succ, pre, cond) and
539-
impliesFalse(pre, cond)
540+
contradicts(pre, cond)
540541
)
541542
or
542543
unreachableBB(pred) and succ = pred.getASuccessor()
@@ -545,8 +546,8 @@ module Pruner {
545546
}
546547

547548
/* Helper for `unreachableEdge` */
548-
private predicate impliesFalse(Constraint a, Constraint b) {
549-
a.impliesFalse(b) or
549+
private predicate contradicts(Constraint a, Constraint b) {
550+
a.contradicts(b) or
550551
a.(ConstrainedByConstant).minValue() > b.(ConstrainedByConstant).maxValue() or
551552
a.(ConstrainedByConstant).maxValue() < b.(ConstrainedByConstant).minValue()
552553
}

0 commit comments

Comments
 (0)