-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Add ComparisonOperation library. #19535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bc4b69b
ca1437a
2b65eeb
0feade4
bd004ab
95289b8
4ebf3ad
8522039
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
private import codeql.rust.elements.Expr | ||
private import codeql.rust.elements.BinaryExpr | ||
private import codeql.rust.elements.Operation | ||
|
||
/** | ||
* A comparison operation, such as `==`, `<` or `>=`. | ||
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
abstract private class ComparisonOperationImpl extends Operation { } | ||
|
||
final class ComparisonOperation = ComparisonOperationImpl; | ||
|
||
/** | ||
* An equality comparison operation, `==` or `!=`. | ||
*/ | ||
abstract private class EqualityOperationImpl extends BinaryExpr, ComparisonOperationImpl { } | ||
|
||
final class EqualityOperation = EqualityOperationImpl; | ||
|
||
/** | ||
* The equal comparison operation, `==`. | ||
*/ | ||
final class EqualOperation extends EqualityOperationImpl, BinaryExpr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We can't use "EqualityOperation" to describe both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Then I think I slightly prefer Equal_s_Operation over EqualOperation, but I'll let you decide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree that's a better name. Updated. |
||
EqualOperation() { this.getOperatorName() = "==" } | ||
} | ||
|
||
/** | ||
* The not equal comparison operation, `!=`. | ||
*/ | ||
final class NotEqualOperation extends EqualityOperationImpl { | ||
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NotEqualOperation() { this.getOperatorName() = "!=" } | ||
} | ||
|
||
/** | ||
* A relational comparison operation, that is, one of `<=`, `<`, `>`, or `>=`. | ||
*/ | ||
abstract private class RelationalOperationImpl extends BinaryExpr, ComparisonOperationImpl { | ||
/** | ||
* 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`. | ||
*/ | ||
abstract Expr getGreaterOperand(); | ||
|
||
/** | ||
* 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`. | ||
*/ | ||
abstract Expr getLesserOperand(); | ||
} | ||
|
||
final class RelationalOperation = RelationalOperationImpl; | ||
|
||
/** | ||
* The less than comparison operation, `<`. | ||
*/ | ||
final class LessThanOperation extends RelationalOperationImpl, BinaryExpr { | ||
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LessThanOperation() { this.getOperatorName() = "<" } | ||
|
||
override Expr getGreaterOperand() { result = this.getRhs() } | ||
|
||
override Expr getLesserOperand() { result = this.getLhs() } | ||
} | ||
|
||
/** | ||
* The greater than comparison operation, `>`. | ||
*/ | ||
final class GreaterThanOperation extends RelationalOperationImpl, BinaryExpr { | ||
GreaterThanOperation() { this.getOperatorName() = ">" } | ||
|
||
override Expr getGreaterOperand() { result = this.getLhs() } | ||
|
||
override Expr getLesserOperand() { result = this.getRhs() } | ||
} | ||
|
||
/** | ||
* The less than or equal comparison operation, `<=`. | ||
*/ | ||
final class LessOrEqualOperation extends RelationalOperationImpl, BinaryExpr { | ||
LessOrEqualOperation() { this.getOperatorName() = "<=" } | ||
|
||
override Expr getGreaterOperand() { result = this.getRhs() } | ||
|
||
override Expr getLesserOperand() { result = this.getLhs() } | ||
} | ||
|
||
/** | ||
* The less than or equal comparison operation, `>=`. | ||
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
final class GreaterOrEqualOperation extends RelationalOperationImpl, BinaryExpr { | ||
GreaterOrEqualOperation() { this.getOperatorName() = ">=" } | ||
|
||
override Expr getGreaterOperand() { result = this.getLhs() } | ||
|
||
override Expr getLesserOperand() { result = this.getRhs() } | ||
} |
Uh oh!
There was an error while loading. Please reload this page.