-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathRedundantComparison.qll
More file actions
44 lines (38 loc) · 1.2 KB
/
RedundantComparison.qll
File metadata and controls
44 lines (38 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import python
class RedundantComparison extends Compare {
RedundantComparison() {
exists(Expr left, Expr right |
this.compares(left, _, right) and
same_variable(left, right)
)
}
predicate maybeMissingSelf() {
exists(Name left |
this.compares(left, _, _) and
not this.isConstant() and
exists(Class cls | left.getScope().getScope() = cls |
exists(SelfAttribute sa | sa.getName() = left.getId() | sa.getClass() = cls)
)
)
}
}
private predicate same_variable(Expr left, Expr right) {
same_name(left, right)
or
same_attribute(left, right)
}
private predicate name_in_comparison(Compare comp, Name n, Variable v) {
comp.contains(n) and v = n.getVariable()
}
private predicate same_name(Name n1, Name n2) {
n1 != n2 and
exists(Compare comp, Variable v |
name_in_comparison(comp, n1, v) and name_in_comparison(comp, n2, v)
)
}
private predicate same_attribute(Attribute a1, Attribute a2) {
a1 != a2 and
exists(Compare comp | comp.contains(a1) and comp.contains(a2)) and
a1.getName() = a2.getName() and
same_name(a1.getObject(), a2.getObject())
}