-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathComparisonOperation.qll
More file actions
130 lines (104 loc) · 3.38 KB
/
ComparisonOperation.qll
File metadata and controls
130 lines (104 loc) · 3.38 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Provides classes for modeling comparisons such as `==`, `!=` and `<`.
*/
import semmle.code.cpp.exprs.Expr
/**
* A C/C++ comparison operation, that is, either an equality operation or a relational operation.
*
* This is a QL base class for all comparisons.
*/
class ComparisonOperation extends BinaryOperation, @cmp_op_expr { }
/**
* A C/C++ equality operation, that is, either "==" or "!=".
*/
class EqualityOperation extends ComparisonOperation, @eq_op_expr {
override int getPrecedence() { result = 9 }
}
/**
* A C/C++ equal expression.
* ```
* bool c = (a == b);
* ```
*/
class EQExpr extends EqualityOperation, @eqexpr {
override string getAPrimaryQlClass() { result = "EQExpr" }
override string getOperator() { result = "==" }
}
/**
* A C/C++ not equal expression.
* ```
* bool c = (a != b);
* ```
*/
class NEExpr extends EqualityOperation, @neexpr {
override string getAPrimaryQlClass() { result = "NEExpr" }
override string getOperator() { result = "!=" }
}
/**
* A C/C++ relational operation, that is, one of `<=`, `<`, `>`, or `>=`.
*/
class RelationalOperation extends ComparisonOperation, @rel_op_expr {
override int getPrecedence() { result = 10 }
/**
* Gets the operand on the "greater" (or "greater-or-equal") side
* of this relational expression, that is, the side that is larger
* if the overall expression evaluates to `true`; for example on
* `x <= 20` this is the `20`, and on `y > 0` it is `y`.
*/
Expr getGreaterOperand() { none() } // overridden in subclasses
/**
* Gets the operand on the "lesser" (or "lesser-or-equal") side
* of this relational expression, that is, the side that is smaller
* if the overall expression evaluates to `true`; for example on
* `x <= 20` this is `x`, and on `y > 0` it is the `0`.
*/
Expr getLesserOperand() { none() } // overridden in subclasses
}
/**
* A C/C++ greater than expression.
* ```
* bool c = (a > b);
* ```
*/
class GTExpr extends RelationalOperation, @gtexpr {
override string getAPrimaryQlClass() { result = "GTExpr" }
override string getOperator() { result = ">" }
override Expr getGreaterOperand() { result = this.getLeftOperand() }
override Expr getLesserOperand() { result = this.getRightOperand() }
}
/**
* A C/C++ less than expression.
* ```
* bool c = (a < b);
* ```
*/
class LTExpr extends RelationalOperation, @ltexpr {
override string getAPrimaryQlClass() { result = "LTExpr" }
override string getOperator() { result = "<" }
override Expr getGreaterOperand() { result = this.getRightOperand() }
override Expr getLesserOperand() { result = this.getLeftOperand() }
}
/**
* A C/C++ greater than or equal expression.
* ```
* bool c = (a >= b);
* ```
*/
class GEExpr extends RelationalOperation, @geexpr {
override string getAPrimaryQlClass() { result = "GEExpr" }
override string getOperator() { result = ">=" }
override Expr getGreaterOperand() { result = this.getLeftOperand() }
override Expr getLesserOperand() { result = this.getRightOperand() }
}
/**
* A C/C++ less than or equal expression.
* ```
* bool c = (a <= b);
* ```
*/
class LEExpr extends RelationalOperation, @leexpr {
override string getAPrimaryQlClass() { result = "LEExpr" }
override string getOperator() { result = "<=" }
override Expr getGreaterOperand() { result = this.getRightOperand() }
override Expr getLesserOperand() { result = this.getLeftOperand() }
}