8000 Rust: Add Operation class by geoffw0 · Pull Request #19454 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

Rust: Add Operation class #19454

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

Merged
merged 10 commits into from
May 13, 2025
Next Next commit
Rust: Add + clean up some QLDoc.
  • Loading branch information
geoffw0 committed May 1, 2025
commit 93f8cea8845783adbac926b459989ba93107537d
18 changes: 12 additions & 6 deletions rust/ql/lib/codeql/rust/elements/AssignmentOperation.qll
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/** Provides classes for assignment operations. */
/**
* Provides classes for assignment operations.
*/

private import rust
private import codeql.rust.elements.internal.BinaryExprImpl

/** An assignment operation. */
/**
* An assignment operation, for example:
* ```rust
* x = y;
* x += y;
* ```
*/
abstract private class AssignmentOperationImpl extends Impl::BinaryExpr { }

final class AssignmentOperation = AssignmentOperationImpl;

/**
* An assignment expression, for example
*
* An assignment expression, for example:
* ```rust
* x = y;
* ```
Expand All @@ -22,8 +29,7 @@ final class AssignmentExpr extends AssignmentOperationImpl {
}

/**
* A compound assignment expression, for example
*
* A compound assignment expression, for example:
* ```rust
* x += y;
* ```
Expand Down
18 changes: 18 additions & 0 deletions rust/ql/lib/codeql/rust/elements/LogicalOperation.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,48 @@ private import codeql.rust.elements.Expr
private import codeql.rust.elements.BinaryExpr
private import codeql.rust.elements.PrefixExpr

/**
* A logical operation, such as `&&`, `||` or `!`.
*/
abstract private class LogicalOperationImpl extends Expr {
abstract Expr getAnOperand();
}

final class LogicalOperation = LogicalOperationImpl;

/**
* A binary logical operation, such as `&&` or `||`.
*/
abstract private class BinaryLogicalOperationImpl extends BinaryExpr, LogicalOperationImpl {
override Expr getAnOperand() { result = [this.getLhs(), this.getRhs()] }
}

final class BinaryLogicalOperation = BinaryLogicalOperationImpl;

/**
* The logical and operation, `&&`.
*/
final class LogicalAndExpr extends BinaryLogicalOperationImpl, BinaryExpr {
LogicalAndExpr() { this.getOperatorName() = "&&" }
}

/**
* The logical or operation, `||`.
*/
final class LogicalOrExpr extends BinaryLogicalOperationImpl {
LogicalOrExpr() { this.getOperatorName() = "||" }
}

/**
* A unary logical operation, such as `!`.
*/
abstract private class UnaryLogicalOperationImpl extends PrefixExpr, LogicalOperationImpl { }

final class UnaryLogicalOperation = UnaryLogicalOperationImpl;

/**
* A logical not operation, `!`.
*/
final class LogicalNotExpr extends UnaryLogicalOperationImpl {
LogicalNotExpr() { this.getOperatorName() = "!" }

Expand Down
0