-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathIncrement.qll
More file actions
76 lines (67 loc) · 2.2 KB
/
Increment.qll
File metadata and controls
76 lines (67 loc) · 2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Provides a library for working with expressions that update the value
* of a numeric variable by incrementing or decrementing it by a certain
* amount.
*/
import cpp
private class AssignAddOrSubExpr extends AssignArithmeticOperation {
AssignAddOrSubExpr() {
this instanceof AssignAddExpr or
this instanceof AssignSubExpr
}
}
private class AddOrSubExpr extends BinaryArithmeticOperation {
AddOrSubExpr() {
this instanceof AddExpr or
this instanceof SubExpr
}
}
/**
* An expression that updates a numeric variable by adding to or subtracting
* from it a certain amount.
*/
abstract class StepCrementUpdateExpr extends Expr {
/**
* The expression in the abstract syntax tree that represents the amount of
* value by which the variable is updated.
*/
abstract Expr getAmountExpr();
}
/**
* An increment or decrement operator application, either postfix or prefix.
*/
class PostfixOrPrefixCrementExpr extends CrementOperation, StepCrementUpdateExpr {
override Expr getAmountExpr() { none() }
}
/**
* An add-then-assign or subtract-then-assign expression in a shortened form,
* i.e. `+=` or `-=`.
*/
class AssignAddOrSubUpdateExpr extends AssignAddOrSubExpr, StepCrementUpdateExpr {
override Expr getAmountExpr() { result = this.getRValue() }
}
/**
* An add-then-assign expression or a subtract-then-assign expression, i.e.
* `x = x + E` or `x = x - E`, where `x` is some variable and `E` an
* arbitrary expression.
*/
class AddOrSubThenAssignExpr extends AssignExpr, StepCrementUpdateExpr {
/** The `x` as in the left-hand side of `x = x + E`. */
VariableAccess lvalueVariable;
/** The `x + E` as in `x = x + E`. */
AddOrSubExpr addOrSubExpr;
/** The `E` as in `x = x + E`. */
Expr amountExpr;
AddOrSubThenAssignExpr() {
this.getLValue() = lvalueVariable and
this.getRValue() = addOrSubExpr and
exists(VariableAccess lvalueVariableAsRvalue |
lvalueVariableAsRvalue = addOrSubExpr.getAnOperand() and
amountExpr = addOrSubExpr.getAnOperand() and
lvalueVariableAsRvalue != amountExpr
|
lvalueVariable.getTarget() = lvalueVariableAsRvalue.(VariableAccess).getTarget()
)
}
override Expr getAmountExpr() { result = amountExpr }
}