|
| 1 | +/** |
| 2 | + * Provides classes for comparison operations. |
| 3 | + */ |
| 4 | + |
| 5 | +private import codeql.rust.elements.BinaryExpr |
| 6 | +private import codeql.rust.elements.Operation |
| 7 | + |
| 8 | +/** |
| 9 | + * A comparison operation, such as `==`, `<`, or `>=`. |
| 10 | + */ |
| 11 | +abstract private class ComparisonOperationImpl extends Operation { } |
| 12 | + |
| 13 | +final class ComparisonOperation = ComparisonOperationImpl; |
| 14 | + |
| 15 | +/** |
| 16 | + * An equality comparison operation, `==` or `!=`. |
| 17 | + */ |
| 18 | +abstract private class EqualityOperationImpl extends BinaryExpr, ComparisonOperationImpl { } |
| 19 | + |
| 20 | +final class EqualityOperation = EqualityOperationImpl; |
| 21 | + |
| 22 | +/** |
| 23 | + * The equal comparison operation, `==`. |
| 24 | + */ |
| 25 | +final class EqualsOperation extends EqualityOperationImpl { |
| 26 | + EqualsOperation() { this.getOperatorName() = "==" } |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * The not equal comparison operation, `!=`. |
| 31 | + */ |
| 32 | +final class NotEqualsOperation extends EqualityOperationImpl { |
| 33 | + NotEqualsOperation() { this.getOperatorName() = "!=" } |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * A relational comparison operation, that is, one of `<=`, `<`, `>`, or `>=`. |
| 38 | + */ |
| 39 | +abstract private class RelationalOperationImpl extends BinaryExpr, ComparisonOperationImpl { |
| 40 | + /** |
| 41 | + * Gets the operand on the "greater" (or "greater-or-equal") side |
| 42 | + * of this relational expression, that is, the side that is larger |
| 43 | + * if the overall expression evaluates to `true`; for example on |
| 44 | + * `x <= 20` this is the `20`, and on `y > 0` it is `y`. |
| 45 | + */ |
| 46 | + abstract Expr getGreaterOperand(); |
| 47 | + |
| 48 | + /** |
| 49 | + * Gets the operand on the "lesser" (or "lesser-or-equal") side |
| 50 | + * of this relational expression, that is, the side that is smaller |
| 51 | + * if the overall expression evaluates to `true`; for example on |
| 52 | + * `x <= 20` this is `x`, and on `y > 0` it is the `0`. |
| 53 | + */ |
| 54 | + abstract Expr getLesserOperand(); |
| 55 | +} |
| 56 | + |
| 57 | +final class RelationalOperation = RelationalOperationImpl; |
| 58 | + |
| 59 | +/** |
| 60 | + * The less than comparison operation, `<`. |
| 61 | + */ |
| 62 | +final class LessThanOperation extends RelationalOperationImpl { |
| 63 | + LessThanOperation() { this.getOperatorName() = "<" } |
| 64 | + |
| 65 | + override Expr getGreaterOperand() { result = this.getRhs() } |
| 66 | + |
| 67 | + override Expr getLesserOperand() { result = this.getLhs() } |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * The greater than comparison operation, `>`. |
| 72 | + */ |
| 73 | +final class GreaterThanOperation extends RelationalOperationImpl { |
| 74 | + GreaterThanOperation() { this.getOperatorName() = ">" } |
| 75 | + |
| 76 | + override Expr getGreaterOperand() { result = this.getLhs() } |
| 77 | + |
| 78 | + override Expr getLesserOperand() { result = this.getRhs() } |
| 79 | +} |
| 80 | + |
| 81 | +/** |
| 82 | + * The less than or equal comparison operation, `<=`. |
| 83 | + */ |
| 84 | +final class LessOrEqualsOperation extends RelationalOperationImpl { |
| 85 | + LessOrEqualsOperation() { this.getOperatorName() = "<=" } |
| 86 | + |
| 87 | + override Expr getGreaterOperand() { result = this.getRhs() } |
| 88 | + |
| 89 | + override Expr getLesserOperand() { result = this.getLhs() } |
| 90 | +} |
| 91 | + |
| 92 | +/** |
| 93 | + * The greater than or equal comparison operation, `>=`. |
| 94 | + */ |
| 95 | +final class GreaterOrEqualsOperation extends RelationalOperationImpl { |
| 96 | + GreaterOrEqualsOperation() { this.getOperatorName() = ">=" } |
| 97 | + |
| 98 | + override Expr getGreaterOperand() { result = this.getLhs() } |
| 99 | + |
| 100 | + override Expr getLesserOperand() { result = this.getRhs() } |
| 101 | +} |
0 commit comments