Skip to content

Commit ea43f16

Browse files
committed
C++: Add toString for RelationStrictness
1 parent a72589d commit ea43f16

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeAnalysisUtils.qll

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import cpp
22

3-
/**
4-
* Describes whether a relation is 'strict' (that is, a `<` or `>`
5-
* relation) or 'non-strict' (a `<=` or `>=` relation).
6-
*/
7-
newtype RelationStrictness =
3+
private newtype TRelationStrictness =
84
/**
95
* Represents that a relation is 'strict' (that is, a `<` or `>` relation).
106
*/
@@ -14,6 +10,19 @@ newtype RelationStrictness =
1410
*/
1511
Nonstrict()
1612

13+
/**
14+
* Describes whether a relation is 'strict' (that is, a `<` or `>`
15+
* relation) or 'non-strict' (a `<=` or `>=` relation).
16+
*/
17+
class RelationStrictness extends TRelationStrictness {
18+
/* Gets the string representation of this relation strictness. */
19+
string toString() {
20+
this = Strict() and result = "strict"
21+
or
22+
this = Nonstrict() and result = "non-strict"
23+
}
24+
}
25+
1726
/**
1827
* Describes whether a relation is 'greater' (that is, a `>` or `>=`
1928
* relation) or 'lesser' (a `<` or `<=` relation).
@@ -105,10 +114,10 @@ predicate relOpWithSwap(
105114
*
106115
* This allows for the relation to be either as written, or with its
107116
* arguments reversed; for example, if `rel` is `x < 5` then
108-
* `relOpWithSwapAndNegate(rel, x, 5, Lesser(), Strict(), true)`,
109-
* `relOpWithSwapAndNegate(rel, 5, x, Greater(), Strict(), true)`,
110-
* `relOpWithSwapAndNegate(rel, x, 5, Greater(), Nonstrict(), false)` and
111-
* `relOpWithSwapAndNegate(rel, 5, x, Lesser(), Nonstrict(), false)` hold.
117+
* - `relOpWithSwapAndNegate(rel, x, 5, Lesser(), Strict(), true)`,
118+
* - `relOpWithSwapAndNegate(rel, 5, x, Greater(), Strict(), true)`,
119+
* - `relOpWithSwapAndNegate(rel, x, 5, Greater(), Nonstrict(), false)` and
120+
* - `relOpWithSwapAndNegate(rel, 5, x, Lesser(), Nonstrict(), false)` hold.
112121
*/
113122
predicate relOpWithSwapAndNegate(
114123
RelationalOperation rel, Expr a, Expr b, RelationDirection dir, RelationStrictness strict,

0 commit comments

Comments
 (0)