mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Rust: Add an Operation class above LogicalOperation, AssignmentOperation etc.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
private import codeql.rust.elements.Expr
|
||||
private import codeql.rust.elements.BinaryExpr
|
||||
private import codeql.rust.elements.PrefixExpr
|
||||
private import codeql.rust.elements.Operation
|
||||
|
||||
/**
|
||||
* A logical operation, such as `&&`, `||` or `!`.
|
||||
*/
|
||||
abstract private class LogicalOperationImpl extends Expr {
|
||||
abstract private class LogicalOperationImpl extends Operation {
|
||||
abstract Expr getAnOperand();
|
||||
}
|
||||
|
||||
|
||||
19
rust/ql/lib/codeql/rust/elements/Operation.qll
Normal file
19
rust/ql/lib/codeql/rust/elements/Operation.qll
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Provides classes for operations.
|
||||
*/
|
||||
|
||||
private import rust
|
||||
private import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl
|
||||
|
||||
/**
|
||||
* INTERNAL: This module contains the customizable definition of `Operation` and should not
|
||||
* be referenced directly.
|
||||
*/
|
||||
module OperationImpl {
|
||||
/**
|
||||
* An operation, for example `&&`, `+=`, `!` or `*`.
|
||||
*/
|
||||
abstract class Operation extends ExprImpl::Expr { }
|
||||
}
|
||||
|
||||
final class Operation = OperationImpl::Operation;
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
private import codeql.rust.elements.internal.generated.BinaryExpr
|
||||
private import codeql.rust.elements.Operation::OperationImpl as OperationImpl
|
||||
|
||||
/**
|
||||
* INTERNAL: This module contains the customizable definition of `BinaryExpr` and should not
|
||||
@@ -22,7 +23,7 @@ module Impl {
|
||||
* x += y;
|
||||
* ```
|
||||
*/
|
||||
class BinaryExpr extends Generated::BinaryExpr {
|
||||
class BinaryExpr extends Generated::BinaryExpr, OperationImpl::Operation {
|
||||
override string toStringImpl() { result = "... " + this.getOperatorName() + " ..." }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
private import codeql.rust.elements.internal.generated.PrefixExpr
|
||||
private import codeql.rust.elements.Operation::OperationImpl as OperationImpl
|
||||
|
||||
/**
|
||||
* INTERNAL: This module contains the customizable definition of `PrefixExpr` and should not
|
||||
@@ -20,7 +21,7 @@ module Impl {
|
||||
* let z = *ptr;
|
||||
* ```
|
||||
*/
|
||||
class PrefixExpr extends Generated::PrefixExpr {
|
||||
class PrefixExpr extends Generated::PrefixExpr, OperationImpl::Operation {
|
||||
override string toStringImpl() { result = this.getOperatorName() + " ..." }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import codeql.rust.elements
|
||||
import codeql.Locations
|
||||
import codeql.files.FileSystem
|
||||
import codeql.rust.elements.Operation
|
||||
import codeql.rust.elements.AssignmentOperation
|
||||
import codeql.rust.elements.LogicalOperation
|
||||
import codeql.rust.elements.AsyncBlockExpr
|
||||
|
||||
@@ -2,6 +2,8 @@ import rust
|
||||
import utils.test.InlineExpectationsTest
|
||||
|
||||
string describe(Expr op) {
|
||||
op instanceof Operation and result = "Operation"
|
||||
or
|
||||
op instanceof PrefixExpr and result = "PrefixExpr"
|
||||
or
|
||||
op instanceof BinaryExpr and result = "BinaryExpr"
|
||||
|
||||
@@ -8,48 +8,48 @@ fn test_operations(
|
||||
let mut x: i32;
|
||||
|
||||
// simple assignment
|
||||
x = y; // $ AssignmentOperation BinaryExpr
|
||||
x = y; // $ Operation AssignmentOperation BinaryExpr
|
||||
|
||||
// comparison operations
|
||||
x == y; // $ BinaryExpr
|
||||
x != y; // $ BinaryExpr
|
||||
x < y; // $ BinaryExpr
|
||||
x <= y; // $ BinaryExpr
|
||||
x > y; // $ BinaryExpr
|
||||
x >= y; // $ BinaryExpr
|
||||
x == y; // $ Operation BinaryExpr
|
||||
x != y; // $ Operation BinaryExpr
|
||||
x < y; // $ Operation BinaryExpr
|
||||
x <= y; // $ Operation BinaryExpr
|
||||
x > y; // $ Operation BinaryExpr
|
||||
x >= y; // $ Operation BinaryExpr
|
||||
|
||||
// arithmetic operations
|
||||
x + y; // $ BinaryExpr
|
||||
x - y; // $ BinaryExpr
|
||||
x * y; // $ BinaryExpr
|
||||
x / y; // $ BinaryExpr
|
||||
x % y; // $ BinaryExpr
|
||||
x += y; // $ AssignmentOperation BinaryExpr
|
||||
x -= y; // $ AssignmentOperation BinaryExpr
|
||||
x *= y; // $ AssignmentOperation BinaryExpr
|
||||
x /= y; // $ AssignmentOperation BinaryExpr
|
||||
x %= y; // $ AssignmentOperation BinaryExpr
|
||||
-x; // $ PrefixExpr
|
||||
x + y; // $ Operation BinaryExpr
|
||||
x - y; // $ Operation BinaryExpr
|
||||
x * y; // $ Operation BinaryExpr
|
||||
x / y; // $ Operation BinaryExpr
|
||||
x % y; // $ Operation BinaryExpr
|
||||
x += y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x -= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x *= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x /= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x %= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
-x; // $ Operation PrefixExpr
|
||||
|
||||
// logical operations
|
||||
a && b; // $ BinaryExpr LogicalOperation
|
||||
a || b; // $ BinaryExpr LogicalOperation
|
||||
!a; // $ PrefixExpr LogicalOperation
|
||||
a && b; // $ Operation BinaryExpr LogicalOperation
|
||||
a || b; // $ Operation BinaryExpr LogicalOperation
|
||||
!a; // $ Operation PrefixExpr LogicalOperation
|
||||
|
||||
// bitwise operations
|
||||
x & y; // $ BinaryExpr
|
||||
x | y; // $ BinaryExpr
|
||||
x ^ y; // $ BinaryExpr
|
||||
x << y; // $ BinaryExpr
|
||||
x >> y; // $ BinaryExpr
|
||||
x &= y; // $ AssignmentOperation BinaryExpr
|
||||
x |= y; // $ AssignmentOperation BinaryExpr
|
||||
x ^= y; // $ AssignmentOperation BinaryExpr
|
||||
x <<= y; // $ AssignmentOperation BinaryExpr
|
||||
x >>= y; // $ AssignmentOperation BinaryExpr
|
||||
x & y; // $ Operation BinaryExpr
|
||||
x | y; // $ Operation BinaryExpr
|
||||
x ^ y; // $ Operation BinaryExpr
|
||||
x << y; // $ Operation BinaryExpr
|
||||
x >> y; // $ Operation BinaryExpr
|
||||
x &= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x |= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x ^= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x <<= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
x >>= y; // $ Operation AssignmentOperation BinaryExpr
|
||||
|
||||
// miscellaneous expressions that might be operations
|
||||
*ptr; // $ PrefixExpr
|
||||
*ptr; // $ Operation PrefixExpr
|
||||
&x; // $ RefExpr
|
||||
res?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user